Пример #1
0
    def test_date_add(self):
        t = datetime.datetime
        self.assertEqual(data.date_add("s", 5, data.str2date("1/1/2005 1:00")), t(2005, 1, 1, 1, 0, 5))
        self.assertEqual(data.date_add("m", 5, data.str2date("1/1/2005 1:00")), t(2005, 1, 1, 1, 5, 0))
        self.assertEqual(data.date_add("s", 5, data.str2date("1/1/2005 1:00:05")), t(2005, 1, 1, 1, 0, 10))

        # A few negative tests:
        self.assertEqual(data.date_add("m", -5, data.str2date("1/1/2005 1:05")), t(2005, 1, 1, 1, 0, 0))
Пример #2
0
    def headers(self):
        timeout = self.timeout * 60
        now = datetime.utcnow()
        expires = data.date_add('s', timeout, now)
        expires = expires.strftime('%a, %d-%b-%Y %H:%M:%S %Z')

        cookies = []
        for key, cookie in self.iteritems():
            # Don't write out cookies that are prefixed with underbars
            # as they are considered private. This also has the side
            # effect of not writing out Urchin cookies like crazy :)
            if key.startswith('_'):
                # TODO: find a better way to avoid writing Urchin cookies
                continue

            if not self.domain is None:
                # Domain must be prefixed with "." and exclude the
                # port.  If the domain already has a "." prefix we've
                # already seen this domain name and can skip.
                # REFERENCE: RFC 2109, RFC 2965
                if not self.domain.startswith('.'):
                    self.domain = '.' + self.domain.split(':')[0]

                # If the domain doesn't look to be a real FQDN, remove:
                if not self.domain.count('.') > 1:
                    self.domain = None

            # Always include the name of the cookie first
            header = []
            header.append('%s=%s' % (key, cookie.value))

            # Supported cookie attributes
            header.append('Expires=%s' % expires)
            header.append('Path=%s' % self.path)

            # Don't include the domain for sites that only use hostnames
            # eg: http://wiki/foo/bar/file.html
            if not self.domain is None:
                header.append('Domain=%s' % self.domain)

            # Create the full header tuple
            cookies.append(('Set-Cookie', '; '.join(header)))

        return cookies
Пример #3
0
    def headers(self):
        timeout = self.timeout * 60
        now = datetime.now(pytz.timezone("GMT"))
        expires = data.date_add("s", timeout, now)
        expires = expires.strftime("%a, %d-%b-%Y %H:%M:%S %Z")

        cookies = []
        for key, cookie in self.iteritems():
            # Don't write out cookies that are prefixed with underbars
            # as they are considered private. This also has the side
            # effect of not writing out Urchin cookies like crazy :)
            if not key.startswith("_"):
                header = []
                header.append("%s=%s" % (key, cookie.value))
                header.append("expires=%s" % expires)
                header.append("path=%s" % self.path)
                header.append("domain=%s" % self.domain)
                cookies.append(("Set-Cookie", "; ".join(header)))

        return cookies