예제 #1
0
파일: _struct.py 프로젝트: bwoodsend/cslug
def struct_repr(self):
    """

    :type self: ctypes.Structure
    """
    params = [
        "{}={}".format(i[0], repr(getattr(self, i[0]))) for i in self._fields_
    ]

    chunks = []
    for param in params[:-1]:
        chunks.append(param)
        chunks.append(",")
        chunks.append(" ")
    if params:
        chunks.append(params[-1])
    chunks.append(")")

    name = type(self).__name__

    wrapper = TextWrapper(initial_indent=name + "(",
                          subsequent_indent=" " * (len(name) + 1))

    lines = wrapper._wrap_chunks(chunks)
    if len(lines) > 1:
        return "\n".join(lines) + "\n"
    return lines[0]
예제 #2
0
 def _wrap_chunks(self, *args, **kwargs):
     # the following doesn't work somehow (likely because of future??)
     # lines = super(InventoryTextWrapper, self)._wrap_chunks(
     #     *args, **kwargs)
     lines = TextWrapper._wrap_chunks(self, *args, **kwargs)
     lines = [re.sub(r'([\b\s]+), (.*)', r'\1\2', line, count=1)
              for line in lines]
     return lines