def test_input(self): assert hexdump( "A" ) == "41 - A\n" assert hexdump( "ÑaB" ) == "c3 91 61 42 - ..aB\n"
def __format_rst(self, obj, hyperlinks = False, width = 70): if hyperlinks: return "\n".join("`ID: %s`_" % x for x in obj) if isinstance(obj, basestring): obj = str(obj) if any(ord(c) > 127 for c in obj): obj = hexdump(obj) elif width: obj = "\n".join(wrap(obj, width, replace_whitespace=False, expand_tabs=False, drop_whitespace=False)) return self.__escape_rst(obj) if ( (isinstance(obj, list) or isinstance(obj, tuple)) and all(isinstance(x, basestring) for x in obj) ): return "\n".join("- " + self.__escape_rst( to_utf8(x) if isinstance(x, basestring) else pformat(x) ) for x in obj) if isinstance(obj, dict): return "\n".join( self.__escape_rst("%s: %s" % (k,v)) for k,v in obj.iteritems()) try: text = str(obj) except Exception: text = pformat(obj) return self.__escape_rst(text)
def __format_rst(self, obj, hyperlinks=False, width=70): if hyperlinks: return "\n".join("`ID: %s`_" % x for x in obj) if isinstance(obj, basestring): obj = str(obj) if any(ord(c) > 127 for c in obj): obj = hexdump(obj) elif width: obj = "\n".join( wrap(obj, width, replace_whitespace=False, expand_tabs=False, drop_whitespace=False)) return self.__escape_rst(obj) if ((isinstance(obj, list) or isinstance(obj, tuple)) and all(isinstance(x, basestring) for x in obj)): return "\n".join("- " + self.__escape_rst(pformat(x)) for x in obj) if isinstance(obj, dict): return "\n".join( self.__escape_rst("%s: %s" % (k, v)) for k, v in obj.iteritems()) try: text = str(obj) except Exception: text = pformat(obj) return self.__escape_rst(text)
def test_empty_imput(self): assert hexdump("") == ""
def test_input(self): assert hexdump("A") == "41 - A\n" assert hexdump("ÑaB") == "c3 91 61 42 - ..aB\n"