Browse Source

make printing ctype arrays pretty.

Slightly buggy in that it assumes all arrays are numbers though..
blinkled
John-Mark Gurney 2 years ago
parent
commit
415e650c69
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      syote_comms.py

+ 9
- 2
syote_comms.py View File

@@ -25,14 +25,21 @@
import os import os
import unittest import unittest


from ctypes import Structure, POINTER, CFUNCTYPE, pointer, sizeof from ctypes import Array, Structure, POINTER, CFUNCTYPE, pointer, sizeof
from ctypes import c_uint8, c_uint16, c_ssize_t, c_size_t, c_uint64, c_int from ctypes import c_uint8, c_uint16, c_ssize_t, c_size_t, c_uint64, c_int
from ctypes import CDLL from ctypes import CDLL


class StructureRepr(object): class StructureRepr(object):
@staticmethod
def __specialrepr(obj):
if isinstance(obj, Array):
return '[ %s ]' % ', '.join(hex(x) for x in obj)

return repr(obj)

def __repr__(self): #pragma: no cover def __repr__(self): #pragma: no cover
return '%s(%s)' % (self.__class__.__name__, ', '.join('%s=%s' % return '%s(%s)' % (self.__class__.__name__, ', '.join('%s=%s' %
(k, getattr(self, k)) for k, v in self._fields_)) (k, self.__specialrepr(getattr(self, k))) for k, v in self._fields_))


class PktBuf(Structure): class PktBuf(Structure):
_fields_ = [ _fields_ = [


||||||
x
 
000:0
Loading…
Cancel
Save