chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpo...@apache.org
Subject svn commit: r1388254 - in /chemistry/cmislib/trunk/src: cmislib.egg-info/SOURCES.txt cmislib/model.py cmislib/net.py
Date Thu, 20 Sep 2012 22:55:43 GMT
Author: jpotts
Date: Thu Sep 20 22:55:42 2012
New Revision: 1388254

URL: http://svn.apache.org/viewvc?rev=1388254&view=rev
Log:
Modified getEntryXmlDoc to always create empty content element; Modified net.py to allow extra
headers to be passed in to rest methods

Modified:
    chemistry/cmislib/trunk/src/cmislib.egg-info/SOURCES.txt
    chemistry/cmislib/trunk/src/cmislib/model.py
    chemistry/cmislib/trunk/src/cmislib/net.py

Modified: chemistry/cmislib/trunk/src/cmislib.egg-info/SOURCES.txt
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib.egg-info/SOURCES.txt?rev=1388254&r1=1388253&r2=1388254&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib.egg-info/SOURCES.txt (original)
+++ chemistry/cmislib/trunk/src/cmislib.egg-info/SOURCES.txt Thu Sep 20 22:55:42 2012
@@ -44,8 +44,8 @@ src/doc/build/examples.html
 src/doc/build/genindex.html
 src/doc/build/index.html
 src/doc/build/install.html
-src/doc/build/modindex.html
 src/doc/build/objects.inv
+src/doc/build/py-modindex.html
 src/doc/build/sample-data.html
 src/doc/build/search.html
 src/doc/build/searchindex.js
@@ -59,15 +59,26 @@ src/doc/build/_sources/index.txt
 src/doc/build/_sources/install.txt
 src/doc/build/_sources/sample-data.txt
 src/doc/build/_sources/tests.txt
+src/doc/build/_static/ajax-loader.gif
 src/doc/build/_static/basic.css
+src/doc/build/_static/comment-bright.png
+src/doc/build/_static/comment-close.png
+src/doc/build/_static/comment.png
 src/doc/build/_static/default.css
 src/doc/build/_static/doctools.js
+src/doc/build/_static/down-pressed.png
+src/doc/build/_static/down.png
 src/doc/build/_static/file.png
 src/doc/build/_static/jquery.js
 src/doc/build/_static/minus.png
 src/doc/build/_static/plus.png
 src/doc/build/_static/pygments.css
 src/doc/build/_static/searchtools.js
+src/doc/build/_static/sidebar.js
+src/doc/build/_static/underscore.js
+src/doc/build/_static/up-pressed.png
+src/doc/build/_static/up.png
+src/doc/build/_static/websupport.js
 src/doc/src/Makefile
 src/doc/src/about.rst
 src/doc/src/code.rst

Modified: chemistry/cmislib/trunk/src/cmislib/model.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/model.py?rev=1388254&r1=1388253&r2=1388254&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/model.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/model.py Thu Sep 20 22:55:42 2012
@@ -209,7 +209,10 @@ class CmisClient(object):
             self._processCommonErrors(result)
             return result
         else:
-            return minidom.parse(result)
+            try:
+                return minidom.parse(result)
+            except ExpatError:
+                raise CmisException('Could not parse server response', url)
 
     def delete(self, url, **kwargs):
 
@@ -257,9 +260,15 @@ class CmisClient(object):
                              password=self.password,
                              **kwargs)
         if type(result) != HTTPError:
-            return minidom.parse(result)
+            try:
+                return minidom.parse(result)
+            except ExpatError:
+                raise CmisException('Could not parse server response', url)
         elif result.code == 201:
-            return minidom.parse(result)
+            try:
+                return minidom.parse(result)
+            except ExpatError:
+                raise CmisException('Could not parse server response', url)
         else:
             self._processCommonErrors(result)
             return result
@@ -293,6 +302,7 @@ class CmisClient(object):
             try:
                 return minidom.parse(result)
             except ExpatError:
+                # This may happen and is normal
                 return None
 
     def _processCommonErrors(self, error):
@@ -4050,6 +4060,8 @@ def getEntryXmlDoc(repo=None, objectType
     entryElement.setAttribute('xmlns:cmisra', CMISRA_NS)
     entryXmlDoc.appendChild(entryElement)
 
+    contentElement = entryXmlDoc.createElementNS(CMISRA_NS, 'cmisra:content')
+
     # if there is a File, encode it and add it to the XML
     if contentFile:
         mimetype = contentType
@@ -4073,7 +4085,6 @@ def getEntryXmlDoc(repo=None, objectType
         # and encode everything.
 
         fileData = contentFile.read().encode("base64")
-        contentElement = entryXmlDoc.createElementNS(CMISRA_NS, 'cmisra:content')
         mediaElement = entryXmlDoc.createElementNS(CMISRA_NS, 'cmisra:mediatype')
         mediaElementText = entryXmlDoc.createTextNode(mimetype)
         mediaElement.appendChild(mediaElementText)
@@ -4083,7 +4094,7 @@ def getEntryXmlDoc(repo=None, objectType
         contentElement.appendChild(mediaElement)
         contentElement.appendChild(base64Element)
 
-        entryElement.appendChild(contentElement)
+    entryElement.appendChild(contentElement)
 
     objectElement = entryXmlDoc.createElementNS(CMISRA_NS, 'cmisra:object')
     objectElement.setAttribute('xmlns:cmis', CMIS_NS)

Modified: chemistry/cmislib/trunk/src/cmislib/net.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/net.py?rev=1388254&r1=1388253&r2=1388254&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/net.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/net.py Thu Sep 20 22:55:42 2012
@@ -112,7 +112,12 @@ class RESTService(object):
 
         """ Makes a get request to the URL specified."""
 
+        headers = None
         if kwargs:
+            if 'headers' in kwargs:
+                headers = kwargs['headers']
+                del(kwargs['headers'])
+                self.logger.debug('Headers passed in:%s' % headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:
@@ -124,7 +129,11 @@ class RESTService(object):
 
         # add a user-agent
         request.add_header('User-Agent', self.user_agent)
-
+        if headers:
+            for k,v in headers.items():
+                self.logger.debug('Adding header:%s:%s' % (k,v))
+                request.add_header(k, v)
+                
         # create a password manager
         passwordManager = HTTPPasswordMgrWithDefaultRealm()
         passwordManager.add_password(None, url, username, password)
@@ -139,7 +148,12 @@ class RESTService(object):
 
         """ Makes a delete request to the URL specified. """
 
+        headers = None
         if kwargs:
+            if 'headers' in kwargs:
+                headers = kwargs['headers']
+                del(kwargs['headers'])
+                self.logger.debug('Headers passed in:%s' % headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:
@@ -151,6 +165,10 @@ class RESTService(object):
 
         # add a user-agent
         request.add_header('User-Agent', self.user_agent)
+        if headers:
+            for k,v in headers.items():
+                self.logger.debug('Adding header:%s:%s' % (k,v))
+                request.add_header(k, v)
 
         # create a password manager
         passwordManager = HTTPPasswordMgrWithDefaultRealm()
@@ -182,7 +200,12 @@ class RESTService(object):
         specified content type.
         """
 
+        headers = None
         if kwargs:
+            if 'headers' in kwargs:
+                headers = kwargs['headers']
+                del(kwargs['headers'])
+                self.logger.debug('Headers passed in:%s' % headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:
@@ -197,6 +220,11 @@ class RESTService(object):
 
         # add a user-agent
         request.add_header('User-Agent', self.user_agent)
+        if headers:
+            for k,v in headers.items():
+                self.logger.debug('Adding header:%s:%s' % (k,v))
+                request.add_header(k, v)
+
         # create a password manager
         passwordManager = HTTPPasswordMgrWithDefaultRealm()
         passwordManager.add_password(None, url, username, password)
@@ -221,7 +249,12 @@ class RESTService(object):
         specified content type.
         """
 
+        headers = None
         if kwargs:
+            if 'headers' in kwargs:
+                headers = kwargs['headers']
+                del(kwargs['headers'])
+                self.logger.debug('Headers passed in:%s' % headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:
@@ -236,6 +269,10 @@ class RESTService(object):
 
         # add a user-agent
         request.add_header('User-Agent', self.user_agent)
+        if headers:
+            for k,v in headers.items():
+                self.logger.debug('Adding header:%s:%s' % (k,v))
+                request.add_header(k, v)
 
         # create a password manager
         passwordManager = HTTPPasswordMgrWithDefaultRealm()



Mime
View raw message