Ejemplo n.º 1
0
 def repr_str(self, x, level):
     s = builtins.repr(x[:self.maxstring])
     if len(s) > self.maxstring:
         i = max(0, (self.maxstring-3)//2)
         j = max(0, self.maxstring-3-i)
         s = builtins.repr(x[:i] + x[len(x)-j:])
         s = s[:i] + '...' + s[len(s)-j:]
     return s
Ejemplo n.º 2
0
 def repr_str(self, x, level):
     s = builtins.repr(x[:self.maxstring])
     if len(s) > self.maxstring:
         i = max(0, (self.maxstring - 3) // 2)
         j = max(0, self.maxstring - 3 - i)
         s = builtins.repr(x[:i] + x[len(x) - j:])
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 3
0
    def repr_bytes(self, x, _level):
        """For bytes object type

        Stock method used for bytes had first step 'repr(x)' which was
            way too slow.

        Using repr_str from python source as a template.
        """
        str_rep = builtins.repr(x[:self.maxbytes])
        if len(str_rep) > self.maxbytes:
            i = max(0, (self.maxbytes - 3) // 2)
            j = max(0, self.maxbytes - 3 - i)
            str_rep = builtins.repr(x[:i] + x[len(x) - j:])
            str_rep = str_rep[:i] + '...' + str_rep[len(str_rep) - j:]
        return str_rep
Ejemplo n.º 4
0
 def repr_int(self, x, level):
     s = builtins.repr(x)
     if len(s) > self.maxlong:
         i = max(0, (self.maxlong - 3) // 2)
         j = max(0, self.maxlong - 3 - i)
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 5
0
def repr(obj, htchar=' ', lfchar='\n', indent=4, basic_offset=0):
    '''A |builtin.repr|_ replacement function for debugging purposes printing
    all object attributes recursively.

    This function does not follow the standard |builtin.repr|_ convention, but
    it prints each object as a set of key/value pairs along with its memory
    location. It also keeps track of the already visited objects, and
    abbreviates their representation.

    :arg obj: The object to be dumped.
        For the rest of the arguments, see :func:`ppretty`.
    :returns: The formatted object dump.

    .. _builtin.repr: https://docs.python.org/3/library/functions.html#repr
    .. |builtin.repr| replace:: :js:func:`repr()`

    '''
    if (isinstance(obj, list) or isinstance(obj, tuple)
            or isinstance(obj, set) or isinstance(obj, dict)):
        return ppretty(obj, basic_offset=basic_offset, repr=repr)

    if not hasattr(obj, '__dict__'):
        return builtins.repr(obj)

    r = ppretty(obj.__dict__, htchar, lfchar, indent, basic_offset, repr)
    return f'{type(obj).__name__}({r})@{hex(id(obj))}'
Ejemplo n.º 6
0
 def repr_int(self, x, level):
     s = builtins.repr(x)
     if len(s) > self.maxlong:
         i = max(0, (self.maxlong - 3)//2)
         j = max(0, self.maxlong - 3 - i)
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 7
0
 def repr_int(self, x, level):
     s = builtins.repr(x) # XXX Hope this isn't too slow...
     if len(s) > self.maxlong:
         i = max(0, (self.maxlong-3)//2)
         j = max(0, self.maxlong-3-i)
         s = s[:i] + '...' + s[len(s)-j:]
     return s
Ejemplo n.º 8
0
 def repr_instance(self, x, level):
     s = builtins.repr(x)
     if len(s) > self.maxother:
         i = max(0, (self.maxother - 3) // 2)
         j = max(0, self.maxother - 3 - i)
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 9
0
 def repr_int(self, x, level):
     s = builtins.repr(x)  # XXX Hope this isn't too slow...
     if len(s) > self.maxlong:
         i = max(0, (self.maxlong - 3) // 2)
         j = max(0, self.maxlong - 3 - i)
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 10
0
def repr(obj, indent=4, max_depth=2):
    """Return a generic representation string for object `obj`.

    Keyword arguments:
    indent -- indentation width
    max_depth -- maximum depth for expanding nested objects
    """
    if not hasattr(obj, '__dict__'):
        # Delegate to the builtin repr() for builtin types
        return builtins.repr(obj)

    tid = _gettid()
    indent_width = _increase_indent() * indent

    # Attribute representation
    if _depth[tid] == max_depth:
        attr_list = ['...']
    else:
        attr_list = ['{0}={1}'.format(attr, val)
                     for attr, val in sorted(obj.__dict__.items())]

    repr_fmt = '{module_name}.{class_name}({attr_repr})@0x{addr:x}'
    ret = repr_fmt.format(module_name=obj.__module__,
                          class_name=type(obj).__name__,
                          attr_repr=', '.join(attr_list),
                          addr=id(obj))
    _decrease_indent()
    return ret
Ejemplo n.º 11
0
 def repr_instance(self, x, level):
     try:
         s = builtins.repr(x)
     except Exception:
         return '<%s instance at %x>' % (x.__class__.__name__, id(x))
     if len(s) > self.maxother:
         i = max(0, (self.maxother - 3) // 2)
         j = max(0, self.maxother - 3 - i)
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 12
0
 def repr_instance(self, x, level):
     try:
         s = builtins.repr(x)
     except Exception:
         return '<%s instance at %x>' % (x.__class__.__name__, id(x))
     if len(s) > self.maxother:
         i = max(0, (self.maxother - 3)//2)
         j = max(0, self.maxother - 3 - i)
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 13
0
 def key_pressed(self, event):
     key = builtins.repr(event.char)
     if key in self.commands:
         self.matrix = self.commands[key](self.matrix)
         if self.done:
             self.matrix = self.add_element()
             self.update_cells()
             self.done = False
     else:
         print('Please use arrow keys')
Ejemplo n.º 14
0
def repr(obj, htchar=' ', lfchar='\n', indent=4, basic_offset=0):
    '''A debug repr() function printing all object attributes recursively'''
    if (isinstance(obj, list) or isinstance(obj, tuple)
            or isinstance(obj, set) or isinstance(obj, dict)):
        return ppretty(obj, basic_offset=basic_offset, repr=repr)

    if not hasattr(obj, '__dict__'):
        return builtins.repr(obj)

    r = ppretty(obj.__dict__, htchar, lfchar, indent, basic_offset, repr)
    return f'{type(obj).__name__}({r})@{hex(id(obj))}'
Ejemplo n.º 15
0
 def repr_instance(self, x, level):
     try:
         s = builtins.repr(x)
         # Bugs in x.__repr__() can cause arbitrary
         # exceptions -- then make up something
     except Exception:
         return '<%s instance at %#x>' % (x.__class__.__name__, id(x))
     if len(s) > self.maxother:
         i = max(0, (self.maxother - 3) // 2)
         j = max(0, self.maxother - 3 - i)
         s = s[:i] + '...' + s[len(s) - j:]
     return s
Ejemplo n.º 16
0
def repr (any):
	def getNumAlphaKey (key):
		if type (key) == str:
			return key
		else:
			return str (1e10 + key)
			
	if type (any) == dict:	
		return '{' + ', '.join ([
			'{}: {}'.format (builtins.repr (key), builtins.repr (any [key]))
			for index, key in enumerate (sorted (any, key = getNumAlphaKey))
		]) + '}'
	elif type (any) == set:
		if any:
			return '{' + ', '.join ([str (item) for item in sorted (list (any))]) + '}'
		else:
			return builtins.repr (any)
	elif type (any) == range:
		return builtins.repr (list (any))
	else:
		return builtins.repr (any)
Ejemplo n.º 17
0
 def repr_instance(self, x, level):
     try:
         s = builtins.repr(x)
         # Bugs in x.__repr__() can cause arbitrary
         # exceptions -- then make up something
     except Exception:
         return '<%s instance at %#x>' % (x.__class__.__name__, id(x))
     if len(s) > self.maxother:
         i = max(0, (self.maxother-3)//2)
         j = max(0, self.maxother-3-i)
         s = s[:i] + '...' + s[len(s)-j:]
     return s
Ejemplo n.º 18
0
def repr(any):
    def getNumAlphaKey(key):
        if type(key) == str:
            return key
        else:
            return str(1e10 + key)

    if type(any) == dict:
        return '{' + ', '.join([
            '{}: {}'.format(builtins.repr(key), builtins.repr(any[key]))
            for index, key in enumerate(sorted(any, key=getNumAlphaKey))
        ]) + '}'
    elif type(any) == set:
        if any:
            return '{' + ', '.join([str(item)
                                    for item in sorted(list(any))]) + '}'
        else:
            return builtins.repr(any)
    elif type(any) == range:
        return builtins.repr(list(any))
    else:
        return builtins.repr(any)
Ejemplo n.º 19
0
    def repr_DataFrame(self, obj: DataFrame, level: int) -> str:  # noqa: N802
        """Create a :class:`str` representation of a :class:`pandas.DataFrame` instance."""
        if level <= 0:
            return f'{obj.__class__.__name__}(...)'

        kwargs = {
            'display.max_rows': self.maxDataFrame,
            'display.max_columns': self.maxDataFrame // 2
        }
        kwargs.update(self.pd_printoptions)
        args = chain.from_iterable(kwargs.items())

        with pd.option_context(*args):
            return builtins.repr(obj)
Ejemplo n.º 20
0
    def repr_ndarray(self, obj: ndarray, level: int) -> str:
        """Create a :class:`str` representation of a :class:`numpy.ndarray` instance."""
        if level <= 0:
            return f'{obj.__class__.__name__}(...)'

        kwargs: _FormatOptions = {
            'threshold': self.maxndarray,
            'edgeitems': self.maxndarray // 2,
            'formatter': self._get_ndformatter(obj),
        }
        kwargs.update(self.np_printoptions)

        with np.printoptions(**kwargs):
            return builtins.repr(obj)
Ejemplo n.º 21
0
    def repr_Series(self, obj: Series, level: int) -> str:  # noqa: N802
        """Create a :class:`str` representation of a :class:`pandas.Series` instance."""
        if PANDAS_EX is not None:
            raise PANDAS_EX

        if level <= 0:
            return f'{obj.__class__.__name__}(...)'

        kwargs = {'display.max_rows': self.maxSeries}
        kwargs.update(self.pd_printoptions)
        args = chain.from_iterable(kwargs.items())

        with pd.option_context(*args):
            return builtins.repr(obj)
Ejemplo n.º 22
0
 def repr1(self, x, level):
     typename = type(x).__name__
     if ' ' in typename:
         parts = typename.split()
         typename = '_'.join(parts)
     if hasattr(self, 'repr_' + typename):
         return getattr(self, 'repr_' + typename)(x, level)
     else:
         s = builtins.repr(x)
         if len(s) > self.maxother:
             i = max(0, (self.maxother - 3) // 2)
             j = max(0, self.maxother - 3 - i)
             s = s[:i] + '...' + s[len(s) - j:]
         return s
Ejemplo n.º 23
0
pow = functools.update_wrapper(
    lambda *args, **kwargs: builtins.pow(*args, **kwargs), builtins.pow)
pow._ = functools.update_wrapper(
    lambda *args, **kwargs: wrap(builtins.pow)(*args, **kwargs), builtins.pow)
print = functools.update_wrapper(
    lambda *args, **kwargs: builtins.print(*args, **kwargs), builtins.print)
print._ = functools.update_wrapper(
    lambda *args, **kwargs: wrap(builtins.print)(*args, **kwargs),
    builtins.print)
range = functools.update_wrapper(
    lambda *args, **kwargs: builtins.range(*args, **kwargs), builtins.range)
range._ = functools.update_wrapper(
    lambda *args, **kwargs: wrap(builtins.range)(*args, **kwargs),
    builtins.range)
repr = functools.update_wrapper(
    lambda *args, **kwargs: builtins.repr(*args, **kwargs), builtins.repr)
repr._ = functools.update_wrapper(
    lambda *args, **kwargs: wrap(builtins.repr)(*args, **kwargs),
    builtins.repr)
reversed = functools.update_wrapper(
    lambda *args, **kwargs: builtins.reversed(*args, **kwargs),
    builtins.reversed)
reversed._ = functools.update_wrapper(
    lambda *args, **kwargs: wrap(builtins.reversed)(*args, **kwargs),
    builtins.reversed)
round = functools.update_wrapper(
    lambda *args, **kwargs: builtins.round(*args, **kwargs), builtins.round)
round._ = functools.update_wrapper(
    lambda *args, **kwargs: wrap(builtins.round)(*args, **kwargs),
    builtins.round)
set = functools.update_wrapper(
Ejemplo n.º 24
0
def test(got, expected):
    if got == expected:
        prefix = ' OK '
    else:
        prefix = '  X '
    print('%s got: %s expected: %s' % (prefix, repr(got), repr(expected)))
Ejemplo n.º 25
0
    def get_calibration(self):
        print('__AC1: ' + repr(self.__AC1))
        print('__AC2: ' + repr(self.__AC2))
        print('__AC3: ' + repr(self.__AC3))
        print('__AC4: ' + repr(self.__AC4))
        print('__AC5: ' + repr(self.__AC5))
        print('__AC6: ' + repr(self.__AC6))

        print('__B1: ' + repr(self.__B1))
        print('__B2: ' + repr(self.__B2))

        print('__MB: ' + repr(self.__MB))
        print('__MC: ' + repr(self.__MC))
        print('__MD: ' + repr(self.__MD))
Ejemplo n.º 26
0
 def __repr__(self):
     return "Post(body='{}', author={})".format(self.body,
                                                repr(self.author))
Ejemplo n.º 27
0
 def __repr__(self):
     vals = self.__data.keys()
     if not vals:
         return type(self).__name__ + '()'
     else:
         return '{' + ', '.join(builtins.repr(v) for v in vals) + '}'
Ejemplo n.º 28
0
def repr(obj):
    if isinstance(obj, ExcelType.Object):
        return str(obj)
    else:
        return builtins.repr(obj)