code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
if kind is None and tag is None:
raise TypeError("get() takes at least one keyword-only argument. 'kind' or 'tag'.")
kinds = self.all
tags = self.all
if kind is not None:
kinds = self.kinds[kind]
if tag is not None:
tags = self.tags[ta... | def get(self, *, kind: Type=None, tag: Hashable=None, **_) -> Iterator | Get an iterator of objects by kind or tag.
kind: Any type. Pass to get a subset of contained items with the given
type.
tag: Any Hashable object. Pass to get a subset of contained items with
the given tag.
Pass both kind and tag to get objects that are both that type... | 3.102009 | 3.344198 | 0.92758 |
self.all.remove(game_object)
for kind in type(game_object).mro():
self.kinds[kind].remove(game_object)
for s in self.tags.values():
s.discard(game_object) | def remove(self, game_object: Hashable) -> None | Remove the given object from the container.
game_object: A hashable contained by container.
Example:
container.remove(myObject) | 4.501195 | 4.797457 | 0.938246 |
next = self.next
self.next = None
if self.next or not self.running:
message = "The Scene.change interface is deprecated. Use the events commands instead."
warn(message, DeprecationWarning)
return self.running, {"scene_class": next} | def change(self) -> Tuple[bool, dict] | Default case, override in subclass as necessary. | 10.59479 | 10.218267 | 1.036848 |
self.game_objects.add(game_object, tags) | def add(self, game_object: Hashable, tags: Iterable=())-> None | Add a game_object to the scene.
game_object: Any GameObject object. The item to be added.
tags: An iterable of Hashable objects. Values that can be used to
retrieve a group containing the game_object.
Examples:
scene.add(MyGameObject())
scene.add(MyGameOb... | 5.515954 | 8.472594 | 0.651035 |
return self.game_objects.get(kind=kind, tag=tag, **kwargs) | def get(self, *, kind: Type=None, tag: Hashable=None, **kwargs) -> Iterator | Get an iterator of GameObjects by kind or tag.
kind: Any type. Pass to get a subset of contained GameObjects with the
given type.
tag: Any Hashable object. Pass to get a subset of contained GameObjects
with the given tag.
Pass both kind and tag to get objects that ar... | 6.635554 | 6.615271 | 1.003066 |
if section is None:
filename = "requirements.txt"
else:
filename = f"requirements-{section}.txt"
with open(filename) as file:
return [line.strip() for line in file] | def requirements(section=None) | Helper for loading dependencies from requirements files. | 2.563999 | 2.434721 | 1.053098 |
filehasher = hashlib.md5()
while True:
data = file.read(8192)
if not data:
break
filehasher.update(data)
file.seek(0)
self.hash_key = filehasher.hexdigest() | def set_hash_key(self, file) | Calculate and store hash key for file. | 2.13027 | 1.948619 | 1.093221 |
def _append_sorted(root, el, comparator):
for child in root:
rel = comparator(el, child)
if rel > 0:
# el fits inside child, add to child and return
_append_sorted(child, el, comparator)
return
if rel < 0:
# child fits inside el, ... | Add el as a child of root, or as a child of one of root's children.
Comparator is a function(a, b) returning > 0 if a is a child of b, < 0 if
b is a child of a, 0 if neither. | null | null | null | |
def _box_in_box(el, child):
return all([
float(el.get('x0')) <= float(child.get('x0')),
float(el.get('x1')) >= float(child.get('x1')),
float(el.get('y0')) <= float(child.get('y0')),
float(el.get('y1')) >= float(child.get('y1')),
]) | Return True if child is contained within el. | null | null | null | |
def _comp_bbox(el, el2):
# only compare if both elements have x/y coordinates
if _comp_bbox_keys_required <= set(el.keys()) and \
_comp_bbox_keys_required <= set(el2.keys()):
if _box_in_box(el2, el):
return 1
if _box_in_box(el, el2):
return -1
... | Return 1 if el in el2, -1 if el2 in el, else 0 | null | null | null | |
def smart_unicode_decode(encoded_string):
if not encoded_string:
return u''
# optimization -- first try ascii
try:
return encoded_string.decode('ascii')
except UnicodeDecodeError:
pass
# detect encoding
detected_encoding = chardet.detect(encoded_string)... | Given an encoded string of unknown format, detect the format with
chardet and return the unicode version.
Example input from bug #11:
('\xfe\xff\x00I\x00n\x00s\x00p\x00e\x00c\x00t\x00i\x00o\x00n\x00'
'\x00R\x00e\x00p\x00o\x00r\x00t\x00 \x00v\x002\x00.\x002') | null | null | null | |
def prepare_for_json_encoding(obj):
obj_type = type(obj)
if obj_type == list or obj_type == tuple:
return [prepare_for_json_encoding(item) for item in obj]
if obj_type == dict:
# alphabetizing keys lets us compare attributes for equality across runs
return OrderedDict(
... | Convert an arbitrary object into just JSON data types (list, dict, unicode str, int, bool, null). | null | null | null | |
def obj_to_string(obj, top=True):
obj = prepare_for_json_encoding(obj)
if type(obj) == six.text_type:
return obj
return json.dumps(obj) | Turn an arbitrary object into a unicode string. If complex (dict/list/tuple), will be json-encoded. | null | null | null | |
def get_page_number(self, index):
# get and cache page ranges
if not hasattr(self, 'page_range_pairs'):
try:
page_ranges = resolve1(self.catalog['PageLabels'])['Nums']
assert len(page_ranges) > 1 and len(page_ranges) % 2 == 0
... | Given an index, return page label as specified by
catalog['PageLabels']['Nums']
In a PDF, page labels are stored as a list of pairs, like
[starting_index, label_format, starting_index, label_format ...]
For example:
[0, {'S': 'D', 'St': 151}, 4, {'S':'R', 'P':'Foo'}]
... | null | null | null | |
def load(self, *page_numbers):
self.tree = self.get_tree(*_flatten(page_numbers))
self.pq = self.get_pyquery(self.tree) | Load etree and pyquery object for entire document, or given page
numbers (ints or lists). After this is called, objects are
available at pdf.tree and pdf.pq.
>>> pdf.load()
>>> pdf.tree
<lxml.etree._ElementTree object at ...>
>>> pdf.pq('LTPage')
[<LTPage... | null | null | null | |
def extract(self, searches, tree=None, as_dict=True):
if self.tree is None or self.pq is None:
self.load()
if tree is None:
pq = self.pq
else:
pq = PyQuery(tree, css_translator=PDFQueryTranslator())
results = []
formatter = No... | >>> foo = pdf.extract([['pages', 'LTPage']])
>>> foo
{'pages': [<LTPage>, <LTPage>]}
>>> pdf.extract([['bar', ':in_bbox("100,100,400,400")']], foo['pages'][0])
{'bar': [<LTTextLineHorizontal>, <LTTextBoxHorizontal>,... | null | null | null | |
def get_pyquery(self, tree=None, page_numbers=None):
if not page_numbers:
page_numbers = []
if tree is None:
if not page_numbers and self.tree is not None:
tree = self.tree
else:
tree = self.get_tree(page_numbers)
... | Wrap given tree in pyquery and return.
If no tree supplied, will generate one from given page_numbers, or
all page numbers. | null | null | null | |
def get_tree(self, *page_numbers):
cache_key = "_".join(map(str, _flatten(page_numbers)))
tree = self._parse_tree_cacher.get(cache_key)
if tree is None:
# set up root
root = parser.makeelement("pdfxml")
if self.doc.info:
for k,... | Return lxml.etree.ElementTree for entire document, or page numbers
given if any. | null | null | null | |
def _clean_text(self, branch):
if branch.text and self.input_text_formatter:
branch.text = self.input_text_formatter(branch.text)
try:
for child in branch:
self._clean_text(child)
if branch.text and branch.text.find(child.text) >= 0... | Remove text from node if same text exists in its children.
Apply string formatter if set. | null | null | null | |
def _getattrs(self, obj, *attrs):
filtered_attrs = {}
for attr in attrs:
if hasattr(obj, attr):
filtered_attrs[attr] = obj_to_string(
self._filter_value(getattr(obj, attr))
)
return filtered_attrs | Return dictionary of given attrs on given object, if they exist,
processing through _filter_value(). | null | null | null | |
def get_layout(self, page):
if type(page) == int:
page = self.get_page(page)
self.interpreter.process_page(page)
layout = self.device.get_result()
layout = self._add_annots(layout, page.annots)
return layout | Get PDFMiner Layout object for given page object or page number. | null | null | null | |
def _cached_pages(self, target_page=-1):
try:
# pdfminer < 20131022
self._pages_iter = self._pages_iter or self.doc.get_pages()
except AttributeError:
# pdfminer >= 20131022
self._pages_iter = self._pages_iter or \
PDFPage.... | Get a page or all pages from page generator, caching results.
This is necessary because PDFMiner searches recursively for pages,
so we won't know how many there are until we parse the whole document,
which we don't want to do until we need to. | null | null | null | |
def _add_annots(self, layout, annots):
if annots:
for annot in resolve1(annots):
annot = resolve1(annot)
if annot.get('Rect') is not None:
annot['bbox'] = annot.pop('Rect') # Rename key
annot = self._set_hwxy_at... | Adds annotations to the layout object | null | null | null | |
def _set_hwxy_attrs(attr):
bbox = attr['bbox']
attr['x0'] = bbox[0]
attr['x1'] = bbox[2]
attr['y0'] = bbox[1]
attr['y1'] = bbox[3]
attr['height'] = attr['y1'] - attr['y0']
attr['width'] = attr['x1'] - attr['x0']
return attr | Using the bbox attribute, set the h, w, x0, x1, y0, and y1
attributes. | null | null | null | |
raise ctypes.WinError(ctypes.get_last_error())
return args | def _check_bool(result, func, args): # pylint: disable=unused-argument
if not result | Used as an error handler for Windows calls
Gets last error if call is not successful | 12.055176 | 8.361044 | 1.441827 |
if filehandle is None:
filehandle = msvcrt.get_osfhandle(sys.__stdout__.fileno())
csbi = ConsoleScreenBufferInfo()
KERNEL32.GetConsoleScreenBufferInfo(filehandle, ctypes.byref(csbi))
return csbi | def get_csbi(filehandle=None) | Returns a CONSOLE_SCREEN_BUFFER_INFO structure for the given console or stdout | 2.89669 | 2.498348 | 1.159442 |
if filehandle is None:
filehandle = msvcrt.get_osfhandle(sys.__stdout__.fileno())
current_mode = wintypes.DWORD()
KERNEL32.GetConsoleMode(filehandle, ctypes.byref(current_mode))
new_mode = 0x0004 | current_mode.value
KERNEL32.SetConsoleMode(filehandle, new_mode) | def enable_vt_mode(filehandle=None) | Enables virtual terminal processing mode for the given console or stdout | 2.369822 | 2.237778 | 1.059007 |
def func(self, content=''):
return self._apply_color(code, content) # pylint: disable=protected-access
setattr(Terminal, color, func) | def create_color_method(color, code) | Create a function for the given color
Done inside this function to keep the variables out of the main scope | 9.170565 | 7.462556 | 1.228877 |
normal = u'\x1B[0m'
seq = u'\x1B[%sm' % code
# Replace any normal sequences with this sequence to support nested colors
return seq + (normal + seq).join(content.split(normal)) + normal | def _apply_color(code, content) | Apply a color code to text | 8.216197 | 7.8767 | 1.043101 |
def func(content=''):
return self._apply_color(u'38;5;%d' % code, content)
return func | def color(self, code) | When color is given as a number, apply that color to the content
While this is designed to support 256 color terminals, Windows will approximate
this with 16 colors | 12.971244 | 9.692566 | 1.338267 |
# In Python 3.3+ we can let the standard library handle this
if GTS_SUPPORTED:
return os.get_terminal_size(self.stream_fd)
window = get_csbi(self.stream_fh).srWindow
return TerminalSize(window.Right - window.Left + 1, window.Bottom - window.Top + 1) | def _height_and_width(self) | Query console for dimensions
Returns named tuple (columns, lines) | 10.46125 | 9.58729 | 1.091158 |
ftp = ftplib.FTP(SITE)
ftp.set_debuglevel(DEBUG)
ftp.login(USER, PASSWD)
ftp.cwd(DIR)
filelist = ftp.nlst()
filecounter = MANAGER.counter(total=len(filelist), desc='Downloading',
unit='files')
for filename in filelist:
with Writer(filename, f... | def download() | Download all files from an FTP share | 3.733722 | 3.515347 | 1.062121 |
self.fileobj.write(block)
self.status.update(len(block)) | def write(self, block) | Write to local file and update progress bar | 6.582901 | 4.568313 | 1.440992 |
with enlighten.Manager() as manager:
with manager.counter(total=SPLINES, desc='Reticulating:', unit='splines') as retic:
for num in range(SPLINES): # pylint: disable=unused-variable
time.sleep(random.uniform(0.1, 0.5)) # Random processing time
retic.update... | def process_files() | Use Manager and Counter as context managers | 3.575188 | 3.358598 | 1.064488 |
with io.open(filename, encoding=encoding) as sourcecode:
for line in sourcecode:
version = RE_VERSION.match(line)
if version:
return version.group(1)
return None | def get_version(filename, encoding='utf8') | Get __version__ definition out of a source file | 3.053578 | 3.03926 | 1.004711 |
with io.open(filename, encoding=encoding) as source:
return source.read() | def readme(filename, encoding='utf8') | Read the contents of a file | 3.725224 | 5.118334 | 0.72782 |
filesize = os.stat(filename).st_size
if filesize:
sys.stdout.write('Misspelled Words:\n')
with io.open(filename, encoding=encoding) as wordlist:
for line in wordlist:
sys.stdout.write(' ' + line)
return 1 if filesize else 0 | def print_spelling_errors(filename, encoding='utf8') | Print misspelled words returned by sphinxcontrib-spelling | 3.248869 | 3.23433 | 1.004495 |
# Simulated preparation
pbar = manager.counter(total=initials, desc='Initializing:', unit='initials')
for num in range(initials): # pylint: disable=unused-variable
time.sleep(random.uniform(0.1, 0.5)) # Random processing time
pbar.update()
pbar.close() | def initialize(manager, initials=15) | Simple progress bar example | 4.774447 | 4.422461 | 1.079591 |
manager = enlighten.get_manager()
initialize(manager, 15)
load(manager, 80)
run_tests(manager, 40)
process_files(manager)
manager.stop() # Clears all temporary counters and progress bars
time.sleep(3) | def main() | Main function | 10.815252 | 10.799357 | 1.001472 |
stream = stream or sys.stdout
isatty = hasattr(stream, 'isatty') and stream.isatty()
kwargs['enabled'] = isatty and kwargs.get('enabled', True)
return Manager(stream=stream, counterclass=counterclass, **kwargs) | def get_manager(stream=None, counterclass=Counter, **kwargs) | Args:
stream(:py:term:`file object`): Output stream. If :py:data:`None`,
defaults to :py:data:`sys.stdout`
counter_class(:py:term:`class`): Progress bar class (Default: :py:class:`Counter`)
kwargs(dict): Any additional :py:term:`keyword arguments<keyword argument>`
will p... | 2.57498 | 2.778427 | 0.926776 |
for key, val in self.defaults.items():
if key not in kwargs:
kwargs[key] = val
kwargs['manager'] = self
counter = self.counter_class(**kwargs)
if position is None:
toRefresh = []
if self.counters:
pos = 2
... | def counter(self, position=None, **kwargs) | Args:
position(int): Line number counting from the bottom of the screen
kwargs(dict): Any additional :py:term:`keyword arguments<keyword argument>`
are passed to :py:class:`Counter`
Returns:
:py:class:`Counter`: Instance of counter class
Get a new pr... | 3.49951 | 3.400225 | 1.029199 |
assert self.resize_lock
except AssertionError:
self.resize_lock = True
term = self.term
term.clear_cache()
newHeight = term.height
newWidth = term.width
lastHeight = lastWidth = 0
while newHeight != lastHeight or ... | def _resize_handler(self, *args, **kwarg): # pylint: disable=unused-argument
# Make sure only one resize handler is running
try | Called when a window resize signal is detected
Resets the scroll window | 4.066381 | 4.155388 | 0.97858 |
# Save scroll offset for resizing
oldOffset = self.scroll_offset
self.scroll_offset = newOffset = max(self.counters.values()) + 1
if not self.enabled:
return
# Set exit handling only once
if not self.process_exit:
atexit.register(self._... | def _set_scroll_area(self, force=False) | Args:
force(bool): Set the scroll area even if no change in height and position is detected
Sets the scroll window based on the counter positions | 4.847734 | 4.713205 | 1.028543 |
if self.process_exit:
try:
term = self.term
if self.set_scroll:
term.reset()
else:
term.move_to(0, term.height)
self.term.feed()
except ValueError: # Possibly closed fi... | def _at_exit(self) | Resets terminal to normal configuration | 9.568307 | 8.741894 | 1.094535 |
if self.enabled:
term = self.term
stream = self.stream
positions = self.counters.values()
if not self.no_resize and RESIZE_SUPPORTED:
signal.signal(signal.SIGWINCH, self.sigwinch_orig)
try:
for num in range(... | def stop(self) | Clean up and reset terminal
This method should be called when the manager and counters will no longer be needed.
Any progress bars that have ``leave`` set to :py:data:`True` or have not been closed
will remain on the console. All others will be cleared.
Manager and all counters will b... | 5.858943 | 5.496691 | 1.065904 |
if self.enabled:
term = self.term
stream = self.stream
try:
term.move_to(0, term.height - position)
# Include \r and term call to cover most conditions
if NEEDS_UNICODE_HELP: # pragma: no cover (Version dependent 2.... | def write(self, output='', flush=True, position=0) | Args:
output(str: Output string
flush(bool): Flush the output stream after writing
position(int): Position relative to the bottom of the screen to write output
Write to stream at a given position | 6.384001 | 6.41677 | 0.994893 |
# Always do minutes and seconds in mm:ss format
minutes = seconds // 60
hours = minutes // 60
rtn = u'{0:02.0f}:{1:02.0f}'.format(minutes % 60, seconds % 60)
# Add hours if there are any
if hours:
rtn = u'{0:d}h {1}'.format(int(hours % 24), rtn)
# Add days if there are... | def _format_time(seconds) | Args:
seconds (float): amount of time
Format time string for eta and elapsed | 2.784911 | 2.830608 | 0.983856 |
if self.color is None:
return content
if self._color and self._color[0] == self.color:
return self._color[1](content)
if self.color in COLORS:
spec = getattr(self.manager.term, self.color)
else:
spec = self.manager.term.color(se... | def _colorize(self, content) | Args:
content(str): Color as a string or number 0 - 255 (Default: None)
Returns:
:py:class:`str`: content formatted with color
Format ``content`` with the color specified for this progress bar
If no color is specified for this instance, the content is returned unmodifi... | 3.485507 | 3.089096 | 1.128326 |
self.count += incr
self.parent.update(incr, force) | def update(self, incr=1, force=False) | Args:
incr(int): Amount to increment ``count`` (Default: 1)
force(bool): Force refresh even if ``min_delta`` has not been reached
Increment progress bar and redraw
Both this counter and the parent are incremented.
Progress bar is only redrawn if min_delta seconds past ... | 9.385905 | 5.240402 | 1.791066 |
# Make sure source is a parent or peer
if source is self.parent or getattr(source, 'parent', None) is self.parent:
if self.count + incr < 0 or source.count - incr < 0:
raise ValueError('Invalid increment: %s' % incr)
if source is self.parent:
... | def update_from(self, source, incr=1, force=False) | Args:
source(:py:class:`SubCounter`): :py:class:`SubCounter` or :py:class:`Counter`
to increment from
incr(int): Amount to increment ``count`` (Default: 1)
force(bool): Force refresh even if ``min_delta`` has not been reached
Move a value to this counter from... | 3.670932 | 3.607832 | 1.01749 |
# Clock stops running when total is reached
if self.count == self.total:
elapsed = self.last_update - self.start
else:
elapsed = time.time() - self.start
return elapsed | def elapsed(self) | Get elapsed time is seconds (float) | 7.504732 | 6.354336 | 1.181041 |
if self.enabled:
self.manager.write(flush=flush, position=self.position) | def clear(self, flush=True) | Args:
flush(bool): Flush stream after clearing progress bar (Default:True)
Clear progress bar | 11.503092 | 13.254638 | 0.867854 |
if clear and not self.leave:
self.clear()
else:
self.refresh()
self.manager.remove(self) | def close(self, clear=False) | Do final refresh and remove from manager
If ``leave`` is True, the default, the effect is the same as :py:meth:`refresh`. | 7.611193 | 4.97271 | 1.530593 |
fields = {}
subcounters = []
for num, subcounter in enumerate(self._subcounters, 1):
if self.total:
subPercentage = subcounter.count / float(self.total)
else:
subPercentage = 0.0
# Save in tuple: count, percentage, ... | def _get_subcounters(self, elapsed) | Args:
elapsed(float): Time since started.
Returns:
:py:class:`tuple`: list of subcounters and dictionary of additional fields
Each subcounter in the list will be in a tuple of (subcounter, percentage)
Fields in the dictionary are addressed in the Format documentation of... | 3.490476 | 3.354206 | 1.040627 |
width = width or self.manager.width
iterations = abs(self.count - self.start_count)
fields = {'bar': u'{0}',
'count': self.count,
'desc': self.desc or u'',
'total': self.total,
'unit': self.unit or u'',
... | def format(self, width=None, elapsed=None) | Args:
width (int): Width in columns to make progress bar
elapsed(float): Time since started. Automatically determined if :py:data:`None`
Returns:
:py:class:`str`: Formatted progress bar or counter
Format progress bar or counter | 3.997903 | 3.920027 | 1.019866 |
if self.enabled:
self.manager.write(output=self.format(elapsed=elapsed),
flush=flush, position=self.position) | def refresh(self, flush=True, elapsed=None) | Args:
flush(bool): Flush stream after writing progress bar (Default:True)
elapsed(float): Time since started. Automatically determined if :py:data:`None`
Redraw progress bar | 8.525968 | 9.173417 | 0.929421 |
self.count += incr
if self.enabled:
currentTime = time.time()
# Update if force, 100%, or minimum delta has been reached
if force or self.count == self.total or \
currentTime - self.last_update >= self.min_delta:
self.last... | def update(self, incr=1, force=False) | Args:
incr(int): Amount to increment ``count`` (Default: 1)
force(bool): Force refresh even if ``min_delta`` has not been reached
Increment progress bar and redraw
Progress bar is only redrawn if ``min_delta`` seconds past since the last update | 5.646006 | 4.54727 | 1.241625 |
subcounter = SubCounter(self, color=color, count=count, all_fields=all_fields)
self._subcounters.append(subcounter)
return subcounter | def add_subcounter(self, color, count=0, all_fields=False) | Args:
color(str): Series color as a string or integer see :ref:`Series Color <series_color>`
count(int): Initial count (Default: 0)
all_fields(bool): Populate ``rate`` and ``eta`` formatting fields (Default: False)
Returns:
:py:class:`SubCounter`: Subcounter instance
Add a subc... | 2.382094 | 3.58415 | 0.664619 |
# Get a top level progress bar
enterprise = manager.counter(total=DATACENTERS, desc='Processing:', unit='datacenters')
# Iterate through data centers
for dnum in range(1, DATACENTERS + 1):
systems = random.randint(*SYSTEMS) # Random number of systems
# Get a child progress bar. l... | def process_files(manager) | Process a random number of files on a random number of systems across multiple data centers | 4.651668 | 4.24742 | 1.095175 |
with enlighten.Counter(total=100, desc='Simple', unit='ticks') as pbar:
for num in range(100): # pylint: disable=unused-variable
time.sleep(0.05)
pbar.update() | def process_files() | Process files with a single progress bar | 4.948991 | 4.136228 | 1.196499 |
pb_connecting = manager.counter(total=units, desc='Loading', unit='services',
color='red', bar_format=BAR_FMT)
pb_loading = pb_connecting.add_subcounter('yellow')
pb_loaded = pb_connecting.add_subcounter('green', all_fields=True)
connecting = []
loading = [... | def load(manager, units=80) | Simulate loading services from a remote node
States are connecting (red), loading(yellow), and loaded (green) | 3.600684 | 3.275332 | 1.099334 |
value = getattr(self, variable)
if value is None:
return False
if value is True:
return True
if random.randint(1, num) == num:
setattr(self, variable, True)
return True
return False | def _state(self, variable, num) | Generic method to randomly determine if state is reached | 3.829702 | 3.249222 | 1.178652 |
pbar = enlighten.Counter(total=count, desc='Simple', unit='ticks',
bar_format=BAR_FMT, counter_format=COUNTER_FMT)
for num in range(100): # pylint: disable=unused-variable
time.sleep(0.05)
pbar.update(1.1) | def process_files(count=None) | Process files with a single progress bar | 5.802391 | 5.308958 | 1.092943 |
self.stream.write(self.normal_cursor)
self.stream.write(self.csr(0, self.height))
self.stream.write(self.move(self.height, 0)) | def reset(self) | Reset scroll window and cursor to default | 6.644414 | 4.79637 | 1.385301 |
self.stream.write(self.hide_cursor)
self.stream.write(self.csr(0, position))
self.stream.write(self.move(position, 0)) | def change_scroll(self, position) | Args:
position (int): Vertical location to end scroll window
Change scroll window | 5.760587 | 5.857982 | 0.983374 |
self.stream.write(self.move(ypos, xpos)) | def move_to(self, xpos, ypos) | Move cursor to specified position | 12.928288 | 11.264468 | 1.147705 |
try:
return self._cache['height_and_width']
except KeyError:
handw = self._cache['height_and_width'] = super(Terminal, self)._height_and_width()
return handw | def _height_and_width(self) | Override for blessings.Terminal._height_and_width
Adds caching | 5.715716 | 3.780308 | 1.511971 |
'''Capture locals, module name, filename, and line number from the
stacktrace to provide the source of the assertion error and
formatted note.
'''
stack = traceback.walk_stack(sys._getframe().f_back)
# We want locals from the test definition (which always begins
# with 'test_' in unittest),... | def get_stack_info() | Capture locals, module name, filename, and line number from the
stacktrace to provide the source of the assertion error and
formatted note. | 7.678405 | 4.72991 | 1.623372 |
'''Fail if ``obj`` is not between ``lower`` and ``upper``.
If ``strict=True`` (default), fail unless
``lower < obj < upper``. If ``strict=False``, fail unless
``lower <= obj <= upper``.
This is equivalent to ``self.assertTrue(lower < obj < upper)``
or ``self.assertTrue(... | def assertBetween(self, obj, lower, upper, strict=True, msg=None) | Fail if ``obj`` is not between ``lower`` and ``upper``.
If ``strict=True`` (default), fail unless
``lower < obj < upper``. If ``strict=False``, fail unless
``lower <= obj <= upper``.
This is equivalent to ``self.assertTrue(lower < obj < upper)``
or ``self.assertTrue(lower <= ob... | 2.669611 | 1.545575 | 1.72726 |
'''Fail if ``sequence`` is not monotonically increasing.
If ``strict=True`` (default), fail unless each element in
``sequence`` is less than the following element as determined
by the ``<`` operator. If ``strict=False``, fail unless each
element in ``sequence`` is less than or e... | def assertMonotonicIncreasing(self, sequence, strict=True, msg=None) | Fail if ``sequence`` is not monotonically increasing.
If ``strict=True`` (default), fail unless each element in
``sequence`` is less than the following element as determined
by the ``<`` operator. If ``strict=False``, fail unless each
element in ``sequence`` is less than or equal to the... | 2.57686 | 1.604229 | 1.606292 |
'''Fail if ``sequence`` is monotonically decreasing.
If ``strict=True`` (default), fail if each element in
``sequence`` is greater than the following element as
determined by the ``>`` operator. If ``strict=False``, fail if
each element in ``sequence`` is greater than or equal t... | def assertNotMonotonicDecreasing(self, sequence, strict=True, msg=None) | Fail if ``sequence`` is monotonically decreasing.
If ``strict=True`` (default), fail if each element in
``sequence`` is greater than the following element as
determined by the ``>`` operator. If ``strict=False``, fail if
each element in ``sequence`` is greater than or equal to the
... | 2.691819 | 1.608763 | 1.673223 |
'''Fail if elements in ``container`` are not unique.
Parameters
----------
container : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
Raises
------
TypeError
... | def assertUnique(self, container, msg=None) | Fail if elements in ``container`` are not unique.
Parameters
----------
container : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
Raises
------
TypeError
If ``c... | 4.274814 | 2.972276 | 1.438229 |
'''If ``filename`` is a string or bytes object, open the
``filename`` and return the file object. If ``filename`` is
file-like (i.e., it has 'read' and 'write' attributes, return
``filename``.
Parameters
----------
filename : str, bytes, file
Raises
... | def _get_or_open_file(filename) | If ``filename`` is a string or bytes object, open the
``filename`` and return the file object. If ``filename`` is
file-like (i.e., it has 'read' and 'write' attributes, return
``filename``.
Parameters
----------
filename : str, bytes, file
Raises
------
... | 3.381946 | 1.572956 | 2.150058 |
'''Fail if ``filename`` does not exist as determined by
``os.path.isfile(filename)``.
Parameters
----------
filename : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
'''
... | def assertFileExists(self, filename, msg=None) | Fail if ``filename`` does not exist as determined by
``os.path.isfile(filename)``.
Parameters
----------
filename : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used. | 4.836887 | 2.027187 | 2.38601 |
'''Fail if ``filename`` does not have the given ``name`` as
determined by the ``==`` operator.
Parameters
----------
filename : str, bytes, file-like
name : str, byes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` ... | def assertFileNameEqual(self, filename, name, msg=None) | Fail if ``filename`` does not have the given ``name`` as
determined by the ``==`` operator.
Parameters
----------
filename : str, bytes, file-like
name : str, byes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard me... | 5.211449 | 1.689125 | 3.085295 |
'''Fail if ``filename`` has the given ``name`` as determined
by the ``!=`` operator.
Parameters
----------
filename : str, bytes, file-like
name : str, byes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard m... | def assertFileNameNotEqual(self, filename, name, msg=None) | Fail if ``filename`` has the given ``name`` as determined
by the ``!=`` operator.
Parameters
----------
filename : str, bytes, file-like
name : str, byes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will... | 5.256299 | 1.70738 | 3.078577 |
'''Fail unless ``filename`` matches ``expected_regex``.
Parameters
----------
filename : str, bytes, file-like
expected_regex : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
... | def assertFileNameRegex(self, filename, expected_regex, msg=None) | Fail unless ``filename`` matches ``expected_regex``.
Parameters
----------
filename : str, bytes, file-like
expected_regex : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
Raises
... | 4.330366 | 1.733763 | 2.497669 |
'''Fail if ``filename`` matches ``expected_regex``.
Parameters
----------
filename : str, bytes, file-like
expected_regex : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
... | def assertFileNameNotRegex(self, filename, expected_regex, msg=None) | Fail if ``filename`` matches ``expected_regex``.
Parameters
----------
filename : str, bytes, file-like
expected_regex : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
Raises
... | 4.321646 | 1.760243 | 2.455142 |
'''Fail if ``filename`` does not have the given ``extension``
as determined by the ``==`` operator.
Parameters
----------
filename : str, bytes, file-like
extension : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:... | def assertFileTypeEqual(self, filename, extension, msg=None) | Fail if ``filename`` does not have the given ``extension``
as determined by the ``==`` operator.
Parameters
----------
filename : str, bytes, file-like
extension : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` ... | 4.885047 | 1.715544 | 2.847521 |
'''Fail if ``filename`` has the given ``extension`` as
determined by the ``!=`` operator.
Parameters
----------
filename : str, bytes, file-like
extension : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest`... | def assertFileTypeNotEqual(self, filename, extension, msg=None) | Fail if ``filename`` has the given ``extension`` as
determined by the ``!=`` operator.
Parameters
----------
filename : str, bytes, file-like
extension : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard m... | 5.072291 | 1.753645 | 2.892428 |
'''Fail if ``filename`` is not encoded with the given
``encoding`` as determined by the '==' operator.
Parameters
----------
filename : str, bytes, file-like
encoding : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mo... | def assertFileEncodingEqual(self, filename, encoding, msg=None) | Fail if ``filename`` is not encoded with the given
``encoding`` as determined by the '==' operator.
Parameters
----------
filename : str, bytes, file-like
encoding : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest... | 4.644382 | 2.087678 | 2.224664 |
'''Fail if ``filename`` is encoded with the given ``encoding``
as determined by the '!=' operator.
Parameters
----------
filename : str, bytes, file-like
encoding : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`u... | def assertFileEncodingNotEqual(self, filename, encoding, msg=None) | Fail if ``filename`` is encoded with the given ``encoding``
as determined by the '!=' operator.
Parameters
----------
filename : str, bytes, file-like
encoding : str, bytes
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` st... | 4.858863 | 2.135895 | 2.27486 |
'''Fail if ``filename`` does not have the given ``size`` as
determined by the '==' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` s... | def assertFileSizeEqual(self, filename, size, msg=None) | Fail if ``filename`` does not have the given ``size`` as
determined by the '==' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard mes... | 5.162169 | 1.674822 | 3.082219 |
'''Fail if ``filename`` has the given ``size`` as determined
by the '!=' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard me... | def assertFileSizeNotEqual(self, filename, size, msg=None) | Fail if ``filename`` has the given ``size`` as determined
by the '!=' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will ... | 5.35629 | 1.732124 | 3.092326 |
'''Fail if ``filename`` does not have the given ``size`` as
determined by their difference rounded to the given number of
decimal ``places`` (default 7) and comparing to zero, or if
their difference is greater than a given ``delta``.
Parameters
----------
filenam... | def assertFileSizeAlmostEqual(
self, filename, size, places=None, msg=None, delta=None) | Fail if ``filename`` does not have the given ``size`` as
determined by their difference rounded to the given number of
decimal ``places`` (default 7) and comparing to zero, or if
their difference is greater than a given ``delta``.
Parameters
----------
filename : str, by... | 4.239718 | 1.5102 | 2.807389 |
'''Fail unless ``filename`` does not have the given ``size``
as determined by their difference rounded to the given number
ofdecimal ``places`` (default 7) and comparing to zero, or if
their difference is greater than a given ``delta``.
Parameters
----------
file... | def assertFileSizeNotAlmostEqual(
self, filename, size, places=None, msg=None, delta=None) | Fail unless ``filename`` does not have the given ``size``
as determined by their difference rounded to the given number
ofdecimal ``places`` (default 7) and comparing to zero, or if
their difference is greater than a given ``delta``.
Parameters
----------
filename : str,... | 4.63483 | 1.516972 | 3.055316 |
'''Fail if ``filename``'s size is not greater than ``size`` as
determined by the '>' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest`... | def assertFileSizeGreater(self, filename, size, msg=None) | Fail if ``filename``'s size is not greater than ``size`` as
determined by the '>' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard m... | 4.681837 | 1.699448 | 2.754916 |
'''Fail if ``filename``'s size is not greater than or equal to
``size`` as determined by the '>=' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:m... | def assertFileSizeGreaterEqual(self, filename, size, msg=None) | Fail if ``filename``'s size is not greater than or equal to
``size`` as determined by the '>=' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittes... | 4.636314 | 1.68073 | 2.758513 |
'''Fail if ``filename``'s size is not less than ``size`` as
determined by the '<' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` st... | def assertFileSizeLess(self, filename, size, msg=None) | Fail if ``filename``'s size is not less than ``size`` as
determined by the '<' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard mess... | 4.789204 | 1.695026 | 2.825446 |
'''Fail if ``filename``'s size is not less than or equal to
``size`` as determined by the '<=' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:... | def assertFileSizeLessEqual(self, filename, size, msg=None) | Fail if ``filename``'s size is not less than or equal to
``size`` as determined by the '<=' operator.
Parameters
----------
filename : str, bytes, file-like
size : int, float
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` ... | 4.527374 | 1.686104 | 2.68511 |
'''Fail if ``levels1`` and ``levels2`` do not have the same
domain.
Parameters
----------
levels1 : iterable
levels2 : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
... | def assertCategoricalLevelsEqual(self, levels1, levels2, msg=None) | Fail if ``levels1`` and ``levels2`` do not have the same
domain.
Parameters
----------
levels1 : iterable
levels2 : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
Raises
... | 2.633651 | 1.699843 | 1.549349 |
'''Fail if ``levels1`` and ``levels2`` have the same domain.
Parameters
----------
levels1 : iterable
levels2 : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
Raises
... | def assertCategoricalLevelsNotEqual(self, levels1, levels2, msg=None) | Fail if ``levels1`` and ``levels2`` have the same domain.
Parameters
----------
levels1 : iterable
levels2 : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
Raises
------
... | 2.873913 | 1.939226 | 1.48199 |
'''Fail if ``level`` is not in ``levels``.
This is equivalent to ``self.assertIn(level, levels)``.
Parameters
----------
level
levels : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will... | def assertCategoricalLevelIn(self, level, levels, msg=None) | Fail if ``level`` is not in ``levels``.
This is equivalent to ``self.assertIn(level, levels)``.
Parameters
----------
level
levels : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
... | 3.861754 | 1.902853 | 2.029455 |
'''Fail if ``level`` is in ``levels``.
This is equivalent to ``self.assertNotIn(level, levels)``.
Parameters
----------
level
levels : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will ... | def assertCategoricalLevelNotIn(self, level, levels, msg=None) | Fail if ``level`` is in ``levels``.
This is equivalent to ``self.assertNotIn(level, levels)``.
Parameters
----------
level
levels : iterable
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be used.
... | 3.784996 | 1.862874 | 2.031805 |
'''Fail if any elements in ``sequence`` are not before
``target``.
If ``target`` is iterable, it must have the same length as
``sequence``
If ``strict=True``, fail unless all elements in ``sequence``
are strictly less than ``target``. If ``strict=False``, fail
u... | def assertDateTimesBefore(self, sequence, target, strict=True, msg=None) | Fail if any elements in ``sequence`` are not before
``target``.
If ``target`` is iterable, it must have the same length as
``sequence``
If ``strict=True``, fail unless all elements in ``sequence``
are strictly less than ``target``. If ``strict=False``, fail
unless all e... | 2.67872 | 1.807768 | 1.481784 |
'''Fail if any elements in ``sequence`` are not in the past.
If the max element is a datetime, "past" is defined as anything
prior to ``datetime.now()``; if the max element is a date,
"past" is defined as anything prior to ``date.today()``.
If ``strict=True``, fail unless all e... | def assertDateTimesPast(self, sequence, strict=True, msg=None) | Fail if any elements in ``sequence`` are not in the past.
If the max element is a datetime, "past" is defined as anything
prior to ``datetime.now()``; if the max element is a date,
"past" is defined as anything prior to ``date.today()``.
If ``strict=True``, fail unless all elements in ... | 3.215503 | 1.674235 | 1.92058 |
'''Fail if any elements in ``sequence`` are not in the future.
If the min element is a datetime, "future" is defined as
anything after ``datetime.now()``; if the min element is a date,
"future" is defined as anything after ``date.today()``.
If ``strict=True``, fail unless all e... | def assertDateTimesFuture(self, sequence, strict=True, msg=None) | Fail if any elements in ``sequence`` are not in the future.
If the min element is a datetime, "future" is defined as
anything after ``datetime.now()``; if the min element is a date,
"future" is defined as anything after ``date.today()``.
If ``strict=True``, fail unless all elements in ... | 3.457873 | 1.683526 | 2.053947 |
'''Fail if any elements in ``sequence`` aren't separated by
the expected ``fequency``.
Parameters
----------
sequence : iterable
frequency : timedelta
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message... | def assertDateTimesFrequencyEqual(self, sequence, frequency, msg=None) | Fail if any elements in ``sequence`` aren't separated by
the expected ``fequency``.
Parameters
----------
sequence : iterable
frequency : timedelta
msg : str
If not provided, the :mod:`marbles.mixins` or
:mod:`unittest` standard message will be us... | 4.822483 | 2.781729 | 1.733628 |
'''Fail unless max element in ``sequence`` is separated from
the present by ``lag`` as determined by the '==' operator.
If the max element is a datetime, "present" is defined as
``datetime.now()``; if the max element is a date, "present"
is defined as ``date.today()``.
... | def assertDateTimesLagEqual(self, sequence, lag, msg=None) | Fail unless max element in ``sequence`` is separated from
the present by ``lag`` as determined by the '==' operator.
If the max element is a datetime, "present" is defined as
``datetime.now()``; if the max element is a date, "present"
is defined as ``date.today()``.
This is equ... | 3.708205 | 1.695533 | 2.187044 |
'''Fail if max element in ``sequence`` is separated from
the present by ``lag`` or more as determined by the '<'
operator.
If the max element is a datetime, "present" is defined as
``datetime.now()``; if the max element is a date, "present"
is defined as ``date.today()``... | def assertDateTimesLagLess(self, sequence, lag, msg=None) | Fail if max element in ``sequence`` is separated from
the present by ``lag`` or more as determined by the '<'
operator.
If the max element is a datetime, "present" is defined as
``datetime.now()``; if the max element is a date, "present"
is defined as ``date.today()``.
... | 3.654718 | 1.689882 | 2.162706 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.