コード例 #1
0
ファイル: __init__.py プロジェクト: stevepiercy/deformdemo
def my_safe_repr(obj, context, maxlevels, level, sort_dicts=True):

    if type(obj) == unicode:
        obj = obj.encode("utf-8")

    # Python 3.8 changed the call signature of pprint._safe_repr.
    # by adding sort_dicts.
    if PY38MIN:
        return pprint._safe_repr(obj, context, maxlevels, level, sort_dicts)
    else:
        return pprint._safe_repr(obj, context, maxlevels, level)
コード例 #2
0
def _non_unicode_repr(objekt, context, maxlevels, level):
    """
    Used to override the pprint format method to get rid of unicode prefixes.

    E.g.: 'John' instead of u'John'.
    """
    if sys.version_info[0] == 3 and sys.version_info[1] >= 8:
        repr_string, isreadable, isrecursive = pprint._safe_repr(
            objekt, context, maxlevels, level, sort_dicts=None)
    else:
        repr_string, isreadable, isrecursive = pprint._safe_repr(
            objekt, context, maxlevels, level)
    if repr_string.startswith('u"') or repr_string.startswith("u'"):
        repr_string = repr_string[1:]
    return repr_string, isreadable, isrecursive
コード例 #3
0
def my_safe_repr(object, context, maxlevels, level):
    typ = pprint._type(object)
    if typ is unicode:
        r = 'u"%s"' % (object.encode("utf8").replace('"', r'\"'))
        return (r, True, False)
    else:
        return pprint._safe_repr(object, context, maxlevels, level)
コード例 #4
0
ファイル: katagami.py プロジェクト: chrono-meter/katagami.py
    def format(self, object, context, maxlevels, level):
        if isinstance(object, StringType):
            return py3_repr_str(object), True, False
        elif isinstance(object, BytesType):
            return py3_repr_bytes(object), True, False

        return pprint._safe_repr(object, context, maxlevels, level)
コード例 #5
0
ファイル: test_utils.py プロジェクト: sunliwen/poco
def my_safe_repr(object, context, maxlevels, level):
    typ = pprint._type(object)
    if typ is unicode:
        r = 'u"%s"' % (object.encode("utf8").replace('"', r'\"'))
        return (r, True, False)
    else:
        return pprint._safe_repr(object, context, maxlevels, level)
コード例 #6
0
ファイル: utils.py プロジェクト: mkmd/parking-demo
    def ascii_format(object_, context, maxlevels, level):
        typ = pprint._type(object_)
        if typ is unicode:
            object_ = str(object_).replace('"', '\\"')  # replace " to '
            rep = "\"%s\"" % object_  # repr(object_)
            return rep, (rep and not rep.startswith('<')), False

        return pprint._safe_repr(object_, context, maxlevels, level)
コード例 #7
0
    def ascii_format(object_, context, maxlevels, level):
        typ = pprint._type(object_)
        if typ is unicode:
            object_ = str(object_).replace('"', '\\"')  # replace " to '
            rep = "\"%s\"" % object_  # repr(object_)
            return rep, (rep and not rep.startswith('<')), False

        return pprint._safe_repr(object_, context, maxlevels, level)
コード例 #8
0
ファイル: cmd_info.py プロジェクト: saimn/doit
def my_safe_repr(obj, context, maxlevels, level):
    """pretty print supressing unicode prefix

    http://stackoverflow.com/questions/16888409/
           suppress-unicode-prefix-on-strings-when-using-pprint
    """
    typ = type(obj)
    if six.PY2 and typ is six.text_type:
        obj = str(obj)
    return pprint._safe_repr(obj, context, maxlevels, level)
コード例 #9
0
def my_safe_repr(obj, context, maxlevels, level):
    """pretty print supressing unicode prefix

    http://stackoverflow.com/questions/16888409/
           suppress-unicode-prefix-on-strings-when-using-pprint
    """
    typ = type(obj)
    if six.PY2 and typ is six.text_type:
        obj = str(obj)
    return pprint._safe_repr(obj, context, maxlevels, level)
コード例 #10
0
ファイル: commands.py プロジェクト: jmrinaldi/sacred
def non_unicode_repr(objekt, context, maxlevels, level):
    """
    Used to override the pprint format method to get rid of unicode prefixes.

    E.g.: 'John' instead of u'John'.
    """
    repr_string, isreadable, isrecursive = pprint._safe_repr(objekt, context,
                                                             maxlevels, level)
    if repr_string.startswith('u"') or repr_string.startswith("u'"):
        repr_string = repr_string[1:]
    return repr_string, isreadable, isrecursive
コード例 #11
0
def _non_unicode_repr(objekt, context, maxlevels, level):
    """
    Used to override the pprint format method to get rid of unicode prefixes.

    E.g.: 'John' instead of u'John'.
    """
    repr_string, isreadable, isrecursive = pprint._safe_repr(
        objekt, context, maxlevels, level)
    if repr_string.startswith('u"') or repr_string.startswith("u'"):
        repr_string = repr_string[1:]
    return repr_string, isreadable, isrecursive
コード例 #12
0
ファイル: tools_lib.py プロジェクト: wliustc/prom_notify
def format(_obj, context, maxlevels, level):
    if isinstance(_obj, bytes):
        #-#        return (repr(_obj.encode('utf8')) or "''", False, False)
        return (("'" + _obj.decode('utf8') + "'") or "''", False, False)
    if isinstance(_obj, str):
        if unquote(_obj) == _obj:
            return (repr(_obj) or "''", False, False)
        else:
            #-#            return (repr(unquote(_obj).decode('unicode-escape').encode('utf8')) or "''", False, False)
            #-#            return (("'" + unquote(_obj).decode('unicode-escape').encode('utf8') + "'") or "''", False, False)
            return (("'" + unquote(_obj) + "'") or "''", False, False)
    return pprint._safe_repr(_obj, context, maxlevels, level)
コード例 #13
0
ファイル: __init__.py プロジェクト: mvyskocil/pyckle
def dumps(obj):
    """Return serialized python object as a string

    :param obj: The python object to be serialized

    :return: String with serialized object
    
    WARNING/TODO: ``dumps`` just checks the object is not
    recursive via ``pprint.isreadable``, but does not
    impose any other limits
    """

    repr_string, isreadable, isrecursive = \
        _safe_repr(obj, {}, None, 0)

    if not isreadable:
        raise TypeError("'{}' is not readable".format(obj))

    return repr_string
コード例 #14
0
ファイル: utils.py プロジェクト: smurfix/pybble
	def format(self, object, context, maxlevels, level):
		typ = type(object)
		if typ in string_types:
			object = object.decode("utf-8")
		elif typ is _dt.datetime:
			return "DT( %s )"%(format_dt(object),),True,False
		elif typ is not unicode:
			return _safe_repr(object, context, maxlevels, level)

		if "'" in object and '"' not in object:
			closure = '"'
			quotes = {'"': '\\"'}
		else:
			closure = "'"
			quotes = {"'": "\\'"}
		qget = quotes.get
		sio = _StringIO()
		write = sio.write
		for char in object:
			if char.isalpha():
				write(char)
			else:
				write(qget(char, repr(char)[2:-1]))
		return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
コード例 #15
0
ファイル: utils.py プロジェクト: smurfix/pybble
    def format(self, object, context, maxlevels, level):
        typ = type(object)
        if typ in string_types:
            object = object.decode("utf-8")
        elif typ is _dt.datetime:
            return "DT( %s )" % (format_dt(object), ), True, False
        elif typ is not unicode:
            return _safe_repr(object, context, maxlevels, level)

        if "'" in object and '"' not in object:
            closure = '"'
            quotes = {'"': '\\"'}
        else:
            closure = "'"
            quotes = {"'": "\\'"}
        qget = quotes.get
        sio = _StringIO()
        write = sio.write
        for char in object:
            if char.isalpha():
                write(char)
            else:
                write(qget(char, repr(char)[2:-1]))
        return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
コード例 #16
0
def my_safe_repr(object, context, maxlevels, level):
    if type(object) == unicode:
        object = object.encode("utf-8")
    return pprint._safe_repr(object, context, maxlevels, level)
コード例 #17
0
ファイル: simplexSplitter.py プロジェクト: iVerb/Simplex
def pprintFormatter(thing, context, maxlevels, level):
    typ = pprint._type(thing)
    if typ is unicode:
        thing = str(thing)
    return pprint._safe_repr(thing, context, maxlevels, level)
コード例 #18
0
def format_print(object, context, maxlevels, level):
    typ = pprint._type(object)
    if typ is unicode:
        object = str(object)
    return pprint._safe_repr(object, context, maxlevels, level)
コード例 #19
0
def my_safe_repr(object, context, maxlevels, level):
	typ = pprint._type(object)
	if typ is unicode:
		object = str(object)
	return pprint._safe_repr(object, context, maxlevels, level)
 def de_unicode(object, context, maxlevels, level):
     if pprint._type(object) is unicode: object = str(object)
     return pprint._safe_repr(object, context, maxlevels, level)
コード例 #21
0
ファイル: misc.py プロジェクト: dingtaocpp/VimLite
 def format(self, object, context, maxlevels, level):
     """Format un object."""
     unused = self
     if type(object) is str:
         return "'" + str(object) + "'", True, False
     return pprint._safe_repr(object, context, maxlevels, level)
コード例 #22
0
ファイル: misc.py プロジェクト: zhonli/vim_pyclewn
 def format(self, object, context, maxlevels, level):
     """Format un object."""
     if isinstance(object, text_type):
         return "'" + str(object) + "'", True, False
     return pprint._safe_repr(object, context, maxlevels, level)
コード例 #23
0
ファイル: collector.py プロジェクト: wuyou33/nsgaiii
def my_safe_repr(object, context, maxlevels, level):
    typ = pprint._type(object)
    if typ is unicode:
        object = str(object.encode('utf-8'))
    return pprint._safe_repr(object, context, maxlevels, level)
コード例 #24
0
def suppress_unicode_repr(object, context, maxlevels, level):
    typ = pprint._type(object)
    if typ is unicode:
        object = str(object)
    return pprint._safe_repr(object, context, maxlevels, level)
コード例 #25
0
ファイル: nodes.py プロジェクト: xxoolm/Ryven
 def update_event(self, inp=-1):
     self.set_output_val(
         0,
         pprint._safe_repr(self.input(0), self.input(1), self.input(2),
                           self.input(3), self.input(4)))
コード例 #26
0
ファイル: awshelpers.py プロジェクト: RamanaK/aws
def no_unicode(object, context, maxlevels, level):
    """ change unicode u'foo' to string 'foo' when pretty printing"""
    if pprint._type(object) is unicode:
        object = str(object)
    return pprint._safe_repr(object, context, maxlevels, level)
コード例 #27
0
def no_unicode(object, context, maxlevels, level):
    """ change unicode u'foo' to string 'foo' when pretty printing"""
    if pprint._type(object) is unicode:
        object = str(object)
    return pprint._safe_repr(object, context, maxlevels, level)
コード例 #28
0
ファイル: misc.py プロジェクト: Skip/vim
 def format(self, object, context, maxlevels, level):
     """Format un object."""
     unused = self
     if type(object) is str:
         return "'" + str(object) + "'", True, False
     return pprint._safe_repr(object, context, maxlevels, level)
コード例 #29
0
ファイル: helpers.py プロジェクト: Ryan-Holben/OKC
def concat(object, context, maxlevels, level):
    """ Concatenate any string which pprint displays.  This is recursive, so it also should apply to dictionary keys and values, for example."""
    if pprint._type(object) is (unicode or str):
        if len(object) > pprint_concatenation_length:
            object = object[:pprint_concatenation_length] + '...'
    return pprint._safe_repr(object, context, maxlevels, level)
コード例 #30
0
 def nice_repr(object, context, maxlevels, level):
     if sys.version_info.major < 3:
         typ = type(object)
         if typ is unicode:
             object = object.encode("utf-8")
     return pprint._safe_repr(object, context, maxlevels, level)
コード例 #31
0
ファイル: misc.py プロジェクト: tracyone/pyclewn_linux
 def format(self, object, context, maxlevels, level):
     """Format un object."""
     if isinstance(object, text_type):
         return "'" + str(object) + "'", True, False
     return pprint._safe_repr(object, context, maxlevels, level)