text
stringlengths
0
828
for k, v in parse_environment_file(envfile):
os.environ.setdefault(k, v)"
4819,"def infer_format(filename:str) -> str:
""""""Return extension identifying format of given filename""""""
_, ext = os.path.splitext(filename)
return ext"
4820,"def reversed_graph(graph:dict) -> dict:
""""""Return given graph reversed""""""
ret = defaultdict(set)
for node, succs in graph.items():
for succ in succs:
ret[succ].add(node)
return dict(ret)"
4821,"def walk(start:list, graphs:iter) -> iter:
""""""walk on given graphs, beginning on start.
Yield all found nodes, including start.
All graph are understood as a single one,
with merged keys and values.
""""""
walked = set([start])
stack = [start]
while len(stack) > 0:
*stack, curr = stack
yield curr
succs = it.chain.from_iterable(graph.get(curr, ()) for graph in graphs)
for succ in succs:
if succ not in walked:
walked.add(curr)
stack.append(succ)"
4822,"def have_cycle(graph:dict) -> frozenset:
""""""Perform a topologic sort to detect any cycle.
Return the set of unsortable nodes. If at least one item,
then there is cycle in given graph.
""""""
# topological sort
walked = set() # walked nodes
nodes = frozenset(it.chain(it.chain.from_iterable(graph.values()), graph.keys())) # all nodes of the graph
preds = reversed_graph(graph) # succ: preds
last_walked_len = -1
while last_walked_len != len(walked):
last_walked_len = len(walked)
for node in nodes - walked:
if len(preds.get(node, set()) - walked) == 0:
walked.add(node)
return frozenset(nodes - walked)"
4823,"def file_lines(bblfile:str) -> iter:
""""""Yield lines found in given file""""""
with open(bblfile) as fd:
yield from (line.rstrip() for line in fd if line.rstrip())"
4824,"def line_type(line:str) -> str:
""""""Give type of input line, as defined in LINE_TYPES
>>> line_type('IN\\ta\\tb')
'IN'
>>> line_type('')
'EMPTY'
""""""
for regex, ltype in LINE_TYPES.items():
if re.fullmatch(regex, line):
return ltype
raise ValueError(""Input line \""{}\"" is not bubble formatted"".format(line))"
4825,"def line_data(line:str) -> tuple:
""""""Return groups found in given line
>>> line_data('IN\\ta\\tb')
('IN', 'a', 'b')
>>> line_data('')
()
""""""
for regex, _ in LINE_TYPES.items():
match = re.fullmatch(regex, line)
if match:
return match.groups()
raise ValueError(""Input line \""{}\"" is not bubble formatted"".format(line))"
4826,"def _catchCurrentViewContent(self):
""""""!
\~english
Catch the current view content
@return: a PIL Image
@note
Automatically converts the cache color mode and at the
same time rotates the captured image data according to
the screen angle
\~chinese
从缓存中抓取当前视图大小的数据
@return: PIL Image 对象
@note 自动转换缓存色彩模式,同时根据屏幕角度设定旋转所抓取的图像数据
""""""
viewContent = None
if self._buffer_color_mode != self._display_color_mode:
viewContent = self._buffer.crop( self.View.rectToArray() ) .convert( self._display_color_mode )
else:
viewContent = self._buffer.crop( self.View.rectToArray() )