desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Context manager support.'
| def __exit__(self, *_exc):
| self.release()
|
'>>> lock = LockBase(\'somefile\')
>>> lock = LockBase(\'somefile\', threaded=False)'
| def __init__(self, path, threaded=True, timeout=None):
| super(LockBase, self).__init__(path)
self.lock_file = (os.path.abspath(path) + '.lock')
self.hostname = socket.gethostname()
self.pid = os.getpid()
if threaded:
t = threading.current_thread()
ident = getattr(t, 'ident', hash(t))
self.tname = ('-%x' % (ident & 4294967295))
... |
'Tell whether or not the file is locked.'
| def is_locked(self):
| raise NotImplemented('implement in subclass')
|
'Return True if this object is locking the file.'
| def i_am_locking(self):
| raise NotImplemented('implement in subclass')
|
'Remove a lock. Useful if a locking thread failed to unlock.'
| def break_lock(self):
| raise NotImplemented('implement in subclass')
|
'Get the PID from the lock file.'
| def read_pid(self):
| return read_pid_from_pidfile(self.path)
|
'Test if the lock is currently held.
The lock is held if the PID file for this lock exists.'
| def is_locked(self):
| return os.path.exists(self.path)
|
'Test if the lock is held by the current process.
Returns ``True`` if the current process ID matches the
number stored in the PID file.'
| def i_am_locking(self):
| return (self.is_locked() and (os.getpid() == self.read_pid()))
|
'Acquire the lock.
Creates the PID file for this lock, or raises an error if
the lock could not be acquired.'
| def acquire(self, timeout=None):
| timeout = (timeout if (timeout is not None) else self.timeout)
end_time = time.time()
if ((timeout is not None) and (timeout > 0)):
end_time += timeout
while True:
try:
write_pid_to_pidfile(self.path)
except OSError as exc:
if (exc.errno == errno.EEXIST):
... |
'Release the lock.
Removes the PID file to release the lock, or raises an
error if the current process does not hold the lock.'
| def release(self):
| if (not self.is_locked()):
raise NotLocked(('%s is not locked' % self.path))
if (not self.i_am_locking()):
raise NotMyLock(('%s is locked, but not by me' % self.path))
remove_existing_pidfile(self.path)
|
'Break an existing lock.
Removes the PID file if it already exists, otherwise does
nothing.'
| def break_lock(self):
| remove_existing_pidfile(self.path)
|
'>>> lock = MkdirLockFile(\'somefile\')
>>> lock = MkdirLockFile(\'somefile\', threaded=False)'
| def __init__(self, path, threaded=True, timeout=None):
| LockBase.__init__(self, path, threaded, timeout)
self.unique_name = os.path.join(self.lock_file, ('%s.%s%s' % (self.hostname, self.tname, self.pid)))
|
'>>> lock = SQLiteLockFile(\'somefile\')
>>> lock = SQLiteLockFile(\'somefile\', threaded=False)'
| def __init__(self, path, threaded=True, timeout=None):
| LockBase.__init__(self, path, threaded, timeout)
self.lock_file = unicode(self.lock_file)
self.unique_name = unicode(self.unique_name)
if (SQLiteLockFile.testdb is None):
import tempfile
(_fd, testdb) = tempfile.mkstemp()
os.close(_fd)
os.unlink(testdb)
del _fd, t... |
'Action implementation.
:param matches:
:type matches: rebulk.match.Matches
:param context:
:type context:
:param when_response: return object from when call.
:type when_response: object
:return: True if the action was runned, False if it wasn\'t.
:rtype: bool'
| @abstractmethod
def then(self, matches, when_response, context):
| pass
|
'Condition implementation.
:param matches:
:type matches: rebulk.match.Matches
:param context:
:type context:
:return: truthy if rule should be triggered and execute then action, falsy if it should not.
:rtype: object'
| @abstractmethod
def when(self, matches, context):
| pass
|
'Disable rule.
:param context:
:type context:
:return: True if rule is enabled, False if disabled
:rtype: bool'
| def enabled(self, context):
| return True
|
'Load rules from a Rule module, class or instance
:param rules:
:type rules:
:return:
:rtype:'
| def load(self, *rules):
| for rule in rules:
if inspect.ismodule(rule):
self.load_module(rule)
elif inspect.isclass(rule):
self.load_class(rule)
else:
self.append(rule)
|
'Load a rules module
:param module:
:type module:
:return:
:rtype:'
| def load_module(self, module):
| for (name, obj) in inspect.getmembers(module, (lambda member: (hasattr(member, '__module__') and (member.__module__ == module.__name__) and inspect.isclass))):
self.load_class(obj)
|
'Load a Rule class.
:param class_:
:type class_:
:return:
:rtype:'
| def load_class(self, class_):
| self.append(class_())
|
'Execute all rules from this rules list. All when condition with same priority will be performed before
calling then actions.
:param matches:
:type matches:
:param context:
:type context:
:return:
:rtype:'
| def execute_all_rules(self, matches, context):
| ret = []
for (priority, priority_rules) in groupby(sorted(self), (lambda rule: rule.priority)):
sorted_rules = toposort_rules(list(priority_rules))
for rules_group in sorted_rules:
rules_group = list(sorted(rules_group, key=self.index))
group_log_level = None
... |
'Default conflict solver to use.'
| @property
def default_conflict_solver(self):
| return _default_conflict_solver
|
'Define default keyword arguments for all patterns
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def defaults(self, **kwargs):
| self._defaults = kwargs
return self
|
'Define default keyword arguments for functional patterns.
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def regex_defaults(self, **kwargs):
| self._regex_defaults = kwargs
return self
|
'Define default keyword arguments for string patterns.
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def string_defaults(self, **kwargs):
| self._string_defaults = kwargs
return self
|
'Define default keyword arguments for functional patterns.
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def functional_defaults(self, **kwargs):
| self._functional_defaults = kwargs
return self
|
'Add patterns chain, using configuration from this chain
:return:
:rtype:'
| def chain(self):
| chain = self.rebulk.chain(**self._kwargs)
chain._defaults = dict(self._defaults)
chain._regex_defaults = dict(self._regex_defaults)
chain._functional_defaults = dict(self._functional_defaults)
chain._string_defaults = dict(self._string_defaults)
return chain
|
'Add re pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def regex(self, *pattern, **kwargs):
| set_defaults(self._kwargs, kwargs)
set_defaults(self._regex_defaults, kwargs)
set_defaults(self._defaults, kwargs)
pattern = self.rebulk.build_re(*pattern, **kwargs)
part = ChainPart(self, pattern)
self.parts.append(part)
return part
|
'Add functional pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def functional(self, *pattern, **kwargs):
| set_defaults(self._kwargs, kwargs)
set_defaults(self._functional_defaults, kwargs)
set_defaults(self._defaults, kwargs)
pattern = self.rebulk.build_functional(*pattern, **kwargs)
part = ChainPart(self, pattern)
self.parts.append(part)
return part
|
'Add string pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def string(self, *pattern, **kwargs):
| set_defaults(self._kwargs, kwargs)
set_defaults(self._functional_defaults, kwargs)
set_defaults(self._defaults, kwargs)
pattern = self.rebulk.build_string(*pattern, **kwargs)
part = ChainPart(self, pattern)
self.parts.append(part)
return part
|
'Close chain builder to continue registering other pattern
:return:
:rtype:'
| def close(self):
| return self.rebulk
|
'Handle a parent match
:param match:
:type match:
:param yield_parent:
:type yield_parent:
:return:
:rtype:'
| def _match_parent(self, match, yield_parent):
| ret = super(Chain, self)._match_parent(match, yield_parent)
original_children = Matches(match.children)
original_end = match.end
while ((not ret) and match.children):
last_pattern = match.children[(-1)].pattern
last_pattern_children = [child for child in match.children if (child.pattern ... |
'Add patterns chain, using configuration from this chain
:return:
:rtype:'
| def chain(self):
| return self._chain.chain()
|
'Hide chain part results from global chain result
:param hidden:
:type hidden:
:return:
:rtype:'
| def hidden(self, hidden=True):
| self._hidden = hidden
return self
|
'Check if the chain part is hidden
:return:
:rtype:'
| @property
def is_hidden(self):
| return self._hidden
|
'Add re pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def regex(self, *pattern, **kwargs):
| return self._chain.regex(*pattern, **kwargs)
|
'Add functional pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def functional(self, *pattern, **kwargs):
| return self._chain.functional(*pattern, **kwargs)
|
'Add string pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def string(self, *pattern, **kwargs):
| return self._chain.string(*pattern, **kwargs)
|
'Close the chain builder to continue registering other patterns
:return:
:rtype:'
| def close(self):
| return self._chain.close()
|
'Define the repeater of the current chain part.
:param value:
:type value:
:return:
:rtype:'
| def repeater(self, value):
| try:
value = int(value)
self.repeater_start = value
self.repeater_end = value
return self
except ValueError:
pass
if (value == '+'):
self.repeater_start = 1
self.repeater_end = None
if (value == '*'):
self.repeater_start = 0
self.re... |
'Update set with iterable
:param iterable:
:type iterable:
:return:
:rtype:'
| def update(self, iterable):
| for elem in iterable:
self.add(elem)
|
'Properties of described object.
:return: all properties that described object can generate grouped by name.
:rtype: dict'
| @abstractproperty
def properties(self):
| pass
|
'Properties for this rule.
:return:
:rtype: dict'
| @property
def properties(self):
| return self._properties
|
'Properties for this rule.
:return:
:rtype: dict'
| @property
def properties(self):
| return self._properties
|
'Properties for Introspection results.
:return:
:rtype:'
| @property
def properties(self):
| properties = defaultdict(list)
for pattern in self.patterns:
for (key, values) in pattern.properties.items():
extend_safe(properties[key], values)
for rule in self.rules:
for (key, values) in rule.properties.items():
extend_safe(properties[key], values)
return pro... |
'Add a match
:param match:
:type match: Match'
| def _add_match(self, match):
| if match.name:
_BaseMatches._base_add(self._name_dict[match.name], match)
for tag in match.tags:
_BaseMatches._base_add(self._tag_dict[tag], match)
_BaseMatches._base_add(self._start_dict[match.start], match)
_BaseMatches._base_add(self._end_dict[match.end], match)
for index in range... |
'Remove a match
:param match:
:type match: Match'
| def _remove_match(self, match):
| if match.name:
_BaseMatches._base_remove(self._name_dict[match.name], match)
for tag in match.tags:
_BaseMatches._base_remove(self._tag_dict[tag], match)
_BaseMatches._base_remove(self._start_dict[match.start], match)
_BaseMatches._base_remove(self._end_dict[match.end], match)
for in... |
'Retrieves the nearest previous matches.
:param match:
:type match:
:param predicate:
:type predicate:
:param index:
:type index: int
:return:
:rtype:'
| def previous(self, match, predicate=None, index=None):
| current = match.start
while (current > (-1)):
previous_matches = self.ending(current)
if previous_matches:
return filter_index(previous_matches, predicate, index)
current -= 1
return filter_index(_BaseMatches._base(), predicate, index)
|
'Retrieves the nearest next matches.
:param match:
:type match:
:param predicate:
:type predicate:
:param index:
:type index: int
:return:
:rtype:'
| def next(self, match, predicate=None, index=None):
| current = (match.start + 1)
while (current <= self._max_end):
next_matches = self.starting(current)
if next_matches:
return filter_index(next_matches, predicate, index)
current += 1
return filter_index(_BaseMatches._base(), predicate, index)
|
'Retrieves a set of Match objects that have the given name.
:param name:
:type name: str
:param predicate:
:type predicate:
:param index:
:type index: int
:return: set of matches
:rtype: set[Match]'
| def named(self, name, predicate=None, index=None):
| return filter_index(_BaseMatches._base(self._name_dict[name]), predicate, index)
|
'Retrieves a set of Match objects that have the given tag defined.
:param tag:
:type tag: str
:param predicate:
:type predicate:
:param index:
:type index: int
:return: set of matches
:rtype: set[Match]'
| def tagged(self, tag, predicate=None, index=None):
| return filter_index(_BaseMatches._base(self._tag_dict[tag]), predicate, index)
|
'Retrieves a set of Match objects that starts at given index.
:param start: the starting index
:type start: int
:param predicate:
:type predicate:
:param index:
:type index: int
:return: set of matches
:rtype: set[Match]'
| def starting(self, start, predicate=None, index=None):
| return filter_index(_BaseMatches._base(self._start_dict[start]), predicate, index)
|
'Retrieves a set of Match objects that ends at given index.
:param end: the ending index
:type end: int
:param predicate:
:type predicate:
:return: set of matches
:rtype: set[Match]'
| def ending(self, end, predicate=None, index=None):
| return filter_index(_BaseMatches._base(self._end_dict[end]), predicate, index)
|
'Retrieves a set of Match objects that are available in given range, sorted from start to end.
:param start: the starting index
:type start: int
:param end: the ending index
:type end: int
:param predicate:
:type predicate:
:param index:
:type index: int
:return: set of matches
:rtype: set[Match]'
| def range(self, start=0, end=None, predicate=None, index=None):
| if (end is None):
end = self.max_end
else:
end = min(self.max_end, end)
ret = _BaseMatches._base()
for match in sorted(self):
if ((match.start < end) and (match.end > start)):
ret.append(match)
return filter_index(ret, predicate, index)
|
'Retrieves a list of chained matches, before position, matching predicate and separated by characters from seps
only.
:param position:
:type position:
:param seps:
:type seps:
:param start:
:type start:
:param predicate:
:type predicate:
:param index:
:type index:
:return:
:rtype:'
| def chain_before(self, position, seps, start=0, predicate=None, index=None):
| if hasattr(position, 'start'):
position = position.start
chain = _BaseMatches._base()
position = min(self.max_end, position)
for i in reversed(range(start, position)):
index_matches = self.at_index(i)
filtered_matches = [index_match for index_match in index_matches if ((not predi... |
'Retrieves a list of chained matches, after position, matching predicate and separated by characters from seps
only.
:param position:
:type position:
:param seps:
:type seps:
:param end:
:type end:
:param predicate:
:type predicate:
:param index:
:type index:
:return:
:rtype:'
| def chain_after(self, position, seps, end=None, predicate=None, index=None):
| if hasattr(position, 'end'):
position = position.end
chain = _BaseMatches._base()
if (end is None):
end = self.max_end
else:
end = min(self.max_end, end)
for i in range(position, end):
index_matches = self.at_index(i)
filtered_matches = [index_match for index_... |
'Retrieves the maximum index.
:return:'
| @property
def max_end(self):
| return (max(len(self.input_string), self._max_end) if self.input_string else self._max_end)
|
'Retrieves the start of hole index from position.
:param position:
:type position:
:param ignore:
:type ignore:
:return:
:rtype:'
| def _hole_start(self, position, ignore=None):
| for lindex in reversed(range(0, position)):
for starting in self.starting(lindex):
if ((not ignore) or (not ignore(starting))):
return lindex
return 0
|
'Retrieves the end of hole index from position.
:param position:
:type position:
:param ignore:
:type ignore:
:return:
:rtype:'
| def _hole_end(self, position, ignore=None):
| for rindex in range(position, self.max_end):
for starting in self.starting(rindex):
if ((not ignore) or (not ignore(starting))):
return rindex
return self.max_end
|
'Retrieves a set of Match objects that are not defined in given range.
:param start:
:type start:
:param end:
:type end:
:param formatter:
:type formatter:
:param ignore:
:type ignore:
:param seps:
:type seps:
:param predicate:
:type predicate:
:param index:
:type index:
:return:
:rtype:'
| def holes(self, start=0, end=None, formatter=None, ignore=None, seps=None, predicate=None, index=None):
| assert (self.input_string if seps else True), 'input_string must be defined when using seps parameter'
if (end is None):
end = self.max_end
else:
end = min(self.max_end, end)
ret = _BaseMatches._base()
hole = False
rindex = start
loop_start = self._hole_s... |
'Retrieves a list of ``Match`` objects that conflicts with given match.
:param match:
:type match:
:param predicate:
:type predicate:
:param index:
:type index:
:return:
:rtype:'
| def conflicting(self, match, predicate=None, index=None):
| ret = _BaseMatches._base()
for i in range(*match.span):
for at_match in self.at_index(i):
if (at_match not in ret):
ret.append(at_match)
ret.remove(match)
return filter_index(ret, predicate, index)
|
'Retrieves a list of matches from given match.'
| def at_match(self, match, predicate=None, index=None):
| return self.at_span(match.span, predicate, index)
|
'Retrieves a list of matches from given (start, end) tuple.'
| def at_span(self, span, predicate=None, index=None):
| starting = self._index_dict[span[0]]
ending = self._index_dict[(span[1] - 1)]
merged = list(starting)
for marker in ending:
if (marker not in merged):
merged.append(marker)
return filter_index(merged, predicate, index)
|
'Retrieves a list of matches from given position'
| def at_index(self, pos, predicate=None, index=None):
| return filter_index(self._index_dict[pos], predicate, index)
|
'Retrieve all names.
:return:'
| @property
def names(self):
| return self._name_dict.keys()
|
'Retrieve all tags.
:return:'
| @property
def tags(self):
| return self._tag_dict.keys()
|
'Converts matches to a dict object.
:param details if True, values will be complete Match object, else it will be only string Match.value property
:type details: bool
:param implicit if True, multiple values will be set as a list in the dict. Else, only the first value
will be kept.
:type implicit: bool
:return:
:rtype... | def to_dict(self, details=False, implicit=False):
| ret = MatchesDict()
for match in sorted(self):
value = (match if details else match.value)
ret.matches[match.name].append(match)
if (value not in ret.values_list[match.name]):
ret.values_list[match.name].append(value)
if (match.name in ret.keys()):
if impl... |
'2-tuple with start and end indices of the match'
| @property
def span(self):
| return (self.start, self.end)
|
'Get the value of the match, using formatter if defined.
:return:
:rtype:'
| @property
def value(self):
| if self._value:
return self._value
if self.formatter:
return self.formatter(self.raw)
return self.raw
|
'Set the value (hardcode)
:param value:
:type value:
:return:
:rtype:'
| @value.setter
def value(self, value):
| self._value = value
|
'Get all names of children
:return:
:rtype:'
| @property
def names(self):
| if (not self.children):
return set([self.name])
else:
ret = set()
for child in self.children:
for name in child.names:
ret.add(name)
return ret
|
'start index of raw value
:return:
:rtype:'
| @property
def raw_start(self):
| if (self._raw_start is None):
return self.start
return self._raw_start
|
'Set start index of raw value
:return:
:rtype:'
| @raw_start.setter
def raw_start(self, value):
| self._raw_start = value
|
'end index of raw value
:return:
:rtype:'
| @property
def raw_end(self):
| if (self._raw_end is None):
return self.end
return self._raw_end
|
'Set end index of raw value
:return:
:rtype:'
| @raw_end.setter
def raw_end(self, value):
| self._raw_end = value
|
'Get the raw value of the match, without using hardcoded value nor formatter.
:return:
:rtype:'
| @property
def raw(self):
| if self.input_string:
return self.input_string[self.raw_start:self.raw_end]
return None
|
'Retrieve the initiator parent of a match
:param match:
:type match:
:return:
:rtype:'
| @property
def initiator(self):
| match = self
while match.parent:
match = match.parent
return match
|
'crop the match with given Match objects or spans tuples
:param crops:
:type crops: list or object
:return: a list of Match objects
:rtype: list[Match]'
| def crop(self, crops, predicate=None, index=None):
| if ((not is_iterable(crops)) or ((len(crops) == 2) and isinstance(crops[0], int))):
crops = [crops]
initial = copy.deepcopy(self)
ret = [initial]
for crop in crops:
if hasattr(crop, 'span'):
(start, end) = crop.span
else:
(start, end) = crop
for cu... |
'Split this match in multiple matches using given separators.
:param seps:
:type seps: string containing separator characters
:return: list of new Match objects
:rtype: list'
| def split(self, seps, predicate=None, index=None):
| split_match = copy.deepcopy(self)
current_match = split_match
ret = []
for i in range(0, len(self.raw)):
if (self.raw[i] in seps):
if (not split_match):
split_match = copy.deepcopy(current_match)
current_match.end = (self.start + i)
elif split_... |
'Creates a new Rebulk object.
:param disabled: if True, this pattern is disabled. Can also be a function(context).
:type disabled: bool|function
:param default_rules: use default rules
:type default_rules:
:return:
:rtype:'
| def __init__(self, disabled=(lambda context: False), default_rules=True):
| if (not callable(disabled)):
self.disabled = (lambda context: disabled)
else:
self.disabled = disabled
self._patterns = []
self._rules = Rules()
if default_rules:
self.rules(ConflictSolver, PrivateRemover)
self._defaults = {}
self._regex_defaults = {}
self._string... |
'Add patterns objects
:param pattern:
:type pattern: rebulk.pattern.Pattern
:return: self
:rtype: Rebulk'
| def pattern(self, *pattern):
| self._patterns.extend(pattern)
return self
|
'Define default keyword arguments for all patterns
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def defaults(self, **kwargs):
| self._defaults = kwargs
return self
|
'Define default keyword arguments for functional patterns.
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def regex_defaults(self, **kwargs):
| self._regex_defaults = kwargs
return self
|
'Add re pattern
:param pattern:
:type pattern:
:return: self
:rtype: Rebulk'
| def regex(self, *pattern, **kwargs):
| self.pattern(self.build_re(*pattern, **kwargs))
return self
|
'Builds a new regular expression pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def build_re(self, *pattern, **kwargs):
| set_defaults(self._regex_defaults, kwargs)
set_defaults(self._defaults, kwargs)
return RePattern(*pattern, **kwargs)
|
'Define default keyword arguments for string patterns.
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def string_defaults(self, **kwargs):
| self._string_defaults = kwargs
return self
|
'Add string pattern
:param pattern:
:type pattern:
:return: self
:rtype: Rebulk'
| def string(self, *pattern, **kwargs):
| self.pattern(self.build_string(*pattern, **kwargs))
return self
|
'Builds a new string pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def build_string(self, *pattern, **kwargs):
| set_defaults(self._string_defaults, kwargs)
set_defaults(self._defaults, kwargs)
return StringPattern(*pattern, **kwargs)
|
'Define default keyword arguments for functional patterns.
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def functional_defaults(self, **kwargs):
| self._functional_defaults = kwargs
return self
|
'Add functional pattern
:param pattern:
:type pattern:
:return: self
:rtype: Rebulk'
| def functional(self, *pattern, **kwargs):
| self.pattern(self.build_functional(*pattern, **kwargs))
return self
|
'Builds a new functional pattern
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def build_functional(self, *pattern, **kwargs):
| set_defaults(self._functional_defaults, kwargs)
set_defaults(self._defaults, kwargs)
return FunctionalPattern(*pattern, **kwargs)
|
'Add patterns chain, using configuration of this rebulk
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def chain(self, **kwargs):
| chain = self.build_chain(**kwargs)
self._patterns.append(chain)
return chain
|
'Builds a new patterns chain
:param pattern:
:type pattern:
:param kwargs:
:type kwargs:
:return:
:rtype:'
| def build_chain(self, **kwargs):
| set_defaults(self._defaults, kwargs)
return Chain(self, **kwargs)
|
'Add rules as a module, class or instance.
:param rules:
:type rules: list[Rule]
:return:'
| def rules(self, *rules):
| self._rules.load(*rules)
return self
|
'Add a children rebulk object
:param rebulks:
:type rebulks: Rebulk
:return:'
| def rebulk(self, *rebulks):
| self._rebulks.extend(rebulks)
return self
|
'Search for all matches with current configuration against input_string
:param string: string to search into
:type string: str
:param context: context to use
:type context: dict
:return: A custom list of matches
:rtype: Matches'
| def matches(self, string, context=None):
| matches = Matches(input_string=string)
if (context is None):
context = {}
self._matches_patterns(matches, context)
self._execute_rules(matches, context)
return matches
|
'Get effective rules for this rebulk object and its children.
:param context:
:type context:
:return:
:rtype:'
| def effective_rules(self, context=None):
| rules = Rules()
rules.extend(self._rules)
for rebulk in self._rebulks:
if (not rebulk.disabled(context)):
extend_safe(rules, rebulk._rules)
return rules
|
'Execute rules for this rebulk and children.
:param matches:
:type matches:
:param context:
:type context:
:return:
:rtype:'
| def _execute_rules(self, matches, context):
| if (not self.disabled(context)):
rules = self.effective_rules(context)
rules.execute_all_rules(matches, context)
|
'Get effective patterns for this rebulk object and its children.
:param context:
:type context:
:return:
:rtype:'
| def effective_patterns(self, context=None):
| patterns = list(self._patterns)
for rebulk in self._rebulks:
if (not rebulk.disabled(context)):
extend_safe(patterns, rebulk._patterns)
return patterns
|
'Search for all matches with current paterns agains input_string
:param matches: matches list
:type matches: Matches
:param context: context to use
:type context: dict
:return:
:rtype:'
| def _matches_patterns(self, matches, context):
| if (not self.disabled(context)):
patterns = self.effective_patterns(context)
for pattern in patterns:
if (not pattern.disabled(context)):
pattern_matches = pattern.matches(matches.input_string, context)
if pattern_matches:
log(pattern.l... |
':param name: Name of this pattern
:type name: str
:param tags: List of tags related to this pattern
:type tags: list[str]
:param formatter: dict (name, func) of formatter to use with this pattern. name is the match name to support,
and func a function(input_string) that returns the formatted string. A single formatter... | def __init__(self, name=None, tags=None, formatter=None, value=None, validator=None, children=False, every=False, private_parent=False, private_children=False, private=False, private_names=None, ignore_names=None, marker=False, format_all=False, validate_all=False, disabled=(lambda context: False), log_level=None, prop... | self.name = name
self.tags = ensure_list(tags)
(self.formatters, self._default_formatter) = ensure_dict(formatter, (lambda x: x))
(self.values, self._default_value) = ensure_dict(value, None)
(self.validators, self._default_validator) = ensure_dict(validator, (lambda match: True))
self.every = e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.