From: Dmitry Shachnev <mitya57@gmail.com>
Description: Fix Docs module not working (patch from upstream SVN)
Origin: upstream
Bug-Upstream: http://code.google.com/p/googlecl/issues/detail?id=449
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=664989

Index: src/googlecl/docs/client.py
===================================================================
--- a/src/googlecl/docs/client.py
+++ b/src/googlecl/docs/client.py
@@ -37,8 +37,8 @@
 import googlecl.client
 from googlecl.docs import SECTION_HEADER
 import googlecl.docs.base
+import atom.data
 
-
 LOG = logging.getLogger(googlecl.docs.LOGGER_NAME + '.client')
 
 
@@ -52,8 +52,35 @@
   app with a command line interface.
 
   """
-  DOCLIST_FEED_URI = gdata.docs.client.DOCLIST_FEED_URI
+  DOCLIST_FEED_URI = '/feeds/default/private/full' 
 
+  # File extension/mimetype pairs of common format.
+  # These seem to have disappeared in python-gdata 2.0.15 and 2.0.16, so here 
+  # they are given explicitly.
+  MIMETYPES = {
+    'CSV': 'text/csv',
+    'TSV': 'text/tab-separated-values',
+    'TAB': 'text/tab-separated-values',
+    'DOC': 'application/msword',
+    'DOCX': ('application/vnd.openxmlformats-officedocument.'
+             'wordprocessingml.document'),
+    'ODS': 'application/x-vnd.oasis.opendocument.spreadsheet',
+    'ODT': 'application/vnd.oasis.opendocument.text',
+    'RTF': 'application/rtf',
+    'SXW': 'application/vnd.sun.xml.writer',
+    'TXT': 'text/plain',
+    'XLS': 'application/vnd.ms-excel',
+    'XLSX': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+    'PDF': 'application/pdf',
+    'PNG': 'image/png',
+    'PPT': 'application/vnd.ms-powerpoint',
+    'PPS': 'application/vnd.ms-powerpoint',
+    'HTM': 'text/html',
+    'HTML': 'text/html',
+    'ZIP': 'application/zip',
+    'SWF': 'application/x-shockwave-flash'
+  }
+  
   def __init__(self, config):
     """Constructor."""
     gdata.docs.client.DocsClient.__init__(self, source='GoogleCL')
@@ -65,9 +92,8 @@
                        folder_or_uri)
 
   def _determine_content_type(self, file_ext):
-    from gdata.docs.data import MIMETYPES
     try:
-      return MIMETYPES[file_ext.upper()]
+      return DocsClientCL.MIMETYPES[file_ext.upper()]
     except KeyError:
       LOG.info('No supported filetype found for extension %s', file_ext)
       return None
@@ -111,7 +137,7 @@
     issue
 
     Args:
-      entry_or_id_or_url: gdata.docs.data.DocsEntry or string representing a
+      entry_or_id_or_url: gdata.data.GDEntry or string representing a
           resource id or URL to download the document from (such as the content
           src link).
       file_path: str The full path to save the file to.  The export
@@ -292,7 +318,35 @@
     Returns:
       Entry representing the document uploaded.
     """
-    return self.upload(path, entry_title, post_uri, content_type)
+    
+    # GoogleCL that uses gdata-2.0.0 through 2.0.4 won't ever see this code.
+    # If it uses gdata-2.0.5 through 2.0.7, it would otherwise give an error 
+    # about a resumable uploader that it doesn't have. This avoids that error.
+    # If it uses gdata-2.0.8, 2.0.9, or 2.0.11 it can't upload docs due to an SSL error.
+    # If it uses gdata-2.0.10, 2.0.12, 2.0.13, 2.0.14 this should allow it to 
+    # upload all allowable file types.
+    
+    if hasattr(gdata.client,"ResumableUploader"):
+      f = open(path)
+      file_size = os.path.getsize(f.name)
+      uploader = gdata.client.ResumableUploader(
+          self, f, content_type, file_size, chunk_size=1048576,
+          desired_class=gdata.data.GDEntry)
 
-
+      # Set metadata for our upload.  
+      entry = gdata.data.GDEntry(title=atom.data.Title(text=entry_title))
+      new_entry = uploader.UploadFile('/feeds/upload/create-session/default/private/full', entry=entry)
+      # These might be useful for a verbose debug statement:
+      # print 'Document uploaded: ' + new_entry.title.text
+      # print 'Quota used: %s' % new_entry.quota_bytes_used.text
+      f.close()
+        
+      return new_entry
+      
+    else:
+      # If we have reached this point, we must be in gdata-2.0.5 through 2.0.7
+      # The upload is guaranteed to fail, so the self.upload call is here to
+      # return whatever the caller wanted.
+      return self.upload(path, entry_title, post_uri, content_type)
+      
 SERVICE_CLASS = DocsClientCL
