forked from VimPlug/jedi
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
""" A universal module with functions / classes without dependencies. """
|
|
import contextlib
|
|
|
|
import settings
|
|
|
|
|
|
class PushBackIterator(object):
|
|
def __init__(self, iterator):
|
|
self.pushes = []
|
|
self.iterator = iterator
|
|
|
|
def push_back(self, value):
|
|
self.pushes.append(value)
|
|
|
|
def __iter__(self):
|
|
return self
|
|
|
|
def next(self):
|
|
""" Python 2 Compatibility """
|
|
return self.__next__()
|
|
|
|
def __next__(self):
|
|
if self.pushes:
|
|
return self.pushes.pop()
|
|
else:
|
|
return next(self.iterator)
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def scale_speed_settings(factor):
|
|
a = settings.max_executions
|
|
b = settings.max_until_execution_unique
|
|
settings.max_executions *= factor
|
|
settings.max_until_execution_unique *= factor
|
|
yield
|
|
settings.max_executions = a
|
|
settings.max_until_execution_unique = b
|
|
|
|
|
|
def indent_block(text, indention=' '):
|
|
""" This function indents a text block with a default of four spaces """
|
|
temp = ''
|
|
while text and text[-1] == '\n':
|
|
temp += text[-1]
|
|
text = text[:-1]
|
|
lines = text.split('\n')
|
|
return '\n'.join(map(lambda s: indention + s, lines)) + temp
|