Exemplo n.º 1
0
 def fromString(klass, st):
     scheme, netloc, path, query, fragment = urllib.parse.urlsplit(st)
     u = klass(
         scheme, netloc,
         
         toBytes(''.join([urllib.parse.unquote(unicode(seg)) for seg in unicode(path).split('/')[1:]])),
         unquerify(toBytes(query)), urllib.parse.unquote(unicode(fragment)))
     return u
Exemplo n.º 2
0
    def prePathURL(self):
        """
        The absolute URL up until the last handled segment of this request.

        @rtype: C{str}.
        """
        return 'http://%s/%s' % (unicode(self.getHeader('host')) or
                                 'localhost', unicode(b'/'.join(self.prepath)))
Exemplo n.º 3
0
    def prePathURL(self):
        """
        The absolute URL up until the last handled segment of this request.

        @rtype: C{str}.
        """
        return 'http://%s/%s' % (unicode(self.getHeader('host')) or 'localhost',
                                 unicode(b'/'.join(self.prepath)))
Exemplo n.º 4
0
def _uqf(query):
    query=unicode(query)
    for x in query.split('&'):
        if '=' in x:
            yield tuple( [urllib.parse.unquote_plus(s) for s in x.split('=', 1)] )
        elif x:
            yield (urllib.parse.unquote_plus(x), None)
Exemplo n.º 5
0
def _serialize(obj, w, seen):
    from nevow import athena

    if isinstance(obj, bool):
        if obj:
            w('true')
        else:
            w('false')
    elif isinstance(obj, (int, float)):
        w(str(obj))
    elif isinstance(obj, bytes):
        obj = unicode(obj)
    elif isinstance(obj, str):
        w('"')
        w(stringEncode(obj))
        w('"')
    elif isinstance(obj, type(None)):
        w('null')
    elif id(obj) in seen:
        raise CycleError(type(obj))
    elif isinstance(obj, (tuple, list)):
        w('[')
        for n, e in enumerate(obj):
            _serialize(e, w, seen)
            if n != len(obj) - 1:
                w(',')
        w(']')
    elif isinstance(obj, dict):
        w('{')
        for n, (k, v) in enumerate(obj.items()):
            _serialize(k, w, seen)
            w(':')
            _serialize(v, w, seen)
            if n != len(obj) - 1:
                w(',')
        w('}')
    elif isinstance(obj, (athena.LiveFragment, athena.LiveElement)):
        _serialize(obj._structured(), w, seen)
    elif isinstance(obj, (rend.Fragment, page.Element)):
        wrapper = tags.div(xmlns="http://www.w3.org/1999/xhtml")
        w('"')
        w(
            stringEncode("".join(
                _flat.flatten(None, wrapper[obj], False,
                              False)).decode('utf-8')))
        w('"')
    else:
        transportable = IAthenaTransportable(obj, None)
        if transportable is not None:
            w('(new ' + transportable.jsClass.encode('ascii') + '(')
            arguments = transportable.getInitialArguments()
            for n, e in enumerate(arguments):
                _serialize(e, w, seen)
                if n != len(arguments) - 1:
                    w(',')
            w('))')
        else:
            raise TypeError("Unsupported type %r: %r" % (type(obj), obj))
Exemplo n.º 6
0
def parse(s):
    """
    Return the object represented by the JSON-encoded string C{s}.
    """
    tokens = tokenise(unicode(s))
    value, tokens = parseValue(tokens)
    if tokens:
        raise ParseError("Unexpected %r" % tokens[0])
    return value
Exemplo n.º 7
0
 def fromContext(klass, context):
     '''Create a URL object that represents the current URL in the traversal
     process.'''
     request = inevow.IRequest(context)
     request.prepath=[toBytes(i) for i in request.prepath]
     uri = toBytes(request.prePathURL())
     if b'?' in toBytes(request.uri):
         uri += b'?' + toBytes(request.uri).split(b'?')[-1]
     return klass.fromString(unicode(uri))
Exemplo n.º 8
0
def _serialize(obj, w, seen):
    from nevow import athena

    if isinstance(obj, bool):
        if obj:
            w('true')
        else:
            w('false')
    elif isinstance(obj, (int, float)):
        w(str(obj))
    elif isinstance(obj, bytes):
        obj=unicode(obj)
    elif isinstance(obj, str):
        w('"')
        w(stringEncode(obj))
        w('"')
    elif isinstance(obj, type(None)):
        w('null')
    elif id(obj) in seen:
        raise CycleError(type(obj))
    elif isinstance(obj, (tuple, list)):
        w('[')
        for n, e in enumerate(obj):
            _serialize(e, w, seen)
            if n != len(obj) - 1:
                w(',')
        w(']')
    elif isinstance(obj, dict):
        w('{')
        for n, (k, v) in enumerate(obj.items()):
            _serialize(k, w, seen)
            w(':')
            _serialize(v, w, seen)
            if n != len(obj) - 1:
                w(',')
        w('}')
    elif isinstance(obj, (athena.LiveFragment, athena.LiveElement)):
        _serialize(obj._structured(), w, seen)
    elif isinstance(obj, (rend.Fragment, page.Element)):
        wrapper = tags.div(xmlns="http://www.w3.org/1999/xhtml")
        w('"')
        w(stringEncode(
                "".join(_flat.flatten(None, wrapper[obj],
                                      False, False)).decode('utf-8')))
        w('"')
    else:
        transportable = IAthenaTransportable(obj, None)
        if transportable is not None:
            w('(new ' + transportable.jsClass.encode('ascii') + '(')
            arguments = transportable.getInitialArguments()
            for n, e in enumerate(arguments):
                _serialize(e, w, seen)
                if n != len(arguments) - 1:
                    w(',')
            w('))')
        else:
            raise TypeError("Unsupported type %r: %r" % (type(obj), obj))
Exemplo n.º 9
0
def parse(s):
    """
    Return the object represented by the JSON-encoded string C{s}.
    """
    tokens = tokenise(unicode(s))
    value, tokens = parseValue(tokens)
    if tokens:
        raise ParseError("Unexpected %r" % tokens[0])
    return value