Changeset ffbe41d for server/lib/gutenbach/ipp/core/request.py
- Timestamp:
- Jan 10, 2012, 7:25:33 PM (12 years ago)
- Branches:
- no-cups
- Children:
- b01b6d1
- Parents:
- ce2abc5
- git-author:
- Jessica B. Hamrick <jhamrick@…> (01/10/12 19:25:33)
- git-committer:
- Jessica B. Hamrick <jhamrick@…> (01/10/12 19:25:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/core/request.py
rce2abc5 rffbe41d 71 71 if request is None: 72 72 # make sure the version number isn't empty 73 assert version is not None 73 if version is None: 74 raise ValueError("version must not be None") 74 75 # make sure verison is a tuple of length 2 75 assert isinstance(version, tuple) 76 assert len(version) == 2 76 if not hasattr(version, '__iter__'): 77 raise ValueError("version must be iterable") 78 if len(version) != 2: 79 raise ValueError("version must be of length 2") 77 80 # make sure the operation id isn't empty 78 assert operation_id is not None 81 if operation_id is None: 82 raise ValueError("operation_id may not be None") 79 83 # make sure the request id isn't empty 80 assert request_id is not None 84 if request_id is None: 85 raise ValueError("request_id may not be None") 81 86 # make sure attribute_groups is a list of Attributes 82 for a in attribute_groups: assert isinstance(a, AttributeGroup) 87 for a in attribute_groups: 88 if not isinstance(a, AttributeGroup): 89 raise ValueError("attribute not of type AttributeGroup") 83 90 84 91 # if the request isn't None, then we'll read directly from … … 90 97 91 98 # read the version-number (two signed chars) 92 self.version 99 self.version = struct.unpack('>bb', request.read(2)) 93 100 length -= 2 94 101 logger.debug("version-number : (0x%X, 0x%X)" % self.version) … … 96 103 # read the operation-id (or status-code, but that's only 97 104 # for a response) (signed short) 98 self.operation_id 105 self.operation_id = struct.unpack('>h', request.read(2))[0] 99 106 length -= 2 100 107 logger.debug("operation-id : 0x%X" % self.operation_id) 101 108 102 109 # read the request-id (signed int) 103 self.request_id 110 self.request_id = struct.unpack('>i', request.read(4))[0] 104 111 length -= 4 105 112 logger.debug("request-id : 0x%X" % self.request_id) … … 130 137 131 138 # read in the value tag (signed char) 132 value_tag 139 value_tag = next_byte 133 140 logger.debug("value-tag : 0x%X" % value_tag) 134 141 135 142 # read in the length of the name (signed short) 136 name_length 143 name_length = struct.unpack('>h', request.read(2))[0] 137 144 length -= 2 138 145 logger.debug("name-length : %i" % name_length) … … 140 147 if name_length != AttributeTags.ZERO_NAME_LENGTH: 141 148 # read the name (a string of name_length bytes) 142 name 149 name = request.read(name_length) 143 150 length -= name_length 144 151 logger.debug("name : %s" % name) 145 152 146 153 # read in the length of the value (signed short) 147 value_length 154 value_length = struct.unpack('>h', request.read(2))[0] 148 155 length -= 2 149 156 logger.debug("value-length : %i" % value_length) 150 157 151 158 # read in the value (string of value_length bytes) 152 value 159 value = request.read(value_length) 153 160 length -= value_length 154 161 … … 162 169 else: 163 170 # read in the length of the value (signed short) 164 value_length 171 value_length = struct.unpack('>h', request.read(2))[0] 165 172 length -= 2 166 173 logger.debug("value-length : %i" % value_length) 167 174 168 175 # read in the value (string of value_length bytes) 169 value 176 value = request.read(value_length) 170 177 length -= value_length 171 178 … … 214 221 215 222 # make sure the version number isn't empty 216 assert self.version is not None 223 if self.version is None: 224 raise ValueError("version is None") 217 225 # make sure verison is a tuple of length 2 218 assert isinstance(self.version, tuple) 219 assert len(self.version) == 2 226 if not hasattr(self.version, '__iter__'): 227 raise ValueError("version is not iterable") 228 if len(self.version) != 2: 229 raise ValueError("version is not of length 2") 220 230 # make sure the operation id isn't empty 221 assert self.operation_id is not None 231 if self.operation_id is None: 232 raise ValueError("operation_id is None") 222 233 # make sure the request id isn't empty 223 assert self.request_id is not None 234 if self.request_id is None: 235 raise ValueError("request_id is None") 224 236 # make sure attribute_groups is a list of Attributes 225 assert len(self.attribute_groups) > 0 226 for a in self.attribute_groups: assert isinstance(a, AttributeGroup) 237 if len(self.attribute_groups) == 0: 238 raise ValueError("no attribute groups") 239 for a in self.attribute_groups: 240 if not isinstance(a, AttributeGroup): 241 raise ValueError("not of type AttributeGroup") 227 242 228 243 # convert the version, operation id, and request id to binary
Note: See TracChangeset
for help on using the changeset viewer.