示例#1
0
 def _handleResponse(self, response):
     if DEBUG:
         print 'received response: ', response.status, response.reason
     content = response.read()
     if DEBUG:
         print 'response content:', content
     if response.status in range(200, 300):
         # success
         return content
     else:
         if response.status == 401:
             # authorization failure
             raise api.ServiceAuthorizationError(response.reason)
         elif response.status == 404:
             # resource does not exists
             raise api.ResourceNotFoundError(response.reason)
         elif response.status == 500:
             # internal server error
             lines = []
             lines.append(_('Returned HTTP reason: %s') % response.reason)
             lines.append(_('Received content:'))
             lines.append(content)
             raise api.ServiceInternalError('\n'.join(lines))
         elif response.status == 503:
             # service unavailable
             raise api.ServiceUnavailableError(response.reason)
         else:
             raise api.ServiceError(response.reason)
示例#2
0
 def postNew(self, blogId, entry, categories):
     if DEBUG:
         print 'started sending'
     s = self.getServerProxy()
     body = {}
     body['flNotOnHomePage'] = False
     body['title'] = entry.title.encode('utf-8')
     body['description'] = renderBodyAsXML(entry.body.encode('utf-8'),
         entry.bodyType)
     body['categories'] = []
     for category in categories:
         body['categories'].append(category.name.encode('utf-8'))
     # publication date turned off as temporary workaround for
     # blox.pl code bug
     #body['pubDate'] = datetime.datetime.now().isoformat()
     body['guid'] = 'allo allo'
     body['author'] = self.userName.encode('utf-8')
     if DEBUG:
         print body
     try:
         assignedId = s.metaWeblog.newPost(blogId, self.userName, self.passwd,
             body, not entry.isDraft)
         return assignedId
     except xmlrpclib.Fault, e:
         raise api.ServiceError(e.faultString)
示例#3
0
 def postModified(self, blogId, entryId, entry, categories):
     if DEBUG:
         print 'started sending'
     s = self.getServerProxy()
     body = []
     body.append(entry.title.encode('utf-8'))
     body.append(
         lib.renderer.renderBodyAsXML(entry.body.encode('utf-8'),
                                      entry.bodyType))
     body = '\n'.join(body)
     try:
         s.blogger.editPost(APPKEY, entryId, self.userName, self.passwd,
                            body, not entry.isDraft)
     except xmlrpclib.Fault, e:
         raise api.ServiceError(e.faultString)