Beispiel #1
0
            lastdata = pairs.pop()

        for name_value in pairs:
            nv = name_value.split('=', 1)
            if len(nv) != 2:
                if strict_parsing:
                    raise MimeFormatError(
                        "bad query field: %s") % ` name_value `
                continue
            if len(nv[1]) or keep_blank_values:
                name = urllib.unquote(nv[0].replace('+', ' '))
                value = urllib.unquote(nv[1].replace('+', ' '))
                yield name, value


parse_urlencoded_stream = generatorToStream(parse_urlencoded_stream)


def parse_urlencoded(stream,
                     maxMem=100 * 1024,
                     maxFields=1024,
                     keep_blank_values=False,
                     strict_parsing=False):
    d = {}
    numFields = 0

    s = parse_urlencoded_stream(stream, maxMem, keep_blank_values,
                                strict_parsing)

    while 1:
        datas = s.read()
Beispiel #2
0
                                      maxMem)
            pairs = str(data).split('&')
            pairs[0] = lastdata + pairs[0]
            lastdata=pairs.pop()
        
        for name_value in pairs:
            nv = name_value.split('=', 1)
            if len(nv) != 2:
                if strict_parsing:
                    raise MimeFormatError("bad query field: %s") % `name_value`
                continue
            if len(nv[1]) or keep_blank_values:
                name = urllib.unquote(nv[0].replace('+', ' '))
                value = urllib.unquote(nv[1].replace('+', ' '))
                yield name, value
parse_urlencoded_stream = generatorToStream(parse_urlencoded_stream)

def parse_urlencoded(stream, maxMem=100*1024, maxFields=1024,
                     keep_blank_values=False, strict_parsing=False):
    d = {}
    numFields = 0

    s=parse_urlencoded_stream(stream, maxMem, keep_blank_values, strict_parsing)
    
    while 1:
        datas = s.read()
        if isinstance(datas, defer.Deferred):
            datas = defer.waitForDeferred(datas)
            yield datas
            datas = datas.getResult()
        if datas is None:
Beispiel #3
0
    
    compress = zlib.compressobj(compressLevel, zlib.DEFLATED, -zlib.MAX_WBITS, zlib.DEF_MEM_LEVEL, 0)
    _compress = compress.compress
    _crc32 = zlib.crc32
    
    yield input.wait
    for buf in input:
        if len(buf) != 0:
            crc = _crc32(buf, crc)
            size += len(buf)
            yield _compress(buf)
        yield input.wait
    
    yield compress.flush()
    yield struct.pack('<LL', crc & 0xFFFFFFFFL, size & 0xFFFFFFFFL)
gzipStream=stream.generatorToStream(gzipStream)

def deflateStream(input, compressLevel=6):
    # NOTE: this produces RFC-conformant but some-browser-incompatible output.
    # The RFC says that you're supposed to output zlib-format data, but many
    # browsers expect raw deflate output. Luckily all those browsers support
    # gzip, also, so they won't even see deflate output. 
    compress = zlib.compressobj(compressLevel, zlib.DEFLATED, zlib.MAX_WBITS, zlib.DEF_MEM_LEVEL, 0)
    _compress = compress.compress
    yield input.wait
    for buf in input:
        if len(buf) != 0:
            yield _compress(buf)
        yield input.wait

    yield compress.flush()
Beispiel #4
0
    _compress = compress.compress
    _crc32 = zlib.crc32

    yield input.wait
    for buf in input:
        if len(buf) != 0:
            crc = _crc32(buf, crc)
            size += len(buf)
            yield _compress(buf)
        yield input.wait

    yield compress.flush()
    yield struct.pack('<LL', crc & 0xFFFFFFFFL, size & 0xFFFFFFFFL)


gzipStream = stream.generatorToStream(gzipStream)


def deflateStream(input, compressLevel=6):
    # NOTE: this produces RFC-conformant but some-browser-incompatible output.
    # The RFC says that you're supposed to output zlib-format data, but many
    # browsers expect raw deflate output. Luckily all those browsers support
    # gzip, also, so they won't even see deflate output.
    compress = zlib.compressobj(compressLevel, zlib.DEFLATED, zlib.MAX_WBITS,
                                zlib.DEF_MEM_LEVEL, 0)
    _compress = compress.compress
    yield input.wait
    for buf in input:
        if len(buf) != 0:
            yield _compress(buf)
        yield input.wait