Пример #1
0
 def _get_sessionid(self):
     """Return session id and subsession."""
     sessionid = self.m_request.session()
     if sessionid and issessionid(sessionid):
         basesession, subsession = parse_sessionid(sessionid)
     else:
         basesession, subsession = None, None
     if basesession is None:
         cookie = self.m_request.cookie('draco-session')
         if cookie and issessionid(cookie.value):
             basesession, dummy = parse_sessionid(cookie.value)
     if subsession is None:
         subsession = 0
     return (basesession, subsession)
Пример #2
0
 def test_roundtrip(self):
     for i in range(100):
         sess = util.generate_sessionid()
         dump = util.dump_sessionid(sess)
         assert util.issessionid(dump)
         parsed = util.parse_sessionid(dump)
         assert sess == parsed
     for i in range(100):
         sess = util.generate_sessionid()
         sess = (sess[0], None)
         dump = util.dump_sessionid(sess)
         assert util.issessionid(dump)
         parsed = util.parse_sessionid(dump)
         assert sess == parsed
     for i in range(100):
         sess = util.generate_sessionid()
         sess = (None, sess[1])
         dump = util.dump_sessionid(sess)
         assert util.issessionid(dump)
         parsed = util.parse_sessionid(dump)
         assert sess == parsed
Пример #3
0
def parse_draco_uri(uri, docroot):
    """Decompose an URI into Draco specific components.

    The return value is the 8-tuple: (protocol, host, path,
        filename, locale, session, pathinfo, args)
    """
    protocol, host, path, args = urimod.parse_uri(uri)
    directory, filename, pathinfo = urimod.resolve_path_uri(path, docroot) 
    parts = pathinfo.split('/')
    if parts and islocale(parts[0]):
        locale = parts[0]
        parts = parts[1:]
    else:
        locale = ''
    if parts and issessionid(parts[0]):
        session = parts[0]
        parts = parts[1:]
    else:
        session = ''
    pathinfo = '/'.join(parts)
    return (protocol, host, directory, filename, locale, session,
            pathinfo, args)
Пример #4
0
 def test_invalid(self):
     py.test.raises(TypeError, util.issessionid, None)
     py.test.raises(TypeError, util.issessionid, 10)
     assert not util.issessionid('invalid')