Пример #1
0
 def test_input(self):
     assert hexdump(
         "A"
     ) == "41                              -                                 A\n"
     assert hexdump(
         "ÑaB"
     ) == "c3 91 61 42                     -                                 ..aB\n"
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 def test_empty_imput(self):
     assert hexdump("") == ""
Пример #5
0
 def test_input(self):
     assert hexdump("A") == "41                              -                                 A\n"
     assert hexdump("ÑaB") == "c3 91 61 42                     -                                 ..aB\n"
Пример #6
0
 def test_empty_imput(self):
     assert hexdump("") == ""