本文整理汇总了Python中reprlib.repr方法的典型用法代码示例。如果您正苦于以下问题:Python reprlib.repr方法的具体用法?Python reprlib.repr怎么用?Python reprlib.repr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reprlib
的用法示例。
在下文中一共展示了reprlib.repr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __str__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def __str__(self, indentation="\n"):
"""print(Email(**args)) method.
Indentation value can be overridden in the function call.
The default is new line"""
return (
"{}From: {}"
"{}To: {}"
"{}Body: {}"
"{}Attachments: {}"
"{}SID: {}".format(
indentation,
self.from_,
indentation,
self.to,
indentation,
reprlib.repr(self.body),
indentation,
self.attachments,
indentation,
self.sid,
)
)
示例2: __str__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def __str__(self, indentation="\n"):
"""print(Telegram(**args)) method.
Indentation value can be overridden in the function call.
The default is new line"""
return (
"{}From: {}"
"{}To: {}"
"{}Chat ID: {}"
"{}Subject: {}"
"{}Body: {}"
"{}Attachments: {}".format(
indentation,
self.from_,
indentation,
self.to,
indentation,
self.chat_id,
indentation,
self.subject,
indentation,
reprlib.repr(self.body),
indentation,
self.attachments,
)
)
示例3: __str__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def __str__(self, indentation="\n"):
"""print(SlackWebhook(**args)) method.
Indentation value can be overridden in the function call.
The default is new line"""
return (
"{}URL: {}"
"{}From: {}"
"{}Subject: {}"
"{}Body: {}"
"{}Attachments: {}".format(
indentation,
self.url,
indentation,
self.from_ or "Not Specified",
indentation,
self.subject,
indentation,
reprlib.repr(self.body),
indentation,
self.attachments,
)
)
示例4: _repr_info
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def _repr_info(self):
info = [self._state.lower()]
if self._state == _FINISHED:
if self._exception is not None:
info.append('exception={!r}'.format(self._exception))
else:
# use reprlib to limit the length of the output, especially
# for very long strings
result = reprlib.repr(self._result)
info.append('result={}'.format(result))
if self._callbacks:
info.append(self.__format_callbacks())
if self._source_traceback:
frame = self._source_traceback[-1]
info.append('created at %s:%s' % (frame[0], frame[1]))
return info
示例5: _format_callback
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def _format_callback(func, args, suffix=''):
if isinstance(func, functools.partial):
if args is not None:
suffix = _format_args(args) + suffix
return _format_callback(func.func, func.args, suffix)
if hasattr(func, '__qualname__'):
func_repr = getattr(func, '__qualname__')
elif hasattr(func, '__name__'):
func_repr = getattr(func, '__name__')
else:
func_repr = repr(func)
if args is not None:
func_repr += _format_args(args)
if suffix:
func_repr += suffix
return func_repr
示例6: trace_dispatch
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def trace_dispatch(self, frame, event, arg):
if self.quitting:
return # None
if event == 'line':
return self.dispatch_line(frame)
if event == 'call':
return self.dispatch_call(frame, arg)
if event == 'return':
return self.dispatch_return(frame, arg)
if event == 'exception':
return self.dispatch_exception(frame, arg)
if event == 'c_call':
return self.trace_dispatch
if event == 'c_exception':
return self.trace_dispatch
if event == 'c_return':
return self.trace_dispatch
print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
return self.trace_dispatch
示例7: _future_repr_info
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def _future_repr_info(future):
# (Future) -> str
"""helper function for Future.__repr__"""
info = [future._state.lower()]
if future._state == _FINISHED:
if future._exception is not None:
info.append(f'exception={future._exception!r}')
else:
# use reprlib to limit the length of the output, especially
# for very long strings
result = reprlib.repr(future._result)
info.append(f'result={result}')
if future._callbacks:
info.append(_format_callbacks(future._callbacks))
if future._source_traceback:
frame = future._source_traceback[-1]
info.append(f'created at {frame[0]}:{frame[1]}')
return info
示例8: _format_callback
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def _format_callback(func, args, kwargs, suffix=''):
if isinstance(func, functools.partial):
suffix = _format_args_and_kwargs(args, kwargs) + suffix
return _format_callback(func.func, func.args, func.keywords, suffix)
if hasattr(func, '__qualname__') and func.__qualname__:
func_repr = func.__qualname__
elif hasattr(func, '__name__') and func.__name__:
func_repr = func.__name__
else:
func_repr = repr(func)
func_repr += _format_args_and_kwargs(args, kwargs)
if suffix:
func_repr += suffix
return func_repr
示例9: _repr_info
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def _repr_info(self):
info = [self._state.lower()]
if self._state == _FINISHED:
if self._exception is not None:
info.append('exception={!r}'.format(self._exception))
else:
# use reprlib to limit the length of the output, especially
# for very long strings
result = reprlib.repr(self._result)
info.append('result={}'.format(result))
if self._callbacks:
info.append(self._format_callbacks())
if self._source_traceback:
frame = self._source_traceback[-1]
info.append('created at %s:%s' % (frame[0], frame[1]))
return info
示例10: _format_callback
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def _format_callback(func, args, suffix=''):
if isinstance(func, functools.partial):
if args is not None:
suffix = _format_args(args) + suffix
return _format_callback(func.func, func.args, suffix)
func_repr = getattr(func, '__qualname__', None)
if not func_repr:
func_repr = repr(func)
if args is not None:
func_repr += _format_args(args)
if suffix:
func_repr += suffix
source = _get_function_source(func) # 获取方法源
if source:
func_repr += ' at %s:%s' % source
return func_repr
示例11: _format_callback
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def _format_callback(func, args, kwargs, suffix=''):
if isinstance(func, functools.partial):
suffix = _format_args_and_kwargs(args, kwargs) + suffix
return _format_callback(func.func, func.args, func.keywords, suffix)
if hasattr(func, '__qualname__'):
func_repr = getattr(func, '__qualname__')
elif hasattr(func, '__name__'):
func_repr = getattr(func, '__name__')
else:
func_repr = repr(func)
func_repr += _format_args_and_kwargs(args, kwargs)
if suffix:
func_repr += suffix
return func_repr
示例12: execute
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def execute(self, operation, parameters=None):
self._current_response, self._iterator, self._paging_state = None, None, None
execute_statement_args = dict(self._prepare_execute_args(operation),
includeResultMetadata=True)
if parameters:
execute_statement_args["parameters"] = self._format_parameter_set(parameters)
logger.debug("execute %s", reprlib.repr(operation.strip()))
try:
res = self._client.execute_statement(**execute_statement_args)
if "columnMetadata" in res:
self._set_description(res["columnMetadata"])
self._current_response = self._render_response(res)
except self._client.exceptions.BadRequestException as e:
if "Please paginate your query" in str(e):
self._start_paginated_query(execute_statement_args)
elif "Database response exceeded size limit" in str(e):
self._start_paginated_query(execute_statement_args, records_per_page=max(1, self.arraysize // 2))
else:
raise self._get_database_error(e) from e
self._iterator = iter(self)
示例13: total_size
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def total_size(o, handlers={}, verbose=False):
""" Returns the approximate memory footprint an object and all of its contents.
Automatically finds the contents of the following builtin containers and
their subclasses: tuple, list, deque, dict, set and frozenset.
To search other containers, add handlers to iterate over their contents:
handlers = {SomeContainerClass: iter,
OtherContainerClass: OtherContainerClass.get_elements}
"""
dict_handler = lambda d: chain.from_iterable(d.items())
all_handlers = {tuple: iter,
list: iter,
deque: iter,
dict: dict_handler,
set: iter,
frozenset: iter,
}
all_handlers.update(handlers) # user handlers take precedence
seen = set() # track which object id's have already been seen
default_size = getsizeof(0) # estimate sizeof object without __sizeof__
def sizeof(o):
if id(o) in seen: # do not double count the same object
return 0
seen.add(id(o))
s = getsizeof(o, default_size)
if verbose:
print(s, type(o), repr(o), file=stderr)
for typ, handler in all_handlers.items():
if isinstance(o, typ):
s += sum(map(sizeof, handler(o)))
break
return s
return sizeof(o)
示例14: __str__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def __str__(self):
return f'{self.tag}, {_r(self.value)}, {self.type}, {self.error}'
示例15: __repr__
# 需要导入模块: import reprlib [as 别名]
# 或者: from reprlib import repr [as 别名]
def __repr__(self):
return f'{self.__class__.__name__}({self.data_type!r}, {_r(self.value)}, {self.service_status!r})'