Browse Source

make printing ctype arrays pretty.

Slightly buggy in that it assumes all arrays are numbers though..
main
John-Mark Gurney 1 year ago
parent
commit
f0945ec93a
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 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 CDLL

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
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):
_fields_ = [


Loading…
Cancel
Save