id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
8,800
srsudar/eg
eg/util.py
page_string
def page_string(str_to_page, pager_cmd): """ Page str_to_page via the pager. """ # By default, we expect the command to be `less -R`. If that is the # pager_cmd, but they don't have less on their machine, odds are they're # just using the default value. In this case the pager will fail, so we'll...
python
def page_string(str_to_page, pager_cmd): """ Page str_to_page via the pager. """ # By default, we expect the command to be `less -R`. If that is the # pager_cmd, but they don't have less on their machine, odds are they're # just using the default value. In this case the pager will fail, so we'll...
[ "def", "page_string", "(", "str_to_page", ",", "pager_cmd", ")", ":", "# By default, we expect the command to be `less -R`. If that is the", "# pager_cmd, but they don't have less on their machine, odds are they're", "# just using the default value. In this case the pager will fail, so we'll", ...
Page str_to_page via the pager.
[ "Page", "str_to_page", "via", "the", "pager", "." ]
96142a74f4416b4a7000c85032c070df713b849e
https://github.com/srsudar/eg/blob/96142a74f4416b4a7000c85032c070df713b849e/eg/util.py#L167-L189
8,801
srsudar/eg
eg/util.py
get_list_of_all_supported_commands
def get_list_of_all_supported_commands(config): """ Generate a list of all the commands that have examples known to eg. The format of the list is the command names. The fact that there are examples for 'cp', for example, would mean that 'cp' was in the list. The format of the list contains addition...
python
def get_list_of_all_supported_commands(config): """ Generate a list of all the commands that have examples known to eg. The format of the list is the command names. The fact that there are examples for 'cp', for example, would mean that 'cp' was in the list. The format of the list contains addition...
[ "def", "get_list_of_all_supported_commands", "(", "config", ")", ":", "default_files", "=", "_recursive_get_all_file_names", "(", "config", ".", "examples_dir", ")", "custom_files", "=", "_recursive_get_all_file_names", "(", "config", ".", "custom_dir", ")", "# Now filter...
Generate a list of all the commands that have examples known to eg. The format of the list is the command names. The fact that there are examples for 'cp', for example, would mean that 'cp' was in the list. The format of the list contains additional information to say if there are only default examples...
[ "Generate", "a", "list", "of", "all", "the", "commands", "that", "have", "examples", "known", "to", "eg", ".", "The", "format", "of", "the", "list", "is", "the", "command", "names", ".", "The", "fact", "that", "there", "are", "examples", "for", "cp", "...
96142a74f4416b4a7000c85032c070df713b849e
https://github.com/srsudar/eg/blob/96142a74f4416b4a7000c85032c070df713b849e/eg/util.py#L206-L280
8,802
srsudar/eg
eg/util.py
get_squeezed_contents
def get_squeezed_contents(contents): """ Squeeze the contents by removing blank lines between definition and example and remove duplicate blank lines except between sections. """ line_between_example_code = substitute.Substitution( '\n\n ', '\n ', True ) lines_b...
python
def get_squeezed_contents(contents): """ Squeeze the contents by removing blank lines between definition and example and remove duplicate blank lines except between sections. """ line_between_example_code = substitute.Substitution( '\n\n ', '\n ', True ) lines_b...
[ "def", "get_squeezed_contents", "(", "contents", ")", ":", "line_between_example_code", "=", "substitute", ".", "Substitution", "(", "'\\n\\n '", ",", "'\\n '", ",", "True", ")", "lines_between_examples", "=", "substitute", ".", "Substitution", "(", "'\\n\\n\\n'...
Squeeze the contents by removing blank lines between definition and example and remove duplicate blank lines except between sections.
[ "Squeeze", "the", "contents", "by", "removing", "blank", "lines", "between", "definition", "and", "example", "and", "remove", "duplicate", "blank", "lines", "except", "between", "sections", "." ]
96142a74f4416b4a7000c85032c070df713b849e
https://github.com/srsudar/eg/blob/96142a74f4416b4a7000c85032c070df713b849e/eg/util.py#L283-L302
8,803
srsudar/eg
eg/util.py
get_colorized_contents
def get_colorized_contents(contents, color_config): """Colorize the contents based on the color_config.""" colorizer = color.EgColorizer(color_config) result = colorizer.colorize_text(contents) return result
python
def get_colorized_contents(contents, color_config): """Colorize the contents based on the color_config.""" colorizer = color.EgColorizer(color_config) result = colorizer.colorize_text(contents) return result
[ "def", "get_colorized_contents", "(", "contents", ",", "color_config", ")", ":", "colorizer", "=", "color", ".", "EgColorizer", "(", "color_config", ")", "result", "=", "colorizer", ".", "colorize_text", "(", "contents", ")", "return", "result" ]
Colorize the contents based on the color_config.
[ "Colorize", "the", "contents", "based", "on", "the", "color_config", "." ]
96142a74f4416b4a7000c85032c070df713b849e
https://github.com/srsudar/eg/blob/96142a74f4416b4a7000c85032c070df713b849e/eg/util.py#L305-L309
8,804
srsudar/eg
eg/util.py
get_substituted_contents
def get_substituted_contents(contents, substitutions): """ Perform a list of substitutions and return the result. contents: the starting string on which to beging substitutions substitutions: list of Substitution objects to call, in order, with the result of the previous substitution. """ ...
python
def get_substituted_contents(contents, substitutions): """ Perform a list of substitutions and return the result. contents: the starting string on which to beging substitutions substitutions: list of Substitution objects to call, in order, with the result of the previous substitution. """ ...
[ "def", "get_substituted_contents", "(", "contents", ",", "substitutions", ")", ":", "result", "=", "contents", "for", "sub", "in", "substitutions", ":", "result", "=", "sub", ".", "apply_and_get_result", "(", "result", ")", "return", "result" ]
Perform a list of substitutions and return the result. contents: the starting string on which to beging substitutions substitutions: list of Substitution objects to call, in order, with the result of the previous substitution.
[ "Perform", "a", "list", "of", "substitutions", "and", "return", "the", "result", "." ]
96142a74f4416b4a7000c85032c070df713b849e
https://github.com/srsudar/eg/blob/96142a74f4416b4a7000c85032c070df713b849e/eg/util.py#L312-L323
8,805
srsudar/eg
eg/util.py
get_resolved_program
def get_resolved_program(program, config_obj): """ Take a program that may be an alias for another program and return the resolved program. It only ever resolves a single level of aliasing, so does not support aliasing to an alias. Returns the original program if the program is not an alias. ...
python
def get_resolved_program(program, config_obj): """ Take a program that may be an alias for another program and return the resolved program. It only ever resolves a single level of aliasing, so does not support aliasing to an alias. Returns the original program if the program is not an alias. ...
[ "def", "get_resolved_program", "(", "program", ",", "config_obj", ")", ":", "alias_dict", "=", "get_alias_dict", "(", "config_obj", ")", "if", "program", "in", "alias_dict", ":", "return", "alias_dict", "[", "program", "]", "else", ":", "return", "program" ]
Take a program that may be an alias for another program and return the resolved program. It only ever resolves a single level of aliasing, so does not support aliasing to an alias. Returns the original program if the program is not an alias.
[ "Take", "a", "program", "that", "may", "be", "an", "alias", "for", "another", "program", "and", "return", "the", "resolved", "program", "." ]
96142a74f4416b4a7000c85032c070df713b849e
https://github.com/srsudar/eg/blob/96142a74f4416b4a7000c85032c070df713b849e/eg/util.py#L351-L365
8,806
srsudar/eg
eg/util.py
get_alias_dict
def get_alias_dict(config_obj): """ Return a dictionary consisting of all aliases known to eg. The format is {'alias': 'resolved_program'}. If the aliases file does not exist, returns an empty dict. """ if not config_obj.examples_dir: return {} alias_file_path = _get_alias_file_pa...
python
def get_alias_dict(config_obj): """ Return a dictionary consisting of all aliases known to eg. The format is {'alias': 'resolved_program'}. If the aliases file does not exist, returns an empty dict. """ if not config_obj.examples_dir: return {} alias_file_path = _get_alias_file_pa...
[ "def", "get_alias_dict", "(", "config_obj", ")", ":", "if", "not", "config_obj", ".", "examples_dir", ":", "return", "{", "}", "alias_file_path", "=", "_get_alias_file_path", "(", "config_obj", ")", "if", "not", "os", ".", "path", ".", "isfile", "(", "alias_...
Return a dictionary consisting of all aliases known to eg. The format is {'alias': 'resolved_program'}. If the aliases file does not exist, returns an empty dict.
[ "Return", "a", "dictionary", "consisting", "of", "all", "aliases", "known", "to", "eg", "." ]
96142a74f4416b4a7000c85032c070df713b849e
https://github.com/srsudar/eg/blob/96142a74f4416b4a7000c85032c070df713b849e/eg/util.py#L368-L385
8,807
testing-cabal/mock
mock/mock.py
NonCallableMock.assert_not_called
def assert_not_called(_mock_self): """assert that the mock was never called. """ self = _mock_self if self.call_count != 0: msg = ("Expected '%s' to not have been called. Called %s times." % (self._mock_name or 'mock', self.call_count)) raise As...
python
def assert_not_called(_mock_self): """assert that the mock was never called. """ self = _mock_self if self.call_count != 0: msg = ("Expected '%s' to not have been called. Called %s times." % (self._mock_name or 'mock', self.call_count)) raise As...
[ "def", "assert_not_called", "(", "_mock_self", ")", ":", "self", "=", "_mock_self", "if", "self", ".", "call_count", "!=", "0", ":", "msg", "=", "(", "\"Expected '%s' to not have been called. Called %s times.\"", "%", "(", "self", ".", "_mock_name", "or", "'mock'"...
assert that the mock was never called.
[ "assert", "that", "the", "mock", "was", "never", "called", "." ]
2f356b28d42a1fd0057c9d8763d3a2cac2284165
https://github.com/testing-cabal/mock/blob/2f356b28d42a1fd0057c9d8763d3a2cac2284165/mock/mock.py#L889-L896
8,808
testing-cabal/mock
mock/mock.py
NonCallableMock.assert_called
def assert_called(_mock_self): """assert that the mock was called at least once """ self = _mock_self if self.call_count == 0: msg = ("Expected '%s' to have been called." % self._mock_name or 'mock') raise AssertionError(msg)
python
def assert_called(_mock_self): """assert that the mock was called at least once """ self = _mock_self if self.call_count == 0: msg = ("Expected '%s' to have been called." % self._mock_name or 'mock') raise AssertionError(msg)
[ "def", "assert_called", "(", "_mock_self", ")", ":", "self", "=", "_mock_self", "if", "self", ".", "call_count", "==", "0", ":", "msg", "=", "(", "\"Expected '%s' to have been called.\"", "%", "self", ".", "_mock_name", "or", "'mock'", ")", "raise", "Assertion...
assert that the mock was called at least once
[ "assert", "that", "the", "mock", "was", "called", "at", "least", "once" ]
2f356b28d42a1fd0057c9d8763d3a2cac2284165
https://github.com/testing-cabal/mock/blob/2f356b28d42a1fd0057c9d8763d3a2cac2284165/mock/mock.py#L898-L905
8,809
testing-cabal/mock
mock/mock.py
NonCallableMock.assert_called_once
def assert_called_once(_mock_self): """assert that the mock was called only once. """ self = _mock_self if not self.call_count == 1: msg = ("Expected '%s' to have been called once. Called %s times." % (self._mock_name or 'mock', self.call_count)) ...
python
def assert_called_once(_mock_self): """assert that the mock was called only once. """ self = _mock_self if not self.call_count == 1: msg = ("Expected '%s' to have been called once. Called %s times." % (self._mock_name or 'mock', self.call_count)) ...
[ "def", "assert_called_once", "(", "_mock_self", ")", ":", "self", "=", "_mock_self", "if", "not", "self", ".", "call_count", "==", "1", ":", "msg", "=", "(", "\"Expected '%s' to have been called once. Called %s times.\"", "%", "(", "self", ".", "_mock_name", "or",...
assert that the mock was called only once.
[ "assert", "that", "the", "mock", "was", "called", "only", "once", "." ]
2f356b28d42a1fd0057c9d8763d3a2cac2284165
https://github.com/testing-cabal/mock/blob/2f356b28d42a1fd0057c9d8763d3a2cac2284165/mock/mock.py#L907-L914
8,810
testing-cabal/mock
mock/mock.py
NonCallableMock.assert_called_once_with
def assert_called_once_with(_mock_self, *args, **kwargs): """assert that the mock was called exactly once and with the specified arguments.""" self = _mock_self if not self.call_count == 1: msg = ("Expected '%s' to be called once. Called %s times." % (self....
python
def assert_called_once_with(_mock_self, *args, **kwargs): """assert that the mock was called exactly once and with the specified arguments.""" self = _mock_self if not self.call_count == 1: msg = ("Expected '%s' to be called once. Called %s times." % (self....
[ "def", "assert_called_once_with", "(", "_mock_self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", "=", "_mock_self", "if", "not", "self", ".", "call_count", "==", "1", ":", "msg", "=", "(", "\"Expected '%s' to be called once. Called %s times.\"",...
assert that the mock was called exactly once and with the specified arguments.
[ "assert", "that", "the", "mock", "was", "called", "exactly", "once", "and", "with", "the", "specified", "arguments", "." ]
2f356b28d42a1fd0057c9d8763d3a2cac2284165
https://github.com/testing-cabal/mock/blob/2f356b28d42a1fd0057c9d8763d3a2cac2284165/mock/mock.py#L939-L947
8,811
earwig/mwparserfromhell
mwparserfromhell/nodes/html_entity.py
HTMLEntity.normalize
def normalize(self): """Return the unicode character represented by the HTML entity.""" chrfunc = chr if py3k else HTMLEntity._unichr if self.named: return chrfunc(htmlentities.name2codepoint[self.value]) if self.hexadecimal: return chrfunc(int(self.value, 16)) ...
python
def normalize(self): """Return the unicode character represented by the HTML entity.""" chrfunc = chr if py3k else HTMLEntity._unichr if self.named: return chrfunc(htmlentities.name2codepoint[self.value]) if self.hexadecimal: return chrfunc(int(self.value, 16)) ...
[ "def", "normalize", "(", "self", ")", ":", "chrfunc", "=", "chr", "if", "py3k", "else", "HTMLEntity", ".", "_unichr", "if", "self", ".", "named", ":", "return", "chrfunc", "(", "htmlentities", ".", "name2codepoint", "[", "self", ".", "value", "]", ")", ...
Return the unicode character represented by the HTML entity.
[ "Return", "the", "unicode", "character", "represented", "by", "the", "HTML", "entity", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/nodes/html_entity.py#L174-L181
8,812
earwig/mwparserfromhell
mwparserfromhell/smart_list.py
SmartList._detach_children
def _detach_children(self): """Remove all children and give them independent parent copies.""" children = [val[0] for val in self._children.values()] for child in children: child()._parent = list(self) self._children.clear()
python
def _detach_children(self): """Remove all children and give them independent parent copies.""" children = [val[0] for val in self._children.values()] for child in children: child()._parent = list(self) self._children.clear()
[ "def", "_detach_children", "(", "self", ")", ":", "children", "=", "[", "val", "[", "0", "]", "for", "val", "in", "self", ".", "_children", ".", "values", "(", ")", "]", "for", "child", "in", "children", ":", "child", "(", ")", ".", "_parent", "=",...
Remove all children and give them independent parent copies.
[ "Remove", "all", "children", "and", "give", "them", "independent", "parent", "copies", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/smart_list.py#L158-L163
8,813
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_parameter
def _handle_parameter(self, default): """Handle a case where a parameter is at the head of the tokens. *default* is the value to use if no parameter name is defined. """ key = None showkey = False self._push() while self._tokens: token = self._tokens....
python
def _handle_parameter(self, default): """Handle a case where a parameter is at the head of the tokens. *default* is the value to use if no parameter name is defined. """ key = None showkey = False self._push() while self._tokens: token = self._tokens....
[ "def", "_handle_parameter", "(", "self", ",", "default", ")", ":", "key", "=", "None", "showkey", "=", "False", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", ...
Handle a case where a parameter is at the head of the tokens. *default* is the value to use if no parameter name is defined.
[ "Handle", "a", "case", "where", "a", "parameter", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L76-L99
8,814
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_template
def _handle_template(self, token): """Handle a case where a template is at the head of the tokens.""" params = [] default = 1 self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.TemplateParamSeparator): i...
python
def _handle_template(self, token): """Handle a case where a template is at the head of the tokens.""" params = [] default = 1 self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.TemplateParamSeparator): i...
[ "def", "_handle_template", "(", "self", ",", "token", ")", ":", "params", "=", "[", "]", "default", "=", "1", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", ...
Handle a case where a template is at the head of the tokens.
[ "Handle", "a", "case", "where", "a", "template", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L102-L122
8,815
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_argument
def _handle_argument(self, token): """Handle a case where an argument is at the head of the tokens.""" name = None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.ArgumentSeparator): name = self._pop() ...
python
def _handle_argument(self, token): """Handle a case where an argument is at the head of the tokens.""" name = None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.ArgumentSeparator): name = self._pop() ...
[ "def", "_handle_argument", "(", "self", ",", "token", ")", ":", "name", "=", "None", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", "isinstance", "(", "token", ...
Handle a case where an argument is at the head of the tokens.
[ "Handle", "a", "case", "where", "an", "argument", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L125-L140
8,816
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_wikilink
def _handle_wikilink(self, token): """Handle a case where a wikilink is at the head of the tokens.""" title = None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.WikilinkSeparator): title = self._pop() ...
python
def _handle_wikilink(self, token): """Handle a case where a wikilink is at the head of the tokens.""" title = None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.WikilinkSeparator): title = self._pop() ...
[ "def", "_handle_wikilink", "(", "self", ",", "token", ")", ":", "title", "=", "None", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", "isinstance", "(", "token", ...
Handle a case where a wikilink is at the head of the tokens.
[ "Handle", "a", "case", "where", "a", "wikilink", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L143-L158
8,817
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_external_link
def _handle_external_link(self, token): """Handle when an external link is at the head of the tokens.""" brackets, url = token.brackets, None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.ExternalLinkSeparator): ...
python
def _handle_external_link(self, token): """Handle when an external link is at the head of the tokens.""" brackets, url = token.brackets, None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.ExternalLinkSeparator): ...
[ "def", "_handle_external_link", "(", "self", ",", "token", ")", ":", "brackets", ",", "url", "=", "token", ".", "brackets", ",", "None", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", ...
Handle when an external link is at the head of the tokens.
[ "Handle", "when", "an", "external", "link", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L161-L176
8,818
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_entity
def _handle_entity(self, token): """Handle a case where an HTML entity is at the head of the tokens.""" token = self._tokens.pop() if isinstance(token, tokens.HTMLEntityNumeric): token = self._tokens.pop() if isinstance(token, tokens.HTMLEntityHex): text =...
python
def _handle_entity(self, token): """Handle a case where an HTML entity is at the head of the tokens.""" token = self._tokens.pop() if isinstance(token, tokens.HTMLEntityNumeric): token = self._tokens.pop() if isinstance(token, tokens.HTMLEntityHex): text =...
[ "def", "_handle_entity", "(", "self", ",", "token", ")", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", "isinstance", "(", "token", ",", "tokens", ".", "HTMLEntityNumeric", ")", ":", "token", "=", "self", ".", "_tokens", ".", ...
Handle a case where an HTML entity is at the head of the tokens.
[ "Handle", "a", "case", "where", "an", "HTML", "entity", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L179-L192
8,819
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_heading
def _handle_heading(self, token): """Handle a case where a heading is at the head of the tokens.""" level = token.level self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.HeadingEnd): title = self._pop() ...
python
def _handle_heading(self, token): """Handle a case where a heading is at the head of the tokens.""" level = token.level self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.HeadingEnd): title = self._pop() ...
[ "def", "_handle_heading", "(", "self", ",", "token", ")", ":", "level", "=", "token", ".", "level", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", "isinstance", ...
Handle a case where a heading is at the head of the tokens.
[ "Handle", "a", "case", "where", "a", "heading", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L195-L206
8,820
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_comment
def _handle_comment(self, token): """Handle a case where an HTML comment is at the head of the tokens.""" self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.CommentEnd): contents = self._pop() return Com...
python
def _handle_comment(self, token): """Handle a case where an HTML comment is at the head of the tokens.""" self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.CommentEnd): contents = self._pop() return Com...
[ "def", "_handle_comment", "(", "self", ",", "token", ")", ":", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", "isinstance", "(", "token", ",", "tokens", ".", "...
Handle a case where an HTML comment is at the head of the tokens.
[ "Handle", "a", "case", "where", "an", "HTML", "comment", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L209-L219
8,821
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_attribute
def _handle_attribute(self, start): """Handle a case where a tag attribute is at the head of the tokens.""" name = quotes = None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.TagAttrEquals): name = self._po...
python
def _handle_attribute(self, start): """Handle a case where a tag attribute is at the head of the tokens.""" name = quotes = None self._push() while self._tokens: token = self._tokens.pop() if isinstance(token, tokens.TagAttrEquals): name = self._po...
[ "def", "_handle_attribute", "(", "self", ",", "start", ")", ":", "name", "=", "quotes", "=", "None", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "token", "=", "self", ".", "_tokens", ".", "pop", "(", ")", "if", "isinstance",...
Handle a case where a tag attribute is at the head of the tokens.
[ "Handle", "a", "case", "where", "a", "tag", "attribute", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L221-L243
8,822
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_tag
def _handle_tag(self, token): """Handle a case where a tag is at the head of the tokens.""" close_tokens = (tokens.TagCloseSelfclose, tokens.TagCloseClose) implicit, attrs, contents, closing_tag = False, [], None, None wiki_markup, invalid = token.wiki_markup, token.invalid or False ...
python
def _handle_tag(self, token): """Handle a case where a tag is at the head of the tokens.""" close_tokens = (tokens.TagCloseSelfclose, tokens.TagCloseClose) implicit, attrs, contents, closing_tag = False, [], None, None wiki_markup, invalid = token.wiki_markup, token.invalid or False ...
[ "def", "_handle_tag", "(", "self", ",", "token", ")", ":", "close_tokens", "=", "(", "tokens", ".", "TagCloseSelfclose", ",", "tokens", ".", "TagCloseClose", ")", "implicit", ",", "attrs", ",", "contents", ",", "closing_tag", "=", "False", ",", "[", "]", ...
Handle a case where a tag is at the head of the tokens.
[ "Handle", "a", "case", "where", "a", "tag", "is", "at", "the", "head", "of", "the", "tokens", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L246-L281
8,823
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder._handle_token
def _handle_token(self, token): """Handle a single token.""" try: return _HANDLERS[type(token)](self, token) except KeyError: err = "_handle_token() got unexpected {0}" raise ParserError(err.format(type(token).__name__))
python
def _handle_token(self, token): """Handle a single token.""" try: return _HANDLERS[type(token)](self, token) except KeyError: err = "_handle_token() got unexpected {0}" raise ParserError(err.format(type(token).__name__))
[ "def", "_handle_token", "(", "self", ",", "token", ")", ":", "try", ":", "return", "_HANDLERS", "[", "type", "(", "token", ")", "]", "(", "self", ",", "token", ")", "except", "KeyError", ":", "err", "=", "\"_handle_token() got unexpected {0}\"", "raise", "...
Handle a single token.
[ "Handle", "a", "single", "token", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L283-L289
8,824
earwig/mwparserfromhell
mwparserfromhell/parser/builder.py
Builder.build
def build(self, tokenlist): """Build a Wikicode object from a list tokens and return it.""" self._tokens = tokenlist self._tokens.reverse() self._push() while self._tokens: node = self._handle_token(self._tokens.pop()) self._write(node) return self...
python
def build(self, tokenlist): """Build a Wikicode object from a list tokens and return it.""" self._tokens = tokenlist self._tokens.reverse() self._push() while self._tokens: node = self._handle_token(self._tokens.pop()) self._write(node) return self...
[ "def", "build", "(", "self", ",", "tokenlist", ")", ":", "self", ".", "_tokens", "=", "tokenlist", "self", ".", "_tokens", ".", "reverse", "(", ")", "self", ".", "_push", "(", ")", "while", "self", ".", "_tokens", ":", "node", "=", "self", ".", "_h...
Build a Wikicode object from a list tokens and return it.
[ "Build", "a", "Wikicode", "object", "from", "a", "list", "tokens", "and", "return", "it", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/builder.py#L291-L299
8,825
earwig/mwparserfromhell
mwparserfromhell/nodes/template.py
Template._select_theory
def _select_theory(theories): """Return the most likely spacing convention given different options. Given a dictionary of convention options as keys and their occurrence as values, return the convention that occurs the most, or ``None`` if there is no clear preferred style. """ ...
python
def _select_theory(theories): """Return the most likely spacing convention given different options. Given a dictionary of convention options as keys and their occurrence as values, return the convention that occurs the most, or ``None`` if there is no clear preferred style. """ ...
[ "def", "_select_theory", "(", "theories", ")", ":", "if", "theories", ":", "values", "=", "tuple", "(", "theories", ".", "values", "(", ")", ")", "best", "=", "max", "(", "values", ")", "confidence", "=", "float", "(", "best", ")", "/", "sum", "(", ...
Return the most likely spacing convention given different options. Given a dictionary of convention options as keys and their occurrence as values, return the convention that occurs the most, or ``None`` if there is no clear preferred style.
[ "Return", "the", "most", "likely", "spacing", "convention", "given", "different", "options", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/nodes/template.py#L93-L105
8,826
earwig/mwparserfromhell
mwparserfromhell/nodes/template.py
Template._get_spacing_conventions
def _get_spacing_conventions(self, use_names): """Try to determine the whitespace conventions for parameters. This will examine the existing parameters and use :meth:`_select_theory` to determine if there are any preferred styles for how much whitespace to put before or after the value....
python
def _get_spacing_conventions(self, use_names): """Try to determine the whitespace conventions for parameters. This will examine the existing parameters and use :meth:`_select_theory` to determine if there are any preferred styles for how much whitespace to put before or after the value....
[ "def", "_get_spacing_conventions", "(", "self", ",", "use_names", ")", ":", "before_theories", "=", "defaultdict", "(", "lambda", ":", "0", ")", "after_theories", "=", "defaultdict", "(", "lambda", ":", "0", ")", "for", "param", "in", "self", ".", "params", ...
Try to determine the whitespace conventions for parameters. This will examine the existing parameters and use :meth:`_select_theory` to determine if there are any preferred styles for how much whitespace to put before or after the value.
[ "Try", "to", "determine", "the", "whitespace", "conventions", "for", "parameters", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/nodes/template.py#L123-L151
8,827
earwig/mwparserfromhell
mwparserfromhell/nodes/template.py
Template._should_remove
def _should_remove(self, i, name): """Look ahead for a parameter with the same name, but hidden. If one exists, we should remove the given one rather than blanking it. """ if self.params[i].showkey: following = self.params[i + 1:] better_matches = [after.name.str...
python
def _should_remove(self, i, name): """Look ahead for a parameter with the same name, but hidden. If one exists, we should remove the given one rather than blanking it. """ if self.params[i].showkey: following = self.params[i + 1:] better_matches = [after.name.str...
[ "def", "_should_remove", "(", "self", ",", "i", ",", "name", ")", ":", "if", "self", ".", "params", "[", "i", "]", ".", "showkey", ":", "following", "=", "self", ".", "params", "[", "i", "+", "1", ":", "]", "better_matches", "=", "[", "after", "....
Look ahead for a parameter with the same name, but hidden. If one exists, we should remove the given one rather than blanking it.
[ "Look", "ahead", "for", "a", "parameter", "with", "the", "same", "name", "but", "hidden", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/nodes/template.py#L172-L182
8,828
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._push
def _push(self, context=0): """Add a new token stack, context, and textbuffer to the list.""" new_ident = (self._head, context) if new_ident in self._bad_routes: raise BadRoute(context) self._stacks.append([[], context, [], new_ident]) self._depth += 1
python
def _push(self, context=0): """Add a new token stack, context, and textbuffer to the list.""" new_ident = (self._head, context) if new_ident in self._bad_routes: raise BadRoute(context) self._stacks.append([[], context, [], new_ident]) self._depth += 1
[ "def", "_push", "(", "self", ",", "context", "=", "0", ")", ":", "new_ident", "=", "(", "self", ".", "_head", ",", "context", ")", "if", "new_ident", "in", "self", ".", "_bad_routes", ":", "raise", "BadRoute", "(", "context", ")", "self", ".", "_stac...
Add a new token stack, context, and textbuffer to the list.
[ "Add", "a", "new", "token", "stack", "context", "and", "textbuffer", "to", "the", "list", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L113-L120
8,829
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._push_textbuffer
def _push_textbuffer(self): """Push the textbuffer onto the stack as a Text node and clear it.""" if self._textbuffer: self._stack.append(tokens.Text(text="".join(self._textbuffer))) self._textbuffer = []
python
def _push_textbuffer(self): """Push the textbuffer onto the stack as a Text node and clear it.""" if self._textbuffer: self._stack.append(tokens.Text(text="".join(self._textbuffer))) self._textbuffer = []
[ "def", "_push_textbuffer", "(", "self", ")", ":", "if", "self", ".", "_textbuffer", ":", "self", ".", "_stack", ".", "append", "(", "tokens", ".", "Text", "(", "text", "=", "\"\"", ".", "join", "(", "self", ".", "_textbuffer", ")", ")", ")", "self", ...
Push the textbuffer onto the stack as a Text node and clear it.
[ "Push", "the", "textbuffer", "onto", "the", "stack", "as", "a", "Text", "node", "and", "clear", "it", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L122-L126
8,830
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._fail_route
def _fail_route(self): """Fail the current tokenization route. Discards the current stack/context/textbuffer and raises :exc:`.BadRoute`. """ context = self._context self._memoize_bad_route() self._pop() raise BadRoute(context)
python
def _fail_route(self): """Fail the current tokenization route. Discards the current stack/context/textbuffer and raises :exc:`.BadRoute`. """ context = self._context self._memoize_bad_route() self._pop() raise BadRoute(context)
[ "def", "_fail_route", "(", "self", ")", ":", "context", "=", "self", ".", "_context", "self", ".", "_memoize_bad_route", "(", ")", "self", ".", "_pop", "(", ")", "raise", "BadRoute", "(", "context", ")" ]
Fail the current tokenization route. Discards the current stack/context/textbuffer and raises :exc:`.BadRoute`.
[ "Fail", "the", "current", "tokenization", "route", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L155-L164
8,831
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._emit_all
def _emit_all(self, tokenlist): """Write a series of tokens to the current stack at once.""" if tokenlist and isinstance(tokenlist[0], tokens.Text): self._emit_text(tokenlist.pop(0).text) self._push_textbuffer() self._stack.extend(tokenlist)
python
def _emit_all(self, tokenlist): """Write a series of tokens to the current stack at once.""" if tokenlist and isinstance(tokenlist[0], tokens.Text): self._emit_text(tokenlist.pop(0).text) self._push_textbuffer() self._stack.extend(tokenlist)
[ "def", "_emit_all", "(", "self", ",", "tokenlist", ")", ":", "if", "tokenlist", "and", "isinstance", "(", "tokenlist", "[", "0", "]", ",", "tokens", ".", "Text", ")", ":", "self", ".", "_emit_text", "(", "tokenlist", ".", "pop", "(", "0", ")", ".", ...
Write a series of tokens to the current stack at once.
[ "Write", "a", "series", "of", "tokens", "to", "the", "current", "stack", "at", "once", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L180-L185
8,832
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._read
def _read(self, delta=0, wrap=False, strict=False): """Read the value at a relative point in the wikicode. The value is read from :attr:`self._head <_head>` plus the value of *delta* (which can be negative). If *wrap* is ``False``, we will not allow attempts to read from the end of the ...
python
def _read(self, delta=0, wrap=False, strict=False): """Read the value at a relative point in the wikicode. The value is read from :attr:`self._head <_head>` plus the value of *delta* (which can be negative). If *wrap* is ``False``, we will not allow attempts to read from the end of the ...
[ "def", "_read", "(", "self", ",", "delta", "=", "0", ",", "wrap", "=", "False", ",", "strict", "=", "False", ")", ":", "index", "=", "self", ".", "_head", "+", "delta", "if", "index", "<", "0", "and", "(", "not", "wrap", "or", "abs", "(", "inde...
Read the value at a relative point in the wikicode. The value is read from :attr:`self._head <_head>` plus the value of *delta* (which can be negative). If *wrap* is ``False``, we will not allow attempts to read from the end of the string if ``self._head + delta`` is negative. If *stric...
[ "Read", "the", "value", "at", "a", "relative", "point", "in", "the", "wikicode", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L195-L215
8,833
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_template
def _parse_template(self, has_content): """Parse a template at the head of the wikicode string.""" reset = self._head context = contexts.TEMPLATE_NAME if has_content: context |= contexts.HAS_TEMPLATE try: template = self._parse(context) except BadR...
python
def _parse_template(self, has_content): """Parse a template at the head of the wikicode string.""" reset = self._head context = contexts.TEMPLATE_NAME if has_content: context |= contexts.HAS_TEMPLATE try: template = self._parse(context) except BadR...
[ "def", "_parse_template", "(", "self", ",", "has_content", ")", ":", "reset", "=", "self", ".", "_head", "context", "=", "contexts", ".", "TEMPLATE_NAME", "if", "has_content", ":", "context", "|=", "contexts", ".", "HAS_TEMPLATE", "try", ":", "template", "="...
Parse a template at the head of the wikicode string.
[ "Parse", "a", "template", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L217-L230
8,834
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_argument
def _parse_argument(self): """Parse an argument at the head of the wikicode string.""" reset = self._head try: argument = self._parse(contexts.ARGUMENT_NAME) except BadRoute: self._head = reset raise self._emit_first(tokens.ArgumentOpen()) ...
python
def _parse_argument(self): """Parse an argument at the head of the wikicode string.""" reset = self._head try: argument = self._parse(contexts.ARGUMENT_NAME) except BadRoute: self._head = reset raise self._emit_first(tokens.ArgumentOpen()) ...
[ "def", "_parse_argument", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "try", ":", "argument", "=", "self", ".", "_parse", "(", "contexts", ".", "ARGUMENT_NAME", ")", "except", "BadRoute", ":", "self", ".", "_head", "=", "reset", "raise", ...
Parse an argument at the head of the wikicode string.
[ "Parse", "an", "argument", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L232-L242
8,835
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_template_or_argument
def _parse_template_or_argument(self): """Parse a template or argument at the head of the wikicode string.""" self._head += 2 braces = 2 while self._read() == "{": self._head += 1 braces += 1 has_content = False self._push() while braces: ...
python
def _parse_template_or_argument(self): """Parse a template or argument at the head of the wikicode string.""" self._head += 2 braces = 2 while self._read() == "{": self._head += 1 braces += 1 has_content = False self._push() while braces: ...
[ "def", "_parse_template_or_argument", "(", "self", ")", ":", "self", ".", "_head", "+=", "2", "braces", "=", "2", "while", "self", ".", "_read", "(", ")", "==", "\"{\"", ":", "self", ".", "_head", "+=", "1", "braces", "+=", "1", "has_content", "=", "...
Parse a template or argument at the head of the wikicode string.
[ "Parse", "a", "template", "or", "argument", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L244-L278
8,836
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_template_param
def _handle_template_param(self): """Handle a template parameter at the head of the string.""" if self._context & contexts.TEMPLATE_NAME: if not self._context & (contexts.HAS_TEXT | contexts.HAS_TEMPLATE): self._fail_route() self._context ^= contexts.TEMPLATE_NAME...
python
def _handle_template_param(self): """Handle a template parameter at the head of the string.""" if self._context & contexts.TEMPLATE_NAME: if not self._context & (contexts.HAS_TEXT | contexts.HAS_TEMPLATE): self._fail_route() self._context ^= contexts.TEMPLATE_NAME...
[ "def", "_handle_template_param", "(", "self", ")", ":", "if", "self", ".", "_context", "&", "contexts", ".", "TEMPLATE_NAME", ":", "if", "not", "self", ".", "_context", "&", "(", "contexts", ".", "HAS_TEXT", "|", "contexts", ".", "HAS_TEMPLATE", ")", ":", ...
Handle a template parameter at the head of the string.
[ "Handle", "a", "template", "parameter", "at", "the", "head", "of", "the", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L280-L292
8,837
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_template_param_value
def _handle_template_param_value(self): """Handle a template parameter's value at the head of the string.""" self._emit_all(self._pop()) self._context ^= contexts.TEMPLATE_PARAM_KEY self._context |= contexts.TEMPLATE_PARAM_VALUE self._emit(tokens.TemplateParamEquals())
python
def _handle_template_param_value(self): """Handle a template parameter's value at the head of the string.""" self._emit_all(self._pop()) self._context ^= contexts.TEMPLATE_PARAM_KEY self._context |= contexts.TEMPLATE_PARAM_VALUE self._emit(tokens.TemplateParamEquals())
[ "def", "_handle_template_param_value", "(", "self", ")", ":", "self", ".", "_emit_all", "(", "self", ".", "_pop", "(", ")", ")", "self", ".", "_context", "^=", "contexts", ".", "TEMPLATE_PARAM_KEY", "self", ".", "_context", "|=", "contexts", ".", "TEMPLATE_P...
Handle a template parameter's value at the head of the string.
[ "Handle", "a", "template", "parameter", "s", "value", "at", "the", "head", "of", "the", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L294-L299
8,838
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_template_end
def _handle_template_end(self): """Handle the end of a template at the head of the string.""" if self._context & contexts.TEMPLATE_NAME: if not self._context & (contexts.HAS_TEXT | contexts.HAS_TEMPLATE): self._fail_route() elif self._context & contexts.TEMPLATE_PARAM...
python
def _handle_template_end(self): """Handle the end of a template at the head of the string.""" if self._context & contexts.TEMPLATE_NAME: if not self._context & (contexts.HAS_TEXT | contexts.HAS_TEMPLATE): self._fail_route() elif self._context & contexts.TEMPLATE_PARAM...
[ "def", "_handle_template_end", "(", "self", ")", ":", "if", "self", ".", "_context", "&", "contexts", ".", "TEMPLATE_NAME", ":", "if", "not", "self", ".", "_context", "&", "(", "contexts", ".", "HAS_TEXT", "|", "contexts", ".", "HAS_TEMPLATE", ")", ":", ...
Handle the end of a template at the head of the string.
[ "Handle", "the", "end", "of", "a", "template", "at", "the", "head", "of", "the", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L301-L309
8,839
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_argument_separator
def _handle_argument_separator(self): """Handle the separator between an argument's name and default.""" self._context ^= contexts.ARGUMENT_NAME self._context |= contexts.ARGUMENT_DEFAULT self._emit(tokens.ArgumentSeparator())
python
def _handle_argument_separator(self): """Handle the separator between an argument's name and default.""" self._context ^= contexts.ARGUMENT_NAME self._context |= contexts.ARGUMENT_DEFAULT self._emit(tokens.ArgumentSeparator())
[ "def", "_handle_argument_separator", "(", "self", ")", ":", "self", ".", "_context", "^=", "contexts", ".", "ARGUMENT_NAME", "self", ".", "_context", "|=", "contexts", ".", "ARGUMENT_DEFAULT", "self", ".", "_emit", "(", "tokens", ".", "ArgumentSeparator", "(", ...
Handle the separator between an argument's name and default.
[ "Handle", "the", "separator", "between", "an", "argument", "s", "name", "and", "default", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L311-L315
8,840
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_wikilink
def _parse_wikilink(self): """Parse an internal wikilink at the head of the wikicode string.""" reset = self._head + 1 self._head += 2 try: # If the wikilink looks like an external link, parse it as such: link, extra, delta = self._really_parse_external_link(True)...
python
def _parse_wikilink(self): """Parse an internal wikilink at the head of the wikicode string.""" reset = self._head + 1 self._head += 2 try: # If the wikilink looks like an external link, parse it as such: link, extra, delta = self._really_parse_external_link(True)...
[ "def", "_parse_wikilink", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "+", "1", "self", ".", "_head", "+=", "2", "try", ":", "# If the wikilink looks like an external link, parse it as such:", "link", ",", "extra", ",", "delta", "=", "self", "."...
Parse an internal wikilink at the head of the wikicode string.
[ "Parse", "an", "internal", "wikilink", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L322-L351
8,841
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_wikilink_separator
def _handle_wikilink_separator(self): """Handle the separator between a wikilink's title and its text.""" self._context ^= contexts.WIKILINK_TITLE self._context |= contexts.WIKILINK_TEXT self._emit(tokens.WikilinkSeparator())
python
def _handle_wikilink_separator(self): """Handle the separator between a wikilink's title and its text.""" self._context ^= contexts.WIKILINK_TITLE self._context |= contexts.WIKILINK_TEXT self._emit(tokens.WikilinkSeparator())
[ "def", "_handle_wikilink_separator", "(", "self", ")", ":", "self", ".", "_context", "^=", "contexts", ".", "WIKILINK_TITLE", "self", ".", "_context", "|=", "contexts", ".", "WIKILINK_TEXT", "self", ".", "_emit", "(", "tokens", ".", "WikilinkSeparator", "(", "...
Handle the separator between a wikilink's title and its text.
[ "Handle", "the", "separator", "between", "a", "wikilink", "s", "title", "and", "its", "text", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L353-L357
8,842
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_bracketed_uri_scheme
def _parse_bracketed_uri_scheme(self): """Parse the URI scheme of a bracket-enclosed external link.""" self._push(contexts.EXT_LINK_URI) if self._read() == self._read(1) == "/": self._emit_text("//") self._head += 2 else: valid = "abcdefghijklmnopqrstu...
python
def _parse_bracketed_uri_scheme(self): """Parse the URI scheme of a bracket-enclosed external link.""" self._push(contexts.EXT_LINK_URI) if self._read() == self._read(1) == "/": self._emit_text("//") self._head += 2 else: valid = "abcdefghijklmnopqrstu...
[ "def", "_parse_bracketed_uri_scheme", "(", "self", ")", ":", "self", ".", "_push", "(", "contexts", ".", "EXT_LINK_URI", ")", "if", "self", ".", "_read", "(", ")", "==", "self", ".", "_read", "(", "1", ")", "==", "\"/\"", ":", "self", ".", "_emit_text"...
Parse the URI scheme of a bracket-enclosed external link.
[ "Parse", "the", "URI", "scheme", "of", "a", "bracket", "-", "enclosed", "external", "link", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L364-L387
8,843
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_free_link_text
def _handle_free_link_text(self, punct, tail, this): """Handle text in a free ext link, including trailing punctuation.""" if "(" in this and ")" in punct: punct = punct[:-1] # ')' is not longer valid punctuation if this.endswith(punct): for i in range(len(this) - 1, 0, ...
python
def _handle_free_link_text(self, punct, tail, this): """Handle text in a free ext link, including trailing punctuation.""" if "(" in this and ")" in punct: punct = punct[:-1] # ')' is not longer valid punctuation if this.endswith(punct): for i in range(len(this) - 1, 0, ...
[ "def", "_handle_free_link_text", "(", "self", ",", "punct", ",", "tail", ",", "this", ")", ":", "if", "\"(\"", "in", "this", "and", "\")\"", "in", "punct", ":", "punct", "=", "punct", "[", ":", "-", "1", "]", "# ')' is not longer valid punctuation", "if", ...
Handle text in a free ext link, including trailing punctuation.
[ "Handle", "text", "in", "a", "free", "ext", "link", "including", "trailing", "punctuation", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L416-L436
8,844
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._is_free_link_end
def _is_free_link_end(self, this, next): """Return whether the current head is the end of a free link.""" # Built from _parse()'s end sentinels: after, ctx = self._read(2), self._context equal_sign_contexts = contexts.TEMPLATE_PARAM_KEY | contexts.HEADING return (this in (self.EN...
python
def _is_free_link_end(self, this, next): """Return whether the current head is the end of a free link.""" # Built from _parse()'s end sentinels: after, ctx = self._read(2), self._context equal_sign_contexts = contexts.TEMPLATE_PARAM_KEY | contexts.HEADING return (this in (self.EN...
[ "def", "_is_free_link_end", "(", "self", ",", "this", ",", "next", ")", ":", "# Built from _parse()'s end sentinels:", "after", ",", "ctx", "=", "self", ".", "_read", "(", "2", ")", ",", "self", ".", "_context", "equal_sign_contexts", "=", "contexts", ".", "...
Return whether the current head is the end of a free link.
[ "Return", "whether", "the", "current", "head", "is", "the", "end", "of", "a", "free", "link", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L438-L448
8,845
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._really_parse_external_link
def _really_parse_external_link(self, brackets): """Really parse an external link.""" if brackets: self._parse_bracketed_uri_scheme() invalid = ("\n", " ", "]") else: self._parse_free_uri_scheme() invalid = ("\n", " ", "[", "]") punct =...
python
def _really_parse_external_link(self, brackets): """Really parse an external link.""" if brackets: self._parse_bracketed_uri_scheme() invalid = ("\n", " ", "]") else: self._parse_free_uri_scheme() invalid = ("\n", " ", "[", "]") punct =...
[ "def", "_really_parse_external_link", "(", "self", ",", "brackets", ")", ":", "if", "brackets", ":", "self", ".", "_parse_bracketed_uri_scheme", "(", ")", "invalid", "=", "(", "\"\\n\"", ",", "\" \"", ",", "\"]\"", ")", "else", ":", "self", ".", "_parse_free...
Really parse an external link.
[ "Really", "parse", "an", "external", "link", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L450-L503
8,846
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._remove_uri_scheme_from_textbuffer
def _remove_uri_scheme_from_textbuffer(self, scheme): """Remove the URI scheme of a new external link from the textbuffer.""" length = len(scheme) while length: if length < len(self._textbuffer[-1]): self._textbuffer[-1] = self._textbuffer[-1][:-length] ...
python
def _remove_uri_scheme_from_textbuffer(self, scheme): """Remove the URI scheme of a new external link from the textbuffer.""" length = len(scheme) while length: if length < len(self._textbuffer[-1]): self._textbuffer[-1] = self._textbuffer[-1][:-length] ...
[ "def", "_remove_uri_scheme_from_textbuffer", "(", "self", ",", "scheme", ")", ":", "length", "=", "len", "(", "scheme", ")", "while", "length", ":", "if", "length", "<", "len", "(", "self", ".", "_textbuffer", "[", "-", "1", "]", ")", ":", "self", ".",...
Remove the URI scheme of a new external link from the textbuffer.
[ "Remove", "the", "URI", "scheme", "of", "a", "new", "external", "link", "from", "the", "textbuffer", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L505-L513
8,847
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_external_link
def _parse_external_link(self, brackets): """Parse an external link at the head of the wikicode string.""" if self._context & contexts.NO_EXT_LINKS or not self._can_recurse(): if not brackets and self._context & contexts.DL_TERM: self._handle_dl_term() else: ...
python
def _parse_external_link(self, brackets): """Parse an external link at the head of the wikicode string.""" if self._context & contexts.NO_EXT_LINKS or not self._can_recurse(): if not brackets and self._context & contexts.DL_TERM: self._handle_dl_term() else: ...
[ "def", "_parse_external_link", "(", "self", ",", "brackets", ")", ":", "if", "self", ".", "_context", "&", "contexts", ".", "NO_EXT_LINKS", "or", "not", "self", ".", "_can_recurse", "(", ")", ":", "if", "not", "brackets", "and", "self", ".", "_context", ...
Parse an external link at the head of the wikicode string.
[ "Parse", "an", "external", "link", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L515-L543
8,848
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_heading
def _parse_heading(self): """Parse a section heading at the head of the wikicode string.""" self._global |= contexts.GL_HEADING reset = self._head self._head += 1 best = 1 while self._read() == "=": best += 1 self._head += 1 context = conte...
python
def _parse_heading(self): """Parse a section heading at the head of the wikicode string.""" self._global |= contexts.GL_HEADING reset = self._head self._head += 1 best = 1 while self._read() == "=": best += 1 self._head += 1 context = conte...
[ "def", "_parse_heading", "(", "self", ")", ":", "self", ".", "_global", "|=", "contexts", ".", "GL_HEADING", "reset", "=", "self", ".", "_head", "self", ".", "_head", "+=", "1", "best", "=", "1", "while", "self", ".", "_read", "(", ")", "==", "\"=\""...
Parse a section heading at the head of the wikicode string.
[ "Parse", "a", "section", "heading", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L545-L568
8,849
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_heading_end
def _handle_heading_end(self): """Handle the end of a section heading at the head of the string.""" reset = self._head self._head += 1 best = 1 while self._read() == "=": best += 1 self._head += 1 current = int(log(self._context / contexts.HEADING_...
python
def _handle_heading_end(self): """Handle the end of a section heading at the head of the string.""" reset = self._head self._head += 1 best = 1 while self._read() == "=": best += 1 self._head += 1 current = int(log(self._context / contexts.HEADING_...
[ "def", "_handle_heading_end", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "self", ".", "_head", "+=", "1", "best", "=", "1", "while", "self", ".", "_read", "(", ")", "==", "\"=\"", ":", "best", "+=", "1", "self", ".", "_head", "+=", ...
Handle the end of a section heading at the head of the string.
[ "Handle", "the", "end", "of", "a", "section", "heading", "at", "the", "head", "of", "the", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L570-L591
8,850
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._really_parse_entity
def _really_parse_entity(self): """Actually parse an HTML entity and ensure that it is valid.""" self._emit(tokens.HTMLEntityStart()) self._head += 1 this = self._read(strict=True) if this == "#": numeric = True self._emit(tokens.HTMLEntityNumeric()) ...
python
def _really_parse_entity(self): """Actually parse an HTML entity and ensure that it is valid.""" self._emit(tokens.HTMLEntityStart()) self._head += 1 this = self._read(strict=True) if this == "#": numeric = True self._emit(tokens.HTMLEntityNumeric()) ...
[ "def", "_really_parse_entity", "(", "self", ")", ":", "self", ".", "_emit", "(", "tokens", ".", "HTMLEntityStart", "(", ")", ")", "self", ".", "_head", "+=", "1", "this", "=", "self", ".", "_read", "(", "strict", "=", "True", ")", "if", "this", "==",...
Actually parse an HTML entity and ensure that it is valid.
[ "Actually", "parse", "an", "HTML", "entity", "and", "ensure", "that", "it", "is", "valid", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L593-L633
8,851
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_entity
def _parse_entity(self): """Parse an HTML entity at the head of the wikicode string.""" reset = self._head try: self._push(contexts.HTML_ENTITY) self._really_parse_entity() except BadRoute: self._head = reset self._emit_text(self._read()) ...
python
def _parse_entity(self): """Parse an HTML entity at the head of the wikicode string.""" reset = self._head try: self._push(contexts.HTML_ENTITY) self._really_parse_entity() except BadRoute: self._head = reset self._emit_text(self._read()) ...
[ "def", "_parse_entity", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "try", ":", "self", ".", "_push", "(", "contexts", ".", "HTML_ENTITY", ")", "self", ".", "_really_parse_entity", "(", ")", "except", "BadRoute", ":", "self", ".", "_head",...
Parse an HTML entity at the head of the wikicode string.
[ "Parse", "an", "HTML", "entity", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L635-L645
8,852
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_comment
def _parse_comment(self): """Parse an HTML comment at the head of the wikicode string.""" self._head += 4 reset = self._head - 1 self._push() while True: this = self._read() if this == self.END: self._pop() self._head = rese...
python
def _parse_comment(self): """Parse an HTML comment at the head of the wikicode string.""" self._head += 4 reset = self._head - 1 self._push() while True: this = self._read() if this == self.END: self._pop() self._head = rese...
[ "def", "_parse_comment", "(", "self", ")", ":", "self", ".", "_head", "+=", "4", "reset", "=", "self", ".", "_head", "-", "1", "self", ".", "_push", "(", ")", "while", "True", ":", "this", "=", "self", ".", "_read", "(", ")", "if", "this", "==", ...
Parse an HTML comment at the head of the wikicode string.
[ "Parse", "an", "HTML", "comment", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L647-L671
8,853
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_blacklisted_tag
def _handle_blacklisted_tag(self): """Handle the body of an HTML tag that is parser-blacklisted.""" strip = lambda text: text.rstrip().lower() while True: this, next = self._read(), self._read(1) if this is self.END: self._fail_route() elif thi...
python
def _handle_blacklisted_tag(self): """Handle the body of an HTML tag that is parser-blacklisted.""" strip = lambda text: text.rstrip().lower() while True: this, next = self._read(), self._read(1) if this is self.END: self._fail_route() elif thi...
[ "def", "_handle_blacklisted_tag", "(", "self", ")", ":", "strip", "=", "lambda", "text", ":", "text", ".", "rstrip", "(", ")", ".", "lower", "(", ")", "while", "True", ":", "this", ",", "next", "=", "self", ".", "_read", "(", ")", ",", "self", ".",...
Handle the body of an HTML tag that is parser-blacklisted.
[ "Handle", "the", "body", "of", "an", "HTML", "tag", "that", "is", "parser", "-", "blacklisted", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L797-L819
8,854
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_single_only_tag_end
def _handle_single_only_tag_end(self): """Handle the end of an implicitly closing single-only HTML tag.""" padding = self._stack.pop().padding self._emit(tokens.TagCloseSelfclose(padding=padding, implicit=True)) self._head -= 1 # Offset displacement done by _handle_tag_close_open ...
python
def _handle_single_only_tag_end(self): """Handle the end of an implicitly closing single-only HTML tag.""" padding = self._stack.pop().padding self._emit(tokens.TagCloseSelfclose(padding=padding, implicit=True)) self._head -= 1 # Offset displacement done by _handle_tag_close_open ...
[ "def", "_handle_single_only_tag_end", "(", "self", ")", ":", "padding", "=", "self", ".", "_stack", ".", "pop", "(", ")", ".", "padding", "self", ".", "_emit", "(", "tokens", ".", "TagCloseSelfclose", "(", "padding", "=", "padding", ",", "implicit", "=", ...
Handle the end of an implicitly closing single-only HTML tag.
[ "Handle", "the", "end", "of", "an", "implicitly", "closing", "single", "-", "only", "HTML", "tag", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L821-L826
8,855
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_single_tag_end
def _handle_single_tag_end(self): """Handle the stream end when inside a single-supporting HTML tag.""" stack = self._stack # We need to find the index of the TagCloseOpen token corresponding to # the TagOpenOpen token located at index 0: depth = 1 for index, token in enu...
python
def _handle_single_tag_end(self): """Handle the stream end when inside a single-supporting HTML tag.""" stack = self._stack # We need to find the index of the TagCloseOpen token corresponding to # the TagOpenOpen token located at index 0: depth = 1 for index, token in enu...
[ "def", "_handle_single_tag_end", "(", "self", ")", ":", "stack", "=", "self", ".", "_stack", "# We need to find the index of the TagCloseOpen token corresponding to", "# the TagOpenOpen token located at index 0:", "depth", "=", "1", "for", "index", ",", "token", "in", "enum...
Handle the stream end when inside a single-supporting HTML tag.
[ "Handle", "the", "stream", "end", "when", "inside", "a", "single", "-", "supporting", "HTML", "tag", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L828-L851
8,856
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_tag
def _parse_tag(self): """Parse an HTML tag at the head of the wikicode string.""" reset = self._head self._head += 1 try: tag = self._really_parse_tag() except BadRoute: self._head = reset self._emit_text("<") else: self._em...
python
def _parse_tag(self): """Parse an HTML tag at the head of the wikicode string.""" reset = self._head self._head += 1 try: tag = self._really_parse_tag() except BadRoute: self._head = reset self._emit_text("<") else: self._em...
[ "def", "_parse_tag", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "self", ".", "_head", "+=", "1", "try", ":", "tag", "=", "self", ".", "_really_parse_tag", "(", ")", "except", "BadRoute", ":", "self", ".", "_head", "=", "reset", "self"...
Parse an HTML tag at the head of the wikicode string.
[ "Parse", "an", "HTML", "tag", "at", "the", "head", "of", "the", "wikicode", "string", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L903-L913
8,857
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._emit_style_tag
def _emit_style_tag(self, tag, markup, body): """Write the body of a tag and the tokens that should surround it.""" self._emit(tokens.TagOpenOpen(wiki_markup=markup)) self._emit_text(tag) self._emit(tokens.TagCloseOpen()) self._emit_all(body) self._emit(tokens.TagOpenClos...
python
def _emit_style_tag(self, tag, markup, body): """Write the body of a tag and the tokens that should surround it.""" self._emit(tokens.TagOpenOpen(wiki_markup=markup)) self._emit_text(tag) self._emit(tokens.TagCloseOpen()) self._emit_all(body) self._emit(tokens.TagOpenClos...
[ "def", "_emit_style_tag", "(", "self", ",", "tag", ",", "markup", ",", "body", ")", ":", "self", ".", "_emit", "(", "tokens", ".", "TagOpenOpen", "(", "wiki_markup", "=", "markup", ")", ")", "self", ".", "_emit_text", "(", "tag", ")", "self", ".", "_...
Write the body of a tag and the tokens that should surround it.
[ "Write", "the", "body", "of", "a", "tag", "and", "the", "tokens", "that", "should", "surround", "it", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L915-L923
8,858
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_italics
def _parse_italics(self): """Parse wiki-style italics.""" reset = self._head try: stack = self._parse(contexts.STYLE_ITALICS) except BadRoute as route: self._head = reset if route.context & contexts.STYLE_PASS_AGAIN: new_ctx = contexts....
python
def _parse_italics(self): """Parse wiki-style italics.""" reset = self._head try: stack = self._parse(contexts.STYLE_ITALICS) except BadRoute as route: self._head = reset if route.context & contexts.STYLE_PASS_AGAIN: new_ctx = contexts....
[ "def", "_parse_italics", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "try", ":", "stack", "=", "self", ".", "_parse", "(", "contexts", ".", "STYLE_ITALICS", ")", "except", "BadRoute", "as", "route", ":", "self", ".", "_head", "=", "reset...
Parse wiki-style italics.
[ "Parse", "wiki", "-", "style", "italics", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L925-L937
8,859
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_bold
def _parse_bold(self): """Parse wiki-style bold.""" reset = self._head try: stack = self._parse(contexts.STYLE_BOLD) except BadRoute: self._head = reset if self._context & contexts.STYLE_SECOND_PASS: self._emit_text("'") ...
python
def _parse_bold(self): """Parse wiki-style bold.""" reset = self._head try: stack = self._parse(contexts.STYLE_BOLD) except BadRoute: self._head = reset if self._context & contexts.STYLE_SECOND_PASS: self._emit_text("'") ...
[ "def", "_parse_bold", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "try", ":", "stack", "=", "self", ".", "_parse", "(", "contexts", ".", "STYLE_BOLD", ")", "except", "BadRoute", ":", "self", ".", "_head", "=", "reset", "if", "self", "....
Parse wiki-style bold.
[ "Parse", "wiki", "-", "style", "bold", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L939-L956
8,860
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._emit_table_tag
def _emit_table_tag(self, open_open_markup, tag, style, padding, close_open_markup, contents, open_close_markup): """Emit a table tag.""" self._emit(tokens.TagOpenOpen(wiki_markup=open_open_markup)) self._emit_text(tag) if style: self._emit_all(style) ...
python
def _emit_table_tag(self, open_open_markup, tag, style, padding, close_open_markup, contents, open_close_markup): """Emit a table tag.""" self._emit(tokens.TagOpenOpen(wiki_markup=open_open_markup)) self._emit_text(tag) if style: self._emit_all(style) ...
[ "def", "_emit_table_tag", "(", "self", ",", "open_open_markup", ",", "tag", ",", "style", ",", "padding", ",", "close_open_markup", ",", "contents", ",", "open_close_markup", ")", ":", "self", ".", "_emit", "(", "tokens", ".", "TagOpenOpen", "(", "wiki_markup"...
Emit a table tag.
[ "Emit", "a", "table", "tag", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1070-L1086
8,861
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_table_style
def _handle_table_style(self, end_token): """Handle style attributes for a table until ``end_token``.""" data = _TagOpenData() data.context = _TagOpenData.CX_ATTR_READY while True: this = self._read() can_exit = (not data.context & data.CX_QUOTED or ...
python
def _handle_table_style(self, end_token): """Handle style attributes for a table until ``end_token``.""" data = _TagOpenData() data.context = _TagOpenData.CX_ATTR_READY while True: this = self._read() can_exit = (not data.context & data.CX_QUOTED or ...
[ "def", "_handle_table_style", "(", "self", ",", "end_token", ")", ":", "data", "=", "_TagOpenData", "(", ")", "data", ".", "context", "=", "_TagOpenData", ".", "CX_ATTR_READY", "while", "True", ":", "this", "=", "self", ".", "_read", "(", ")", "can_exit", ...
Handle style attributes for a table until ``end_token``.
[ "Handle", "style", "attributes", "for", "a", "table", "until", "end_token", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1088-L1115
8,862
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._parse_table
def _parse_table(self): """Parse a wikicode table by starting with the first line.""" reset = self._head self._head += 2 try: self._push(contexts.TABLE_OPEN) padding = self._handle_table_style("\n") except BadRoute: self._head = reset ...
python
def _parse_table(self): """Parse a wikicode table by starting with the first line.""" reset = self._head self._head += 2 try: self._push(contexts.TABLE_OPEN) padding = self._handle_table_style("\n") except BadRoute: self._head = reset ...
[ "def", "_parse_table", "(", "self", ")", ":", "reset", "=", "self", ".", "_head", "self", ".", "_head", "+=", "2", "try", ":", "self", ".", "_push", "(", "contexts", ".", "TABLE_OPEN", ")", "padding", "=", "self", ".", "_handle_table_style", "(", "\"\\...
Parse a wikicode table by starting with the first line.
[ "Parse", "a", "wikicode", "table", "by", "starting", "with", "the", "first", "line", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1117-L1144
8,863
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_table_row
def _handle_table_row(self): """Parse as style until end of the line, then continue.""" self._head += 2 if not self._can_recurse(): self._emit_text("|-") self._head -= 1 return self._push(contexts.TABLE_OPEN | contexts.TABLE_ROW_OPEN) padding ...
python
def _handle_table_row(self): """Parse as style until end of the line, then continue.""" self._head += 2 if not self._can_recurse(): self._emit_text("|-") self._head -= 1 return self._push(contexts.TABLE_OPEN | contexts.TABLE_ROW_OPEN) padding ...
[ "def", "_handle_table_row", "(", "self", ")", ":", "self", ".", "_head", "+=", "2", "if", "not", "self", ".", "_can_recurse", "(", ")", ":", "self", ".", "_emit_text", "(", "\"|-\"", ")", "self", ".", "_head", "-=", "1", "return", "self", ".", "_push...
Parse as style until end of the line, then continue.
[ "Parse", "as", "style", "until", "end", "of", "the", "line", "then", "continue", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1146-L1164
8,864
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_table_cell
def _handle_table_cell(self, markup, tag, line_context): """Parse as normal syntax unless we hit a style marker, then parse style as HTML attributes and the remainder as normal syntax.""" old_context = self._context padding, style = "", None self._head += len(markup) rese...
python
def _handle_table_cell(self, markup, tag, line_context): """Parse as normal syntax unless we hit a style marker, then parse style as HTML attributes and the remainder as normal syntax.""" old_context = self._context padding, style = "", None self._head += len(markup) rese...
[ "def", "_handle_table_cell", "(", "self", ",", "markup", ",", "tag", ",", "line_context", ")", ":", "old_context", "=", "self", ".", "_context", "padding", ",", "style", "=", "\"\"", ",", "None", "self", ".", "_head", "+=", "len", "(", "markup", ")", "...
Parse as normal syntax unless we hit a style marker, then parse style as HTML attributes and the remainder as normal syntax.
[ "Parse", "as", "normal", "syntax", "unless", "we", "hit", "a", "style", "marker", "then", "parse", "style", "as", "HTML", "attributes", "and", "the", "remainder", "as", "normal", "syntax", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1166-L1203
8,865
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_table_cell_end
def _handle_table_cell_end(self, reset_for_style=False): """Returns the current context, with the TABLE_CELL_STYLE flag set if it is necessary to reset and parse style attributes.""" if reset_for_style: self._context |= contexts.TABLE_CELL_STYLE else: self._contex...
python
def _handle_table_cell_end(self, reset_for_style=False): """Returns the current context, with the TABLE_CELL_STYLE flag set if it is necessary to reset and parse style attributes.""" if reset_for_style: self._context |= contexts.TABLE_CELL_STYLE else: self._contex...
[ "def", "_handle_table_cell_end", "(", "self", ",", "reset_for_style", "=", "False", ")", ":", "if", "reset_for_style", ":", "self", ".", "_context", "|=", "contexts", ".", "TABLE_CELL_STYLE", "else", ":", "self", ".", "_context", "&=", "~", "contexts", ".", ...
Returns the current context, with the TABLE_CELL_STYLE flag set if it is necessary to reset and parse style attributes.
[ "Returns", "the", "current", "context", "with", "the", "TABLE_CELL_STYLE", "flag", "set", "if", "it", "is", "necessary", "to", "reset", "and", "parse", "style", "attributes", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1205-L1212
8,866
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._handle_end
def _handle_end(self): """Handle the end of the stream of wikitext.""" if self._context & contexts.FAIL: if self._context & contexts.TAG_BODY: if is_single(self._stack[1].text): return self._handle_single_tag_end() if self._context & contexts.T...
python
def _handle_end(self): """Handle the end of the stream of wikitext.""" if self._context & contexts.FAIL: if self._context & contexts.TAG_BODY: if is_single(self._stack[1].text): return self._handle_single_tag_end() if self._context & contexts.T...
[ "def", "_handle_end", "(", "self", ")", ":", "if", "self", ".", "_context", "&", "contexts", ".", "FAIL", ":", "if", "self", ".", "_context", "&", "contexts", ".", "TAG_BODY", ":", "if", "is_single", "(", "self", ".", "_stack", "[", "1", "]", ".", ...
Handle the end of the stream of wikitext.
[ "Handle", "the", "end", "of", "the", "stream", "of", "wikitext", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1223-L1234
8,867
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer._verify_safe
def _verify_safe(self, this): """Make sure we are not trying to write an invalid character.""" context = self._context if context & contexts.FAIL_NEXT: return False if context & contexts.WIKILINK_TITLE: if this == "]" or this == "{": self._context ...
python
def _verify_safe(self, this): """Make sure we are not trying to write an invalid character.""" context = self._context if context & contexts.FAIL_NEXT: return False if context & contexts.WIKILINK_TITLE: if this == "]" or this == "{": self._context ...
[ "def", "_verify_safe", "(", "self", ",", "this", ")", ":", "context", "=", "self", ".", "_context", "if", "context", "&", "contexts", ".", "FAIL_NEXT", ":", "return", "False", "if", "context", "&", "contexts", ".", "WIKILINK_TITLE", ":", "if", "this", "=...
Make sure we are not trying to write an invalid character.
[ "Make", "sure", "we", "are", "not", "trying", "to", "write", "an", "invalid", "character", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1236-L1297
8,868
earwig/mwparserfromhell
mwparserfromhell/parser/tokenizer.py
Tokenizer.tokenize
def tokenize(self, text, context=0, skip_style_tags=False): """Build a list of tokens from a string of wikicode and return it.""" split = self.regex.split(text) self._text = [segment for segment in split if segment] self._head = self._global = self._depth = 0 self._bad_routes = s...
python
def tokenize(self, text, context=0, skip_style_tags=False): """Build a list of tokens from a string of wikicode and return it.""" split = self.regex.split(text) self._text = [segment for segment in split if segment] self._head = self._global = self._depth = 0 self._bad_routes = s...
[ "def", "tokenize", "(", "self", ",", "text", ",", "context", "=", "0", ",", "skip_style_tags", "=", "False", ")", ":", "split", "=", "self", ".", "regex", ".", "split", "(", "text", ")", "self", ".", "_text", "=", "[", "segment", "for", "segment", ...
Build a list of tokens from a string of wikicode and return it.
[ "Build", "a", "list", "of", "tokens", "from", "a", "string", "of", "wikicode", "and", "return", "it", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/parser/tokenizer.py#L1450-L1465
8,869
earwig/mwparserfromhell
mwparserfromhell/nodes/extras/attribute.py
Attribute._value_needs_quotes
def _value_needs_quotes(val): """Return valid quotes for the given value, or None if unneeded.""" if not val: return None val = "".join(str(node) for node in val.filter_text(recursive=False)) if not any(char.isspace() for char in val): return None if "'" i...
python
def _value_needs_quotes(val): """Return valid quotes for the given value, or None if unneeded.""" if not val: return None val = "".join(str(node) for node in val.filter_text(recursive=False)) if not any(char.isspace() for char in val): return None if "'" i...
[ "def", "_value_needs_quotes", "(", "val", ")", ":", "if", "not", "val", ":", "return", "None", "val", "=", "\"\"", ".", "join", "(", "str", "(", "node", ")", "for", "node", "in", "val", ".", "filter_text", "(", "recursive", "=", "False", ")", ")", ...
Return valid quotes for the given value, or None if unneeded.
[ "Return", "valid", "quotes", "for", "the", "given", "value", "or", "None", "if", "unneeded", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/nodes/extras/attribute.py#L60-L71
8,870
earwig/mwparserfromhell
mwparserfromhell/nodes/extras/attribute.py
Attribute._set_padding
def _set_padding(self, attr, value): """Setter for the value of a padding attribute.""" if not value: setattr(self, attr, "") else: value = str(value) if not value.isspace(): raise ValueError("padding must be entirely whitespace") s...
python
def _set_padding(self, attr, value): """Setter for the value of a padding attribute.""" if not value: setattr(self, attr, "") else: value = str(value) if not value.isspace(): raise ValueError("padding must be entirely whitespace") s...
[ "def", "_set_padding", "(", "self", ",", "attr", ",", "value", ")", ":", "if", "not", "value", ":", "setattr", "(", "self", ",", "attr", ",", "\"\"", ")", "else", ":", "value", "=", "str", "(", "value", ")", "if", "not", "value", ".", "isspace", ...
Setter for the value of a padding attribute.
[ "Setter", "for", "the", "value", "of", "a", "padding", "attribute", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/nodes/extras/attribute.py#L73-L81
8,871
earwig/mwparserfromhell
mwparserfromhell/nodes/extras/attribute.py
Attribute.coerce_quotes
def coerce_quotes(quotes): """Coerce a quote type into an acceptable value, or raise an error.""" orig, quotes = quotes, str(quotes) if quotes else None if quotes not in [None, '"', "'"]: raise ValueError("{!r} is not a valid quote type".format(orig)) return quotes
python
def coerce_quotes(quotes): """Coerce a quote type into an acceptable value, or raise an error.""" orig, quotes = quotes, str(quotes) if quotes else None if quotes not in [None, '"', "'"]: raise ValueError("{!r} is not a valid quote type".format(orig)) return quotes
[ "def", "coerce_quotes", "(", "quotes", ")", ":", "orig", ",", "quotes", "=", "quotes", ",", "str", "(", "quotes", ")", "if", "quotes", "else", "None", "if", "quotes", "not", "in", "[", "None", ",", "'\"'", ",", "\"'\"", "]", ":", "raise", "ValueError...
Coerce a quote type into an acceptable value, or raise an error.
[ "Coerce", "a", "quote", "type", "into", "an", "acceptable", "value", "or", "raise", "an", "error", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/nodes/extras/attribute.py#L84-L89
8,872
earwig/mwparserfromhell
mwparserfromhell/wikicode.py
Wikicode._indexed_ifilter
def _indexed_ifilter(self, recursive=True, matches=None, flags=FLAGS, forcetype=None): """Iterate over nodes and their corresponding indices in the node list. The arguments are interpreted as for :meth:`ifilter`. For each tuple ``(i, node)`` yielded by this method, ``se...
python
def _indexed_ifilter(self, recursive=True, matches=None, flags=FLAGS, forcetype=None): """Iterate over nodes and their corresponding indices in the node list. The arguments are interpreted as for :meth:`ifilter`. For each tuple ``(i, node)`` yielded by this method, ``se...
[ "def", "_indexed_ifilter", "(", "self", ",", "recursive", "=", "True", ",", "matches", "=", "None", ",", "flags", "=", "FLAGS", ",", "forcetype", "=", "None", ")", ":", "match", "=", "self", ".", "_build_matcher", "(", "matches", ",", "flags", ")", "if...
Iterate over nodes and their corresponding indices in the node list. The arguments are interpreted as for :meth:`ifilter`. For each tuple ``(i, node)`` yielded by this method, ``self.index(node) == i``. Note that if *recursive* is ``True``, ``self.nodes[i]`` might not be the node itself...
[ "Iterate", "over", "nodes", "and", "their", "corresponding", "indices", "in", "the", "node", "list", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/wikicode.py#L90-L110
8,873
earwig/mwparserfromhell
mwparserfromhell/wikicode.py
Wikicode._get_tree
def _get_tree(self, code, lines, marker, indent): """Build a tree to illustrate the way the Wikicode object was parsed. The method that builds the actual tree is ``__showtree__`` of ``Node`` objects. *code* is the ``Wikicode`` object to build a tree for. *lines* is the list to append th...
python
def _get_tree(self, code, lines, marker, indent): """Build a tree to illustrate the way the Wikicode object was parsed. The method that builds the actual tree is ``__showtree__`` of ``Node`` objects. *code* is the ``Wikicode`` object to build a tree for. *lines* is the list to append th...
[ "def", "_get_tree", "(", "self", ",", "code", ",", "lines", ",", "marker", ",", "indent", ")", ":", "def", "write", "(", "*", "args", ")", ":", "\"\"\"Write a new line following the proper indentation rules.\"\"\"", "if", "lines", "and", "lines", "[", "-", "1"...
Build a tree to illustrate the way the Wikicode object was parsed. The method that builds the actual tree is ``__showtree__`` of ``Node`` objects. *code* is the ``Wikicode`` object to build a tree for. *lines* is the list to append the tree to, which is returned at the end of the method...
[ "Build", "a", "tree", "to", "illustrate", "the", "way", "the", "Wikicode", "object", "was", "parsed", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/wikicode.py#L207-L231
8,874
earwig/mwparserfromhell
mwparserfromhell/wikicode.py
Wikicode._build_filter_methods
def _build_filter_methods(cls, **meths): """Given Node types, build the corresponding i?filter shortcuts. The should be given as keys storing the method's base name paired with values storing the corresponding :class:`.Node` type. For example, the dict may contain the pair ``("templates...
python
def _build_filter_methods(cls, **meths): """Given Node types, build the corresponding i?filter shortcuts. The should be given as keys storing the method's base name paired with values storing the corresponding :class:`.Node` type. For example, the dict may contain the pair ``("templates...
[ "def", "_build_filter_methods", "(", "cls", ",", "*", "*", "meths", ")", ":", "doc", "=", "\"\"\"Iterate over {0}.\n\n This is equivalent to :meth:`{1}` with *forcetype* set to\n :class:`~{2.__module__}.{2.__name__}`.\n \"\"\"", "make_ifilter", "=", "lambda", "ft...
Given Node types, build the corresponding i?filter shortcuts. The should be given as keys storing the method's base name paired with values storing the corresponding :class:`.Node` type. For example, the dict may contain the pair ``("templates", Template)``, which will produce the metho...
[ "Given", "Node", "types", "build", "the", "corresponding", "i?filter", "shortcuts", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/wikicode.py#L234-L261
8,875
earwig/mwparserfromhell
mwparserfromhell/wikicode.py
Wikicode.matches
def matches(self, other): """Do a loose equivalency test suitable for comparing page names. *other* can be any string-like object, including :class:`.Wikicode`, or an iterable of these. This operation is symmetric; both sides are adjusted. Specifically, whitespace and markup is stripped...
python
def matches(self, other): """Do a loose equivalency test suitable for comparing page names. *other* can be any string-like object, including :class:`.Wikicode`, or an iterable of these. This operation is symmetric; both sides are adjusted. Specifically, whitespace and markup is stripped...
[ "def", "matches", "(", "self", ",", "other", ")", ":", "cmp", "=", "lambda", "a", ",", "b", ":", "(", "a", "[", "0", "]", ".", "upper", "(", ")", "+", "a", "[", "1", ":", "]", "==", "b", "[", "0", "]", ".", "upper", "(", ")", "+", "b", ...
Do a loose equivalency test suitable for comparing page names. *other* can be any string-like object, including :class:`.Wikicode`, or an iterable of these. This operation is symmetric; both sides are adjusted. Specifically, whitespace and markup is stripped and the first letter's case ...
[ "Do", "a", "loose", "equivalency", "test", "suitable", "for", "comparing", "page", "names", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/wikicode.py#L495-L515
8,876
earwig/mwparserfromhell
mwparserfromhell/wikicode.py
Wikicode.ifilter
def ifilter(self, recursive=True, matches=None, flags=FLAGS, forcetype=None): """Iterate over nodes in our list matching certain conditions. If *forcetype* is given, only nodes that are instances of this type (or tuple of types) are yielded. Setting *recursive* to ``True`` will ...
python
def ifilter(self, recursive=True, matches=None, flags=FLAGS, forcetype=None): """Iterate over nodes in our list matching certain conditions. If *forcetype* is given, only nodes that are instances of this type (or tuple of types) are yielded. Setting *recursive* to ``True`` will ...
[ "def", "ifilter", "(", "self", ",", "recursive", "=", "True", ",", "matches", "=", "None", ",", "flags", "=", "FLAGS", ",", "forcetype", "=", "None", ")", ":", "gen", "=", "self", ".", "_indexed_ifilter", "(", "recursive", ",", "matches", ",", "flags",...
Iterate over nodes in our list matching certain conditions. If *forcetype* is given, only nodes that are instances of this type (or tuple of types) are yielded. Setting *recursive* to ``True`` will iterate over all children and their descendants. ``RECURSE_OTHERS`` will only iterate ove...
[ "Iterate", "over", "nodes", "in", "our", "list", "matching", "certain", "conditions", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/wikicode.py#L517-L543
8,877
earwig/mwparserfromhell
mwparserfromhell/wikicode.py
Wikicode.get_sections
def get_sections(self, levels=None, matches=None, flags=FLAGS, flat=False, include_lead=None, include_headings=True): """Return a list of sections within the page. Sections are returned as :class:`.Wikicode` objects with a shared node list (implemented using :class:`.SmartL...
python
def get_sections(self, levels=None, matches=None, flags=FLAGS, flat=False, include_lead=None, include_headings=True): """Return a list of sections within the page. Sections are returned as :class:`.Wikicode` objects with a shared node list (implemented using :class:`.SmartL...
[ "def", "get_sections", "(", "self", ",", "levels", "=", "None", ",", "matches", "=", "None", ",", "flags", "=", "FLAGS", ",", "flat", "=", "False", ",", "include_lead", "=", "None", ",", "include_headings", "=", "True", ")", ":", "title_matcher", "=", ...
Return a list of sections within the page. Sections are returned as :class:`.Wikicode` objects with a shared node list (implemented using :class:`.SmartList`) so that changes to sections are reflected in the parent Wikicode object. Each section contains all of its subsections, unless *...
[ "Return", "a", "list", "of", "sections", "within", "the", "page", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/wikicode.py#L552-L615
8,878
earwig/mwparserfromhell
mwparserfromhell/wikicode.py
Wikicode.strip_code
def strip_code(self, normalize=True, collapse=True, keep_template_params=False): """Return a rendered string without unprintable code such as templates. The way a node is stripped is handled by the :meth:`~.Node.__strip__` method of :class:`.Node` objects, which gener...
python
def strip_code(self, normalize=True, collapse=True, keep_template_params=False): """Return a rendered string without unprintable code such as templates. The way a node is stripped is handled by the :meth:`~.Node.__strip__` method of :class:`.Node` objects, which gener...
[ "def", "strip_code", "(", "self", ",", "normalize", "=", "True", ",", "collapse", "=", "True", ",", "keep_template_params", "=", "False", ")", ":", "kwargs", "=", "{", "\"normalize\"", ":", "normalize", ",", "\"collapse\"", ":", "collapse", ",", "\"keep_temp...
Return a rendered string without unprintable code such as templates. The way a node is stripped is handled by the :meth:`~.Node.__strip__` method of :class:`.Node` objects, which generally return a subset of their nodes or ``None``. For example, templates and tags are removed completely...
[ "Return", "a", "rendered", "string", "without", "unprintable", "code", "such", "as", "templates", "." ]
98dc30902d35c714a70aca8e6616f49d71cb24cc
https://github.com/earwig/mwparserfromhell/blob/98dc30902d35c714a70aca8e6616f49d71cb24cc/mwparserfromhell/wikicode.py#L617-L653
8,879
Yubico/python-pyhsm
pyhsm/stick_daemon.py
write_pid_file
def write_pid_file(fn): """ Create a file with our PID. """ if not fn: return None if fn == '' or fn == "''": # work around argument passings in init-scripts return None f = open(fn, "w") f.write("%s\n" % (os.getpid())) f.close()
python
def write_pid_file(fn): """ Create a file with our PID. """ if not fn: return None if fn == '' or fn == "''": # work around argument passings in init-scripts return None f = open(fn, "w") f.write("%s\n" % (os.getpid())) f.close()
[ "def", "write_pid_file", "(", "fn", ")", ":", "if", "not", "fn", ":", "return", "None", "if", "fn", "==", "''", "or", "fn", "==", "\"''\"", ":", "# work around argument passings in init-scripts", "return", "None", "f", "=", "open", "(", "fn", ",", "\"w\"",...
Create a file with our PID.
[ "Create", "a", "file", "with", "our", "PID", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/stick_daemon.py#L54-L63
8,880
Yubico/python-pyhsm
pyhsm/util.py
input_validate_str
def input_validate_str(string, name, max_len=None, exact_len=None): """ Input validation for strings. """ if type(string) is not str: raise pyhsm.exception.YHSM_WrongInputType(name, str, type(string)) if max_len != None and len(string) > max_len: raise pyhsm.exception.YHSM_InputTooLong(name,...
python
def input_validate_str(string, name, max_len=None, exact_len=None): """ Input validation for strings. """ if type(string) is not str: raise pyhsm.exception.YHSM_WrongInputType(name, str, type(string)) if max_len != None and len(string) > max_len: raise pyhsm.exception.YHSM_InputTooLong(name,...
[ "def", "input_validate_str", "(", "string", ",", "name", ",", "max_len", "=", "None", ",", "exact_len", "=", "None", ")", ":", "if", "type", "(", "string", ")", "is", "not", "str", ":", "raise", "pyhsm", ".", "exception", ".", "YHSM_WrongInputType", "(",...
Input validation for strings.
[ "Input", "validation", "for", "strings", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/util.py#L57-L65
8,881
Yubico/python-pyhsm
pyhsm/util.py
input_validate_int
def input_validate_int(value, name, max_value=None): """ Input validation for integers. """ if type(value) is not int: raise pyhsm.exception.YHSM_WrongInputType(name, int, type(value)) if max_value != None and value > max_value: raise pyhsm.exception.YHSM_WrongInputSize(name, max_value, valu...
python
def input_validate_int(value, name, max_value=None): """ Input validation for integers. """ if type(value) is not int: raise pyhsm.exception.YHSM_WrongInputType(name, int, type(value)) if max_value != None and value > max_value: raise pyhsm.exception.YHSM_WrongInputSize(name, max_value, valu...
[ "def", "input_validate_int", "(", "value", ",", "name", ",", "max_value", "=", "None", ")", ":", "if", "type", "(", "value", ")", "is", "not", "int", ":", "raise", "pyhsm", ".", "exception", ".", "YHSM_WrongInputType", "(", "name", ",", "int", ",", "ty...
Input validation for integers.
[ "Input", "validation", "for", "integers", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/util.py#L67-L73
8,882
Yubico/python-pyhsm
pyhsm/util.py
input_validate_nonce
def input_validate_nonce(nonce, name='nonce', pad = False): """ Input validation for nonces. """ if type(nonce) is not str: raise pyhsm.exception.YHSM_WrongInputType( \ name, str, type(nonce)) if len(nonce) > pyhsm.defines.YSM_AEAD_NONCE_SIZE: raise pyhsm.exception.YHSM_InputTooL...
python
def input_validate_nonce(nonce, name='nonce', pad = False): """ Input validation for nonces. """ if type(nonce) is not str: raise pyhsm.exception.YHSM_WrongInputType( \ name, str, type(nonce)) if len(nonce) > pyhsm.defines.YSM_AEAD_NONCE_SIZE: raise pyhsm.exception.YHSM_InputTooL...
[ "def", "input_validate_nonce", "(", "nonce", ",", "name", "=", "'nonce'", ",", "pad", "=", "False", ")", ":", "if", "type", "(", "nonce", ")", "is", "not", "str", ":", "raise", "pyhsm", ".", "exception", ".", "YHSM_WrongInputType", "(", "name", ",", "s...
Input validation for nonces.
[ "Input", "validation", "for", "nonces", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/util.py#L75-L86
8,883
Yubico/python-pyhsm
pyhsm/util.py
input_validate_key_handle
def input_validate_key_handle(key_handle, name='key_handle'): """ Input validation for key_handles. """ if type(key_handle) is not int: try: return key_handle_to_int(key_handle) except pyhsm.exception.YHSM_Error: raise pyhsm.exception.YHSM_WrongInputType(name, int, type(k...
python
def input_validate_key_handle(key_handle, name='key_handle'): """ Input validation for key_handles. """ if type(key_handle) is not int: try: return key_handle_to_int(key_handle) except pyhsm.exception.YHSM_Error: raise pyhsm.exception.YHSM_WrongInputType(name, int, type(k...
[ "def", "input_validate_key_handle", "(", "key_handle", ",", "name", "=", "'key_handle'", ")", ":", "if", "type", "(", "key_handle", ")", "is", "not", "int", ":", "try", ":", "return", "key_handle_to_int", "(", "key_handle", ")", "except", "pyhsm", ".", "exce...
Input validation for key_handles.
[ "Input", "validation", "for", "key_handles", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/util.py#L88-L95
8,884
Yubico/python-pyhsm
pyhsm/util.py
input_validate_yubikey_secret
def input_validate_yubikey_secret(data, name='data'): """ Input validation for YHSM_YubiKeySecret or string. """ if isinstance(data, pyhsm.aead_cmd.YHSM_YubiKeySecret): data = data.pack() return input_validate_str(data, name)
python
def input_validate_yubikey_secret(data, name='data'): """ Input validation for YHSM_YubiKeySecret or string. """ if isinstance(data, pyhsm.aead_cmd.YHSM_YubiKeySecret): data = data.pack() return input_validate_str(data, name)
[ "def", "input_validate_yubikey_secret", "(", "data", ",", "name", "=", "'data'", ")", ":", "if", "isinstance", "(", "data", ",", "pyhsm", ".", "aead_cmd", ".", "YHSM_YubiKeySecret", ")", ":", "data", "=", "data", ".", "pack", "(", ")", "return", "input_val...
Input validation for YHSM_YubiKeySecret or string.
[ "Input", "validation", "for", "YHSM_YubiKeySecret", "or", "string", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/util.py#L97-L101
8,885
Yubico/python-pyhsm
pyhsm/util.py
input_validate_aead
def input_validate_aead(aead, name='aead', expected_len=None, max_aead_len = pyhsm.defines.YSM_AEAD_MAX_SIZE): """ Input validation for YHSM_GeneratedAEAD or string. """ if isinstance(aead, pyhsm.aead_cmd.YHSM_GeneratedAEAD): aead = aead.data if expected_len != None: return input_validate_st...
python
def input_validate_aead(aead, name='aead', expected_len=None, max_aead_len = pyhsm.defines.YSM_AEAD_MAX_SIZE): """ Input validation for YHSM_GeneratedAEAD or string. """ if isinstance(aead, pyhsm.aead_cmd.YHSM_GeneratedAEAD): aead = aead.data if expected_len != None: return input_validate_st...
[ "def", "input_validate_aead", "(", "aead", ",", "name", "=", "'aead'", ",", "expected_len", "=", "None", ",", "max_aead_len", "=", "pyhsm", ".", "defines", ".", "YSM_AEAD_MAX_SIZE", ")", ":", "if", "isinstance", "(", "aead", ",", "pyhsm", ".", "aead_cmd", ...
Input validation for YHSM_GeneratedAEAD or string.
[ "Input", "validation", "for", "YHSM_GeneratedAEAD", "or", "string", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/util.py#L103-L110
8,886
Yubico/python-pyhsm
pyhsm/util.py
validate_cmd_response_nonce
def validate_cmd_response_nonce(got, used): """ Check that the returned nonce matches nonce used in request. A request nonce of 000000000000 means the HSM should generate a nonce internally though, so if 'used' is all zeros we actually check that 'got' does NOT match 'used'. """ if used == '000...
python
def validate_cmd_response_nonce(got, used): """ Check that the returned nonce matches nonce used in request. A request nonce of 000000000000 means the HSM should generate a nonce internally though, so if 'used' is all zeros we actually check that 'got' does NOT match 'used'. """ if used == '000...
[ "def", "validate_cmd_response_nonce", "(", "got", ",", "used", ")", ":", "if", "used", "==", "'000000000000'", ".", "decode", "(", "'hex'", ")", ":", "if", "got", "==", "used", ":", "raise", "(", "pyhsm", ".", "exception", ".", "YHSM_Error", "(", "\"Bad ...
Check that the returned nonce matches nonce used in request. A request nonce of 000000000000 means the HSM should generate a nonce internally though, so if 'used' is all zeros we actually check that 'got' does NOT match 'used'.
[ "Check", "that", "the", "returned", "nonce", "matches", "nonce", "used", "in", "request", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/util.py#L152-L164
8,887
Yubico/python-pyhsm
pyhsm/hmac_cmd.py
_raw_pack
def _raw_pack(key_handle, flags, data): """ Common code for packing payload to YHSM_HMAC_SHA1_GENERATE command. """ # #define YHSM_HMAC_RESET 0x01 // Flag to indicate reset at first packet # #define YHSM_HMAC_FINAL 0x02 // Flag to indicate that the hash shall be calculated ...
python
def _raw_pack(key_handle, flags, data): """ Common code for packing payload to YHSM_HMAC_SHA1_GENERATE command. """ # #define YHSM_HMAC_RESET 0x01 // Flag to indicate reset at first packet # #define YHSM_HMAC_FINAL 0x02 // Flag to indicate that the hash shall be calculated ...
[ "def", "_raw_pack", "(", "key_handle", ",", "flags", ",", "data", ")", ":", "# #define YHSM_HMAC_RESET 0x01 // Flag to indicate reset at first packet", "# #define YHSM_HMAC_FINAL 0x02 // Flag to indicate that the hash shall be calculated", "# typedef struct {", "# ...
Common code for packing payload to YHSM_HMAC_SHA1_GENERATE command.
[ "Common", "code", "for", "packing", "payload", "to", "YHSM_HMAC_SHA1_GENERATE", "command", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/hmac_cmd.py#L110-L122
8,888
Yubico/python-pyhsm
pyhsm/hmac_cmd.py
YHSM_Cmd_HMAC_SHA1_Write.next
def next(self, data, final = False, to_buffer = False): """ Add more input to the HMAC SHA1. """ if final: self.flags = pyhsm.defines.YSM_HMAC_SHA1_FINAL else: self.flags = 0x0 if to_buffer: self.flags |= pyhsm.defines.YSM_HMAC_SHA1_TO_...
python
def next(self, data, final = False, to_buffer = False): """ Add more input to the HMAC SHA1. """ if final: self.flags = pyhsm.defines.YSM_HMAC_SHA1_FINAL else: self.flags = 0x0 if to_buffer: self.flags |= pyhsm.defines.YSM_HMAC_SHA1_TO_...
[ "def", "next", "(", "self", ",", "data", ",", "final", "=", "False", ",", "to_buffer", "=", "False", ")", ":", "if", "final", ":", "self", ".", "flags", "=", "pyhsm", ".", "defines", ".", "YSM_HMAC_SHA1_FINAL", "else", ":", "self", ".", "flags", "=",...
Add more input to the HMAC SHA1.
[ "Add", "more", "input", "to", "the", "HMAC", "SHA1", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/hmac_cmd.py#L53-L65
8,889
Yubico/python-pyhsm
pyhsm/hmac_cmd.py
YHSM_Cmd_HMAC_SHA1_Write.get_hash
def get_hash(self): """ Get the HMAC-SHA1 that has been calculated this far. """ if not self.executed: raise pyhsm.exception.YHSM_Error("HMAC-SHA1 hash not available, before execute().") return self.result.hash_result
python
def get_hash(self): """ Get the HMAC-SHA1 that has been calculated this far. """ if not self.executed: raise pyhsm.exception.YHSM_Error("HMAC-SHA1 hash not available, before execute().") return self.result.hash_result
[ "def", "get_hash", "(", "self", ")", ":", "if", "not", "self", ".", "executed", ":", "raise", "pyhsm", ".", "exception", ".", "YHSM_Error", "(", "\"HMAC-SHA1 hash not available, before execute().\"", ")", "return", "self", ".", "result", ".", "hash_result" ]
Get the HMAC-SHA1 that has been calculated this far.
[ "Get", "the", "HMAC", "-", "SHA1", "that", "has", "been", "calculated", "this", "far", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/hmac_cmd.py#L67-L73
8,890
Yubico/python-pyhsm
pyhsm/val/validation_server.py
check_signature
def check_signature(params): """ Verify the signature of the parameters in an OTP v2.0 verify request. Returns ValResultBool, Key """ if 'id' in params: try: id_int = int(params['id'][0]) except: my_log_message(args, syslog.LOG_INFO, "Non-numerical client id ...
python
def check_signature(params): """ Verify the signature of the parameters in an OTP v2.0 verify request. Returns ValResultBool, Key """ if 'id' in params: try: id_int = int(params['id'][0]) except: my_log_message(args, syslog.LOG_INFO, "Non-numerical client id ...
[ "def", "check_signature", "(", "params", ")", ":", "if", "'id'", "in", "params", ":", "try", ":", "id_int", "=", "int", "(", "params", "[", "'id'", "]", "[", "0", "]", ")", "except", ":", "my_log_message", "(", "args", ",", "syslog", ".", "LOG_INFO",...
Verify the signature of the parameters in an OTP v2.0 verify request. Returns ValResultBool, Key
[ "Verify", "the", "signature", "of", "the", "parameters", "in", "an", "OTP", "v2", ".", "0", "verify", "request", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L297-L326
8,891
Yubico/python-pyhsm
pyhsm/val/validation_server.py
validate_oath_hotp
def validate_oath_hotp(self, params): """ Validate OATH-HOTP code using YubiHSM HMAC-SHA1 hashing with token keys secured in AEAD's that we have stored in an SQLite3 database. """ from_key = params["hotp"][0] if not re.match(hotp_valid_input, from_key): self.log_error("IN: %s, Invalid OA...
python
def validate_oath_hotp(self, params): """ Validate OATH-HOTP code using YubiHSM HMAC-SHA1 hashing with token keys secured in AEAD's that we have stored in an SQLite3 database. """ from_key = params["hotp"][0] if not re.match(hotp_valid_input, from_key): self.log_error("IN: %s, Invalid OA...
[ "def", "validate_oath_hotp", "(", "self", ",", "params", ")", ":", "from_key", "=", "params", "[", "\"hotp\"", "]", "[", "0", "]", "if", "not", "re", ".", "match", "(", "hotp_valid_input", ",", "from_key", ")", ":", "self", ".", "log_error", "(", "\"IN...
Validate OATH-HOTP code using YubiHSM HMAC-SHA1 hashing with token keys secured in AEAD's that we have stored in an SQLite3 database.
[ "Validate", "OATH", "-", "HOTP", "code", "using", "YubiHSM", "HMAC", "-", "SHA1", "hashing", "with", "token", "keys", "secured", "in", "AEAD", "s", "that", "we", "have", "stored", "in", "an", "SQLite3", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L339-L382
8,892
Yubico/python-pyhsm
pyhsm/val/validation_server.py
validate_oath_totp
def validate_oath_totp(self, params): """ Validate OATH-TOTP code using YubiHSM HMAC-SHA1 hashing with token keys secured in AEAD's that we have stored in an SQLite3 database. """ from_key = params["totp"][0] if not re.match(totp_valid_input, from_key): self.log_error("IN: %s, Invalid OA...
python
def validate_oath_totp(self, params): """ Validate OATH-TOTP code using YubiHSM HMAC-SHA1 hashing with token keys secured in AEAD's that we have stored in an SQLite3 database. """ from_key = params["totp"][0] if not re.match(totp_valid_input, from_key): self.log_error("IN: %s, Invalid OA...
[ "def", "validate_oath_totp", "(", "self", ",", "params", ")", ":", "from_key", "=", "params", "[", "\"totp\"", "]", "[", "0", "]", "if", "not", "re", ".", "match", "(", "totp_valid_input", ",", "from_key", ")", ":", "self", ".", "log_error", "(", "\"IN...
Validate OATH-TOTP code using YubiHSM HMAC-SHA1 hashing with token keys secured in AEAD's that we have stored in an SQLite3 database.
[ "Validate", "OATH", "-", "TOTP", "code", "using", "YubiHSM", "HMAC", "-", "SHA1", "hashing", "with", "token", "keys", "secured", "in", "AEAD", "s", "that", "we", "have", "stored", "in", "an", "SQLite3", "database", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L384-L428
8,893
Yubico/python-pyhsm
pyhsm/val/validation_server.py
validate_pwhash
def validate_pwhash(_self, params): """ Validate password hash using YubiHSM. """ pwhash, nonce, aead, key_handle = get_pwhash_bits(params) d_aead = aead.decode('hex') plaintext_len = len(d_aead) - pyhsm.defines.YSM_AEAD_MAC_SIZE pw = pwhash.ljust(plaintext_len, chr(0x0)) if hsm.validate...
python
def validate_pwhash(_self, params): """ Validate password hash using YubiHSM. """ pwhash, nonce, aead, key_handle = get_pwhash_bits(params) d_aead = aead.decode('hex') plaintext_len = len(d_aead) - pyhsm.defines.YSM_AEAD_MAC_SIZE pw = pwhash.ljust(plaintext_len, chr(0x0)) if hsm.validate...
[ "def", "validate_pwhash", "(", "_self", ",", "params", ")", ":", "pwhash", ",", "nonce", ",", "aead", ",", "key_handle", "=", "get_pwhash_bits", "(", "params", ")", "d_aead", "=", "aead", ".", "decode", "(", "'hex'", ")", "plaintext_len", "=", "len", "("...
Validate password hash using YubiHSM.
[ "Validate", "password", "hash", "using", "YubiHSM", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L430-L440
8,894
Yubico/python-pyhsm
pyhsm/val/validation_server.py
get_pwhash_bits
def get_pwhash_bits(params): """ Extract bits for password hash validation from params. """ if not "pwhash" in params or \ not "nonce" in params or \ not "aead" in params or \ not "kh" in params: raise Exception("Missing required parameter in request (pwhash, nonce, a...
python
def get_pwhash_bits(params): """ Extract bits for password hash validation from params. """ if not "pwhash" in params or \ not "nonce" in params or \ not "aead" in params or \ not "kh" in params: raise Exception("Missing required parameter in request (pwhash, nonce, a...
[ "def", "get_pwhash_bits", "(", "params", ")", ":", "if", "not", "\"pwhash\"", "in", "params", "or", "not", "\"nonce\"", "in", "params", "or", "not", "\"aead\"", "in", "params", "or", "not", "\"kh\"", "in", "params", ":", "raise", "Exception", "(", "\"Missi...
Extract bits for password hash validation from params.
[ "Extract", "bits", "for", "password", "hash", "validation", "from", "params", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L442-L453
8,895
Yubico/python-pyhsm
pyhsm/val/validation_server.py
get_oath_hotp_bits
def get_oath_hotp_bits(params): """ Extract the OATH-HOTP uid and OTP from params. """ if "uid" in params: return params["uid"][0], int(params["hotp"][0]) m = re.match("^([cbdefghijklnrtuv]*)([0-9]{6,8})", params["hotp"][0]) uid, otp, = m.groups() return uid, int(otp),
python
def get_oath_hotp_bits(params): """ Extract the OATH-HOTP uid and OTP from params. """ if "uid" in params: return params["uid"][0], int(params["hotp"][0]) m = re.match("^([cbdefghijklnrtuv]*)([0-9]{6,8})", params["hotp"][0]) uid, otp, = m.groups() return uid, int(otp),
[ "def", "get_oath_hotp_bits", "(", "params", ")", ":", "if", "\"uid\"", "in", "params", ":", "return", "params", "[", "\"uid\"", "]", "[", "0", "]", ",", "int", "(", "params", "[", "\"hotp\"", "]", "[", "0", "]", ")", "m", "=", "re", ".", "match", ...
Extract the OATH-HOTP uid and OTP from params.
[ "Extract", "the", "OATH", "-", "HOTP", "uid", "and", "OTP", "from", "params", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L455-L461
8,896
Yubico/python-pyhsm
pyhsm/val/validation_server.py
load_clients_file
def load_clients_file(filename): """ Load a list of base64 encoded shared secrets for numerical client ids. Returns a dict. Format of file is expected to be # This is a comment. Blank lines are OK. 123,c2hhcmVkIHNlY3JldA== 456,MTIzNDU2Nzg5MDEyMw== """ res = {} con...
python
def load_clients_file(filename): """ Load a list of base64 encoded shared secrets for numerical client ids. Returns a dict. Format of file is expected to be # This is a comment. Blank lines are OK. 123,c2hhcmVkIHNlY3JldA== 456,MTIzNDU2Nzg5MDEyMw== """ res = {} con...
[ "def", "load_clients_file", "(", "filename", ")", ":", "res", "=", "{", "}", "content", "=", "[", "]", "try", ":", "fhandle", "=", "file", "(", "filename", ")", "content", "=", "fhandle", ".", "readlines", "(", ")", "fhandle", ".", "close", "(", ")",...
Load a list of base64 encoded shared secrets for numerical client ids. Returns a dict. Format of file is expected to be # This is a comment. Blank lines are OK. 123,c2hhcmVkIHNlY3JldA== 456,MTIzNDU2Nzg5MDEyMw==
[ "Load", "a", "list", "of", "base64", "encoded", "shared", "secrets", "for", "numerical", "client", "ids", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L657-L696
8,897
Yubico/python-pyhsm
pyhsm/val/validation_server.py
run
def run(): """ Start the BaseHTTPServer and serve requests forever. """ server_address = (args.listen_addr, args.listen_port) httpd = YHSM_VALServer(server_address, YHSM_VALRequestHandler) my_log_message(args, syslog.LOG_INFO, "Serving requests to 'http://%s:%s%s' (YubiHSM: '%s')" \ ...
python
def run(): """ Start the BaseHTTPServer and serve requests forever. """ server_address = (args.listen_addr, args.listen_port) httpd = YHSM_VALServer(server_address, YHSM_VALRequestHandler) my_log_message(args, syslog.LOG_INFO, "Serving requests to 'http://%s:%s%s' (YubiHSM: '%s')" \ ...
[ "def", "run", "(", ")", ":", "server_address", "=", "(", "args", ".", "listen_addr", ",", "args", ".", "listen_port", ")", "httpd", "=", "YHSM_VALServer", "(", "server_address", ",", "YHSM_VALRequestHandler", ")", "my_log_message", "(", "args", ",", "syslog", ...
Start the BaseHTTPServer and serve requests forever.
[ "Start", "the", "BaseHTTPServer", "and", "serve", "requests", "forever", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L709-L717
8,898
Yubico/python-pyhsm
pyhsm/val/validation_server.py
main
def main(): """ The main function that will be executed when running this as a stand alone script. """ my_name = os.path.basename(sys.argv[0]) if not my_name: my_name = "yhsm-validation-server" syslog.openlog(my_name, syslog.LOG_PID, syslog.LOG_LOCAL0) global args args = parse_a...
python
def main(): """ The main function that will be executed when running this as a stand alone script. """ my_name = os.path.basename(sys.argv[0]) if not my_name: my_name = "yhsm-validation-server" syslog.openlog(my_name, syslog.LOG_PID, syslog.LOG_LOCAL0) global args args = parse_a...
[ "def", "main", "(", ")", ":", "my_name", "=", "os", ".", "path", ".", "basename", "(", "sys", ".", "argv", "[", "0", "]", ")", "if", "not", "my_name", ":", "my_name", "=", "\"yhsm-validation-server\"", "syslog", ".", "openlog", "(", "my_name", ",", "...
The main function that will be executed when running this as a stand alone script.
[ "The", "main", "function", "that", "will", "be", "executed", "when", "running", "this", "as", "a", "stand", "alone", "script", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L727-L754
8,899
Yubico/python-pyhsm
pyhsm/val/validation_server.py
YHSM_VALRequestHandler.do_GET
def do_GET(self): """ Process validation GET requests. All modes of validation (OTP, OATH and PWHASH) must be explicitly enabled in `args' to be allowed. """ if self.path.startswith(args.serve_url): res = None log_res = None mode = Non...
python
def do_GET(self): """ Process validation GET requests. All modes of validation (OTP, OATH and PWHASH) must be explicitly enabled in `args' to be allowed. """ if self.path.startswith(args.serve_url): res = None log_res = None mode = Non...
[ "def", "do_GET", "(", "self", ")", ":", "if", "self", ".", "path", ".", "startswith", "(", "args", ".", "serve_url", ")", ":", "res", "=", "None", "log_res", "=", "None", "mode", "=", "None", "params", "=", "urlparse", ".", "parse_qs", "(", "self", ...
Process validation GET requests. All modes of validation (OTP, OATH and PWHASH) must be explicitly enabled in `args' to be allowed.
[ "Process", "validation", "GET", "requests", "." ]
b6e2744d1ea15c352a0fc1d6ebc5950026b71311
https://github.com/Yubico/python-pyhsm/blob/b6e2744d1ea15c352a0fc1d6ebc5950026b71311/pyhsm/val/validation_server.py#L122-L186