_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q278100 | MetricMarkdown.generateMarkdown | test | def generateMarkdown(self):
"""
Look up each of the metrics and then output in Markdown
"""
self.generateMetricDefinitions()
self.generateFieldDefinitions()
self.generateDashboardDefinitions()
self.outputMarkdown() | python | {
"resource": ""
} |
q278101 | ParserBase.parse | test | def parse(self, text):
"""Attempt to parse source code."""
self.original_text = text
try:
return getattr(self, self.entry_point)(text)
except (DeadEnd) as exc:
raise ParserError(self.most_consumed, "Failed to parse input") from exc
return tree | python | {
"resource": ""
} |
q278102 | ParserBase._attempting | test | def _attempting(self, text):
"""Keeps track of the furthest point in the source code the parser has reached to this point."""
consumed = len(self.original_text) - len(text)
self.most_consumed = max(consumed, self.most_consumed) | python | {
"resource": ""
} |
q278103 | MeasurementGet.add_arguments | test | def add_arguments(self):
"""
Add specific command line arguments for this command
"""
# Call our parent to add the default arguments
ApiCli.add_arguments(self)
# Command specific arguments
self.parser.add_argument('-f', '--format', dest='format', action='stor... | python | {
"resource": ""
} |
q278104 | MeasurementGet.parse_time_date | test | def parse_time_date(self, s):
"""
Attempt to parse the passed in string into a valid datetime.
If we get a parse error then assume the string is an epoch time
and convert to a datetime.
"""
try:
ret = parser.parse(str(s))
except ValueError:
... | python | {
"resource": ""
} |
q278105 | MeasurementGet.output_csv | test | def output_csv(self, text):
"""
Output results in CSV format
"""
payload = json.loads(text)
# Print CSV header
print("{0},{1},{2},{3},{4}".format('timestamp', 'metric', 'aggregate', 'source', 'value'))
metric_name = self._metric_name
# Loop through the agg... | python | {
"resource": ""
} |
q278106 | MeasurementGet.output_json | test | def output_json(self, text):
"""
Output results in structured JSON format
"""
payload = json.loads(text)
data = []
metric_name = self._metric_name
for r in payload['result']['aggregates']['key']:
timestamp = self._format_timestamp(r[0][0])
... | python | {
"resource": ""
} |
q278107 | MeasurementGet.output_raw | test | def output_raw(self, text):
"""
Output results in raw JSON format
"""
payload = json.loads(text)
out = json.dumps(payload, sort_keys=True, indent=self._indent, separators=(',', ': '))
print(self.colorize_json(out)) | python | {
"resource": ""
} |
q278108 | MeasurementGet.output_xml | test | def output_xml(self, text):
"""
Output results in JSON format
"""
# Create the main document nodes
document = Element('results')
comment = Comment('Generated by TrueSight Pulse measurement-get CLI')
document.append(comment)
aggregates = SubElement(documen... | python | {
"resource": ""
} |
q278109 | trimmed_pred_default | test | def trimmed_pred_default(node, parent):
"""The default predicate used in Node.trimmed."""
return isinstance(node, ParseNode) and (node.is_empty or node.is_type(ParseNodeType.terminal)) | python | {
"resource": ""
} |
q278110 | pprint | test | def pprint(root, depth=0, space_unit=" ", *, source_len=0, file=None):
"""Pretting print a parse tree."""
spacing = space_unit * depth
if isinstance(root, str):
print("{0}terminal@(?): {1}".format(spacing, root), file=file)
else:
if root.position is None:
position = -1
elif root.position <... | python | {
"resource": ""
} |
q278111 | repetition | test | def repetition(extractor, bounds, *, ignore_whitespace=False):
"""Returns a partial of _get_repetition that accepts only a text argument."""
return partial(_get_repetition, extractor, bounds=bounds, ignore_whitespace=ignore_whitespace) | python | {
"resource": ""
} |
q278112 | _get_terminal | test | def _get_terminal(value, text):
"""Checks the beginning of text for a value. If it is found, a terminal ParseNode is returned
filled out appropriately for the value it found. DeadEnd is raised if the value does not match.
"""
if text and text.startswith(value):
return ParseNode(ParseNodeType.terminal,
... | python | {
"resource": ""
} |
q278113 | _get_repetition | test | def _get_repetition(extractor, text, *, bounds=(0, None), ignore_whitespace=False):
"""Tries to pull text with extractor repeatedly.
Bounds is a 2-tuple of (lbound, ubound) where lbound is a number and ubound is a number or None.
If the ubound is None, this method will execute extractor on text until extrator ra... | python | {
"resource": ""
} |
q278114 | _get_exclusion | test | def _get_exclusion(extractor, exclusion, text):
"""Returns extractor's result if exclusion does not match.
If exclusion raises DeadEnd (meaning it did not match) then the result of extractor(text) is
returned. Otherwise, if exclusion does not raise DeadEnd it means it did match, and we then
raise DeadEnd.
""... | python | {
"resource": ""
} |
q278115 | _count_leading_whitespace | test | def _count_leading_whitespace(text):
"""Returns the number of characters at the beginning of text that are whitespace."""
idx = 0
for idx, char in enumerate(text):
if not char.isspace():
return idx
return idx + 1 | python | {
"resource": ""
} |
q278116 | _call_extractor | test | def _call_extractor(extractor, text):
"""This method calls an extractor on some text.
If extractor is just a string, it is passed as the first value to _get_terminal. Otherwise it is
treated as a callable and text is passed directly to it.
This makes it so you can have a shorthand of terminal(val) <-> val.
... | python | {
"resource": ""
} |
q278117 | ParseNode.position | test | def position(self):
"""Gets the position of the text the ParseNode processed. If the ParseNode does not have its
own position, it looks to its first child for its position.
'Value Nodes' (terminals) must have their own position, otherwise this method will throw an
exception when it tries to get the pos... | python | {
"resource": ""
} |
q278118 | ParseNode.is_empty | test | def is_empty(self):
"""Returns True if this node has no children, or if all of its children are ParseNode instances
and are empty.
"""
return all(isinstance(c, ParseNode) and c.is_empty for c in self.children) | python | {
"resource": ""
} |
q278119 | ParseNode.add_ignored | test | def add_ignored(self, ignored):
"""Add ignored text to the node. This will add the length of the ignored text to the node's
consumed property.
"""
if ignored:
if self.ignored:
self.ignored = ignored + self.ignored
else:
self.ignored = ignored
self.consumed += len(ignored... | python | {
"resource": ""
} |
q278120 | ParseNode.is_type | test | def is_type(self, value):
"""Returns True if node_type == value.
If value is a tuple, node_type is checked against each member and True is returned if any of
them match.
"""
if isinstance(value, tuple):
for opt in value:
if self.node_type == opt:
return True
return Fal... | python | {
"resource": ""
} |
q278121 | ParseNode.flattened | test | def flattened(self, pred=flattened_pred_default):
"""Flattens nodes by hoisting children up to ancestor nodes.
A node is hoisted if pred(node) returns True.
"""
if self.is_value:
return self
new_children = []
for child in self.children:
if child.is_empty:
continue
n... | python | {
"resource": ""
} |
q278122 | ParseNode.trimmed | test | def trimmed(self, pred=trimmed_pred_default):
"""Trim a ParseTree.
A node is trimmed if pred(node) returns True.
"""
new_children = []
for child in self.children:
if isinstance(child, ParseNode):
new_child = child.trimmed(pred)
else:
new_child = child
if not pred... | python | {
"resource": ""
} |
q278123 | ParseNode.merged | test | def merged(self, other):
"""Returns a new ParseNode whose type is this node's type, and whose children are all the
children from this node and the other whose length is not 0.
"""
children = [c for c in itertools.chain(self.children, other.children) if len(c) > 0]
# NOTE: Only terminals should have ... | python | {
"resource": ""
} |
q278124 | ParseNode.retyped | test | def retyped(self, new_type):
"""Returns a new node with the same contents as self, but with a new node_type."""
return ParseNode(new_type,
children=list(self.children),
consumed=self.consumed,
position=self.position,
ignored... | python | {
"resource": ""
} |
q278125 | ParseNode.compressed | test | def compressed(self, new_type=None, *, include_ignored=False):
"""Turns the node into a value node, whose single string child is the concatenation of all its
children.
"""
values = []
consumed = 0
ignored = None
for i, child in enumerate(self.children):
consumed += child.consumed
... | python | {
"resource": ""
} |
q278126 | Cursor.position | test | def position(self) -> Position:
"""The current position of the cursor."""
return Position(self._index, self._lineno, self._col_offset) | python | {
"resource": ""
} |
q278127 | Cursor.max_readed_position | test | def max_readed_position(self) -> Position:
"""The index of the deepest character readed."""
return Position(self._maxindex, self._maxline, self._maxcol) | python | {
"resource": ""
} |
q278128 | Cursor.step_next_char | test | def step_next_char(self):
"""Puts the cursor on the next character."""
self._index += 1
self._col_offset += 1
if self._index > self._maxindex:
self._maxindex = self._index
self._maxcol = self._col_offset
self._maxline = self._lineno | python | {
"resource": ""
} |
q278129 | Cursor.step_next_line | test | def step_next_line(self):
"""Sets cursor as beginning of next line."""
self._eol.append(self.position)
self._lineno += 1
self._col_offset = 0 | python | {
"resource": ""
} |
q278130 | Cursor.step_prev_line | test | def step_prev_line(self):
"""Sets cursor as end of previous line."""
#TODO(bps): raise explicit error for unregistered eol
#assert self._eol[-1].index == self._index
if len(self._eol) > 0:
self.position = self._eol.pop() | python | {
"resource": ""
} |
q278131 | Stream.last_readed_line | test | def last_readed_line(self) -> str:
"""Usefull string to compute error message."""
mpos = self._cursor.max_readed_position
mindex = mpos.index
# search last \n
prevline = mindex - 1 if mindex == self.eos_index else mindex
while prevline >= 0 and self._content[prevline] != ... | python | {
"resource": ""
} |
q278132 | Stream.incpos | test | def incpos(self, length: int=1) -> int:
"""Increment the cursor to the next character."""
if length < 0:
raise ValueError("length must be positive")
i = 0
while (i < length):
if self._cursor.index < self._len:
if self.peek_char == '\n':
... | python | {
"resource": ""
} |
q278133 | Stream.save_context | test | def save_context(self) -> bool:
"""Save current position."""
self._contexts.append(self._cursor.position)
return True | python | {
"resource": ""
} |
q278134 | Stream.restore_context | test | def restore_context(self) -> bool:
"""Rollback to previous saved position."""
self._cursor.position = self._contexts.pop()
return False | python | {
"resource": ""
} |
q278135 | to_fmt | test | def to_fmt(self, with_from=False) -> fmt.indentable:
"""
Return a Fmt representation of Translator for pretty-printing
"""
txt = fmt.sep("\n", [
fmt.sep(
" ",
[
self._type_source,
"to",
self._type_target,
'='... | python | {
"resource": ""
} |
q278136 | Scope.set_name | test | def set_name(self, name: str):
""" You could set the name after construction """
self.name = name
# update internal names
lsig = self._hsig.values()
self._hsig = {}
for s in lsig:
self._hsig[s.internal_name()] = s | python | {
"resource": ""
} |
q278137 | Scope.count_vars | test | def count_vars(self) -> int:
""" Count var define by this scope """
n = 0
for s in self._hsig.values():
if hasattr(s, 'is_var') and s.is_var:
n += 1
return n | python | {
"resource": ""
} |
q278138 | Scope.count_funs | test | def count_funs(self) -> int:
""" Count function define by this scope """
n = 0
for s in self._hsig.values():
if hasattr(s, 'is_fun') and s.is_fun:
n += 1
return n | python | {
"resource": ""
} |
q278139 | Scope.__update_count | test | def __update_count(self):
""" Update internal counters """
self._ntypes = self.count_types()
self._nvars = self.count_vars()
self._nfuns = self.count_funs() | python | {
"resource": ""
} |
q278140 | Scope.update | test | def update(self, sig: list or Scope) -> Scope:
""" Update the Set with values of another Set """
values = sig
if hasattr(sig, 'values'):
values = sig.values()
for s in values:
if self.is_namespace:
s.set_parent(self)
if isinstance(s, Sc... | python | {
"resource": ""
} |
q278141 | Scope.union | test | def union(self, sig: Scope) -> Scope:
""" Create a new Set produce by the union of 2 Set """
new = Scope(sig=self._hsig.values(), state=self.state)
new |= sig
return new | python | {
"resource": ""
} |
q278142 | Scope.intersection_update | test | def intersection_update(self, oset: Scope) -> Scope:
""" Update Set with common values of another Set """
keys = list(self._hsig.keys())
for k in keys:
if k not in oset:
del self._hsig[k]
else:
self._hsig[k] = oset.get(k)
return sel... | python | {
"resource": ""
} |
q278143 | Scope.intersection | test | def intersection(self, sig: Scope) -> Scope:
""" Create a new Set produce by the intersection of 2 Set """
new = Scope(sig=self._hsig.values(), state=self.state)
new &= sig
return new | python | {
"resource": ""
} |
q278144 | Scope.difference_update | test | def difference_update(self, oset: Scope) -> Scope:
""" Remove values common with another Set """
keys = list(self._hsig.keys())
for k in keys:
if k in oset:
del self._hsig[k]
return self | python | {
"resource": ""
} |
q278145 | Scope.difference | test | def difference(self, sig: Scope) -> Scope:
""" Create a new Set produce by a Set subtracted by another Set """
new = Scope(sig=self._hsig.values(), state=self.state)
new -= sig
return new | python | {
"resource": ""
} |
q278146 | Scope.symmetric_difference_update | test | def symmetric_difference_update(self, oset: Scope) -> Scope:
""" Remove common values
and Update specific values from another Set
"""
skey = set()
keys = list(self._hsig.keys())
for k in keys:
if k in oset:
skey.add(k)
for k in oset... | python | {
"resource": ""
} |
q278147 | Scope.symmetric_difference | test | def symmetric_difference(self, sig: Scope) -> Scope:
""" Create a new Set with values present in only one Set """
new = Scope(sig=self._hsig.values(), state=self.state)
new ^= sig
return new | python | {
"resource": ""
} |
q278148 | Scope.add | test | def add(self, it: Signature) -> bool:
""" Add it to the Set """
if isinstance(it, Scope):
it.state = StateScope.EMBEDDED
txt = it.internal_name()
it.set_parent(self)
if self.is_namespace:
txt = it.internal_name()
if txt == "":
txt = '_'... | python | {
"resource": ""
} |
q278149 | Scope.remove | test | def remove(self, it: Signature) -> bool:
""" Remove it but raise KeyError if not found """
txt = it.internal_name()
if txt not in self._hsig:
raise KeyError(it.show_name() + ' not in Set')
sig = self._hsig[txt]
if isinstance(sig, Scope):
sig.state = StateS... | python | {
"resource": ""
} |
q278150 | Scope.discard | test | def discard(self, it: Signature) -> bool:
""" Remove it only if present """
txt = it.internal_name()
if txt in self._hsig:
sig = self._hsig[txt]
if isinstance(sig, Scope):
sig.state = StateScope.LINKED
del self._hsig[txt]
return Tru... | python | {
"resource": ""
} |
q278151 | Scope.values | test | def values(self) -> [Signature]:
""" Retrieve all values """
if self.state == StateScope.EMBEDDED and self.parent is not None:
return list(self._hsig.values()) + list(self.parent().values())
else:
return self._hsig.values() | python | {
"resource": ""
} |
q278152 | Scope.first | test | def first(self) -> Signature:
""" Retrieve the first Signature ordered by mangling descendant """
k = sorted(self._hsig.keys())
return self._hsig[k[0]] | python | {
"resource": ""
} |
q278153 | Scope.last | test | def last(self) -> Signature:
""" Retrieve the last Signature ordered by mangling descendant """
k = sorted(self._hsig.keys())
return self._hsig[k[-1]] | python | {
"resource": ""
} |
q278154 | Scope.get | test | def get(self, key: str, default=None) -> Signature:
""" Get a signature instance by its internal_name """
item = default
if key in self._hsig:
item = self._hsig[key]
return item | python | {
"resource": ""
} |
q278155 | Scope.get_by_symbol_name | test | def get_by_symbol_name(self, name: str) -> Scope:
""" Retrieve a Set of all signature by symbol name """
lst = []
for s in self.values():
if s.name == name:
# create an EvalCtx only when necessary
lst.append(EvalCtx.from_sig(s))
# include paren... | python | {
"resource": ""
} |
q278156 | Scope.getsig_by_symbol_name | test | def getsig_by_symbol_name(self, name: str) -> Signature:
""" Retrieve the unique Signature of a symbol.
Fail if the Signature is not unique
"""
subscope = self.get_by_symbol_name(name)
if len(subscope) != 1:
raise KeyError("%s have multiple candidates in scope" % name... | python | {
"resource": ""
} |
q278157 | Scope.get_all_polymorphic_return | test | def get_all_polymorphic_return(self) -> bool:
""" For now, polymorphic return type are handle by symbol artefact.
--> possible multi-polymorphic but with different constraint attached!
"""
lst = []
for s in self.values():
if hasattr(s, 'tret') and s.tret.is_polymorph... | python | {
"resource": ""
} |
q278158 | Scope.callInjector | test | def callInjector(self, old: Node, trans: Translator) -> Node:
""" If don't have injector call from parent """
if self.astTranslatorInjector is None:
if self.parent is not None:
# TODO: think if we forward for all StateScope
# forward to parent scope
... | python | {
"resource": ""
} |
q278159 | normalize | test | def normalize(ast: Node) -> Node:
"""
Normalize an AST nodes.
all builtins containers are replace by referencable subclasses
"""
res = ast
typemap = {DictNode, ListNode, TupleNode}
if type(ast) is dict:
res = DictNode(ast)
elif type(ast) is list:
res = ListNode(ast)
... | python | {
"resource": ""
} |
q278160 | Node.set | test | def set(self, othernode):
"""allow to completly mutate the node into any subclasses of Node"""
self.__class__ = othernode.__class__
self.clean()
if len(othernode) > 0:
for k, v in othernode.items():
self[k] = v
for k, v in vars(othernode).items():
... | python | {
"resource": ""
} |
q278161 | ListNodeItem.rvalues | test | def rvalues(self):
"""
in reversed order
"""
tmp = self
while tmp is not None:
yield tmp.data
tmp = tmp.prev | python | {
"resource": ""
} |
q278162 | _hit_ok | test | def _hit_ok(hit, min_hit_charge, max_hit_charge):
''' Check if given hit is withing the limits.
'''
# Omit hits with charge < min_hit_charge
if hit['charge'] < min_hit_charge:
return False
# Omit hits with charge > max_hit_charge
if max_hit_charge != 0 and hit['charge'] > max_hit_charge... | python | {
"resource": ""
} |
q278163 | EvalCtx.get_compute_sig | test | def get_compute_sig(self) -> Signature:
"""
Compute a signature Using resolution!!!
TODO: discuss of relevance of a final generation for a signature
"""
tret = []
tparams = []
for t in self.tret.components:
if t in self.resolution and self.resolution[... | python | {
"resource": ""
} |
q278164 | EvalCtx.resolve | test | def resolve(self):
"""
Process the signature and find definition for type.
"""
# collect types for resolution
t2resolv = []
if hasattr(self._sig, 'tret'):
t2resolv.append(self._sig.tret)
if hasattr(self._sig, 'tparams') and self._sig.tparams is not Non... | python | {
"resource": ""
} |
q278165 | EvalCtx.get_resolved_names | test | def get_resolved_names(self, type_name: TypeName) -> list:
"""
Use self.resolution to subsitute type_name.
Allow to instanciate polymorphic type ?1, ?toto
"""
if not isinstance(type_name, TypeName):
raise Exception("Take a TypeName as parameter not a %s"
... | python | {
"resource": ""
} |
q278166 | EvalCtx.set_resolved_name | test | def set_resolved_name(self, ref: dict, type_name2solve: TypeName,
type_name_ref: TypeName):
"""
Warning!!! Need to rethink it when global poly type
"""
if self.resolution[type_name2solve.value] is None:
self.resolution[type_name2solve.value] = ref[ty... | python | {
"resource": ""
} |
q278167 | S3Saver._delete_local | test | def _delete_local(self, filename):
"""Deletes the specified file from the local filesystem."""
if os.path.exists(filename):
os.remove(filename) | python | {
"resource": ""
} |
q278168 | S3Saver._delete_s3 | test | def _delete_s3(self, filename, bucket_name):
"""Deletes the specified file from the given S3 bucket."""
conn = S3Connection(self.access_key_id, self.access_key_secret)
bucket = conn.get_bucket(bucket_name)
if type(filename).__name__ == 'Key':
filename = '/' + filename.name
... | python | {
"resource": ""
} |
q278169 | S3Saver.delete | test | def delete(self, filename, storage_type=None, bucket_name=None):
"""Deletes the specified file, either locally or from S3, depending on the file's storage type."""
if not (storage_type and bucket_name):
self._delete_local(filename)
else:
if storage_type != 's3':
... | python | {
"resource": ""
} |
q278170 | S3Saver._save_local | test | def _save_local(self, temp_file, filename, obj):
"""Saves the specified file to the local file system."""
path = self._get_path(filename)
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path), self.permission | 0o111)
fd = open(path, 'wb')
... | python | {
"resource": ""
} |
q278171 | S3Saver._save_s3 | test | def _save_s3(self, temp_file, filename, obj):
"""Saves the specified file to the configured S3 bucket."""
conn = S3Connection(self.access_key_id, self.access_key_secret)
bucket = conn.get_bucket(self.bucket_name)
path = self._get_s3_path(filename)
k = bucket.new_key(path)
... | python | {
"resource": ""
} |
q278172 | S3Saver.save | test | def save(self, temp_file, filename, obj):
"""Saves the specified file to either S3 or the local filesystem, depending on the currently enabled storage type."""
if not (self.storage_type and self.bucket_name):
ret = self._save_local(temp_file, filename, obj)
else:
if self... | python | {
"resource": ""
} |
q278173 | S3Saver._find_by_path_s3 | test | def _find_by_path_s3(self, path, bucket_name):
"""Finds files by licking an S3 bucket's contents by prefix."""
conn = S3Connection(self.access_key_id, self.access_key_secret)
bucket = conn.get_bucket(bucket_name)
s3_path = self._get_s3_path(path)
return bucket.list(prefix=s3_p... | python | {
"resource": ""
} |
q278174 | enum | test | def enum(*sequential, **named):
"""
Build an enum statement
"""
#: build enums from parameter
enums = dict(zip(sequential, range(len(sequential))), **named)
enums['map'] = copy.copy(enums)
#: build reverse mapping
enums['rmap'] = {}
for key, value in enums.items():
if type(va... | python | {
"resource": ""
} |
q278175 | checktypes | test | def checktypes(func):
"""Decorator to verify arguments and return types."""
sig = inspect.signature(func)
types = {}
for param in sig.parameters.values():
# Iterate through function's parameters and build the list of
# arguments types
param_type = param.annotation
if par... | python | {
"resource": ""
} |
q278176 | set_one | test | def set_one(chainmap, thing_name, callobject):
""" Add a mapping with key thing_name for callobject in chainmap with
namespace handling.
"""
namespaces = reversed(thing_name.split("."))
lstname = []
for name in namespaces:
lstname.insert(0, name)
strname = '.'.join(lstname)
... | python | {
"resource": ""
} |
q278177 | add_method | test | def add_method(cls):
"""Attach a method to a class."""
def wrapper(f):
#if hasattr(cls, f.__name__):
# raise AttributeError("{} already has a '{}' attribute".format(
# cls.__name__, f.__name__))
setattr(cls, f.__name__, f)
return f
return wrapper | python | {
"resource": ""
} |
q278178 | hook | test | def hook(cls, hookname=None, erase=False):
"""Attach a method to a parsing class and register it as a parser hook.
The method is registered with its name unless hookname is provided.
"""
if not hasattr(cls, '_hooks'):
raise TypeError(
"%s didn't seems to be a BasicParser subsclas... | python | {
"resource": ""
} |
q278179 | rule | test | def rule(cls, rulename=None, erase=False):
"""Attach a method to a parsing class and register it as a parser rule.
The method is registered with its name unless rulename is provided.
"""
if not hasattr(cls, '_rules'):
raise TypeError(
"%s didn't seems to be a BasicParser subsclas... | python | {
"resource": ""
} |
q278180 | directive | test | def directive(directname=None):
"""Attach a class to a parsing class and register it as a parser directive.
The class is registered with its name unless directname is provided.
"""
global _directives
class_dir_list = _directives
def wrapper(f):
nonlocal directname
if direct... | python | {
"resource": ""
} |
q278181 | decorator | test | def decorator(directname=None):
"""
Attach a class to a parsing decorator and register it to the global
decorator list.
The class is registered with its name unless directname is provided
"""
global _decorators
class_deco_list = _decorators
def wrapper(f):
nonlocal d... | python | {
"resource": ""
} |
q278182 | bind | test | def bind(self, dst: str, src: Node) -> bool:
"""Allow to alias a node to another name.
Useful to bind a node to _ as return of Rule::
R = [
__scope__:L [item:I #add_item(L, I]* #bind('_', L)
]
It's also the default behaviour of ':>'
"""
for m in self.rule_nodes.maps:... | python | {
"resource": ""
} |
q278183 | read_eol | test | def read_eol(self) -> bool:
"""Return True if the parser can consume an EOL byte sequence."""
if self.read_eof():
return False
self._stream.save_context()
self.read_char('\r')
if self.read_char('\n'):
return self._stream.validate_context()
return self._stream.restore_context() | python | {
"resource": ""
} |
q278184 | BasicParser.push_rule_nodes | test | def push_rule_nodes(self) -> bool:
"""Push context variable to store rule nodes."""
if self.rule_nodes is None:
self.rule_nodes = collections.ChainMap()
self.tag_cache = collections.ChainMap()
self.id_cache = collections.ChainMap()
else:
self.rule_... | python | {
"resource": ""
} |
q278185 | BasicParser.pop_rule_nodes | test | def pop_rule_nodes(self) -> bool:
"""Pop context variable that store rule nodes"""
self.rule_nodes = self.rule_nodes.parents
self.tag_cache = self.tag_cache.parents
self.id_cache = self.id_cache.parents
return True | python | {
"resource": ""
} |
q278186 | BasicParser.value | test | def value(self, n: Node) -> str:
"""Return the text value of the node"""
id_n = id(n)
idcache = self.id_cache
if id_n not in idcache:
return ""
name = idcache[id_n]
tag_cache = self.tag_cache
if name not in tag_cache:
raise Exception("Incoh... | python | {
"resource": ""
} |
q278187 | BasicParser.parsed_stream | test | def parsed_stream(self, content: str, name: str=None):
"""Push a new Stream into the parser.
All subsequent called functions will parse this new stream,
until the 'popStream' function is called.
"""
self._streams.append(Stream(content, name)) | python | {
"resource": ""
} |
q278188 | BasicParser.begin_tag | test | def begin_tag(self, name: str) -> Node:
"""Save the current index under the given name."""
# Check if we could attach tag cache to current rule_nodes scope
self.tag_cache[name] = Tag(self._stream, self._stream.index)
return True | python | {
"resource": ""
} |
q278189 | BasicParser.end_tag | test | def end_tag(self, name: str) -> Node:
"""Extract the string between saved and current index."""
self.tag_cache[name].set_end(self._stream.index)
return True | python | {
"resource": ""
} |
q278190 | BasicParser.set_rules | test | def set_rules(cls, rules: dict) -> bool:
"""
Merge internal rules set with the given rules
"""
cls._rules = cls._rules.new_child()
for rule_name, rule_pt in rules.items():
if '.' not in rule_name:
rule_name = cls.__module__ \
+ '.' ... | python | {
"resource": ""
} |
q278191 | BasicParser.set_hooks | test | def set_hooks(cls, hooks: dict) -> bool:
"""
Merge internal hooks set with the given hooks
"""
cls._hooks = cls._hooks.new_child()
for hook_name, hook_pt in hooks.items():
if '.' not in hook_name:
hook_name = cls.__module__ \
+ '.' ... | python | {
"resource": ""
} |
q278192 | BasicParser.set_directives | test | def set_directives(cls, directives: dict) -> bool:
"""
Merge internal directives set with the given directives.
For working directives, attach it only in the dsl.Parser class
"""
meta._directives = meta._directives.new_child()
for dir_name, dir_pt in directives.items():
... | python | {
"resource": ""
} |
q278193 | BasicParser.eval_rule | test | def eval_rule(self, name: str) -> Node:
"""Evaluate a rule by name."""
# context created by caller
n = Node()
id_n = id(n)
self.rule_nodes['_'] = n
self.id_cache[id_n] = '_'
# TODO: other behavior for empty rules?
if name not in self.__class__._rules:
... | python | {
"resource": ""
} |
q278194 | BasicParser.eval_hook | test | def eval_hook(self, name: str, ctx: list) -> Node:
"""Evaluate the hook by its name"""
if name not in self.__class__._hooks:
# TODO: don't always throw error, could have return True by default
self.diagnostic.notify(
error.Severity.ERROR,
"Unknown ... | python | {
"resource": ""
} |
q278195 | BasicParser.peek_text | test | def peek_text(self, text: str) -> bool:
"""Same as readText but doesn't consume the stream."""
start = self._stream.index
stop = start + len(text)
if stop > self._stream.eos_index:
return False
return self._stream[self._stream.index:stop] == text | python | {
"resource": ""
} |
q278196 | BasicParser.one_char | test | def one_char(self) -> bool:
"""Read one byte in stream"""
if self.read_eof():
return False
self._stream.incpos()
return True | python | {
"resource": ""
} |
q278197 | BasicParser.read_char | test | def read_char(self, c: str) -> bool:
"""
Consume the c head byte, increment current index and return True
else return False. It use peekchar and it's the same as '' in BNF.
"""
if self.read_eof():
return False
self._stream.save_context()
if c == self._... | python | {
"resource": ""
} |
q278198 | BasicParser.read_until_eof | test | def read_until_eof(self) -> bool:
"""Consume all the stream. Same as EOF in BNF."""
if self.read_eof():
return True
# TODO: read ALL
self._stream.save_context()
while not self.read_eof():
self._stream.incpos()
return self._stream.validate_context() | python | {
"resource": ""
} |
q278199 | BasicParser.ignore_blanks | test | def ignore_blanks(self) -> bool:
"""Consume whitespace characters."""
self._stream.save_context()
if not self.read_eof() and self._stream.peek_char in " \t\v\f\r\n":
while (not self.read_eof()
and self._stream.peek_char in " \t\v\f\r\n"):
self._stre... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.