Changeset ffbe41d
- 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)
- Location:
- server/lib/gutenbach
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
server/lib/gutenbach/ipp/core/attribute.py
r793432f rffbe41d 59 59 """ 60 60 61 if name is not None: 62 assert isinstance(name, str), \ 63 "Attribute name must be a string!" 61 if name is not None and not isinstance(name, str): 62 raise ValueError("attribute name must be a string") 64 63 if values is None: 65 64 values = [] 66 65 for value in values: 67 assert isinstance(value, Value), \68 "Value %s must be of type Value" % (value,)66 if not isinstance(value, Value): 67 raise ValueError("value %s must be of type Value" % (value,)) 69 68 70 69 self.name = name … … 83 82 """ 84 83 85 assert self.name is not None, \86 "cannot pack unnamed attribute!"87 assert len(self.values) > 0, \88 "cannot pack empty attribute!"84 if self.name is None: 85 raise ValueError, "cannot pack unnamed attribute" 86 if len(self.values) == 0: 87 raise ValueError, "cannot pack empty attribute" 89 88 90 89 # get the binary data for all the values … … 94 93 # get the name length (0 for everything but the first 95 94 # value) 96 if i == 0: 97 name_length = len(self.name) 98 else: 99 name_length = 0 95 name_length = len(self.name) if i == 0 else 0 100 96 101 97 logger.debug("dumping name : %s" % self.name) … … 113 109 # the value tag in binary 114 110 tag_bin = struct.pack('>b', v.tag) 115 116 111 # the name length in binary 117 112 name_length_bin = struct.pack('>h', name_length) 118 119 113 # the name in binary 120 114 name_bin = self.name 121 122 115 # the value length in binary 123 116 value_length_bin = struct.pack('>h', value_length) 124 117 118 # add the binary value to the list of values 119 vlist = [tag_bin, name_length_bin, value_length_bin, value_bin] 125 120 if i == 0: 126 values.append(''.join([tag_bin, 127 name_length_bin, 128 name_bin, 129 value_length_bin, 130 value_bin])) 131 else: 132 values.append(''.join([tag_bin, 133 name_length_bin, 134 value_length_bin, 135 value_bin])) 121 vlist.insert(2, name_bin) 122 values.append(''.join(vlist)) 136 123 137 124 # concatenate everything together and return it along with the -
server/lib/gutenbach/ipp/core/attributegroup.py
r793432f rffbe41d 33 33 """ 34 34 35 if tag is not None: 36 assert isinstance(tag, int), \ 37 "tag must be a character!" 35 if tag is not None and not isinstance(tag, int): 36 raise ValueError("tag must be a character") 38 37 39 38 self.tag = tag … … 87 86 88 87 for a in attributes: 89 assert isinstance(a, Attribute), \90 "attribute must be of type Attribute!"88 if not isinstance(a, Attribute): 89 raise ValueError("attribute must be of type Attribute") 91 90 92 91 for a in attributes: -
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 -
server/lib/gutenbach/ipp/core/value.py
r793432f rffbe41d 46 46 47 47 # make sure the arguments are valid 48 if value is not None: 49 assert tag is not None, \ 50 "tag must not be null because " + \ 51 "value is not null!" 48 if value is not None and tag is None: 49 raise ValueError("tag may not be None") 52 50 53 51 # initialize member variables 54 self.tag = tag# one byte, the type of value55 self.value = value# non-binary value of self.value52 self.tag = tag # one byte, the type of value 53 self.value = value # non-binary value of self.value 56 54 57 55 def __cmp__(self, other): … … 76 74 """ 77 75 78 assert tag is not None, \79 "Cannot unpack values with unspecified value tag!"80 assert packed_value is not None, \81 "Cannot unpack null values!"76 if tag is None: 77 raise ValueError("cannot unpack values with no value tag") 78 if packed_value is None: 79 raise ValueError("cannot unpack null values") 82 80 83 81 value = None … … 172 170 173 171 """ 174 175 assert self.tag is not None, \176 "cannot pack value with null value tag!"177 assert self.value is not None, \178 "cannot pack null value!"172 173 if self.tag is None: 174 raise ValueError("cannot pack value with null tag") 175 if self.value is None: 176 raise ValueError("cannot pack null value") 179 177 180 178 packed_value = None … … 221 219 # contains the units 222 220 223 packed_value = truct.pack('>iib', *self.value)221 packed_value = struct.pack('>iib', *self.value) 224 222 225 223 elif self.tag == OctetStringTags.RANGE_OF_INTEGER: … … 291 289 return self.packed_value_size + 1 292 290 293 @property294 def pyobj(self):295 return (self.tag, self.value)296 297 291 def __str__(self): 298 292 return str(self.value) -
server/lib/gutenbach/server/printer.py
rce2abc5 rffbe41d 1 #import alsaaudio as aa2 1 from . import InvalidJobException, InvalidPrinterStateException 3 2 from . import Job … … 45 44 46 45 47 #def __init__(self, name, card, mixer):48 46 def __init__(self, name): 49 47 … … 52 50 self.time_created = int(time.time()) 53 51 self.state = "idle" 54 55 # if card >= len(aa.cards()):56 # raise aa.ALSAAudioError(57 # "Audio card at index %d does not exist!" % card)58 # elif mixer not in aa.mixers(card):59 # raise aa.ALSAAudioError(60 # "Audio mixer '%s' does not exist!" % mixer)61 62 # self.card = card63 # self.mixer = mixer64 52 65 53 self.finished_jobs = [] -
server/lib/gutenbach/server/requests.py
re58af05 rffbe41d 281 281 """ 282 282 283 284 283 operation = request.attribute_groups[0] 285 284 -
server/lib/gutenbach/server/server.py
re58af05 rffbe41d 79 79 chunk = self.rfile.read(size) 80 80 clrf = self.rfile.read(2) 81 assert clrf == "\r\n" 81 if clrf != "\r\n": 82 raise ipp.errors.ServerErrorInternalError( 83 "clrf != \\r\\n (is '%s')" % clrf) 82 84 tmp.write(chunk) 83 85
Note: See TracChangeset
for help on using the changeset viewer.