本文整理汇总了Python中inspect.cleandoc方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.cleandoc方法的具体用法?Python inspect.cleandoc怎么用?Python inspect.cleandoc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inspect
的用法示例。
在下文中一共展示了inspect.cleandoc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_command
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def _make_command(f, name, attrs, cls):
if isinstance(f, Command):
raise TypeError('Attempted to convert a callback into a '
'command twice.')
try:
params = f.__click_params__
params.reverse()
del f.__click_params__
except AttributeError:
params = []
help = attrs.get('help')
if help is None:
help = inspect.getdoc(f)
if isinstance(help, bytes):
help = help.decode('utf-8')
else:
help = inspect.cleandoc(help)
attrs['help'] = help
_check_for_unicode_literals()
return cls(name=name or f.__name__.lower().replace('_', '-'),
callback=f, params=params, **attrs)
示例2: option
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def option(*param_decls, **attrs):
"""Attaches an option to the command. All positional arguments are
passed as parameter declarations to :class:`Option`; all keyword
arguments are forwarded unchanged (except ``cls``).
This is equivalent to creating an :class:`Option` instance manually
and attaching it to the :attr:`Command.params` list.
:param cls: the option class to instantiate. This defaults to
:class:`Option`.
"""
def decorator(f):
# Issue 926, copy attrs, so pre-defined options can re-use the same cls=
option_attrs = attrs.copy()
if 'help' in option_attrs:
option_attrs['help'] = inspect.cleandoc(option_attrs['help'])
OptionClass = option_attrs.pop('cls', Option)
_param_memo(f, OptionClass(param_decls, **option_attrs))
return f
return decorator
示例3: _make_command
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def _make_command(f, name, attrs, cls):
if isinstance(f, Command):
raise TypeError('Attempted to convert a callback into a '
'command twice.')
try:
params = f.__click_params__
params.reverse()
del f.__click_params__
except AttributeError:
params = []
help = attrs.get('help')
if help is None:
help = inspect.getdoc(f)
if isinstance(help, bytes):
help = help.decode('utf-8')
else:
help = inspect.cleandoc(help)
attrs['help'] = help
_check_for_unicode_literals()
return cls(name=name or f.__name__.lower(),
callback=f, params=params, **attrs)
示例4: option
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def option(*param_decls, **attrs):
"""Attaches an option to the command. All positional arguments are
passed as parameter declarations to :class:`Option`; all keyword
arguments are forwarded unchanged (except ``cls``).
This is equivalent to creating an :class:`Option` instance manually
and attaching it to the :attr:`Command.params` list.
:param cls: the option class to instantiate. This defaults to
:class:`Option`.
"""
def decorator(f):
if 'help' in attrs:
attrs['help'] = inspect.cleandoc(attrs['help'])
OptionClass = attrs.pop('cls', Option)
_param_memo(f, OptionClass(param_decls, **attrs))
return f
return decorator
示例5: _make_command
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def _make_command(f, name, attrs, cls):
if isinstance(f, Command):
raise TypeError('Attempted to convert a callback into a '
'command twice.')
try:
params = f.__click_params__
params.reverse()
del f.__click_params__
except AttributeError:
params = []
help = attrs.get('help')
if help is None:
help = inspect.getdoc(f)
if isinstance(help, bytes):
help = help.decode('utf-8')
else:
help = inspect.cleandoc(help)
attrs['help'] = help
return cls(name=name or f.__name__.lower(),
callback=f, params=params, **attrs)
示例6: get_docstring
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def get_docstring(node, clean=True):
"""
Return the docstring for the given node or None if no docstring can
be found. If the node provided does not have docstrings a TypeError
will be raised.
"""
if not isinstance(node, (AsyncFunctionDef, FunctionDef, ClassDef, Module)):
raise TypeError("%r can't have docstrings" % node.__class__.__name__)
if not(node.body and isinstance(node.body[0], Expr)):
return
node = node.body[0].value
if isinstance(node, Str):
text = node.s
elif isinstance(node, Constant) and isinstance(node.value, str):
text = node.value
else:
return
if clean:
import inspect
text = inspect.cleandoc(text)
return text
示例7: get_full_help
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def get_full_help(self, prefix: str):
return inspect.cleandoc(
f"""
*RSS Feed 구독*
채널에서 RSS를 구독할 때 사용됩니다.
구독하기로 한 주소에서 1분 간격으로 새 글을 찾습니다.
`{prefix}rss add URL` (URL을 해당 채널에서 구독합니다)
`{prefix}rss list` (해당 채널에서 구독중인 RSS Feed 목록을 가져옵니다)
`{prefix}rss del ID` (고유번호가 ID인 RSS 구독을 중지합니다)
`add` 대신 `추가` 를 사용할 수 있습니다.
`list` 대신 `목록` 을 사용할 수 있습니다.
`del` 대신 `delete`, `삭제`, `제거` 를 사용할 수 있습니다."""
)
示例8: get_full_help
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def get_full_help(self, prefix: str):
return inspect.cleandoc(
f"""
*가챠 계산기*
해로운 문명, 가챠에 관련된 계산을 도와줍니다.
`{prefix}가챠 수집 10` (총 10종을 모두 수집하려면 얼마나 구입해야하는지 계산)
`{prefix}가챠 수집 10/20` (총 20종 중에 10종을 수집하려면 얼마나 구입해야하는지 계산)
`{prefix}가챠 수집 전체 20종류중에 10종류` (위와 동일한 주문을 한국어 표현식으로도 가능합니다.)
`{prefix}가챠 도전 5%` (5% 확률요소의 성공을 위해 필요한 도전 횟수를 계산)
`{prefix}가챠 도전 0.1` (10%(`0.1`) 확률요소의 성공을 위해 필요한 도전 횟수를 계산)
`{prefix}가챠 도전 --성공 10 3%` (3% 확률요소의 10회 성공을 위해 필요한 도전 횟수를 계산)
Aliases
- `수집`대신 `collect`를 사용할 수 있습니다.
- `도전`대신 `challenge`를 사용할 수 있습니다.
- `도전`에서 `--성공`대신 `--성공횟수`/`--successes`/`-s`를 사용할 수 있습니다.
"""
)
示例9: create_function_stub
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def create_function_stub(fn_name, fn_argspec, fn_docstring, indent=0):
def shift_right(string, prefix):
return ''.join(prefix + line for line in string.splitlines(True))
fn_docstring = shift_right(inspect.cleandoc(fn_docstring), " " * (indent + 1))
ret = '''
def %s%s:
"""%s"""
pass
''' % (fn_name, fn_argspec, fn_docstring)
ret = ret[1:] # remove first /n
ret = ret.replace('\t', " ")
if indent:
prefix = " " * indent
ret = shift_right(ret, prefix)
return ret
示例10: _make_command
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def _make_command(f, name, attrs, cls):
if isinstance(f, Command):
raise TypeError("Attempted to convert a callback into a command twice.")
try:
params = f.__click_params__
params.reverse()
del f.__click_params__
except AttributeError:
params = []
help = attrs.get("help")
if help is None:
help = inspect.getdoc(f)
if isinstance(help, bytes):
help = help.decode("utf-8")
else:
help = inspect.cleandoc(help)
attrs["help"] = help
_check_for_unicode_literals()
return cls(
name=name or f.__name__.lower().replace("_", "-"),
callback=f,
params=params,
**attrs
)
示例11: option
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def option(*param_decls, **attrs):
"""Attaches an option to the command. All positional arguments are
passed as parameter declarations to :class:`Option`; all keyword
arguments are forwarded unchanged (except ``cls``).
This is equivalent to creating an :class:`Option` instance manually
and attaching it to the :attr:`Command.params` list.
:param cls: the option class to instantiate. This defaults to
:class:`Option`.
"""
def decorator(f):
# Issue 926, copy attrs, so pre-defined options can re-use the same cls=
option_attrs = attrs.copy()
if "help" in option_attrs:
option_attrs["help"] = inspect.cleandoc(option_attrs["help"])
OptionClass = option_attrs.pop("cls", Option)
_param_memo(f, OptionClass(param_decls, **option_attrs))
return f
return decorator
示例12: registerAPIs
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def registerAPIs(self, apidefs):
'''
API definition is in format: `(name, handler, container, discoverinfo)`
if the handler is a generator, container should be specified
handler should accept two arguments::
def handler(name, params):
...
`name` is the method name, `params` is a dictionary contains the parameters.
the handler can either return the result directly, or be a generator (async-api),
and write the result to container.retvalue on exit.
e.g::
('method1', self.method1), # method1 directly returns the result
('method2', self.method2, self) # method2 is an async-api
Use api() to automatically generate API definitions.
'''
handlers = [self._createHandler(*apidef) for apidef in apidefs]
self.handler.registerAllHandlers(handlers)
self.discoverinfo.update((apidef[0], apidef[3] if len(apidef) > 3 else {'description':cleandoc(apidef[1].__doc__)}) for apidef in apidefs)
示例13: find_documented_attributes
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def find_documented_attributes(class_name, attrs):
"""Parse the documentation to retrieve all attributes that have been
documented and their documentation
"""
# If a class is not documented we return an empty list
if '__doc__' not in attrs:
return []
current_class_doc = inspect.cleandoc(attrs['__doc__'])
parsed_doc = docscrape.ClassDoc(None, doc=current_class_doc)
attr_docs = parsed_doc['Parameters'] + parsed_doc['Attributes'] + \
parsed_doc['Other Parameters']
attr_and_doc = []
create_property_doc = BaseMeta.create_property_doc
for attr_doc in attr_docs:
attr_name = attr_doc[0]
if ':' in attr_name:
raise ValueError("Attribute '%s' has not a proper "
"documentation, a space might be missing "
"before colon" % attr_name)
attr_and_doc += [(attr_name,
create_property_doc(class_name, attr_doc))]
return attr_and_doc
示例14: modules_config
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def modules_config():
"""Show menu of all modules and allow user to enter one"""
global DB
code, tag = DIALOG.menu("Modules", choices=[(module.name, inspect.cleandoc(getattr(module, "__doc__", None) or ""))
for module in MODULES.modules if getattr(module, "config", {})])
if code == DIALOG.OK:
for mod in MODULES.modules:
if mod.name == tag:
# Match
while not module_config(mod):
pass
return modules_config()
return None
示例15: _makeDoc
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import cleandoc [as 别名]
def _makeDoc(doc, indent=''):
if doc is None:
return ''
doc = inspect.cleandoc(doc)
pre = '\n' + indent + '// '
doc = '// ' + doc
doc = doc.replace('\n', pre)
return doc