Esempio n. 1
0
 def __init__(self, _data=None):
     if _data is None:
         _data = bytearray()
     elif not isinstance(_data, bytearray):
         _data = bytearray(_data)
     self.data = _data
     self.rdata = buffer(_data)
     self._order(self.BE)
Esempio n. 2
0
 def __init__(self, _data=None):
     if _data is None:
         _data = bytearray()
     elif not isinstance(_data, bytearray):
         _data = bytearray(_data)
     self.data = _data
     self.rdata = buffer(_data)
     self._order(self.BE)
Esempio n. 3
0
    def __init__(self, name, chunk_size=default_chunk_size):
        self.chunk_size = chunk_size
        self._internal = bytearray(chunk_size)
        self.buf = buffer(self._internal)

        self.name = name
        self.envelope = BodyGenerator(self.name,
                                      disptype='form-data',
                                      subtype='form-data')
        self.headers = self.envelope.headers
Esempio n. 4
0
    def __init__(self, name, chunk_size=default_chunk_size):
        self.chunk_size = chunk_size
        self._internal = bytearray(chunk_size)
        self.buf = buffer(self._internal)

        self.name = name
        self.envelope = BodyGenerator(self.name,
                                      disptype='form-data',
                                      subtype='form-data')
        self.headers = self.envelope.headers
Esempio n. 5
0
    def __init__(self, name, chunk_size=default_chunk_size):
        """
        An abstract class of buffered generator which encodes
        multipart/form-data.
        """
        self.chunk_size = chunk_size
        self._internal = bytearray(chunk_size)
        self.buf = buffer(self._internal)

        self.name = name
        self.envelope = BodyGenerator(self.name,
                                      disptype='form-data',
                                      subtype='form-data')
        self.headers = self.envelope.headers
Esempio n. 6
0
    def __init__(self, name, chunk_size=default_chunk_size):
        """
        An abstract class of buffered generator which encodes
        multipart/form-data.
        """
        self.chunk_size = chunk_size
        self._internal = bytearray(chunk_size)
        self.buf = buffer(self._internal)

        self.name = name
        self.envelope = BodyGenerator(self.name,
                                      disptype='form-data',
                                      subtype='form-data')
        self.headers = self.envelope.headers
Esempio n. 7
0
 def gen_chunks(self, gen):
     """
     Takes a bytes generator and yields chunks of a maximum of [chunk_size]
     bytes.
     """
     for data in gen:
         if not isinstance(data, six.binary_type):
             data = data.encode('utf-8')
         size = len(data)
         if size < self.chunk_size:
             yield data
         else:
             mv = buffer(data)
             offset = 0
             while offset < size:
                 nb = min(self.chunk_size, size - offset)
                 yield mv[offset:offset + nb]
                 offset += nb
Esempio n. 8
0
 def gen_chunks(self, gen):
     """
     Takes a bytes generator and yields chunks of a maximum of [chunk_size]
     bytes.
     """
     for data in gen:
         if not isinstance(data, six.binary_type):
             data = data.encode('utf-8')
         size = len(data)
         if size < self.chunk_size:
             yield data
         else:
             mv = buffer(data)
             offset = 0
             while offset < size:
                 nb = min(self.chunk_size, size - offset)
                 yield mv[offset:offset + nb]
                 offset += nb
Esempio n. 9
0
    def __init__(self, name, chunk_size=default_chunk_size):
        """Generator that encodes multipart/form-data.

        An abstract class of buffered generator which encodes
        multipart/form-data.

        Keyword arguments:
        name -- the name of the file to encode
        chunk_size -- the maxiumum size for any chunk in bytes
        """
        self.chunk_size = chunk_size
        self._internal = bytearray(chunk_size)
        self.buf = buffer(self._internal)

        self.name = name
        self.envelope = BodyGenerator(self.name,
                                      disptype='form-data',
                                      subtype='form-data')
        self.headers = self.envelope.headers
Esempio n. 10
0
    def gen_chunks(self, gen):
        """Generates byte chunks of a given size.

        Takes a bytes generator and yields chunks of a maximum of
        ``chunk_size`` bytes.

        Parameters
        ----------
        gen : generator
            The bytes generator that produces the bytes
        """
        for data in gen:
            size = len(data)
            if size < self.chunk_size:
                yield data
            else:
                mv = buffer(data)
                offset = 0
                while offset < size:
                    nb = min(self.chunk_size, size - offset)
                    yield mv[offset:offset + nb]
                    offset += nb
Esempio n. 11
0
    def gen_chunks(self, gen):
        """Generates byte chunks of a given size.

        Takes a bytes generator and yields chunks of a maximum of
        ``chunk_size`` bytes.

        Parameters
        ----------
        gen : generator
            The bytes generator that produces the bytes
        """
        for data in gen:
            size = len(data)
            if size < self.chunk_size:
                yield data
            else:
                mv = buffer(data)
                offset = 0
                while offset < size:
                    nb = min(self.chunk_size, size - offset)
                    yield mv[offset:offset + nb]
                    offset += nb
Esempio n. 12
0
    def gen_chunks(self, gen):
        """Generates byte chunks of a given size.

        Takes a bytes generator and yields chunks of a maximum of [chunk_size]
        bytes.

        Keyword arguments:
        gen -- the bytes generator that produces the bytes
        """
        for data in gen:
            if not isinstance(data, six.binary_type):
                data = data.encode('utf-8')
            size = len(data)
            if size < self.chunk_size:
                yield data
            else:
                mv = buffer(data)
                offset = 0
                while offset < size:
                    nb = min(self.chunk_size, size - offset)
                    yield mv[offset:offset + nb]
                    offset += nb