text
stringlengths
0
828
except ImportError:
return
try:
return getattr(
__import__('%s' % (package), globals(), locals(), [related_name]),
related_name
)
except Exception as e:
if ignore_exceptions:
current_app.logger.exception(
'Can not import ""{}"" package'.format(package)
)
else:
raise e"
4849,"def ansi(string, *args):
"""""" Convenience function to chain multiple ColorWrappers to a string """"""
ansi = ''
for arg in args:
arg = str(arg)
if not re.match(ANSI_PATTERN, arg):
raise ValueError('Additional arguments must be ansi strings')
ansi += arg
return ansi + string + colorama.Style.RESET_ALL"
4850,"def puts(*args, **kwargs):
""""""
Full feature printing function featuring
trimming and padding for both files and ttys
""""""
# parse kwargs
trim = kwargs.pop('trim', False)
padding = kwargs.pop('padding', None)
stream = kwargs.pop('stream', sys.stdout)
# HACK: check if stream is IndentedFile
indent = getattr(stream, 'indent', 0)
# stringify args
args = [str(i) for i in args]
# helpers
def trimstr(ansi, width):
string = ''; size = 0; i = 0
while i < len(ansi):
mobj = re.match(ANSI_PATTERN, ansi[i:])
if mobj:
# append ansi code
string = string + mobj.group(0)
i += len(mobj.group(0))
else:
# loop for more ansi codes even at max width
size += 1
if size > width: break
# append normal char
string = string + ansi[i]
i += 1
return (string, size)
# process strings
if not stream.isatty():
# remove ansi codes and print
for string in args:
stream.write(re.sub(ANSI_PATTERN, '', string) + '\n')
else:
# get terminal width
try: curses.setupterm()
except:
trim = False
padding = None
else:
width = curses.tigetnum('cols') - indent
for string in args:
if trim or padding:
trimmed, size = trimstr(string, width)
# trim string
if trim:
if len(trimmed) < len(string):
trimmed = trimstr(string, width - 3)[0] + colorama.Style.RESET_ALL + '...'
string = trimmed
# add padding
if padding:
string += padding * (width - size)
# print final string
stream.write(string + '\n')"
4851,"def _restore_tree_for(root, translate):
# type: (Any, Dict[Type[Nonterminal], Type[Rule]]) -> Union[Nonterminal, Terminal]
""""""
Create part of AST that generate epsilon.
:param root: Symbol in the original rule that results in epsilon.