Ignore:
Timestamp:
Dec 27, 2011, 10:20:10 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
e58af05
Parents:
ee8e6d0
git-author:
Jessica B. Hamrick <jhamrick@…> (12/27/11 22:20:10)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/27/11 22:20:10)
Message:

Add support for chunking, i.e. receiving file data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/ipp/core/request.py

    r793432f r7c143c9  
    33from .constants import AttributeTags
    44from .value import Value
     5from .errors import ClientErrorBadRequest
    56import sys
    67import struct
    78import logging
     9import tempfile
    810
    911# initialize logger
     
    8385        # that file handle
    8486        if request is not None:
     87            # minimum length is
     88            if length < 9:
     89                raise ClientErrorBadRequest("length (%d) < 9" % length)
     90           
    8591            # read the version-number (two signed chars)
    8692            self.version        = struct.unpack('>bb', request.read(2))
     
    105111            # read in the next byte
    106112            next_byte = struct.unpack('>b', request.read(1))[0]
    107             length -=1
     113            length -= 1
    108114            logger.debug("next byte : 0x%X" % next_byte)
    109115
     
    179185            # once we hit the end-of-attributes tag, the only thing
    180186            # left is the data, so go ahead and read all of it
    181             assert length >= 0
    182             self.data = request.read(length)
    183             logger.debug("data : %s" % self.data)
     187            if length < 0:
     188                raise ClientErrorBadRequest("length (%d) < 0" % length)
     189           
     190            self.data = tempfile.TemporaryFile()
     191            self.data.write(request.read(length))
     192            self.data.seek(0)
     193           
     194            logger.debug("data : %d bytes" % length)
    184195
    185196        # otherwise, just set the class variables to the keyword
     
    228239        end_of_attributes_tag = struct.pack('>b', AttributeTags.END)
    229240
    230         # convert the data to binary
    231         if self.data is not None:
    232             data = ''.join([struct.pack('>b', x) for x in self.data])
    233         else:
    234             data = ''
    235 
    236241        # append everything together and return it
    237         return preattributes + attribute_groups + end_of_attributes_tag + data
     242        return preattributes + attribute_groups + end_of_attributes_tag, self.data
    238243
    239244    def __repr__(self):
Note: See TracChangeset for help on using the changeset viewer.