def test_encode(self): """Convert local time to universal time. """ # November dt_utc = datetime(2007, 11, 6, 8, 49, 37) expected = 'Tue, 06 Nov 2007 08:49:37 GMT' dt_local = datetime_utc2local(dt_utc) self.assertEqual(HTTPDate.encode(dt_local), expected) # August dt_utc = datetime(2007, 8, 6, 8, 49, 37) expected = 'Mon, 06 Aug 2007 08:49:37 GMT' dt_local = datetime_utc2local(dt_utc) self.assertEqual(HTTPDate.encode(dt_local), expected)
def encode(cookies): output = [] for name in cookies: cookie = cookies[name] aux = [] aux.append('%s="%s"' % (name, cookie.value)) # The parameters expires = cookie.expires if expires is not None: if isinstance(expires, datetime): expires = HTTPDate.encode(expires) aux.append('expires=%s' % expires) if cookie.domain is not None: aux.append('domain=%s' % cookie.domain) if cookie.path is not None: aux.append('path=%s' % cookie.path) else: aux.append('path=/') if cookie.max_age is not None: aux.append('max-age="%s"' % cookie.max_age) if cookie.comment is not None: aux.append('comment="%s"' % cookie.comment) if cookie.secure is not None: aux.append('secure="%s"' % cookie.secure) # The value output.append('; '.join(aux)) return ', '.join(output)
def to_opml_stream(self, context): namespace = {} namespace['title'] = self.get_property('title') namespace['mtime'] = HTTPDate.encode(self.get_mtime()) revisions = self.get_revisions(context) name = email = None if revisions: root = context.root username = revisions[0]['username'] user = root.get_user(username) if user: name = user.get_title() email = user.get_property('email') owner = {'name': name, 'email': email} namespace['owner'] = owner # Feeds articles, errors = self.get_articles() feeds_cache = deepcopy(self.handler.feeds_summary) feeds = [] for uri, data in feeds_cache.iteritems(): feeds.append({'title': data['title'], 'nb_articles': data['nb_articles'], 'uri': uri, 'type': 'rss' # FIXME hardcoded }) namespace['feeds'] = feeds handler = self.get_resource('/ui/rssfeeds/RssFeeds_export_to_opml.xml') return stl(handler, namespace=namespace)
def _set_auth_cookie(self, cookie): # Compute expires datetime (FIXME Use the request date) session_timeout = self.server.session_timeout if session_timeout != timedelta(0): expires = self.timestamp + session_timeout expires = HTTPDate.encode(expires) else: expires = None # Set cookie self.set_cookie('iauth', cookie, path='/', expires=expires)
def GET(self, resource, context): """Protocol used (with restedit.py): 1- We add a header to the content of the file 2- The header is separated from the rest of the file by a "\n\n". 3- An entry in the header is: header-name:header-body\n The header-name does not contain ":" and the header-body does not contain "\n" 4- Everything is sent in utf-8 """ uri = context.uri header = [ 'url:%s://%s%s' % (uri.scheme, uri.authority, uri.path[:-1]), 'last-modified:%s' % HTTPDate.encode(resource.get_value('mtime')), 'content_type:%s' % resource.get_content_type(), 'title:%s' % resource.get_title().encode('utf-8'), 'include-Cookie:iauth="%s"' % context.get_cookie('iauth'), 'include-X-User-Agent:%s' % context.get_header('User-Agent') ] # Try to guess the extension (optional) filename = resource.get_value('filename') if filename: extension = splitext(filename)[1] if extension: extension = extension[1:] if extension in resource.get_all_extensions(): # All OK header.append('extension:.%s' % extension) # Authorization part auth = context.get_header('Authorization') if auth: header.append('auth:%s' % auth) # Add the "\n\n" and make the header header.append('\n') header = '\n'.join(header) data = resource.get_value('data').to_str() # TODO known bug from ExternalEditor requires rfc1123_date() # Using RESPONSE.setHeader('Pragma', 'no-cache') would be better, but # this chokes crappy most MSIE versions when downloads happen on SSL. # cf. http://support.microsoft.com/support/kb/articles/q316/4/31.asp #context.set_header('Last-Modified', rfc1123_date()) context.set_header('Pragma', 'no-cache') context.content_type = 'application/x-restedit' context.set_content_disposition('inline', '%s.restedit' % resource.name) return header + data
def _set_auth_cookie(self, cookie): session_timeout = self.get_session_timeout() expires = self.timestamp + session_timeout # If never expires, set cookie's expire date in 365 days # By default, if we don't give expires date, # the cookie will expires at the end of the browser session # (so when restarting the browser) if not session_timeout: expires += timedelta(days=365) # Encode expires expires = HTTPDate.encode(expires) # Set cookie self.set_cookie('iauth', cookie, path='/', expires=expires)
def GET(self, resource, context): """Protocol used (with restedit.py): 1- We add a header to the content of the file 2- The header is separated from the rest of the file by a "\n\n". 3- An entry in the header is: header-name:header-body\n The header-name does not contain ":" and the header-body does not contain "\n" 4- Everything is sent in utf-8 """ uri = context.uri header = [ 'url:%s://%s%s' % (uri.scheme, uri.authority, uri.path[:-1]), 'last-modified:%s' % HTTPDate.encode(resource.get_value('mtime')), 'content_type:%s' % resource.get_content_type(), 'title:%s' % resource.get_title().encode('utf-8'), 'include-Cookie:iauth="%s"' % context.get_cookie('iauth'), 'include-X-User-Agent:%s' % context.get_header('User-Agent')] # Try to guess the extension (optional) filename = resource.get_value('filename') if filename: extension = splitext(filename)[1] if extension: extension = extension[1:] if extension in resource.get_all_extensions(): # All OK header.append('extension:.%s' % extension) # Authorization part auth = context.get_header('Authorization') if auth: header.append('auth:%s' % auth) # Add the "\n\n" and make the header header.append('\n') header = '\n'.join(header) data = resource.get_value('data').to_str() # TODO known bug from ExternalEditor requires rfc1123_date() # Using RESPONSE.setHeader('Pragma', 'no-cache') would be better, but # this chokes crappy most MSIE versions when downloads happen on SSL. # cf. http://support.microsoft.com/support/kb/articles/q316/4/31.asp #context.set_header('Last-Modified', rfc1123_date()) context.set_header('Pragma', 'no-cache') context.content_type = 'application/x-restedit' context.set_content_disposition('inline', '%s.restedit' % resource.name) return header + data