Ignore:
Timestamp:
Jan 10, 2012, 7:25:33 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
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)
Message:

Clean up core ipp code a bit

File:
1 edited

Legend:

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

    r793432f rffbe41d  
    5959        """
    6060
    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")
    6463        if values is None:
    6564            values = []
    6665        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,))
    6968
    7069        self.name = name
     
    8382        """
    8483
    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"
    8988
    9089        # get the binary data for all the values
     
    9493            # get the name length (0 for everything but the first
    9594            # 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
    10096
    10197            logger.debug("dumping name : %s" % self.name)
     
    113109            # the value tag in binary
    114110            tag_bin = struct.pack('>b', v.tag)
    115 
    116111            # the name length in binary
    117112            name_length_bin = struct.pack('>h', name_length)
    118 
    119113            # the name in binary
    120114            name_bin = self.name
    121 
    122115            # the value length in binary
    123116            value_length_bin = struct.pack('>h', value_length)
    124117
     118            # add the binary value to the list of values
     119            vlist = [tag_bin, name_length_bin, value_length_bin, value_bin]
    125120            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))
    136123
    137124        # concatenate everything together and return it along with the
Note: See TracChangeset for help on using the changeset viewer.