ó
³9—^c           @   sK  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z y  d d l m	 Z	 m
 Z
 m Z Wn7 e k
 r³ d d l m	 Z	 m Z d d l m
 Z
 n Xd d l m Z e j Z d Z d	 Z d
 Z d d d d d d d d g Z d d g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d S(   s(  Python client library for the Facebook Platform.

This client library is designed to support the Graph API and the
official Facebook JavaScript SDK, which is the canonical way to
implement Facebook authentication. Read more about the Graph API at
https://developers.facebook.com/docs/graph-api.

iÿÿÿÿN(   t   parse_qst	   urlencodet   urlparse(   R    R   (   R   i   (   t   versions   https://graph.facebook.com/s   https://www.facebook.com/s   dialog/oauth?s   2.11s   2.12s   3.0s   3.1s   3.2s   3.3s   4.0s   5.0t   placet
   placetopict   GraphAPIc           B   sé   e  Z d  Z d d d d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d d „ Z d „  Z d d d d d „ Z e d „ Z d „  Z d „  Z d „  Z d d „ Z RS(   sj  A client for the Facebook Graph API.

    https://developers.facebook.com/docs/graph-api

    The Graph API is made up of the objects in Facebook (e.g., people,
    pages, events, photos) and the connections between them (e.g.,
    friends, photo tags, and event RSVPs). This client provides access
    to those primitive types in a generic way. For example, given an
    OAuth access token, this will fetch the profile of the active user
    and the list of the user's friends:

       graph = facebook.GraphAPI(access_token)
       user = graph.get_object("me")
       friends = graph.get_connections(user["id"], "friends")

    You can see a list of all of the objects and connections supported
    by the API at https://developers.facebook.com/docs/graph-api/reference/.

    You can obtain an access token via OAuth or by using the Facebook
    JavaScript SDK. See
    https://developers.facebook.com/docs/facebook-login for details.

    If you are using the JavaScript SDK, you can use the
    get_user_from_cookie() method below to get the OAuth access token
    for the active user from the cookie saved by the SDK.

    c   
      C   s+  t  d } | |  _ | |  _ | |  _ | p4 t j ƒ  |  _ d  |  _ | rÒ t	 j
 d ƒ } | j t | ƒ ƒ }	 |	 d  k	 rÃ t | ƒ t  k r­ t d t t  ƒ j d ƒ ƒ ‚ qÏ d t | ƒ |  _ qß t d ƒ ‚ n d | |  _ | r'| r't j | j d ƒ d | j d ƒ d	 t j ƒj ƒ  |  _ n  d  S(
   Ni    s   ^\d\.\d{1,2}$s   Valid API versions are s   []t   vsA   Version number should be in the following format: #.# (e.g. 2.0).t   asciit   msgt	   digestmod(   t   VALID_API_VERSIONSt   access_tokent   timeoutt   proxiest   requestst   Sessiont   sessiont   Nonet   app_secret_hmact   ret   compilet   searcht   strt   GraphAPIErrort   stripR   t   hmact   newt   encodet   hashlibt   sha256t	   hexdigest(
   t   selfR   R   R   R   R   t
   app_secrett   default_versiont   version_regext   match(    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   __init__R   s.    

				c         C   s3   |  j  d j |  j | ƒ i  ƒ d } d „  | Dƒ S(   s.   Fetches the permissions object from the graph.s   {0}/{1}/permissionst   datac         S   s*   h  |  ]  } | d  d k r | d ’ q S(   t   statust   grantedt
   permission(    (   t   .0t   x(    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pys	   <setcomp>ƒ   s   	 (   t   requestt   formatR   (   R    t   user_idt   response(    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_permissions~   s    c         K   s   |  j  d j |  j | ƒ | ƒ S(   s(   Fetches the given object from the graph.s   {0}/{1}(   R,   R-   R   (   R    t   idt   args(    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt
   get_object…   s    c         K   s*   d j  | ƒ | d <|  j |  j d | ƒ S(   s¢   Fetches all of the given object from the graph.

        We return a map from ID to object. If any of the IDs are
        invalid, we raise an exception.
        t   ,t   idst   /(   t   joinR,   R   (   R    R5   R2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_objects‰   s    c         K   sI   | t  k r( t d d j t  ƒ ƒ ‚ n  | | d <|  j |  j d | ƒ S(   s2   https://developers.facebook.com/docs/places/searchs   Valid types are: %ss   , t   types   /search/(   t   VALID_SEARCH_TYPESR   R7   R,   R   (   R    R9   R2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyR   ’   s
    
c         K   s"   |  j  d j |  j | | ƒ | ƒ S(   s)   Fetches the connections for given object.s   {0}/{1}/{2}(   R,   R-   R   (   R    R1   t   connection_nameR2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_connectionsœ   s    c         k   s   xz t  r| |  j | | |  } x | d D] } | Vq) W| j d i  ƒ j d ƒ } | s] d St t | ƒ j ƒ } | d =q Wd S(   s§   Get all pages from a get_connections call

        This will iterate over all pages returned by a get_connections call
        and yield the individual items.
        R&   t   pagingt   nextNR   (   t   TrueR<   t   getR    R   t   query(   R    R1   R;   R2   t   paget   postR>   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_all_connections¢   s    		c         K   s@   |  j  s t d ƒ ‚ |  j d j |  j | | ƒ d | d d ƒS(   s‚  Writes the given object to the graph, connected to the given parent.

        For example,

            graph.put_object("me", "feed", message="Hello, world")

        writes "Hello, world" to the active user's wall. Likewise, this
        will comment on the first post of the active user's feed:

            feed = graph.get_connections("me", "feed")
            post = feed["data"][0]
            graph.put_object(post["id"], "comments", message="First!")

        Certain operations require extended permissions. See
        https://developers.facebook.com/docs/facebook-login/permissions
        for details about permissions.

        s(   Write operations require an access tokens   {0}/{1}/{2}t	   post_argst   methodt   POST(   R   t   AssertionErrorR,   R-   R   (   R    t   parent_objectR;   R&   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt
   put_object²   s
    c         C   s   |  j  | d d | ƒS(   s+   Writes the given comment on the given post.t   commentst   message(   RJ   (   R    t	   object_idRL   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   put_commentÌ   s    c         C   s   |  j  | d ƒ S(   s   Likes the given post.t   likes(   RJ   (   R    RM   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   put_likeÐ   s    c         C   s"   |  j  d j |  j | ƒ d d ƒS(   s4   Deletes the object with the given ID from the graph.s   {0}/{1}RF   t   DELETE(   R,   R-   R   (   R    R1   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   delete_objectÔ   s    c         C   s   |  j  d j | | ƒ d d ƒS(   s9   Deletes the Request with the given ID for the given user.s   {0}_{1}RF   RQ   (   R,   R-   (   R    R.   t
   request_id(    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   delete_requestÚ   s    s	   me/photosc         K   s5   |  j  d j |  j | ƒ d | d i | d 6d d ƒS(   sÐ   
        Upload an image using multipart/form-data.

        image - A file object representing the image to be uploaded.
        album_path - A path representing where the image should be uploaded.

        s   {0}/{1}RE   t   filest   sourceRF   RG   (   R,   R-   R   (   R    t   imaget
   album_patht   kwargs(    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt	   put_photoà   s
    c      	   C   s×   i |  j  d 6} y< |  j j d t |  j d d | d |  j d |  j ƒ} Wn7 t j k
 r… } t	 j
 | j ƒ  ƒ } t | ƒ ‚ n Xy- | j } | d j d d	 ƒ } t | ƒ SWn t k
 rÒ t d
 ƒ ‚ n Xd S(   s?   Fetches the current version number of the Graph API being used.R   t   GETs   /met   paramsR   R   s   facebook-api-versionR   t    s    API version number not availableN(   R   R   R,   t   FACEBOOK_GRAPH_URLR   R   R   R   t	   HTTPErrort   jsont   loadst   readR   t   headerst   replaceR   t	   Exception(   R    R2   R/   t   eRc   R   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_versionï   s"    			c            s  ˆ  d k r t ƒ  ‰  n  ˆ d k	 r- d } n  ‡  ‡ f d †  } |  j r[ | d |  j ƒ n  |  j rw | d |  j ƒ n  yG |  j j | pŒ d t | d |  j d ˆ  d ˆ d	 |  j d
 | ƒ} Wn7 t	 j
 k
 r÷ } t j | j ƒ  ƒ } t | ƒ ‚ n X| j }	 d |	 d k r | j ƒ  }
 nÈ d |	 d k r^|	 d } i | j d 6| d 6| j d 6}
 nŠ d t | j ƒ k rÜt | j ƒ } d | k rÇi | d d d 6}
 d | k rÙ| d d |
 d <qÙqèt | j ƒ  ƒ ‚ n t d ƒ ‚ |
 rt |
 t ƒ r|
 j d ƒ rt |
 ƒ ‚ n  |
 S(   sÐ   Fetches the given path in the Graph API.

        We translate args to a valid query string. If post_args is
        given, we send a POST request to the given path with the given
        arguments.

        RG   c            s<   ˆ r |  ˆ k r | ˆ |  <n |  ˆ  k r8 | ˆ  |  <n  d  S(   N(    (   t   arg_namet	   arg_value(   R2   RE   (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   _add_to_post_args_or_args  s    R   t   appsecret_proofR[   R   R\   R&   R   RU   R`   s   content-types   image/s	   mime-typet   urli    t   expiress,   Maintype was not text, image, or querystringt   errorN(   R   t   dictR   R   R   R,   R^   R   R   R   R_   R`   Ra   Rb   R   Rc   t   contentRl   R    t   textt
   isinstanceR@   (   R    t   pathR2   RE   RU   RF   Rj   R/   Rf   Rc   t   resultt   mimetypet	   query_str(    (   R2   RE   sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyR,     sR    
					
			

$c         C   sX   | r d j  | | ƒ Si d d 6| d 6| d 6} |  j d j  |  j ƒ d | ƒd Sd	 S(
   s  
        Get the application's access token as a string.
        If offline=True, use the concatenated app ID and secret
        instead of making an API call.
        <https://developers.facebook.com/docs/facebook-login/
        access-tokens#apptokens>
        s   {0}|{1}t   client_credentialst
   grant_typet	   client_idt   client_secrets   {0}/oauth/access_tokenR2   R   N(   R-   R,   R   (   R    t   app_idR!   t   offlineR2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_app_access_tokenJ  s    
c         C   s>   i | d 6| d 6| d 6| d 6} |  j  d j |  j ƒ | ƒ S(   s¿   Get an access token from the "code" returned from an OAuth dialog.

        Returns a dict containing the user-specific access token and its
        expiration date (if applicable).

        t   codet   redirect_uriRy   Rz   s   {0}/oauth/access_token(   R,   R-   R   (   R    R~   R   R{   R!   R2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_access_token_from_code_  s    	
c         C   sD   i | d 6| d 6d d 6|  j  d 6} |  j d j |  j ƒ d | ƒS(   s¿   
        Extends the expiration time of a valid OAuth access token. See
        <https://developers.facebook.com/docs/facebook-login/access-tokens/
        expiration-and-extension>

        Ry   Rz   t   fb_exchange_tokenRx   s   {0}/oauth/access_tokenR2   (   R   R,   R-   R   (   R    R{   R!   R2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   extend_access_tokens  s    c         C   s>   i | d 6d j  | | ƒ d 6} |  j |  j d d d | ƒS(   sz  
        Gets information about a user access token issued by an app. See
        <https://developers.facebook.com/docs/facebook-login/
        access-tokens/debugging-and-error-handling>

        We can generate the app access token by concatenating the app
        id and secret: <https://developers.facebook.com/docs/
        facebook-login/access-tokens#apptokens>

        t   input_tokens   {0}|{1}R   R6   t   debug_tokenR2   (   R-   R,   R   (   R    t   tokenR{   R!   R2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   debug_access_token…  s    c         K   sc   d j  t |  j t ƒ } i | d 6| d 6} | rH d j | ƒ | d <n  | j | ƒ | t | ƒ S(   s&   Build a URL to create an OAuth dialog.s
   {0}{1}/{2}Ry   R   R4   t   scope(   R-   t   FACEBOOK_WWW_URLR   t   FACEBOOK_OAUTH_DIALOG_PATHR7   t   updateR   (   R    R{   t
   canvas_urlt   permsRY   Rl   R2   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_auth_url–  s    N(   t   __name__t
   __module__t   __doc__R   R%   R0   R3   R8   R   R<   RD   RJ   RN   RP   RR   RT   RZ   Rg   R,   t   FalseR}   R€   R‚   R†   R   (    (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyR   5   s4   %					
								D			R   c           B   s   e  Z d  „  Z RS(   c         C   sE  | |  _  d  |  _ d  |  _ y | d |  _ Wn  t t f k
 rN d |  _ n Xy | d |  _ WnË t t f k
 r-yf | d d |  _ | d j d ƒ |  _ | d j d ƒ |  _ |  j sÛ | d j d d ƒ |  _ n  Wq.t t f k
 r)y | d	 |  _ Wq*t t f k
 r%| |  _ q*Xq.Xn Xt	 j
 |  |  j ƒ d  S(
   Nt
   error_codeR]   t   error_descriptionRn   RL   R~   t   error_subcodeR9   t	   error_msg(   Rt   R   R~   R”   R9   t   KeyErrort	   TypeErrorRL   R@   Re   R%   (   R    Rt   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyR%   ¤  s,    				 (   RŽ   R   R%   (    (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyR   £  s   c         C   sƒ   |  j  d | d ƒ } | s  d St | | ƒ } | s9 d Sy# t ƒ  j | d d | | ƒ } Wn t k
 rp d SX| d | d <| S(   s#  Parses the cookie set by the official Facebook JavaScript SDK.

    cookies should be a dictionary-like object mapping cookie names to
    cookie values.

    If the user is logged in via Facebook, we return a dictionary with
    the keys "uid" and "access_token". The former is the user's
    Facebook ID, and the latter can be used to make authenticated
    requests to the Graph API. If the user is not logged in, we
    return None.

    Read more about Facebook authentication at
    https://developers.facebook.com/docs/facebook-login.

    t   fbsr_R]   R~   R.   t   uidN(   R@   R   t   parse_signed_requestR   R€   R   (   t   cookiesR{   R!   t   cookiet   parsed_requestRt   (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   get_user_from_cookieÃ  s    	c         C   sA  yw t  t |  j d d ƒ ƒ \ } } t j | d d t | ƒ d d ƒ } t j | d d t | ƒ d d ƒ } Wn7 t k
 r‹ t St k
 rœ t St	 j
 k
 r° t SXt j | j d ƒ ƒ } | j d d ƒ j ƒ  d k rë t S| j d ƒ } | j d ƒ } t j | d	 | d
 t j ƒj ƒ  } | | k r=t S| S(   s<   Return dictionary with signed request data.

    We return a dictionary containing the information in the
    signed_request. This includes a user_id if the user has authorised
    your application, as well as any information requested.

    If the signed_request is malformed or corrupted, False is returned.

    t   .i   t   =i   R   t	   algorithmR]   s   HMAC-SHA256R	   R
   (   t   mapR   t   splitt   base64t   urlsafe_b64decodet   lent
   IndexErrorR‘   R—   t   binasciit   ErrorR`   Ra   t   decodeR@   t   upperR   R   R   R   R   t   digest(   t   signed_requestR!   t   encoded_sigt   payloadt   sigR&   t   expected_sig(    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyRš   ã  s,    
!#'(   R   R   R   R¨   R¤   R   R`   R   t   urllib.parseR    R   R   t   ImportErrort   urllibR]   R   t   __version__R^   Rˆ   R‰   R   R:   t   objectR   Re   R   Rž   Rš   (    (    (    sB   /var/www/agenderbackend/venv/src/facebook-sdk/facebook/__init__.pyt   <module>   s0    	ÿ o 	 