_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q249300 | Storage.open | train | def open(self, filename, mode='r', **kwargs):
'''
Open the file and return a file-like object.
:param str filename: The storage root-relative filename
:param str mode: The open mode (``(r|w)b?``)
:raises FileNotFound: If trying to read a file that does not exists
'''
| python | {
"resource": ""
} |
q249301 | Storage.write | train | def write(self, filename, content, overwrite=False):
'''
Write content to a file.
:param str filename: The storage root-relative filename
:param content: The content to write in the file
:param bool overwrite: Whether to wllow overwrite or not
:raises FileExists: If the ... | python | {
"resource": ""
} |
q249302 | Storage.metadata | train | def metadata(self, filename):
'''
Get some metadata for a given file.
Can vary from a backend to another but some are always present:
- `filename`: the base filename (without the path/prefix)
- `url`: the file public URL
| python | {
"resource": ""
} |
q249303 | Storage.serve | train | def serve(self, filename):
'''Serve a file given its filename'''
if not self.exists(filename):
| python | {
"resource": ""
} |
q249304 | make_thumbnail | train | def make_thumbnail(file, size, bbox=None):
'''
Generate a thumbnail for a given image file.
:param file file: The source image file to thumbnail
:param int size: The thumbnail size in pixels (Thumbnails are | python | {
"resource": ""
} |
q249305 | pip | train | def pip(filename):
"""Parse pip reqs file and transform it to setuptools requirements."""
requirements = []
for line in open(join(ROOT, 'requirements', filename)):
line = line.strip()
if not line or '://' in line:
continue
| python | {
"resource": ""
} |
q249306 | BaseBackend.move | train | def move(self, filename, target):
'''
Move a file given its filename to another path in the storage
Default implementation perform a copy then a delete.
Backends should overwrite | python | {
"resource": ""
} |
q249307 | BaseBackend.save | train | def save(self, file_or_wfs, filename, overwrite=False):
'''
Save a file-like object or a `werkzeug.FileStorage` with the specified filename.
:param storage: The file or the storage to be saved.
:param filename: The destination in the storage.
:param overwrite: if `False`, raise ... | python | {
"resource": ""
} |
q249308 | BaseBackend.metadata | train | def metadata(self, filename):
'''
Fetch all available metadata for a given file
'''
meta = self.get_metadata(filename)
# Fix backend mime misdetection
| python | {
"resource": ""
} |
q249309 | BaseBackend.as_binary | train | def as_binary(self, content, encoding='utf8'):
'''Perform content encoding for binary write'''
if hasattr(content, 'read'):
return content.read()
| python | {
"resource": ""
} |
q249310 | S3Backend.get_metadata | train | def get_metadata(self, filename):
'''Fetch all availabe metadata'''
obj = self.bucket.Object(filename)
checksum = 'md5:{0}'.format(obj.e_tag[1:-1])
mime = obj.content_type.split(';', 1)[0] if obj.content_type else None
return {
| python | {
"resource": ""
} |
q249311 | ImageReference.thumbnail | train | def thumbnail(self, size):
'''Get the thumbnail filename for a given size'''
if size in self.thumbnail_sizes:
return self.thumbnails.get(str(size))
| python | {
"resource": ""
} |
q249312 | ImageReference.full | train | def full(self, external=False):
'''Get the full image URL in respect with ``max_size``'''
| python | {
"resource": ""
} |
q249313 | ImageReference.best_url | train | def best_url(self, size=None, external=False):
'''
Provide the best thumbnail for downscaling.
If there is no match, provide the bigger if exists or the original
'''
if not self.thumbnail_sizes:
return self.url
elif not size:
self.thumbnail_sizes.... | python | {
"resource": ""
} |
q249314 | ImageReference.rerender | train | def rerender(self):
'''
Rerender all derived images from the original.
If optmization settings or expected sizes changed,
they will be used for the new rendering.
'''
with self.fs.open(self.original, 'rb') as f_img:
| python | {
"resource": ""
} |
q249315 | get_file | train | def get_file(fs, filename):
'''Serve files for storages with direct file access''' | python | {
"resource": ""
} |
q249316 | init_app | train | def init_app(app, *storages):
'''
Initialize Storages configuration
Register blueprint if necessary.
:param app: The `~flask.Flask` instance to get the configuration from.
:param storages: A `Storage` instance list to register and configure.
'''
# Set default configuration
app.config.... | python | {
"resource": ""
} |
q249317 | LocalBackend.get_metadata | train | def get_metadata(self, filename):
'''Fetch all available metadata'''
dest = self.path(filename)
with open(dest, 'rb', buffering=0) as f:
checksum = 'sha1:{0}'.format(sha1(f))
return {
'checksum': checksum,
| python | {
"resource": ""
} |
q249318 | Dummy.on_touch_move | train | def on_touch_move(self, touch):
"""Follow the touch"""
if touch is not self._touch:
return False
self.pos = (
| python | {
"resource": ""
} |
q249319 | Thing.clear | train | def clear(self):
"""Unset everything."""
for k in list(self.keys()):
if k not | python | {
"resource": ""
} |
q249320 | AbstractEngine.loading | train | def loading(self):
"""Context manager for when you need to instantiate entities upon unpacking"""
if getattr(self, '_initialized', False):
raise ValueError("Already | python | {
"resource": ""
} |
q249321 | AbstractEngine.dice | train | def dice(self, n, d):
"""Roll ``n`` dice with ``d`` faces, and yield the results.
This is an iterator. You'll get the result of each die in
| python | {
"resource": ""
} |
q249322 | AbstractEngine.dice_check | train | def dice_check(self, n, d, target, comparator='<='):
"""Roll ``n`` dice with ``d`` sides, sum them, and return whether they
are <= ``target``.
If ``comparator`` is provided, use it instead of <=. You may
use a string like '<' or '>='.
"""
from operator import gt, lt, ge... | python | {
"resource": ""
} |
q249323 | AbstractEngine.percent_chance | train | def percent_chance(self, pct):
"""Given a ``pct``% chance of something happening right now, decide at
random whether it actually happens, and return ``True`` or
``False`` as appropriate.
Values not between 0 and 100 are treated as though they
were 0 or 100, whichever is | python | {
"resource": ""
} |
q249324 | Engine._remember_avatarness | train | def _remember_avatarness(
self, character, graph, node,
is_avatar=True, branch=None, turn=None,
tick=None
):
"""Use this to record a change in avatarness.
Should be called whenever a node that wasn't an avatar of a
character now is, and whenever a node th... | python | {
"resource": ""
} |
q249325 | Engine._init_caches | train | def _init_caches(self):
from .xcollections import (
StringStore,
FunctionStore,
CharacterMapping,
UniversalMapping
)
from .cache import (
Cache,
NodeContentsCache,
InitializedCache,
EntitylessCache,
... | python | {
"resource": ""
} |
q249326 | Engine.close | train | def close(self):
"""Commit changes and close the database."""
import sys, os
for store in self.stores:
if hasattr(store, 'save'):
store.save(reimport=False)
path, filename = os.path.split(store._filename)
| python | {
"resource": ""
} |
q249327 | Engine.advance | train | def advance(self):
"""Follow the next rule if available.
If we've run out of rules, reset the rules iterator.
"""
try:
return next(self._rules_iter)
except InnerStopIteration:
self._rules_iter = self._follow_rules()
| python | {
"resource": ""
} |
q249328 | Engine.del_character | train | def del_character(self, name):
"""Remove the Character from the database entirely.
This also deletes all its history. You'd better be sure.
""" | python | {
"resource": ""
} |
q249329 | Engine.alias | train | def alias(self, v, stat='dummy'):
"""Return a representation of a value suitable for use in historical queries.
It will behave much as if you assigned the value to some entity and then used its
``historical`` method to get a reference to the set of its past values, which
happens to cont... | python | {
"resource": ""
} |
q249330 | MainScreen.on_play_speed | train | def on_play_speed(self, *args):
"""Change the interval at which ``self.play`` is called to match my
current ``play_speed``.
| python | {
"resource": ""
} |
q249331 | MainScreen.remake_display | train | def remake_display(self, *args):
"""Remake any affected widgets after a change in my ``kv``.
"""
Builder.load_string(self.kv)
if hasattr(self, '_kv_layout'):
| python | {
"resource": ""
} |
q249332 | MainScreen.next_turn | train | def next_turn(self, *args):
"""Advance time by one turn, if it's not blocked.
Block time by setting ``engine.universal['block'] = True``"""
if self.tmp_block:
return
eng = self.app.engine
dial = self.dialoglayout
if eng.universal.get('block'):
Log... | python | {
"resource": ""
} |
q249333 | setgraphval | train | def setgraphval(delta, graph, key, val):
"""Change a delta to say that a graph stat was set to a | python | {
"resource": ""
} |
q249334 | setnode | train | def setnode(delta, graph, node, exists):
"""Change a delta to say that a node was created or deleted"""
| python | {
"resource": ""
} |
q249335 | setnodeval | train | def setnodeval(delta, graph, node, key, value):
"""Change a delta to say that a node stat was set to a certain value"""
if (
graph in delta and 'nodes' in delta[graph] and
node in delta[graph]['nodes'] and not | python | {
"resource": ""
} |
q249336 | setedge | train | def setedge(delta, is_multigraph, graph, orig, dest, idx, exists):
"""Change a delta to say that an edge was created or deleted"""
if is_multigraph(graph):
delta.setdefault(graph, {}).setdefault('edges', {})\
.setdefault(orig, {}).setdefault(dest, | python | {
"resource": ""
} |
q249337 | setedgeval | train | def setedgeval(delta, is_multigraph, graph, orig, dest, idx, key, value):
"""Change a delta to say that an edge stat was set to a certain value"""
if is_multigraph(graph):
if (
graph in delta and 'edges' in delta[graph] and
orig in delta[graph]['edges'] and dest in delta[graph]['... | python | {
"resource": ""
} |
q249338 | ORM.advancing | train | def advancing(self):
"""A context manager for when time is moving forward one turn at a time.
When used in LiSE, this means that the game is being simulated.
It changes how the caching works, making it more efficient.
"""
| python | {
"resource": ""
} |
q249339 | ORM.batch | train | def batch(self):
"""A context manager for when you're creating lots of state.
Reads will be much slower in a batch, but writes will be faster.
You *can* combine this with ``advancing`` but it isn't any faster.
"""
| python | {
"resource": ""
} |
q249340 | ORM.get_delta | train | def get_delta(self, branch, turn_from, tick_from, turn_to, tick_to):
"""Get a dictionary describing changes to all graphs.
The keys are graph names. Their values are dictionaries of the graphs'
attributes' new values, with ``None`` for deleted keys. Also in those graph
dictionaries are ... | python | {
"resource": ""
} |
q249341 | ORM._init_caches | train | def _init_caches(self):
from collections import defaultdict
from .cache import Cache, NodesCache, EdgesCache
self._where_cached = defaultdict(list)
self._global_cache = self.query._global_cache = {}
self._node_objs = node_objs = WeakValueDictionary()
self._get_node_stuff ... | python | {
"resource": ""
} |
q249342 | ORM.is_parent_of | train | def is_parent_of(self, parent, child):
"""Return whether ``child`` is a branch descended from ``parent`` at
any remove.
"""
if parent == 'trunk':
return True
if child == 'trunk':
return False
if child not in self._branches:
raise Value... | python | {
"resource": ""
} |
q249343 | ORM._copy_plans | train | def _copy_plans(self, branch_from, turn_from, tick_from):
"""Collect all plans that are active at the given time and copy them to the current branch"""
plan_ticks = self._plan_ticks
plan_ticks_uncommitted = self._plan_ticks_uncommitted
time_plan = self._time_plan
plans = self._pl... | python | {
"resource": ""
} |
q249344 | ORM.delete_plan | train | def delete_plan(self, plan):
"""Delete the portion of a plan that has yet to occur.
:arg plan: integer ID of a plan, as given by ``with self.plan() as plan:``
"""
branch, turn, tick = self._btt()
to_delete = []
plan_ticks = self._plan_ticks[plan]
for trn, tcks i... | python | {
"resource": ""
} |
q249345 | ORM._nbtt | train | def _nbtt(self):
"""Increment the tick and return branch, turn, tick
Unless we're viewing the past, in which case raise HistoryError.
Idea is you use this when you want to advance time, which you
can only do once per branch, turn, tick.
"""
from .cache import HistoryEr... | python | {
"resource": ""
} |
q249346 | ORM.commit | train | def commit(self):
"""Write the state of all graphs to the database and commit the transaction.
Also saves the current branch, turn, and tick.
"""
self.query.globl['branch'] = self._obranch
self.query.globl['turn'] = self._oturn
self.query.globl['tick'] = self._otick
... | python | {
"resource": ""
} |
q249347 | ORM.new_graph | train | def new_graph(self, name, data=None, **attr):
"""Return a new instance of type Graph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
| python | {
"resource": ""
} |
q249348 | ORM.new_digraph | train | def new_digraph(self, name, data=None, **attr):
"""Return a new instance of type DiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
| python | {
"resource": ""
} |
q249349 | ORM.new_multigraph | train | def new_multigraph(self, name, data=None, **attr):
"""Return a new instance of type MultiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
| python | {
"resource": ""
} |
q249350 | ORM.new_multidigraph | train | def new_multidigraph(self, name, data=None, **attr):
"""Return a new instance of type MultiDiGraph, initialized with the given
data if provided.
:arg name: a name for the graph
:arg data: dictionary or NetworkX graph object providing initial state
"""
| python | {
"resource": ""
} |
q249351 | ORM.get_graph | train | def get_graph(self, name):
"""Return a graph previously created with ``new_graph``,
``new_digraph``, ``new_multigraph``, or
``new_multidigraph``
:arg name: name of an existing graph
"""
if name in self._graph_objs:
return self._graph_objs[name]
graph... | python | {
"resource": ""
} |
q249352 | ORM.del_graph | train | def del_graph(self, name):
"""Remove all traces of a graph's existence from the database
:arg name: name of an existing graph
"""
# make sure the graph exists before deleting anything
self.get_graph(name) | python | {
"resource": ""
} |
q249353 | read_tree_dendropy | train | def read_tree_dendropy(tree):
'''Create a TreeSwift tree from a DendroPy tree
Args:
``tree`` (``dendropy.datamodel.treemodel``): A Dendropy ``Tree`` object
Returns:
``Tree``: A TreeSwift tree created from ``tree``
'''
out = Tree(); d2t = dict()
if not hasattr(tree, 'preorder_no... | python | {
"resource": ""
} |
q249354 | read_tree_newick | train | def read_tree_newick(newick):
'''Read a tree from a Newick string or file
Args:
``newick`` (``str``): Either a Newick string or the path to a Newick file (plain-text or gzipped)
Returns:
``Tree``: The tree represented by ``newick``. If the Newick file has multiple trees (one per line), a `... | python | {
"resource": ""
} |
q249355 | read_tree_nexus | train | def read_tree_nexus(nexus):
'''Read a tree from a Nexus string or file
Args:
``nexus`` (``str``): Either a Nexus string or the path to a Nexus file (plain-text or gzipped)
Returns:
``dict`` of ``Tree``: A dictionary of the trees represented by ``nexus``, where keys are tree names (``str``)... | python | {
"resource": ""
} |
q249356 | read_tree | train | def read_tree(input, schema):
'''Read a tree from a string or file
Args:
``input`` (``str``): Either a tree string, a path to a tree file (plain-text or gzipped), or a DendroPy Tree object
``schema`` (``str``): The schema of ``input`` (DendroPy, Newick, NeXML, or Nexus)
Returns:
*... | python | {
"resource": ""
} |
q249357 | Tree.avg_branch_length | train | def avg_branch_length(self, terminal=True, internal=True):
'''Compute the average length of the selected branches of this ``Tree``. Edges with length ``None`` will be treated as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
`... | python | {
"resource": ""
} |
q249358 | Tree.branch_lengths | train | def branch_lengths(self, terminal=True, internal=True):
'''Generator over the lengths of the selected branches of this ``Tree``. Edges with length ``None`` will be output as 0-length
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
``int... | python | {
"resource": ""
} |
q249359 | Tree.closest_leaf_to_root | train | def closest_leaf_to_root(self):
'''Return the leaf that is closest to the root and the corresponding distance. Edges with no length will be considered to have a length of 0
Returns:
``tuple``: First value is the closest leaf to the root, and second value is the corresponding distance
... | python | {
"resource": ""
} |
q249360 | Tree.coalescence_times | train | def coalescence_times(self, backward=True):
'''Generator over the times of successive coalescence events
Args:
``backward`` (``bool``): ``True`` to go backward in time (i.e., leaves to root), otherwise ``False``
'''
if not isinstance(backward, bool):
| python | {
"resource": ""
} |
q249361 | Tree.coalescence_waiting_times | train | def coalescence_waiting_times(self, backward=True):
'''Generator over the waiting times of successive coalescence events
Args:
``backward`` (``bool``): ``True`` to go backward in time (i.e., leaves to root), otherwise ``False``
'''
if not isinstance(backward, bool):
... | python | {
"resource": ""
} |
q249362 | Tree.colless | train | def colless(self, normalize='leaves'):
'''Compute the Colless balance index of this ``Tree``. If the tree has polytomies, they will be randomly resolved
Args:
``normalize`` (``str``): How to normalize the Colless index (if at all)
* ``None`` to not normalize
* ``"l... | python | {
"resource": ""
} |
q249363 | Tree.condense | train | def condense(self):
'''If siblings have the same label, merge them. If they have edge lengths, the resulting ``Node`` will have the larger of the lengths'''
self.resolve_polytomies(); labels_below = dict(); longest_leaf_dist = dict()
for node in self.traverse_postorder():
if node.is_... | python | {
"resource": ""
} |
q249364 | Tree.deroot | train | def deroot(self, label='OLDROOT'):
'''If the tree has a root edge, drop the edge to be a child of the root node
Args:
``label`` (``str``): The desired label of the new child
'''
if self.root.edge_length is not None:
| python | {
"resource": ""
} |
q249365 | Tree.distance_between | train | def distance_between(self, u, v):
'''Return the distance between nodes ``u`` and ``v`` in this ``Tree``
Args:
``u`` (``Node``): Node ``u``
``v`` (``Node``): Node ``v``
Returns:
``float``: The distance between nodes ``u`` and ``v``
'''
if not... | python | {
"resource": ""
} |
q249366 | Tree.edge_length_sum | train | def edge_length_sum(self, terminal=True, internal=True):
'''Compute the sum of all selected edge lengths in this ``Tree``
Args:
``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False``
``internal`` (``bool``): ``True`` to include internal branches, ot... | python | {
"resource": ""
} |
q249367 | Tree.extract_subtree | train | def extract_subtree(self, node):
'''Return a copy of the subtree rooted at ``node``
Args:
``node`` (``Node``): The root of the desired subtree
Returns:
``Tree``: A copy of the subtree rooted at ``node``
| python | {
"resource": ""
} |
q249368 | Tree.extract_tree_without | train | def extract_tree_without(self, labels, suppress_unifurcations=True):
'''Extract a copy of this ``Tree`` without the leaves labeled by the strings in ``labels``
Args:
``labels`` (``set``): Set of leaf labels to exclude
``suppress_unifurcations`` (``bool``): ``True`` to suppress ... | python | {
"resource": ""
} |
q249369 | Tree.extract_tree_with | train | def extract_tree_with(self, labels, suppress_unifurcations=True):
'''Extract a copy of this ``Tree`` with only the leaves labeled by the strings in ``labels``
Args:
``leaves`` (``set``): Set of leaf labels to include.
``suppress_unifurcations`` (``bool``): ``True`` to suppress ... | python | {
"resource": ""
} |
q249370 | Tree.furthest_from_root | train | def furthest_from_root(self):
'''Return the ``Node`` that is furthest from the root and the corresponding distance. Edges with no length will be considered to have a length of 0
Returns:
``tuple``: First value is the furthest ``Node`` from the root, and second value is the corresponding dis... | python | {
"resource": ""
} |
q249371 | Tree.indent | train | def indent(self, space=4):
'''Return an indented Newick string, just like ``nw_indent`` in Newick Utilities
Args:
``space`` (``int``): The number of spaces a tab should equal
Returns:
``str``: An indented Newick string
'''
if not isinstance(space,int):
... | python | {
"resource": ""
} |
q249372 | Tree.lineages_through_time | train | def lineages_through_time(self, present_day=None, show_plot=True, color='#000000', xmin=None, xmax=None, ymin=None, ymax=None, title=None, xlabel=None, ylabel=None):
'''Compute the number of lineages through time. If seaborn is installed, a plot is shown as well
Args:
``present_day`` (``flo... | python | {
"resource": ""
} |
q249373 | Tree.newick | train | def newick(self):
'''Output this ``Tree`` as a Newick string
Returns:
``str``: Newick string of this ``Tree``
'''
if self.root.edge_length is None:
suffix = ';'
elif isinstance(self.root.edge_length,int):
suffix = ':%d;' % self.root.edge_lengt... | python | {
"resource": ""
} |
q249374 | Tree.num_lineages_at | train | def num_lineages_at(self, distance):
'''Returns the number of lineages of this ``Tree`` that exist ``distance`` away from the root
Args:
``distance`` (``float``): The distance away from the root
Returns:
``int``: The number of lineages that exist ``distance`` away from ... | python | {
"resource": ""
} |
q249375 | Tree.num_nodes | train | def num_nodes(self, leaves=True, internal=True):
'''Compute the total number of selected nodes in this ``Tree``
Args:
``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False``
``internal`` (``bool``): ``True`` to include internal nodes, otherwise ``False``
... | python | {
"resource": ""
} |
q249376 | Tree.rename_nodes | train | def rename_nodes(self, renaming_map):
'''Rename nodes in this ``Tree``
Args:
``renaming_map`` (``dict``): A dictionary mapping old labels (keys) to new labels (values)
'''
if not isinstance(renaming_map, dict):
raise TypeError("renaming_map | python | {
"resource": ""
} |
q249377 | Tree.sackin | train | def sackin(self, normalize='leaves'):
'''Compute the Sackin balance index of this ``Tree``
Args:
``normalize`` (``str``): How to normalize the Sackin index (if at all)
* ``None`` to not normalize
* ``"leaves"`` to normalize by the number of leaves
* ``... | python | {
"resource": ""
} |
q249378 | Tree.scale_edges | train | def scale_edges(self, multiplier):
'''Multiply all edges in this ``Tree`` by ``multiplier``'''
if not isinstance(multiplier,int) and not isinstance(multiplier,float):
| python | {
"resource": ""
} |
q249379 | Tree.suppress_unifurcations | train | def suppress_unifurcations(self):
'''Remove all nodes with only one child and directly attach child to parent'''
q = deque(); q.append(self.root)
while len(q) != 0:
node = q.popleft()
if len(node.children) != 1:
q.extend(node.children); continue
... | python | {
"resource": ""
} |
q249380 | Tree.traverse_inorder | train | def traverse_inorder(self, leaves=True, internal=True):
'''Perform an inorder traversal of the ``Node`` objects in this ``Tree``
Args:
``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False``
| python | {
"resource": ""
} |
q249381 | Tree.traverse_levelorder | train | def traverse_levelorder(self, leaves=True, internal=True):
'''Perform a levelorder traversal of the ``Node`` objects in this ``Tree``'''
for node in | python | {
"resource": ""
} |
q249382 | Tree.traverse_postorder | train | def traverse_postorder(self, leaves=True, internal=True):
'''Perform a postorder traversal of the ``Node`` objects in this ``Tree``
Args:
``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False``
| python | {
"resource": ""
} |
q249383 | Tree.traverse_preorder | train | def traverse_preorder(self, leaves=True, internal=True):
'''Perform a preorder traversal of the ``Node`` objects in this ``Tree``
Args:
``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False``
| python | {
"resource": ""
} |
q249384 | Tree.write_tree_newick | train | def write_tree_newick(self, filename, hide_rooted_prefix=False):
'''Write this ``Tree`` to a Newick file
Args:
``filename`` (``str``): Path to desired output file (plain-text or gzipped)
'''
if not isinstance(filename, str):
raise TypeError("filename must be a st... | python | {
"resource": ""
} |
q249385 | update_window | train | def update_window(turn_from, tick_from, turn_to, tick_to, updfun, branchd):
"""Iterate over a window of time in ``branchd`` and call ``updfun`` on the values"""
if turn_from in branchd:
# Not including the exact tick you started from because deltas are *changes*
for past_state in branchd[turn_fr... | python | {
"resource": ""
} |
q249386 | update_backward_window | train | def update_backward_window(turn_from, tick_from, turn_to, tick_to, updfun, branchd):
"""Iterate backward over a window of time in ``branchd`` and call ``updfun`` on the values"""
if turn_from in branchd:
for future_state in reversed(branchd[turn_from][:tick_from]):
updfun(*future_state)
... | python | {
"resource": ""
} |
q249387 | within_history | train | def within_history(rev, windowdict):
"""Return whether the windowdict has history at the revision."""
if not windowdict:
return False
begin = windowdict._past[0][0] if windowdict._past else \
| python | {
"resource": ""
} |
q249388 | WindowDict.future | train | def future(self, rev=None):
"""Return a Mapping of items after the given revision.
Default revision is the last one looked up.
"""
| python | {
"resource": ""
} |
q249389 | WindowDict.past | train | def past(self, rev=None):
"""Return a Mapping of items at or before the given revision.
Default revision is the last one looked up.
""" | python | {
"resource": ""
} |
q249390 | WindowDict.seek | train | def seek(self, rev):
"""Arrange the caches to help look up the given revision."""
# TODO: binary search? Perhaps only when one or the other
# stack is very large?
if not self:
return
if type(rev) is not int:
raise TypeError("rev must be int")
past ... | python | {
"resource": ""
} |
q249391 | WindowDict.rev_before | train | def rev_before(self, rev: int) -> int:
"""Return the latest past rev on | python | {
"resource": ""
} |
q249392 | WindowDict.rev_after | train | def rev_after(self, rev: int) -> int:
"""Return the earliest future rev on which | python | {
"resource": ""
} |
q249393 | WindowDict.truncate | train | def truncate(self, rev: int) -> None:
"""Delete everything after the given revision."""
self.seek(rev)
| python | {
"resource": ""
} |
q249394 | ELiDEApp.build_config | train | def build_config(self, config):
"""Set config defaults"""
for sec in 'LiSE', 'ELiDE':
config.adddefaultsection(sec)
config.setdefaults(
'LiSE',
{
'world': 'sqlite:///LiSEworld.db',
'language': 'eng',
'logfile': '... | python | {
"resource": ""
} |
q249395 | ELiDEApp.build | train | def build(self):
"""Make sure I can use the database, create the tables as needed, and
return the root widget.
"""
self.icon = 'icon_24px.png'
config = self.config
Logger.debug(
"ELiDEApp: starting with world {}, path {}".format(
config['LiSE'... | python | {
"resource": ""
} |
q249396 | ELiDEApp.on_pause | train | def on_pause(self):
"""Sync the database with the current state of the game."""
| python | {
"resource": ""
} |
q249397 | ELiDEApp.on_stop | train | def on_stop(self, *largs):
"""Sync the database, wrap up the game, and halt."""
self.strings.save()
self.funcs.save()
| python | {
"resource": ""
} |
q249398 | ELiDEApp.delete_selection | train | def delete_selection(self):
"""Delete both the selected widget and whatever it represents."""
selection = self.selection
if selection is None:
return
if isinstance(selection, ArrowWidget):
self.mainscreen.boardview.board.rm_arrow(
selection.origin.... | python | {
"resource": ""
} |
q249399 | ELiDEApp.new_board | train | def new_board(self, name):
"""Make a board for a character name, and switch to it."""
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.