text
stringlengths
0
828
else:
string_repr = None
value = Token(rule.name, cursor, value, string_repr)
token = value
expected = rule.name in expectation
if not expected and rule.skip:
# If we didn't expect this rule to match, and if its skippable,
# just skip it. :-)
token = None
elif not expected and as_accept:
# If we didn't expect this rule to match but are just accepting
# instead of expecting, restore to the original location and stop.
self.scanner.restore(cursor)
return None
self.token = token
if as_accept and token and token.type == eof:
if eof in expectation:
return token
return None
if token.type is None:
raise TokenizationError(token)
if not as_accept and expectation and token.type not in expectation:
raise UnexpectedTokenError(expectation, token)
assert not as_accept or (token and token.type in expectation)
return token"
901,"def append(self, event, help=""""):
""""""Creates a new event. `event` may be iterable or string
Args:
event (str): Name of event to declare
Kwrgs:
help (str): Help string for the event
Raises:
TypeError
**Please** describe the event and its calling arguments in the help
string.
""""""
if isinstance(event, str):
self._events[event] = HookList(is_waterfall=self.is_waterfall)
self._help[event] = (help, getframeinfo(stack()[1][0]))
if not help:
logger.warning(""Great, don't say anything about your hooks and \
wait for plugin creators to figure it out."")
elif isinstance(event, Iterable):
# Depricated. It does not give the ability to give help string
# TODO: Remove this
for name in event:
self.append(name)
else:
raise TypeError(""Invalid event name!"")"
902,"def hook(self, function, event, dependencies):
""""""Tries to load the hook to the event
Args:
function (func): Function that will be called when the event is called
Kwargs:
dependencies (str): String or Iterable with modules whose hooks should be called before this one
Raises:
NameError
Note that the dependencies are module-wide, that means that if
`parent.foo` and `parent.bar` are both subscribed to `example` event
and `child` enumerates `parent` as dependcy, **both** `foo` and `bar`
must be called in order for the dependcy to get resolved.
""""""
# Hooks all events (recursively)
if event is None:
for e in self._events.keys():
self.hook(function, e, dependencies)
return
# Hook multiple, but specific events (recursively)
if not isinstance(event, str) and isinstance(event, Iterable):
for e in event:
self.hook(function, e, dependencies)
return
# Hook a simple event
event_list = self._events.get(event, None)
if event_list is None:
raise NameError(
""Invalid key provided '%s'. Valid options: %s""
% (event, "", "".join(self._events.keys()))
)
return
return event_list.hook(function, dependencies)"
903,"def call(path, *args, encoding=""utf-8"", show_command=False):
""""""使用 subprocess.check_output 调用 git 命令。
:param str path: git 仓库文件夹路径。