Changeset 7c143c9 for server/lib/gutenbach/ipp/core/request.py
- Timestamp:
- Dec 27, 2011, 10:20:10 PM (12 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/core/request.py
r793432f r7c143c9 3 3 from .constants import AttributeTags 4 4 from .value import Value 5 from .errors import ClientErrorBadRequest 5 6 import sys 6 7 import struct 7 8 import logging 9 import tempfile 8 10 9 11 # initialize logger … … 83 85 # that file handle 84 86 if request is not None: 87 # minimum length is 88 if length < 9: 89 raise ClientErrorBadRequest("length (%d) < 9" % length) 90 85 91 # read the version-number (two signed chars) 86 92 self.version = struct.unpack('>bb', request.read(2)) … … 105 111 # read in the next byte 106 112 next_byte = struct.unpack('>b', request.read(1))[0] 107 length -= 1113 length -= 1 108 114 logger.debug("next byte : 0x%X" % next_byte) 109 115 … … 179 185 # once we hit the end-of-attributes tag, the only thing 180 186 # 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) 184 195 185 196 # otherwise, just set the class variables to the keyword … … 228 239 end_of_attributes_tag = struct.pack('>b', AttributeTags.END) 229 240 230 # convert the data to binary231 if self.data is not None:232 data = ''.join([struct.pack('>b', x) for x in self.data])233 else:234 data = ''235 236 241 # append everything together and return it 237 return preattributes + attribute_groups + end_of_attributes_tag +data242 return preattributes + attribute_groups + end_of_attributes_tag, self.data 238 243 239 244 def __repr__(self):
Note: See TracChangeset
for help on using the changeset viewer.