Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def test_rfc850_variation(self):
     """Variation of RFC-850, uses full month name and full year.
     (unknow sender)
     """
     date = 'Tuesday, 06-November-07 08:49:37 GMT'
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)
Exemplo n.º 3
0
 def decode(data):
     # Some browsers add a "length" parameter to the "If-Modified-Since"
     # header, it is an extension to the HTTP 1.0 protocol by Netscape,
     # http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html
     if ';' in data:
         data = data.split(';')[0]
     return HTTPDate.decode(data)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 def test_asctime(self):
     """ANSI C's asctime().
     """
     # Convert to 'Tue Nov  6 09:49:37 2007' in UTC+1
     date = self.expected.ctime()
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)
Exemplo n.º 7
0
 def test_rfc1123_variation(self):
     """Variation of RFC-1123, uses full day name.
     (sent by Netscape 4)
     """
     date = 'Tuesday, 06 Nov 2007 08:49:37 GMT'
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
 def get_mtime(cls, ref):
     mtime = cls._get_metadata(ref, 'getlastmodified')
     if mtime is not None:
         return HTTPDate.decode(mtime)
     return cls.non_existent_time
Exemplo n.º 15
0
 def get_mtime(cls, reference):
     response = cls._head(reference)
     mtime = response.getheader('last-modified')
     if mtime is None:
         return None
     return HTTPDate.decode(mtime)
Exemplo n.º 16
0
 def test_rfc_2822(self):
     """RFC 2822
     """
     date = 'Tue, 06 Nov 2007 10:49:37 +0200'
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)
Exemplo n.º 17
0
 def test_timezone(self):
     """CST is GMT-6.
     """
     date = 'Tue, 06 Nov 2007 02:49:37 CST'
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)
Exemplo n.º 18
0
 def get_mtime(cls, ref):
     mtime = cls._get_metadata(ref, "getlastmodified")
     if mtime is not None:
         return HTTPDate.decode(mtime)
     return cls.non_existent_time
Exemplo n.º 19
0
 def test_rfc850(self):
     """RFC 850
     """
     date = 'Tuesday, 06-Nov-07 08:49:37 GMT'
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)
Exemplo n.º 20
0
 def test_rfc822(self):
     """RFC 822 is the ancestor of RFC 1123.
     """
     date = 'Tue, 06 Nov 07 08:49:37 GMT'
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)
Exemplo n.º 21
0
 def get_mtime(cls, reference):
     response = cls._head(reference)
     mtime = response.getheader('last-modified')
     if mtime is None:
         return None
     return HTTPDate.decode(mtime)
Exemplo n.º 22
0
 def test_rfc1123(self):
     """RFC 1123 is mainly used in HTTP.
     """
     date = 'Tue, 06 Nov 2007 08:49:37 GMT'
     date = HTTPDate.decode(date)
     self.assertEqual(date, self.expected)