code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def selective_len(str, max):
"""Return the length of str, considering only characters below max."""
res = 0
for c in str:
if ord(c) < max:
res += 1
return res | Return the length of str, considering only characters below max. | selective_len | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/punycode.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/punycode.py | MIT |
def selective_find(str, char, index, pos):
"""Return a pair (index, pos), indicating the next occurrence of
char in str. index is the position of the character considering
only ordinals up to and including char, and pos is the position in
the full string. index/pos is the starting position in the full
... | Return a pair (index, pos), indicating the next occurrence of
char in str. index is the position of the character considering
only ordinals up to and including char, and pos is the position in
the full string. index/pos is the starting position in the full
string. | selective_find | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/punycode.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/punycode.py | MIT |
def quopri_encode(input, errors='strict'):
"""Encode the input, returning a tuple (output object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
... | Encode the input, returning a tuple (output object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
| quopri_encode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/quopri_codec.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/quopri_codec.py | MIT |
def quopri_decode(input, errors='strict'):
"""Decode the input, returning a tuple (output object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
... | Decode the input, returning a tuple (output object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
| quopri_decode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/quopri_codec.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/quopri_codec.py | MIT |
def uu_encode(input,errors='strict',filename='<data>',mode=0666):
""" Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for... | Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
| uu_encode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/uu_codec.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/uu_codec.py | MIT |
def uu_decode(input,errors='strict'):
""" Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing th... | Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing this slot.
errors defines the error han... | uu_decode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/uu_codec.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/uu_codec.py | MIT |
def zlib_encode(input,errors='strict'):
""" Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
... | Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
| zlib_encode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/zlib_codec.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/zlib_codec.py | MIT |
def zlib_decode(input,errors='strict'):
""" Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing ... | Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing this slot.
errors defines the error han... | zlib_decode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/zlib_codec.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/zlib_codec.py | MIT |
def normalize_encoding(encoding):
""" Normalize an encoding name.
Normalization works as follows: all non-alphanumeric
characters except the dot used for Python package names are
collapsed and replaced with a single underscore, e.g. ' -;#'
becomes '_'. Leading and trailing undersc... | Normalize an encoding name.
Normalization works as follows: all non-alphanumeric
characters except the dot used for Python package names are
collapsed and replaced with a single underscore, e.g. ' -;#'
becomes '_'. Leading and trailing underscores are removed.
Note that encod... | normalize_encoding | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/encodings/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/encodings/__init__.py | MIT |
def bootstrap(root=None, upgrade=False, user=False,
altinstall=False, default_pip=True,
verbosity=0):
"""
Bootstrap pip into the current Python installation (or the given root
directory).
Note that calling this function will alter both sys.path and os.environ.
"""
if... |
Bootstrap pip into the current Python installation (or the given root
directory).
Note that calling this function will alter both sys.path and os.environ.
| bootstrap | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/ensurepip/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/ensurepip/__init__.py | MIT |
def _uninstall_helper(verbosity=0):
"""Helper to support a clean default uninstall process on Windows
Note that calling this function may alter os.environ.
"""
# Nothing to do if pip was never installed, or has been removed
try:
import pip
except ImportError:
return
# If th... | Helper to support a clean default uninstall process on Windows
Note that calling this function may alter os.environ.
| _uninstall_helper | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/ensurepip/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/ensurepip/__init__.py | MIT |
def run(self, cmd):
"""Profile an exec-compatible string in the script
environment.
The globals from the __main__ module are used as both the
globals and locals for the script.
"""
import __main__
dict = __main__.__dict__
return self.runctx(cmd, dict, dic... | Profile an exec-compatible string in the script
environment.
The globals from the __main__ module are used as both the
globals and locals for the script.
| run | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/hotshot/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/hotshot/__init__.py | MIT |
def runctx(self, cmd, globals, locals):
"""Evaluate an exec-compatible string in a specific
environment.
The string is compiled before profiling begins.
"""
code = compile(cmd, "<string>", "exec")
self._prof.runcode(code, globals, locals)
return self | Evaluate an exec-compatible string in a specific
environment.
The string is compiled before profiling begins.
| runctx | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/hotshot/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/hotshot/__init__.py | MIT |
def index(self, index):
"Return string version of index decoded according to current text."
return "%s.%s" % self._decode(index, endflag=1) | Return string version of index decoded according to current text. | index | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/mock_tk.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/mock_tk.py | MIT |
def _decode(self, index, endflag=0):
"""Return a (line, char) tuple of int indexes into self.data.
This implements .index without converting the result back to a string.
The result is contrained by the number of lines and linelengths of
self.data. For many indexes, the result is initial... | Return a (line, char) tuple of int indexes into self.data.
This implements .index without converting the result back to a string.
The result is contrained by the number of lines and linelengths of
self.data. For many indexes, the result is initially (1, 0).
The input index may have any... | _decode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/mock_tk.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/mock_tk.py | MIT |
def _endex(self, endflag):
'''Return position for 'end' or line overflow corresponding to endflag.
-1: position before terminal \n; for .insert(), .delete
0: position after terminal \n; for .get, .delete index 1
1: same viewed as beginning of non-existent next line (for .index)
'''
... | Return position for 'end' or line overflow corresponding to endflag.
-1: position before terminal
; for .insert(), .delete
0: position after terminal
; for .get, .delete index 1
1: same viewed as beginning of non-existent next line (for .index)
| _endex | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/mock_tk.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/mock_tk.py | MIT |
def insert(self, index, chars):
"Insert chars before the character at index."
if not chars: # ''.splitlines() is [], not ['']
return
chars = chars.splitlines(True)
if chars[-1][-1] == '\n':
chars.append('')
line, char = self._decode(index, -1)
be... | Insert chars before the character at index. | insert | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/mock_tk.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/mock_tk.py | MIT |
def get(self, index1, index2=None):
"Return slice from index1 to index2 (default is 'index1+1')."
startline, startchar = self._decode(index1)
if index2 is None:
endline, endchar = startline, startchar+1
else:
endline, endchar = self._decode(index2)
if st... | Return slice from index1 to index2 (default is 'index1+1'). | get | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/mock_tk.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/mock_tk.py | MIT |
def delete(self, index1, index2=None):
'''Delete slice from index1 to index2 (default is 'index1+1').
Adjust default index2 ('index+1) for line ends.
Do not delete the terminal \n at the very end of self.data ([-1][-1]).
'''
startline, startchar = self._decode(index1, -1)
... | Delete slice from index1 to index2 (default is 'index1+1').
Adjust default index2 ('index+1) for line ends.
Do not delete the terminal
at the very end of self.data ([-1][-1]).
| delete | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/mock_tk.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/mock_tk.py | MIT |
def test_paste_text_no_selection(self):
"Test pasting into text without a selection."
text = self.text
tag, ans = '', 'onetwo\n'
text.delete('1.0', 'end')
text.insert('1.0', 'one', tag)
text.event_generate('<<Paste>>')
self.assertEqual(text.get('1.0', 'end'), ans) | Test pasting into text without a selection. | test_paste_text_no_selection | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_editmenu.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_editmenu.py | MIT |
def test_paste_text_selection(self):
"Test pasting into text with a selection."
text = self.text
tag, ans = 'sel', 'two\n'
text.delete('1.0', 'end')
text.insert('1.0', 'one', tag)
text.event_generate('<<Paste>>')
self.assertEqual(text.get('1.0', 'end'), ans) | Test pasting into text with a selection. | test_paste_text_selection | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_editmenu.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_editmenu.py | MIT |
def test_paste_entry_no_selection(self):
"Test pasting into an entry without a selection."
# On 3.6, generated <<Paste>> fails without empty select range
# for 'no selection'. Live widget works fine.
entry = self.entry
end, ans = 0, 'onetwo'
entry.delete(0, 'end')
... | Test pasting into an entry without a selection. | test_paste_entry_no_selection | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_editmenu.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_editmenu.py | MIT |
def test_paste_entry_selection(self):
"Test pasting into an entry with a selection."
entry = self.entry
end, ans = 'end', 'two'
entry.delete(0, 'end')
entry.insert(0, 'one')
entry.select_range(0, end)
entry.event_generate('<<Paste>>')
self.assertEqual(entr... | Test pasting into an entry with a selection. | test_paste_entry_selection | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_editmenu.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_editmenu.py | MIT |
def test_paste_spin_no_selection(self):
"Test pasting into a spinbox without a selection."
# See note above for entry.
spin = self.spin
end, ans = 0, 'onetwo'
spin.delete(0, 'end')
spin.insert(0, 'one')
spin.selection('range', 0, end) # see note
spin.even... | Test pasting into a spinbox without a selection. | test_paste_spin_no_selection | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_editmenu.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_editmenu.py | MIT |
def test_paste_spin_selection(self):
"Test pasting into a spinbox with a selection."
spin = self.spin
end, ans = 'end', 'two'
spin.delete(0, 'end')
spin.insert(0, 'one')
spin.selection('range', 0, end)
spin.event_generate('<<Paste>>')
self.assertEqual(spin... | Test pasting into a spinbox with a selection. | test_paste_spin_selection | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_editmenu.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_editmenu.py | MIT |
def test_init(self):
"""
test corner cases in the init method
"""
with self.assertRaises(ValueError) as ve:
self.text.tag_add('console', '1.0', '1.end')
p = self.get_parser('1.5')
self.assertIn('precedes', str(ve.exception))
# test without ps1
... |
test corner cases in the init method
| test_init | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_hyperparser.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_hyperparser.py | MIT |
def test_paren_corner(self):
"""
Test corner cases in flash_paren_event and paren_closed_event.
These cases force conditional expression and alternate paths.
"""
text = self.text
pm = ParenMatch(self.editwin)
text.insert('insert', '# this is a commen)')
... |
Test corner cases in flash_paren_event and paren_closed_event.
These cases force conditional expression and alternate paths.
| test_paren_corner | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/idlelib/idle_test/test_parenmatch.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/idlelib/idle_test/test_parenmatch.py | MIT |
def _resolve_name(name, package, level):
"""Return the absolute name of the module to be imported."""
if not hasattr(package, 'rindex'):
raise ValueError("'package' not set to a string")
dot = len(package)
for x in xrange(level, 1, -1):
try:
dot = package.rindex('.', 0, dot)
... | Return the absolute name of the module to be imported. | _resolve_name | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/importlib/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/importlib/__init__.py | MIT |
def import_module(name, package=None):
"""Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
if name.startswith('.'):
if not pack... | Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
| import_module | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/importlib/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/importlib/__init__.py | MIT |
def py_scanstring(s, end, encoding=None, strict=True,
_b=BACKSLASH, _m=STRINGCHUNK.match):
"""Scan the string s for a JSON string. End is the index of the
character in s after the quote that started the JSON string.
Unescapes all valid JSON string escape sequences and raises ValueError
on attemp... | Scan the string s for a JSON string. End is the index of the
character in s after the quote that started the JSON string.
Unescapes all valid JSON string escape sequences and raises ValueError
on attempt to decode an invalid string. If strict is False then literal
control characters are allowed in the s... | py_scanstring | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/decoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/decoder.py | MIT |
def __init__(self, encoding=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, strict=True,
object_pairs_hook=None):
"""``encoding`` determines the encoding used to interpret any ``str``
objects decoded by this instance (utf-8 by default). It has no
... | ``encoding`` determines the encoding used to interpret any ``str``
objects decoded by this instance (utf-8 by default). It has no
effect when decoding ``unicode`` objects.
Note that currently only encodings that are a superset of ASCII work,
strings of other encodings should be passed ... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/decoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/decoder.py | MIT |
def decode(self, s, _w=WHITESPACE.match):
"""Return the Python representation of ``s`` (a ``str`` or ``unicode``
instance containing a JSON document)
"""
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
end = _w(s, end).end()
if end != len(s):
raise ValueErr... | Return the Python representation of ``s`` (a ``str`` or ``unicode``
instance containing a JSON document)
| decode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/decoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/decoder.py | MIT |
def raw_decode(self, s, idx=0):
"""Decode a JSON document from ``s`` (a ``str`` or ``unicode``
beginning with a JSON document) and return a 2-tuple of the Python
representation and the index in ``s`` where the document ended.
This can be used to decode a JSON document from a string that... | Decode a JSON document from ``s`` (a ``str`` or ``unicode``
beginning with a JSON document) and return a 2-tuple of the Python
representation and the index in ``s`` where the document ended.
This can be used to decode a JSON document from a string that may
have extraneous data at the en... | raw_decode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/decoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/decoder.py | MIT |
def encode_basestring(s):
"""Return a JSON representation of a Python string
"""
def replace(match):
return ESCAPE_DCT[match.group(0)]
return '"' + ESCAPE.sub(replace, s) + '"' | Return a JSON representation of a Python string
| encode_basestring | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/encoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/encoder.py | MIT |
def py_encode_basestring_ascii(s):
"""Return an ASCII-only JSON representation of a Python string
"""
if isinstance(s, str) and HAS_UTF8.search(s) is not None:
s = s.decode('utf-8')
def replace(match):
s = match.group(0)
try:
return ESCAPE_DCT[s]
except KeyEr... | Return an ASCII-only JSON representation of a Python string
| py_encode_basestring_ascii | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/encoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/encoder.py | MIT |
def __init__(self, skipkeys=False, ensure_ascii=True,
check_circular=True, allow_nan=True, sort_keys=False,
indent=None, separators=None, encoding='utf-8', default=None):
"""Constructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to atte... | Constructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to attempt
encoding of keys that are not str, int, long, float or None. If
skipkeys is True, such items are simply skipped.
If *ensure_ascii* is true (the default), all non-ASCII
... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/encoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/encoder.py | MIT |
def encode(self, o):
"""Return a JSON string representation of a Python data structure.
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
"""
# This is for extremely simple cases and benchmarks.
if isinstance(o, basestring):
if isin... | Return a JSON string representation of a Python data structure.
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
| encode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/encoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/encoder.py | MIT |
def iterencode(self, o, _one_shot=False):
"""Encode the given object and yield each string
representation as available.
For example::
for chunk in JSONEncoder().iterencode(bigobject):
mysocket.write(chunk)
"""
if self.check_circular:
mar... | Encode the given object and yield each string
representation as available.
For example::
for chunk in JSONEncoder().iterencode(bigobject):
mysocket.write(chunk)
| iterencode | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/encoder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/encoder.py | MIT |
def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
encoding='utf-8', default=None, sort_keys=False, **kw):
"""Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
``.write()``-supporting file-like object).
I... | Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
``.write()``-supporting file-like object).
If ``skipkeys`` is true then ``dict`` keys that are not basic types
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
will be skipped instead of raising a ``TypeError``.
If `... | dump | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/__init__.py | MIT |
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
encoding='utf-8', default=None, sort_keys=False, **kw):
"""Serialize ``obj`` to a JSON formatted ``str``.
If ``skipkeys`` is true then ``dict`` keys that are not basic ... | Serialize ``obj`` to a JSON formatted ``str``.
If ``skipkeys`` is true then ``dict`` keys that are not basic types
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
will be skipped instead of raising a ``TypeError``.
If ``ensure_ascii`` is false, all non-ASCII characters are no... | dumps | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/__init__.py | MIT |
def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
a JSON document) to a Python object.
If the contents of ``fp`` is encoded with an... | Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
a JSON document) to a Python object.
If the contents of ``fp`` is encoded with an ASCII based encoding other
than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
be specified. Encodings that are not ASCII based (s... | load | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/__init__.py | MIT |
def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
"""Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
document) to a Python object.
If ``s`` is a ``str`` instance and is encoded with an... | Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
document) to a Python object.
If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
must be specified. Encodings that are not ASCII based (su... | loads | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/json/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/json/__init__.py | MIT |
def simulate_mouse_click(widget, x, y):
"""Generate proper events to click at the x, y position (tries to act
like an X server)."""
widget.event_generate('<Enter>', x=0, y=0)
widget.event_generate('<Motion>', x=x, y=y)
widget.event_generate('<ButtonPress-1>', x=x, y=y)
widget.event_generate('<Bu... | Generate proper events to click at the x, y position (tries to act
like an X server). | simulate_mouse_click | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib-tk/test/test_ttk/support.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib-tk/test/test_ttk/support.py | MIT |
def add_fixer(self, fixer):
"""Reduces a fixer's pattern tree to a linear path and adds it
to the matcher(a common Aho-Corasick automaton). The fixer is
appended on the matching states and called when they are
reached"""
self.fixers.append(fixer)
tree = reduce_tree(fixer.... | Reduces a fixer's pattern tree to a linear path and adds it
to the matcher(a common Aho-Corasick automaton). The fixer is
appended on the matching states and called when they are
reached | add_fixer | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_matcher.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_matcher.py | MIT |
def add(self, pattern, start):
"Recursively adds a linear pattern to the AC automaton"
#print("adding pattern", pattern, "to", start)
if not pattern:
#print("empty pattern")
return [start]
if isinstance(pattern[0], tuple):
#alternatives
#pr... | Recursively adds a linear pattern to the AC automaton | add | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_matcher.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_matcher.py | MIT |
def run(self, leaves):
"""The main interface with the bottom matcher. The tree is
traversed from the bottom using the constructed
automaton. Nodes are only checked once as the tree is
retraversed. When the automaton fails, we give it one more
shot(in case the above tree matches a... | The main interface with the bottom matcher. The tree is
traversed from the bottom using the constructed
automaton. Nodes are only checked once as the tree is
retraversed. When the automaton fails, we give it one more
shot(in case the above tree matches as a whole with the
rejecte... | run | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_matcher.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_matcher.py | MIT |
def print_ac(self):
"Prints a graphviz diagram of the BM automaton(for debugging)"
print("digraph g{")
def print_node(node):
for subnode_key in node.transition_table.keys():
subnode = node.transition_table[subnode_key]
print("%d -> %d [label=%s] //%s" ... | Prints a graphviz diagram of the BM automaton(for debugging) | print_ac | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_matcher.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_matcher.py | MIT |
def leaf_to_root(self):
"""Internal method. Returns a characteristic path of the
pattern tree. This method must be run for all leaves until the
linear subpatterns are merged into a single"""
node = self
subp = []
while node:
if node.type == TYPE_ALTERNATIVES:
... | Internal method. Returns a characteristic path of the
pattern tree. This method must be run for all leaves until the
linear subpatterns are merged into a single | leaf_to_root | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_utils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_utils.py | MIT |
def get_linear_subpattern(self):
"""Drives the leaf_to_root method. The reason that
leaf_to_root must be run multiple times is because we need to
reject 'group' matches; for example the alternative form
(a | b c) creates a group [b c] that needs to be matched. Since
matching mult... | Drives the leaf_to_root method. The reason that
leaf_to_root must be run multiple times is because we need to
reject 'group' matches; for example the alternative form
(a | b c) creates a group [b c] that needs to be matched. Since
matching multiple linear patterns overcomes the automaton... | get_linear_subpattern | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_utils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_utils.py | MIT |
def leaves(self):
"Generator that returns the leaves of the tree"
for child in self.children:
for x in child.leaves():
yield x
if not self.children:
yield self | Generator that returns the leaves of the tree | leaves | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_utils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_utils.py | MIT |
def reduce_tree(node, parent=None):
"""
Internal function. Reduces a compiled pattern tree to an
intermediate representation suitable for feeding the
automaton. This also trims off any optional pattern elements(like
[a], a*).
"""
new_node = None
#switch on the node type
if node.type... |
Internal function. Reduces a compiled pattern tree to an
intermediate representation suitable for feeding the
automaton. This also trims off any optional pattern elements(like
[a], a*).
| reduce_tree | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_utils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_utils.py | MIT |
def get_characteristic_subpattern(subpatterns):
"""Picks the most characteristic from a list of linear patterns
Current order used is:
names > common_names > common_chars
"""
if not isinstance(subpatterns, list):
return subpatterns
if len(subpatterns)==1:
return subpatterns[0]
... | Picks the most characteristic from a list of linear patterns
Current order used is:
names > common_names > common_chars
| get_characteristic_subpattern | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_utils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_utils.py | MIT |
def rec_test(sequence, test_func):
"""Tests test_func on all items of sequence and items of included
sub-iterables"""
for x in sequence:
if isinstance(x, (list, tuple)):
for y in rec_test(x, test_func):
yield y
else:
yield test_func(x) | Tests test_func on all items of sequence and items of included
sub-iterables | rec_test | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/btm_utils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/btm_utils.py | MIT |
def __init__(self, options, log):
"""Initializer. Subclass may override.
Args:
options: a dict containing the options passed to RefactoringTool
that could be used to customize the fixer through the command line.
log: a list to append warnings and other messages to.
... | Initializer. Subclass may override.
Args:
options: a dict containing the options passed to RefactoringTool
that could be used to customize the fixer through the command line.
log: a list to append warnings and other messages to.
| __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def compile_pattern(self):
"""Compiles self.PATTERN into self.pattern.
Subclass may override if it doesn't want to use
self.{pattern,PATTERN} in .match().
"""
if self.PATTERN is not None:
PC = PatternCompiler()
self.pattern, self.pattern_tree = PC.compile... | Compiles self.PATTERN into self.pattern.
Subclass may override if it doesn't want to use
self.{pattern,PATTERN} in .match().
| compile_pattern | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def set_filename(self, filename):
"""Set the filename, and a logger derived from it.
The main refactoring tool should call this.
"""
self.filename = filename
self.logger = logging.getLogger(filename) | Set the filename, and a logger derived from it.
The main refactoring tool should call this.
| set_filename | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def match(self, node):
"""Returns match for a given parse tree node.
Should return a true or false object (not necessarily a bool).
It may return a non-empty dict of matching sub-nodes as
returned by a matching pattern.
Subclass may override.
"""
results = {"nod... | Returns match for a given parse tree node.
Should return a true or false object (not necessarily a bool).
It may return a non-empty dict of matching sub-nodes as
returned by a matching pattern.
Subclass may override.
| match | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def new_name(self, template=u"xxx_todo_changeme"):
"""Return a string suitable for use as an identifier
The new name is guaranteed not to conflict with other identifiers.
"""
name = template
while name in self.used_names:
name = template + unicode(self.numbers.next()... | Return a string suitable for use as an identifier
The new name is guaranteed not to conflict with other identifiers.
| new_name | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def cannot_convert(self, node, reason=None):
"""Warn the user that a given chunk of code is not valid Python 3,
but that it cannot be converted automatically.
First argument is the top-level node for the code in question.
Optional second argument is why it can't be converted.
""... | Warn the user that a given chunk of code is not valid Python 3,
but that it cannot be converted automatically.
First argument is the top-level node for the code in question.
Optional second argument is why it can't be converted.
| cannot_convert | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def warning(self, node, reason):
"""Used for warning the user about possible uncertainty in the
translation.
First argument is the top-level node for the code in question.
Optional second argument is why it can't be converted.
"""
lineno = node.get_lineno()
self.... | Used for warning the user about possible uncertainty in the
translation.
First argument is the top-level node for the code in question.
Optional second argument is why it can't be converted.
| warning | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def start_tree(self, tree, filename):
"""Some fixers need to maintain tree-wide state.
This method is called once, at the start of tree fix-up.
tree - the root node of the tree to be processed.
filename - the name of the file the tree came from.
"""
self.used_names = tre... | Some fixers need to maintain tree-wide state.
This method is called once, at the start of tree fix-up.
tree - the root node of the tree to be processed.
filename - the name of the file the tree came from.
| start_tree | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_base.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_base.py | MIT |
def ArgList(args, lparen=LParen(), rparen=RParen()):
"""A parenthesised argument list, used by Call()"""
node = Node(syms.trailer, [lparen.clone(), rparen.clone()])
if args:
node.insert_child(1, Node(syms.arglist, args))
return node | A parenthesised argument list, used by Call() | ArgList | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def FromImport(package_name, name_leafs):
""" Return an import statement in the form:
from package import name_leafs"""
# XXX: May not handle dotted imports properly (eg, package_name='foo.bar')
#assert package_name == '.' or '.' not in package_name, "FromImport has "\
# "not been tested w... | Return an import statement in the form:
from package import name_leafs | FromImport | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def is_tuple(node):
"""Does the node represent a tuple literal?"""
if isinstance(node, Node) and node.children == [LParen(), RParen()]:
return True
return (isinstance(node, Node)
and len(node.children) == 3
and isinstance(node.children[0], Leaf)
and isinstance(nod... | Does the node represent a tuple literal? | is_tuple | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def is_list(node):
"""Does the node represent a list literal?"""
return (isinstance(node, Node)
and len(node.children) > 1
and isinstance(node.children[0], Leaf)
and isinstance(node.children[-1], Leaf)
and node.children[0].value == u"["
and node.childr... | Does the node represent a list literal? | is_list | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def attr_chain(obj, attr):
"""Follow an attribute chain.
If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
use this to iterate over all objects in the chain. Iteration is
terminated by getattr(x, attr) is None.
Args:
obj: the starting object
attr: the name of the cha... | Follow an attribute chain.
If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
use this to iterate over all objects in the chain. Iteration is
terminated by getattr(x, attr) is None.
Args:
obj: the starting object
attr: the name of the chaining attribute
Yields:
... | attr_chain | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def in_special_context(node):
""" Returns true if node is in an environment where all that is required
of it is being iterable (ie, it doesn't matter if it returns a list
or an iterator).
See test_map_nochange in test_fixers.py for some examples and tests.
"""
global p0, p1, p2, ... | Returns true if node is in an environment where all that is required
of it is being iterable (ie, it doesn't matter if it returns a list
or an iterator).
See test_map_nochange in test_fixers.py for some examples and tests.
| in_special_context | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def is_probably_builtin(node):
"""
Check that something isn't an attribute or function name etc.
"""
prev = node.prev_sibling
if prev is not None and prev.type == token.DOT:
# Attribute lookup.
return False
parent = node.parent
if parent.type in (syms.funcdef, syms.classdef):... |
Check that something isn't an attribute or function name etc.
| is_probably_builtin | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def touch_import(package, name, node):
""" Works like `does_tree_import` but adds an import statement
if it was not imported. """
def is_import_stmt(node):
return (node.type == syms.simple_stmt and node.children and
is_import(node.children[0]))
root = find_root(node)
if... | Works like `does_tree_import` but adds an import statement
if it was not imported. | touch_import | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def find_binding(name, node, package=None):
""" Returns the node which binds variable name, otherwise None.
If optional argument package is supplied, only imports will
be returned.
See test cases for examples."""
for child in node.children:
ret = None
if child.type == sym... | Returns the node which binds variable name, otherwise None.
If optional argument package is supplied, only imports will
be returned.
See test cases for examples. | find_binding | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def _is_import_binding(node, name, package=None):
""" Will reuturn node if node will import name, or node
will import * from package. None is returned otherwise.
See test cases for examples. """
if node.type == syms.import_name and not package:
imp = node.children[1]
if imp.typ... | Will reuturn node if node will import name, or node
will import * from package. None is returned otherwise.
See test cases for examples. | _is_import_binding | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/fixer_util.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/fixer_util.py | MIT |
def diff_texts(a, b, filename):
"""Return a unified diff of two strings."""
a = a.splitlines()
b = b.splitlines()
return difflib.unified_diff(a, b, filename, filename,
"(original)", "(refactored)",
lineterm="") | Return a unified diff of two strings. | diff_texts | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/main.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/main.py | MIT |
def __init__(self, fixers, options, explicit, nobackups, show_diffs,
input_base_dir='', output_dir='', append_suffix=''):
"""
Args:
fixers: A list of fixers to import.
options: A dict with RefactoringTool configuration.
explicit: A list of fixers to r... |
Args:
fixers: A list of fixers to import.
options: A dict with RefactoringTool configuration.
explicit: A list of fixers to run even if they are explicit.
nobackups: If true no backup '.bak' files will be created for those
files that are being ref... | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/main.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/main.py | MIT |
def __init__(self, grammar_file=_PATTERN_GRAMMAR_FILE):
"""Initializer.
Takes an optional alternative filename for the pattern grammar.
"""
self.grammar = driver.load_grammar(grammar_file)
self.syms = pygram.Symbols(self.grammar)
self.pygrammar = pygram.python_grammar
... | Initializer.
Takes an optional alternative filename for the pattern grammar.
| __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/patcomp.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/patcomp.py | MIT |
def compile_pattern(self, input, debug=False, with_tree=False):
"""Compiles a pattern string to a nested pytree.*Pattern object."""
tokens = tokenize_wrapper(input)
try:
root = self.driver.parse_tokens(tokens, debug=debug)
except parse.ParseError as e:
raise Patte... | Compiles a pattern string to a nested pytree.*Pattern object. | compile_pattern | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/patcomp.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/patcomp.py | MIT |
def compile_node(self, node):
"""Compiles a node, recursively.
This is one big switch on the node type.
"""
# XXX Optimize certain Wildcard-containing-Wildcard patterns
# that can be merged
if node.type == self.syms.Matcher:
node = node.children[0] # Avoid un... | Compiles a node, recursively.
This is one big switch on the node type.
| compile_node | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/patcomp.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/patcomp.py | MIT |
def pattern_convert(grammar, raw_node_info):
"""Converts raw node information to a Node or Leaf instance."""
type, value, context, children = raw_node_info
if children or type in grammar.number2symbol:
return pytree.Node(type, children, context=context)
else:
return pytree.Leaf(type, val... | Converts raw node information to a Node or Leaf instance. | pattern_convert | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/patcomp.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/patcomp.py | MIT |
def __init__(self, grammar):
"""Initializer.
Creates an attribute for each grammar symbol (nonterminal),
whose value is the symbol's type (an int >= 256).
"""
for name, symbol in grammar.symbol2number.iteritems():
setattr(self, name, symbol) | Initializer.
Creates an attribute for each grammar symbol (nonterminal),
whose value is the symbol's type (an int >= 256).
| __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pygram.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pygram.py | MIT |
def __eq__(self, other):
"""
Compare two nodes for equality.
This calls the method _eq().
"""
if self.__class__ is not other.__class__:
return NotImplemented
return self._eq(other) |
Compare two nodes for equality.
This calls the method _eq().
| __eq__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def __ne__(self, other):
"""
Compare two nodes for inequality.
This calls the method _eq().
"""
if self.__class__ is not other.__class__:
return NotImplemented
return not self._eq(other) |
Compare two nodes for inequality.
This calls the method _eq().
| __ne__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def set_prefix(self, prefix):
"""
Set the prefix for the node (see Leaf class).
DEPRECATED; use the prefix property directly.
"""
warnings.warn("set_prefix() is deprecated; use the prefix property",
DeprecationWarning, stacklevel=2)
self.prefix = pr... |
Set the prefix for the node (see Leaf class).
DEPRECATED; use the prefix property directly.
| set_prefix | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def get_prefix(self):
"""
Return the prefix for the node (see Leaf class).
DEPRECATED; use the prefix property directly.
"""
warnings.warn("get_prefix() is deprecated; use the prefix property",
DeprecationWarning, stacklevel=2)
return self.prefix |
Return the prefix for the node (see Leaf class).
DEPRECATED; use the prefix property directly.
| get_prefix | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def replace(self, new):
"""Replace this node with a new one in the parent."""
assert self.parent is not None, str(self)
assert new is not None
if not isinstance(new, list):
new = [new]
l_children = []
found = False
for ch in self.parent.children:
... | Replace this node with a new one in the parent. | replace | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def get_lineno(self):
"""Return the line number which generated the invocant node."""
node = self
while not isinstance(node, Leaf):
if not node.children:
return
node = node.children[0]
return node.lineno | Return the line number which generated the invocant node. | get_lineno | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def remove(self):
"""
Remove the node from the tree. Returns the position of the node in its
parent's children before it was removed.
"""
if self.parent:
for i, node in enumerate(self.parent.children):
if node is self:
self.parent.c... |
Remove the node from the tree. Returns the position of the node in its
parent's children before it was removed.
| remove | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def next_sibling(self):
"""
The node immediately following the invocant in their parent's children
list. If the invocant does not have a next sibling, it is None
"""
if self.parent is None:
return None
# Can't use index(); we need to test by identity
... |
The node immediately following the invocant in their parent's children
list. If the invocant does not have a next sibling, it is None
| next_sibling | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def prev_sibling(self):
"""
The node immediately preceding the invocant in their parent's children
list. If the invocant does not have a previous sibling, it is None.
"""
if self.parent is None:
return None
# Can't use index(); we need to test by identity
... |
The node immediately preceding the invocant in their parent's children
list. If the invocant does not have a previous sibling, it is None.
| prev_sibling | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def get_suffix(self):
"""
Return the string immediately following the invocant node. This is
effectively equivalent to node.next_sibling.prefix
"""
next_sib = self.next_sibling
if next_sib is None:
return u""
return next_sib.prefix |
Return the string immediately following the invocant node. This is
effectively equivalent to node.next_sibling.prefix
| get_suffix | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def __init__(self,type, children,
context=None,
prefix=None,
fixers_applied=None):
"""
Initializer.
Takes a type constant (a symbol number >= 256), a sequence of
child nodes, and an optional context keyword argument.
As a side ... |
Initializer.
Takes a type constant (a symbol number >= 256), a sequence of
child nodes, and an optional context keyword argument.
As a side effect, the parent pointers of the children are updated.
| __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def post_order(self):
"""Return a post-order iterator for the tree."""
for child in self.children:
for node in child.post_order():
yield node
yield self | Return a post-order iterator for the tree. | post_order | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def pre_order(self):
"""Return a pre-order iterator for the tree."""
yield self
for child in self.children:
for node in child.pre_order():
yield node | Return a pre-order iterator for the tree. | pre_order | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def _prefix_getter(self):
"""
The whitespace and comments preceding this node in the input.
"""
if not self.children:
return ""
return self.children[0].prefix |
The whitespace and comments preceding this node in the input.
| _prefix_getter | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def set_child(self, i, child):
"""
Equivalent to 'node.children[i] = child'. This method also sets the
child's parent attribute appropriately.
"""
child.parent = self
self.children[i].parent = None
self.children[i] = child
self.changed() |
Equivalent to 'node.children[i] = child'. This method also sets the
child's parent attribute appropriately.
| set_child | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def insert_child(self, i, child):
"""
Equivalent to 'node.children.insert(i, child)'. This method also sets
the child's parent attribute appropriately.
"""
child.parent = self
self.children.insert(i, child)
self.changed() |
Equivalent to 'node.children.insert(i, child)'. This method also sets
the child's parent attribute appropriately.
| insert_child | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def __init__(self, type, value,
context=None,
prefix=None,
fixers_applied=[]):
"""
Initializer.
Takes a type constant (a token number < 256), a string value, and an
optional context keyword argument.
"""
assert 0 <= type... |
Initializer.
Takes a type constant (a token number < 256), a string value, and an
optional context keyword argument.
| __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def clone(self):
"""Return a cloned (deep) copy of self."""
return Leaf(self.type, self.value,
(self.prefix, (self.lineno, self.column)),
fixers_applied=self.fixers_applied) | Return a cloned (deep) copy of self. | clone | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def convert(gr, raw_node):
"""
Convert raw node information to a Node or Leaf instance.
This is passed to the parser driver which calls it whenever a reduction of a
grammar rule produces a new complete node, so that the tree is build
strictly bottom-up.
"""
type, value, context, children = ... |
Convert raw node information to a Node or Leaf instance.
This is passed to the parser driver which calls it whenever a reduction of a
grammar rule produces a new complete node, so that the tree is build
strictly bottom-up.
| convert | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def match(self, node, results=None):
"""
Does this pattern exactly match a node?
Returns True if it matches, False if not.
If results is not None, it must be a dict which will be
updated with the nodes matching named subpatterns.
Default implementation for non-wildcard... |
Does this pattern exactly match a node?
Returns True if it matches, False if not.
If results is not None, it must be a dict which will be
updated with the nodes matching named subpatterns.
Default implementation for non-wildcard patterns.
| match | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def match_seq(self, nodes, results=None):
"""
Does this pattern exactly match a sequence of nodes?
Default implementation for non-wildcard patterns.
"""
if len(nodes) != 1:
return False
return self.match(nodes[0], results) |
Does this pattern exactly match a sequence of nodes?
Default implementation for non-wildcard patterns.
| match_seq | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
def generate_matches(self, nodes):
"""
Generator yielding all matches for this pattern.
Default implementation for non-wildcard patterns.
"""
r = {}
if nodes and self.match(nodes[0], r):
yield 1, r |
Generator yielding all matches for this pattern.
Default implementation for non-wildcard patterns.
| generate_matches | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/lib2to3/pytree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/lib2to3/pytree.py | MIT |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.