σ
ΰΖχXc           @` sΉ   d  Z  d d l m Z m Z m Z y
 e Z Wn e k
 r? n Xd d l Z d d l	 Z	 d d l
 Z
 d Z d a d   Z d   Z d   Z d d	 e d
  Z d d  Z d d  Z d S(   s#   Functions for Github authorisation.i    (   t   absolute_importt   print_functiont   divisionNt   ipython_toolsc          C` sε   t  d  k	 r t  Sd d  l }  |  j d t  a  t  d  k	 r> t  St d  t d  } t j d  } i d d g d 6d	 d
 6d d 6} t j	 d d | | f d t
 j |  } | j   t
 j | j  d a  |  j d t t   t  S(   Ni    t   githubs   Please enter your github username and password. These are not stored, only used to get an oAuth token. You can revoke this at any time on Github.s
   Username: s
   Password: t   public_repot   gistt   scopess   IPython toolst   notes4   https://github.com/ipython/ipython/tree/master/toolst   note_urls%   https://api.github.com/authorizationst   autht   datat   token(   R   t   Nonet   keyringt   get_passwordt   fake_usernamet   printt   inputt   getpasst   requestst   postt   jsont   dumpst   raise_for_statust   loadst   textt   set_password(   R   t   usert   pwt   auth_requestt   response(    (    s2   /tmp/pip-build-X4mzal/theano/theano/misc/gh_api.pyt   get_auth_token   s(    



c           C` s   i d t    d 6S(   Ns   token t   Authorization(   R    (    (    (    s2   /tmp/pip-build-X4mzal/theano/theano/misc/gh_api.pyt   make_auth_header5   s    c         C` sN   d j  d |  d |  } t j i | d 6 } t j | d | d t   d  S(   Ns<   https://api.github.com/repos/{project}/issues/{num}/commentst   projectt   numt   bodyR   t   headers(   t   formatR   R   R   R   R"   (   R#   R$   R%   t   urlt   payload(    (    s2   /tmp/pip-build-X4mzal/theano/theano/misc/gh_api.pyt   post_issue_comment9   s    t    t   filec         C` s   t  j i | d 6t d 6i i |  d 6| 6d 6 j d  } | rJ t   n i  } t j d d | d | } | j   t  j | j	  } | d	 S(
   s-   Post some text to a Gist, and return the URL.t   descriptiont   publict   contentt   filess   utf-8s   https://api.github.com/gistsR   R&   t   html_url(
   R   R   t   Truet   encodeR"   R   R   R   R   R   (   R/   R-   t   filenameR
   t	   post_dataR&   R   t   response_data(    (    s2   /tmp/pip-build-X4mzal/theano/theano/misc/gh_api.pyt	   post_gist?   s    		
i   c         C` s   | d k r' d j  d |  d |  } n' | d k rN d j  d |  d |  } n  t j |  } | j   | d k r t j | j  d St j | j  S(   sT   get pull request info  by number

    github_api : version of github api to use
    i   s3   http://github.com/api/v2/json/pulls/{project}/{num}R#   R$   i   s2   https://api.github.com/repos/{project}/pulls/{num}t   pull(   R'   R   t   getR   R   R   R   (   R#   R$   t
   github_apiR(   R   (    (    s2   /tmp/pip-build-X4mzal/theano/theano/misc/gh_api.pyt   get_pull_requestR   s    
c         C` s|   | d k r! d j  d |   } n d j  d |   } t j |  } | j   | d k rl t j | j  d St j | j  S(   sI   get pull request list

    github_api : version of github api to use
    i   s,   https://api.github.com/repos/{project}/pullsR#   s-   http://github.com/api/v2/json/pulls/{project}i   t   pulls(   R'   R   R9   R   R   R   R   (   R#   R:   R(   R   (    (    s2   /tmp/pip-build-X4mzal/theano/theano/misc/gh_api.pyt   get_pulls_listb   s    
(   t   __doc__t
   __future__R    R   R   t	   raw_inputR   t	   NameErrorR   R   R   R   R   R   R    R"   R*   t   FalseR7   R;   R=   (    (    (    s2   /tmp/pip-build-X4mzal/theano/theano/misc/gh_api.pyt   <module>   s    
	!		