Changeset 5746

Show
Ignore:
Timestamp:
07/29/10 20:38:42 (3 years ago)
Author:
kosma
Message:

fix str to return strings, not print them

Location:
umpa/branches/link-layer-integration/umit/umpa
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • umpa/branches/link-layer-integration/umit/umpa/_packets.py

    r5601 r5746  
    123123        """ 
    124124 
    125         print "Packet contains %d protocols" % len(self.protos) 
    126         for proto in self.protos: 
    127             print proto 
    128         return super(Packet, self).__str__() 
     125        info = [] 
     126        info.append("Packet contains %d protocols" % len(self.protos)) 
     127        info.extend([ str(proto) for proto in self.protos ]) 
     128        info.append(super(Packet, self).__str__()) 
     129 
     130        return "\n".join(info) 
    129131 
    130132    def include(self, *protos): 
  • umpa/branches/link-layer-integration/umit/umpa/protocols/_fields.py

    r5170 r5746  
    652652        """ 
    653653 
    654         print "| +-[ %-25s ]\t%s" % (self.name, self._shortname) 
    655         print "| | \\" 
    656         for bit in self._ordered_fields: 
    657             print self._value[bit] 
    658         print "| | /" 
    659         return "| \\-[ %-25s ]\tcontains %d bit flags" % (self.name, 
    660                                                     len(self._ordered_fields)) 
     654        info = [] 
     655 
     656        info.append("| +-[ %-25s ]\t%s" % (self.name, self._shortname)) 
     657        info.append("| | \\") 
     658        info.extend([ str(self._value[bit]) for bit in self._ordered_fields ]) 
     659        info.append("| | /") 
     660        info.append("| \\-[ %-25s ]\tcontains %d bit flags" % 
     661                                       (self.name, len(self._ordered_fields))) 
     662 
     663        return "\n".join(info) 
    661664 
    662665    def get(self, *names): 
  • umpa/branches/link-layer-integration/umit/umpa/protocols/_protocols.py

    r5170 r5746  
    111111        """ 
    112112 
    113         print "+-< %-27s >" % self.name 
    114         print "| \\" 
    115         for field in self.get_fields(): 
    116             print field 
    117         print "\\-< %-27s >\tcontains %d fields" % (self.name, 
    118                                                             len(self._fields)) 
    119         return super(Protocol, self).__str__() 
     113        info = [] 
     114        info.append("+-< %-27s >" % self.name) 
     115        info.append("| \\") 
     116        info.extend([ str(field) for field in self.get_fields() ]) 
     117        info.append("\\-< %-27s >\tcontains %d fields" % (self.name, len(self._fields))) 
     118        info.append(super(Protocol, self).__str__()) 
     119 
     120        return "\n".join(info) 
    120121 
    121122    def _is_valid(self, field):