m
Fc           @   s   d  Z  d Z d k Z d k Z d k Z d k Z d Z d Z	 d Z
 h  d d <d d	 <d
 d <d d <d d <d d <d d <d d <Z d e f d     YZ d e f d     YZ d e i i f d     YZ d e i i f d     YZ d S(   s   DocsService extends the GDataService to streamline Google Documents
  operations.

  DocsService: Provides methods to query feeds and manipulate items.
                    Extends GDataService.

  DocumentQuery: Queries a Google Document list feed.

s   api.jfisher (Jeff Fisher)Ns%   http://schemas.google.com/g/2005#kinds,   http://schemas.google.com/docs/2007#documents/   http://schemas.google.com/docs/2007#spreadsheett   CSVs   text/comma-separated-valuest   DOCs   application/mswordt   ODSs.   application/vnd.oasis.opendocument.spreadsheett   ODTs'   application/vnd.oasis.opendocument.textt   RTFs   application/rtft   SXWs   application/vnd.sun.xml.writert   TXTs
   text/plaint   XLSs   application/vnd.ms-excelt   Errorc           B   s   t  Z RS(   N(   t   __name__t
   __module__(    (    (    t1   /mit/freeculture/lib/python/gdata/docs/service.pyR   5   s   t   RequestErrorc           B   s   t  Z RS(   N(   R	   R
   (    (    (    R   R   9   s   t   DocsServicec           B   sn   t  Z d  Z e e e d e d  Z e i i d  Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z RS(
   sE   Client extension for the Google Documents service Document List feed.s   docs.google.comc         C   s;   t  i i i |  d | d | d d d | d | d | d S(	   s  Constructor for the DocsService.

    Args:
      email: string (optional) The e-mail address of the account to use for
             authentication.
      password: string (optional) The password of the account to use for
                authentication.
      source: string (optional) The name of the user's application.
      server: string (optional) The server the feed is hosted on.
      additional_headers: dict (optional) Any additional HTTP headers to be
                          transmitted to the service in the form of key-value
                          pairs.

    Yields:
      A DocsService object used to communicate with the Google Documents
      service.
    t   emailt   passwordt   servicet   writelyt   sourcet   servert   additional_headersN(
   t   gdataR   t   GDataServicet   __init__t   selfR   R   R   R   R   (   R   R   R   R   R   R   (    (    R   R   A   s
     c         C   s   |  i | d | S(   s  Queries the Document List feed and returns the resulting feed of
       entries.

    Args:
      uri: string The full URI to be queried. This can contain query
           parameters, a hostname, or simply the relative path to a Document
           List feed. The DocumentQuery object is useful when constructing
           query parameters.
      converter: func (optional) A function which will be executed on the
                 retrieved item, generally to render it into a Python object.
                 By default the DocumentListFeedFromString function is used to
                 return a DocumentListFeed object. This is because most feed
                 queries will result in a feed and not a single entry.
    t	   converterN(   R   t   Gett   uriR   (   R   R   R   (    (    R   t   QueryZ   s     c         C   s   |  i | d t i i S(   s  Retrieves a DocumentListFeed by retrieving a URI based off the Document
       List feed, including any query parameters. A DocumentQuery object can
       be used to construct these parameters.

    Args:
      uri: string The URI of the feed being retrieved possibly with query
           parameters.

    Returns:
      A DocumentListFeed object representing the feed returned by the server.
    R   N(   R   R   R   R   t   docst   DocumentListFeedFromString(   R   R   (    (    R   t   QueryDocumentListFeedl   s     c         C   s   |  i | d t i i S(   s   Retrieves a particular DocumentListEntry by its unique URI.

    Args:
      uri: string The unique URI of an entry in a Document List feed.

    Returns:
      A DocumentListEntry object representing the retrieved entry.
      R   N(   R   R   R   R   R   t   DocumentListEntryFromString(   R   R   (    (    R   t   GetDocumentListEntryz   s     c         C   s%   t  i i i   } |  i | i    S(   s6   Retrieves a feed containing all of a user's documents.N(   R   R   R   t   DocumentQueryt   qR   R   t   ToUri(   R   R#   (    (    R   t   GetDocumentListFeed   s     c         C   s+   t  i d t d t  } |  i | | |  S(   s  Uploads a spreadsheet inside of a MediaSource object to the Document
       List feed with the given title.

    Args:
      media_source: MediaSource The MediaSource object containing a spreadsheet
                    file to be uploaded.
      title: string The title of the spreadsheet on the server after being
             uploaded.

    Returns:
      A GDataEntry containing information about the spreadsheet created on the
      Google Documents service.
    t   schemet   termN(	   t   atomt   Categoryt   DATA_KIND_SCHEMEt   SPREADSHEET_KIND_TERMt   categoryR   t   _UploadFilet   media_sourcet   title(   R   R.   R/   R,   (    (    R   t   UploadSpreadsheet   s     c         C   s+   t  i d t d t  } |  i | | |  S(   s  Uploads a document inside of a MediaSource object to the Document List
       feed with the given title.

    Args:
      media_source: MediaSource The MediaSource object containing a document
                    file to be uploaded.
      title: string The title of the document on the server after being
             uploaded.

    Returns:
      A GDataEntry containing information about the document created on the
      Google Documents service.
    R&   R'   N(	   R(   R)   R*   t   DOCUMENT_KIND_TERMR,   R   R-   R.   R/   (   R   R.   R/   R,   (    (    R   t   UploadDocument   s     c      
   C   s_   t  i   } t i d |  | _ | i i |  |  i	 | d d | d h  d | i <} | S(   s)   Uploads a file to the Document List feed.t   texts   /feeds/documents/private/fullR.   t   extra_headerst   SlugN(   R   t
   GDataEntryt   media_entryR(   t   TitleR/   R,   t   appendR   t   PostR.   t	   file_name(   R   R.   R/   R,   R7   (    (    R   R-      s     (   R	   R
   t   __doc__t   NoneR   R   R   R   R   R   R!   R%   R0   R2   R-   (    (    (    R   R   =   s    					R"   c           B   s2   t  Z d  Z d d d e e e d  Z d   Z RS(   sE   Object used to construct a URI to query the Google Document List feeds   /feeds/documentst   privatet   fullc         C   s5   | |  _  | |  _ t i i i |  | | | |  d S(   s  Constructor for Document List Query

    Args:
      feed: string (optional) The path for the feed. (e.g. '/feeds/documents')
      visibility: string (optional) The visibility chosen for the current feed.
      projection: string (optional) The projection chosen for the current feed.
      text_query: string (optional) The contents of the q query parameter. This
                  string is URL escaped upon conversion to a URI.
      params: dict (optional) Parameter value string pairs which become URL
              params when translated to a URI. These parameters are added to
              the query's items.
      categories: list (optional) List of category strings which should be
              included as query categories. See gdata.service.Query for
              additional documentation.

    Yields:
      A DocumentQuery object used to construct a URI based on the Document
      List feed.
    N(   t
   visibilityR   t
   projectionR   R   R   R   t   feedt
   text_queryt   paramst
   categories(   R   RB   R@   RA   RC   RD   RE   (    (    R   R      s     		c         C   sL   |  i } d i | |  i |  i g  |  _ t i i i	 |   } | |  _ | S(   s   Generates a URI from the query parameters set in the object.

    Returns:
      A string containing the URI used to retrieve entries from the Document
      List feed.
    t   /N(   R   RB   t   old_feedt   joinR@   RA   R   R   R   R$   t   new_feed(   R   RG   RI   (    (    R   R$      s     	!	(   R	   R
   R<   R=   R   R$   (    (    (    R   R"      s    (   R<   t
   __author__t   urllibt   atom.serviceR(   t   gdata.serviceR   t
   gdata.docsR*   R1   R+   t   SUPPORTED_FILETYPESt	   ExceptionR   R   R   R   R   R   R"   (   R   R   R"   R1   RO   RK   RJ   R*   R   R(   R+   R   (    (    R   t   ?   s   				N~