partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
valid | Streamlet.outer_left_join | Return a new Streamlet by left join_streamlet with this streamlet | heronpy/streamlet/streamlet.py | def outer_left_join(self, join_streamlet, window_config, join_function):
"""Return a new Streamlet by left join_streamlet with this streamlet
"""
from heronpy.streamlet.impl.joinbolt import JoinStreamlet, JoinBolt
join_streamlet_result = JoinStreamlet(JoinBolt.OUTER_LEFT, window_config,
... | def outer_left_join(self, join_streamlet, window_config, join_function):
"""Return a new Streamlet by left join_streamlet with this streamlet
"""
from heronpy.streamlet.impl.joinbolt import JoinStreamlet, JoinBolt
join_streamlet_result = JoinStreamlet(JoinBolt.OUTER_LEFT, window_config,
... | [
"Return",
"a",
"new",
"Streamlet",
"by",
"left",
"join_streamlet",
"with",
"this",
"streamlet"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heronpy/streamlet/streamlet.py#L178-L186 | [
"def",
"outer_left_join",
"(",
"self",
",",
"join_streamlet",
",",
"window_config",
",",
"join_function",
")",
":",
"from",
"heronpy",
".",
"streamlet",
".",
"impl",
".",
"joinbolt",
"import",
"JoinStreamlet",
",",
"JoinBolt",
"join_streamlet_result",
"=",
"JoinSt... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | Streamlet.outer_join | Return a new Streamlet by outer join_streamlet with this streamlet | heronpy/streamlet/streamlet.py | def outer_join(self, join_streamlet, window_config, join_function):
"""Return a new Streamlet by outer join_streamlet with this streamlet
"""
from heronpy.streamlet.impl.joinbolt import JoinStreamlet, JoinBolt
join_streamlet_result = JoinStreamlet(JoinBolt.OUTER, window_config,
... | def outer_join(self, join_streamlet, window_config, join_function):
"""Return a new Streamlet by outer join_streamlet with this streamlet
"""
from heronpy.streamlet.impl.joinbolt import JoinStreamlet, JoinBolt
join_streamlet_result = JoinStreamlet(JoinBolt.OUTER, window_config,
... | [
"Return",
"a",
"new",
"Streamlet",
"by",
"outer",
"join_streamlet",
"with",
"this",
"streamlet"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heronpy/streamlet/streamlet.py#L188-L197 | [
"def",
"outer_join",
"(",
"self",
",",
"join_streamlet",
",",
"window_config",
",",
"join_function",
")",
":",
"from",
"heronpy",
".",
"streamlet",
".",
"impl",
".",
"joinbolt",
"import",
"JoinStreamlet",
",",
"JoinBolt",
"join_streamlet_result",
"=",
"JoinStreaml... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | Streamlet.reduce_by_key_and_window | Return a new Streamlet in which each (key, value) pair of this Streamlet are collected
over the time_window and then reduced using the reduce_function | heronpy/streamlet/streamlet.py | def reduce_by_key_and_window(self, window_config, reduce_function):
"""Return a new Streamlet in which each (key, value) pair of this Streamlet are collected
over the time_window and then reduced using the reduce_function
"""
from heronpy.streamlet.impl.reducebykeyandwindowbolt import ReduceByKeyAndW... | def reduce_by_key_and_window(self, window_config, reduce_function):
"""Return a new Streamlet in which each (key, value) pair of this Streamlet are collected
over the time_window and then reduced using the reduce_function
"""
from heronpy.streamlet.impl.reducebykeyandwindowbolt import ReduceByKeyAndW... | [
"Return",
"a",
"new",
"Streamlet",
"in",
"which",
"each",
"(",
"key",
"value",
")",
"pair",
"of",
"this",
"Streamlet",
"are",
"collected",
"over",
"the",
"time_window",
"and",
"then",
"reduced",
"using",
"the",
"reduce_function"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heronpy/streamlet/streamlet.py#L199-L206 | [
"def",
"reduce_by_key_and_window",
"(",
"self",
",",
"window_config",
",",
"reduce_function",
")",
":",
"from",
"heronpy",
".",
"streamlet",
".",
"impl",
".",
"reducebykeyandwindowbolt",
"import",
"ReduceByKeyAndWindowStreamlet",
"reduce_streamlet",
"=",
"ReduceByKeyAndWi... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | Streamlet._default_stage_name_calculator | This is the method that's implemented by the operators to get the name of the Streamlet
:return: The name of the operator | heronpy/streamlet/streamlet.py | def _default_stage_name_calculator(self, prefix, existing_stage_names):
"""This is the method that's implemented by the operators to get the name of the Streamlet
:return: The name of the operator
"""
index = 1
calculated_name = ""
while True:
calculated_name = prefix + "-" + str(index)
... | def _default_stage_name_calculator(self, prefix, existing_stage_names):
"""This is the method that's implemented by the operators to get the name of the Streamlet
:return: The name of the operator
"""
index = 1
calculated_name = ""
while True:
calculated_name = prefix + "-" + str(index)
... | [
"This",
"is",
"the",
"method",
"that",
"s",
"implemented",
"by",
"the",
"operators",
"to",
"get",
"the",
"name",
"of",
"the",
"Streamlet",
":",
"return",
":",
"The",
"name",
"of",
"the",
"operator"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heronpy/streamlet/streamlet.py#L233-L244 | [
"def",
"_default_stage_name_calculator",
"(",
"self",
",",
"prefix",
",",
"existing_stage_names",
")",
":",
"index",
"=",
"1",
"calculated_name",
"=",
"\"\"",
"while",
"True",
":",
"calculated_name",
"=",
"prefix",
"+",
"\"-\"",
"+",
"str",
"(",
"index",
")",
... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | MachinesHandler.get | get method | heron/tools/tracker/src/python/handlers/machineshandler.py | def get(self):
""" get method """
clusters = self.get_arguments(constants.PARAM_CLUSTER)
environs = self.get_arguments(constants.PARAM_ENVIRON)
topology_names = self.get_arguments(constants.PARAM_TOPOLOGY)
ret = {}
if len(topology_names) > 1:
if not clusters:
message = "Missing a... | def get(self):
""" get method """
clusters = self.get_arguments(constants.PARAM_CLUSTER)
environs = self.get_arguments(constants.PARAM_ENVIRON)
topology_names = self.get_arguments(constants.PARAM_TOPOLOGY)
ret = {}
if len(topology_names) > 1:
if not clusters:
message = "Missing a... | [
"get",
"method"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/tools/tracker/src/python/handlers/machineshandler.py#L58-L103 | [
"def",
"get",
"(",
"self",
")",
":",
"clusters",
"=",
"self",
".",
"get_arguments",
"(",
"constants",
".",
"PARAM_CLUSTER",
")",
"environs",
"=",
"self",
".",
"get_arguments",
"(",
"constants",
".",
"PARAM_ENVIRON",
")",
"topology_names",
"=",
"self",
".",
... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | _async_stream_process_output | Stream and handle the output of a process
:param process: the process to stream the output for
:param stream_fn: the function that applies handler to process
:param handler: a function that will be called for each log line
:return: None | heron/common/src/python/utils/proc.py | def _async_stream_process_output(process, stream_fn, handler):
""" Stream and handle the output of a process
:param process: the process to stream the output for
:param stream_fn: the function that applies handler to process
:param handler: a function that will be called for each log line
:return: None
"""
... | def _async_stream_process_output(process, stream_fn, handler):
""" Stream and handle the output of a process
:param process: the process to stream the output for
:param stream_fn: the function that applies handler to process
:param handler: a function that will be called for each log line
:return: None
"""
... | [
"Stream",
"and",
"handle",
"the",
"output",
"of",
"a",
"process",
":",
"param",
"process",
":",
"the",
"process",
"to",
"stream",
"the",
"output",
"for",
":",
"param",
"stream_fn",
":",
"the",
"function",
"that",
"applies",
"handler",
"to",
"process",
":",... | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/common/src/python/utils/proc.py#L52-L66 | [
"def",
"_async_stream_process_output",
"(",
"process",
",",
"stream_fn",
",",
"handler",
")",
":",
"logging_thread",
"=",
"Thread",
"(",
"target",
"=",
"stream_fn",
",",
"args",
"=",
"(",
"process",
",",
"handler",
",",
")",
")",
"# Setting the logging thread as... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | pick | Get the topology jars
:param dirname:
:param pattern:
:return: | heron/tools/cli/src/python/jars.py | def pick(dirname, pattern):
'''
Get the topology jars
:param dirname:
:param pattern:
:return:
'''
file_list = fnmatch.filter(os.listdir(dirname), pattern)
return file_list[0] if file_list else None | def pick(dirname, pattern):
'''
Get the topology jars
:param dirname:
:param pattern:
:return:
'''
file_list = fnmatch.filter(os.listdir(dirname), pattern)
return file_list[0] if file_list else None | [
"Get",
"the",
"topology",
"jars",
":",
"param",
"dirname",
":",
":",
"param",
"pattern",
":",
":",
"return",
":"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/tools/cli/src/python/jars.py#L28-L36 | [
"def",
"pick",
"(",
"dirname",
",",
"pattern",
")",
":",
"file_list",
"=",
"fnmatch",
".",
"filter",
"(",
"os",
".",
"listdir",
"(",
"dirname",
")",
",",
"pattern",
")",
"return",
"file_list",
"[",
"0",
"]",
"if",
"file_list",
"else",
"None"
] | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | MetricsTimelineHandler.get | get method | heron/tools/tracker/src/python/handlers/metricstimelinehandler.py | def get(self):
""" get method """
try:
cluster = self.get_argument_cluster()
role = self.get_argument_role()
environ = self.get_argument_environ()
topology_name = self.get_argument_topology()
component = self.get_argument_component()
metric_names = self.get_required_arguments... | def get(self):
""" get method """
try:
cluster = self.get_argument_cluster()
role = self.get_argument_role()
environ = self.get_argument_environ()
topology_name = self.get_argument_topology()
component = self.get_argument_component()
metric_names = self.get_required_arguments... | [
"get",
"method"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/tools/tracker/src/python/handlers/metricstimelinehandler.py#L57-L79 | [
"def",
"get",
"(",
"self",
")",
":",
"try",
":",
"cluster",
"=",
"self",
".",
"get_argument_cluster",
"(",
")",
"role",
"=",
"self",
".",
"get_argument_role",
"(",
")",
"environ",
"=",
"self",
".",
"get_argument_environ",
"(",
")",
"topology_name",
"=",
... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | create_parser | create parser | heron/tools/explorer/src/python/main.py | def create_parser():
""" create parser """
help_epilog = '''Getting more help:
heron-explorer help <command> Disply help and options for <command>\n
For detailed documentation, go to http://heronstreaming.io'''
parser = argparse.ArgumentParser(
prog='heron-explorer',
epilog=help_epilog,
... | def create_parser():
""" create parser """
help_epilog = '''Getting more help:
heron-explorer help <command> Disply help and options for <command>\n
For detailed documentation, go to http://heronstreaming.io'''
parser = argparse.ArgumentParser(
prog='heron-explorer',
epilog=help_epilog,
... | [
"create",
"parser"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/tools/explorer/src/python/main.py#L54-L89 | [
"def",
"create_parser",
"(",
")",
":",
"help_epilog",
"=",
"'''Getting more help:\n heron-explorer help <command> Disply help and options for <command>\\n\n For detailed documentation, go to http://heronstreaming.io'''",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"prog"... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | run | run command | heron/tools/explorer/src/python/main.py | def run(command, *args):
""" run command """
# show all clusters
if command == 'clusters':
return clusters.run(command, *args)
# show topologies
elif command == 'topologies':
return topologies.run(command, *args)
# physical plan
elif command == 'containers':
return physicalplan.run_container... | def run(command, *args):
""" run command """
# show all clusters
if command == 'clusters':
return clusters.run(command, *args)
# show topologies
elif command == 'topologies':
return topologies.run(command, *args)
# physical plan
elif command == 'containers':
return physicalplan.run_container... | [
"run",
"command"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/tools/explorer/src/python/main.py#L96-L128 | [
"def",
"run",
"(",
"command",
",",
"*",
"args",
")",
":",
"# show all clusters",
"if",
"command",
"==",
"'clusters'",
":",
"return",
"clusters",
".",
"run",
"(",
"command",
",",
"*",
"args",
")",
"# show topologies",
"elif",
"command",
"==",
"'topologies'",
... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | extract_common_args | extract common args | heron/tools/explorer/src/python/main.py | def extract_common_args(command, parser, cl_args):
""" extract common args """
try:
# do not pop like cli because ``topologies`` subcommand still needs it
cluster_role_env = cl_args['cluster/[role]/[env]']
config_path = cl_args['config_path']
except KeyError:
# if some of the arguments are not fou... | def extract_common_args(command, parser, cl_args):
""" extract common args """
try:
# do not pop like cli because ``topologies`` subcommand still needs it
cluster_role_env = cl_args['cluster/[role]/[env]']
config_path = cl_args['config_path']
except KeyError:
# if some of the arguments are not fou... | [
"extract",
"common",
"args"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/tools/explorer/src/python/main.py#L132-L158 | [
"def",
"extract_common_args",
"(",
"command",
",",
"parser",
",",
"cl_args",
")",
":",
"try",
":",
"# do not pop like cli because ``topologies`` subcommand still needs it",
"cluster_role_env",
"=",
"cl_args",
"[",
"'cluster/[role]/[env]'",
"]",
"config_path",
"=",
"cl_args"... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | main | main | heron/tools/explorer/src/python/main.py | def main(args):
""" main """
# create the argument parser
parser = create_parser()
# if no argument is provided, print help and exit
if not args:
parser.print_help()
return 0
# insert the boolean values for some of the options
all_args = parse.insert_bool_values(args)
# parse the args
args,... | def main(args):
""" main """
# create the argument parser
parser = create_parser()
# if no argument is provided, print help and exit
if not args:
parser.print_help()
return 0
# insert the boolean values for some of the options
all_args = parse.insert_bool_values(args)
# parse the args
args,... | [
"main"
] | apache/incubator-heron | python | https://github.com/apache/incubator-heron/blob/ad10325a0febe89ad337e561ebcbe37ec5d9a5ac/heron/tools/explorer/src/python/main.py#L164-L206 | [
"def",
"main",
"(",
"args",
")",
":",
"# create the argument parser",
"parser",
"=",
"create_parser",
"(",
")",
"# if no argument is provided, print help and exit",
"if",
"not",
"args",
":",
"parser",
".",
"print_help",
"(",
")",
"return",
"0",
"# insert the boolean v... | ad10325a0febe89ad337e561ebcbe37ec5d9a5ac |
valid | expand_args | Parses command strings and returns a Popen-ready list. | envoy/core.py | def expand_args(command):
"""Parses command strings and returns a Popen-ready list."""
# Prepare arguments.
if isinstance(command, (str, unicode)):
splitter = shlex.shlex(command.encode('utf-8'))
splitter.whitespace = '|'
splitter.whitespace_split = True
command = []
... | def expand_args(command):
"""Parses command strings and returns a Popen-ready list."""
# Prepare arguments.
if isinstance(command, (str, unicode)):
splitter = shlex.shlex(command.encode('utf-8'))
splitter.whitespace = '|'
splitter.whitespace_split = True
command = []
... | [
"Parses",
"command",
"strings",
"and",
"returns",
"a",
"Popen",
"-",
"ready",
"list",
"."
] | kennethreitz/envoy | python | https://github.com/kennethreitz/envoy/blob/ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a/envoy/core.py#L175-L194 | [
"def",
"expand_args",
"(",
"command",
")",
":",
"# Prepare arguments.",
"if",
"isinstance",
"(",
"command",
",",
"(",
"str",
",",
"unicode",
")",
")",
":",
"splitter",
"=",
"shlex",
".",
"shlex",
"(",
"command",
".",
"encode",
"(",
"'utf-8'",
")",
")",
... | ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a |
valid | run | Executes a given commmand and returns Response.
Blocks until process is complete, or timeout is reached. | envoy/core.py | def run(command, data=None, timeout=None, kill_timeout=None, env=None, cwd=None):
"""Executes a given commmand and returns Response.
Blocks until process is complete, or timeout is reached.
"""
command = expand_args(command)
history = []
for c in command:
if len(history):
... | def run(command, data=None, timeout=None, kill_timeout=None, env=None, cwd=None):
"""Executes a given commmand and returns Response.
Blocks until process is complete, or timeout is reached.
"""
command = expand_args(command)
history = []
for c in command:
if len(history):
... | [
"Executes",
"a",
"given",
"commmand",
"and",
"returns",
"Response",
"."
] | kennethreitz/envoy | python | https://github.com/kennethreitz/envoy/blob/ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a/envoy/core.py#L197-L232 | [
"def",
"run",
"(",
"command",
",",
"data",
"=",
"None",
",",
"timeout",
"=",
"None",
",",
"kill_timeout",
"=",
"None",
",",
"env",
"=",
"None",
",",
"cwd",
"=",
"None",
")",
":",
"command",
"=",
"expand_args",
"(",
"command",
")",
"history",
"=",
"... | ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a |
valid | connect | Spawns a new process from the given command. | envoy/core.py | def connect(command, data=None, env=None, cwd=None):
"""Spawns a new process from the given command."""
# TODO: support piped commands
command_str = expand_args(command).pop()
environ = dict(os.environ)
environ.update(env or {})
process = subprocess.Popen(command_str,
universal_newline... | def connect(command, data=None, env=None, cwd=None):
"""Spawns a new process from the given command."""
# TODO: support piped commands
command_str = expand_args(command).pop()
environ = dict(os.environ)
environ.update(env or {})
process = subprocess.Popen(command_str,
universal_newline... | [
"Spawns",
"a",
"new",
"process",
"from",
"the",
"given",
"command",
"."
] | kennethreitz/envoy | python | https://github.com/kennethreitz/envoy/blob/ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a/envoy/core.py#L235-L254 | [
"def",
"connect",
"(",
"command",
",",
"data",
"=",
"None",
",",
"env",
"=",
"None",
",",
"cwd",
"=",
"None",
")",
":",
"# TODO: support piped commands",
"command_str",
"=",
"expand_args",
"(",
"command",
")",
".",
"pop",
"(",
")",
"environ",
"=",
"dict"... | ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a |
valid | ConnectedCommand.send | Sends a line to std_in. | envoy/core.py | def send(self, str, end='\n'):
"""Sends a line to std_in."""
return self._process.stdin.write(str+end) | def send(self, str, end='\n'):
"""Sends a line to std_in."""
return self._process.stdin.write(str+end) | [
"Sends",
"a",
"line",
"to",
"std_in",
"."
] | kennethreitz/envoy | python | https://github.com/kennethreitz/envoy/blob/ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a/envoy/core.py#L144-L146 | [
"def",
"send",
"(",
"self",
",",
"str",
",",
"end",
"=",
"'\\n'",
")",
":",
"return",
"self",
".",
"_process",
".",
"stdin",
".",
"write",
"(",
"str",
"+",
"end",
")"
] | ab463a14da47bd8334cdf5e64f6b9dd2ba9dd28a |
valid | bracket_split | DOES NOT RETURN EMPTY STRINGS (can only return empty bracket content if strip=True) | js2py/translators/friendly_nodes.py | def bracket_split(source, brackets=('()', '{}', '[]'), strip=False):
"""DOES NOT RETURN EMPTY STRINGS (can only return empty bracket content if strip=True)"""
starts = [e[0] for e in brackets]
in_bracket = 0
n = 0
last = 0
while n < len(source):
e = source[n]
if not in_bracket an... | def bracket_split(source, brackets=('()', '{}', '[]'), strip=False):
"""DOES NOT RETURN EMPTY STRINGS (can only return empty bracket content if strip=True)"""
starts = [e[0] for e in brackets]
in_bracket = 0
n = 0
last = 0
while n < len(source):
e = source[n]
if not in_bracket an... | [
"DOES",
"NOT",
"RETURN",
"EMPTY",
"STRINGS",
"(",
"can",
"only",
"return",
"empty",
"bracket",
"content",
"if",
"strip",
"=",
"True",
")"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/translators/friendly_nodes.py#L96-L120 | [
"def",
"bracket_split",
"(",
"source",
",",
"brackets",
"=",
"(",
"'()'",
",",
"'{}'",
",",
"'[]'",
")",
",",
"strip",
"=",
"False",
")",
":",
"starts",
"=",
"[",
"e",
"[",
"0",
"]",
"for",
"e",
"in",
"brackets",
"]",
"in_bracket",
"=",
"0",
"n",... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | Js | Converts Py type to PyJs type | js2py/base.py | def Js(val, Clamped=False):
'''Converts Py type to PyJs type'''
if isinstance(val, PyJs):
return val
elif val is None:
return undefined
elif isinstance(val, basestring):
return PyJsString(val, StringPrototype)
elif isinstance(val, bool):
return true if val else false
... | def Js(val, Clamped=False):
'''Converts Py type to PyJs type'''
if isinstance(val, PyJs):
return val
elif val is None:
return undefined
elif isinstance(val, basestring):
return PyJsString(val, StringPrototype)
elif isinstance(val, bool):
return true if val else false
... | [
"Converts",
"Py",
"type",
"to",
"PyJs",
"type"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L145-L213 | [
"def",
"Js",
"(",
"val",
",",
"Clamped",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"val",
",",
"PyJs",
")",
":",
"return",
"val",
"elif",
"val",
"is",
"None",
":",
"return",
"undefined",
"elif",
"isinstance",
"(",
"val",
",",
"basestring",
")"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJsStrictEq | a===b | js2py/base.py | def PyJsStrictEq(a, b):
'''a===b'''
tx, ty = Type(a), Type(b)
if tx != ty:
return false
if tx == 'Undefined' or tx == 'Null':
return true
if a.is_primitive(): #string bool and number case
return Js(a.value == b.value)
if a.Class == b.Class == 'PyObjectWrapper':
r... | def PyJsStrictEq(a, b):
'''a===b'''
tx, ty = Type(a), Type(b)
if tx != ty:
return false
if tx == 'Undefined' or tx == 'Null':
return true
if a.is_primitive(): #string bool and number case
return Js(a.value == b.value)
if a.Class == b.Class == 'PyObjectWrapper':
r... | [
"a",
"===",
"b"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L1014-L1025 | [
"def",
"PyJsStrictEq",
"(",
"a",
",",
"b",
")",
":",
"tx",
",",
"ty",
"=",
"Type",
"(",
"a",
")",
",",
"Type",
"(",
"b",
")",
"if",
"tx",
"!=",
"ty",
":",
"return",
"false",
"if",
"tx",
"==",
"'Undefined'",
"or",
"tx",
"==",
"'Null'",
":",
"r... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJs.put | Just like in js: self.prop op= val
for example when op is '+' it will be self.prop+=val
op can be either None for simple assignment or one of:
* / % + - << >> & ^ | | js2py/base.py | def put(self, prop, val, op=None): #external use!
'''Just like in js: self.prop op= val
for example when op is '+' it will be self.prop+=val
op can be either None for simple assignment or one of:
* / % + - << >> & ^ |'''
if self.Class == 'Undefined' or self.Class == 'Nu... | def put(self, prop, val, op=None): #external use!
'''Just like in js: self.prop op= val
for example when op is '+' it will be self.prop+=val
op can be either None for simple assignment or one of:
* / % + - << >> & ^ |'''
if self.Class == 'Undefined' or self.Class == 'Nu... | [
"Just",
"like",
"in",
"js",
":",
"self",
".",
"prop",
"op",
"=",
"val",
"for",
"example",
"when",
"op",
"is",
"+",
"it",
"will",
"be",
"self",
".",
"prop",
"+",
"=",
"val",
"op",
"can",
"be",
"either",
"None",
"for",
"simple",
"assignment",
"or",
... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L357-L427 | [
"def",
"put",
"(",
"self",
",",
"prop",
",",
"val",
",",
"op",
"=",
"None",
")",
":",
"#external use!",
"if",
"self",
".",
"Class",
"==",
"'Undefined'",
"or",
"self",
".",
"Class",
"==",
"'Null'",
":",
"raise",
"MakeError",
"(",
"'TypeError'",
",",
"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJs.abstract_relational_comparison | self<other if self_first else other<self.
Returns the result of the question: is self smaller than other?
in case self_first is false it returns the answer of:
is other smaller than self.
result is PyJs type: bool or undefined | js2py/base.py | def abstract_relational_comparison(self, other, self_first=True):
''' self<other if self_first else other<self.
Returns the result of the question: is self smaller than other?
in case self_first is false it returns the answer of:
is other smal... | def abstract_relational_comparison(self, other, self_first=True):
''' self<other if self_first else other<self.
Returns the result of the question: is self smaller than other?
in case self_first is false it returns the answer of:
is other smal... | [
"self<other",
"if",
"self_first",
"else",
"other<self",
".",
"Returns",
"the",
"result",
"of",
"the",
"question",
":",
"is",
"self",
"smaller",
"than",
"other?",
"in",
"case",
"self_first",
"is",
"false",
"it",
"returns",
"the",
"answer",
"of",
":",
"is",
... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L825-L843 | [
"def",
"abstract_relational_comparison",
"(",
"self",
",",
"other",
",",
"self_first",
"=",
"True",
")",
":",
"px",
"=",
"self",
".",
"to_primitive",
"(",
"'Number'",
")",
"py",
"=",
"other",
".",
"to_primitive",
"(",
"'Number'",
")",
"if",
"not",
"self_fi... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJs.abstract_equality_comparison | returns the result of JS == compare.
result is PyJs type: bool | js2py/base.py | def abstract_equality_comparison(self, other):
''' returns the result of JS == compare.
result is PyJs type: bool'''
tx, ty = self.TYPE, other.TYPE
if tx == ty:
if tx == 'Undefined' or tx == 'Null':
return true
if tx == 'Number' or tx == 'String... | def abstract_equality_comparison(self, other):
''' returns the result of JS == compare.
result is PyJs type: bool'''
tx, ty = self.TYPE, other.TYPE
if tx == ty:
if tx == 'Undefined' or tx == 'Null':
return true
if tx == 'Number' or tx == 'String... | [
"returns",
"the",
"result",
"of",
"JS",
"==",
"compare",
".",
"result",
"is",
"PyJs",
"type",
":",
"bool"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L873-L899 | [
"def",
"abstract_equality_comparison",
"(",
"self",
",",
"other",
")",
":",
"tx",
",",
"ty",
"=",
"self",
".",
"TYPE",
",",
"other",
".",
"TYPE",
"if",
"tx",
"==",
"ty",
":",
"if",
"tx",
"==",
"'Undefined'",
"or",
"tx",
"==",
"'Null'",
":",
"return",... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJs.callprop | Call a property prop as a method (this will be self).
NOTE: dont pass this and arguments here, these will be added
automatically! | js2py/base.py | def callprop(self, prop, *args):
'''Call a property prop as a method (this will be self).
NOTE: dont pass this and arguments here, these will be added
automatically!'''
if not isinstance(prop, basestring):
prop = prop.to_string().value
cand = self.get(prop)
i... | def callprop(self, prop, *args):
'''Call a property prop as a method (this will be self).
NOTE: dont pass this and arguments here, these will be added
automatically!'''
if not isinstance(prop, basestring):
prop = prop.to_string().value
cand = self.get(prop)
i... | [
"Call",
"a",
"property",
"prop",
"as",
"a",
"method",
"(",
"this",
"will",
"be",
"self",
")",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L984-L995 | [
"def",
"callprop",
"(",
"self",
",",
"prop",
",",
"*",
"args",
")",
":",
"if",
"not",
"isinstance",
"(",
"prop",
",",
"basestring",
")",
":",
"prop",
"=",
"prop",
".",
"to_string",
"(",
")",
".",
"value",
"cand",
"=",
"self",
".",
"get",
"(",
"pr... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJsFunction._set_name | name is py type | js2py/base.py | def _set_name(self, name):
'''name is py type'''
if self.own.get('name'):
self.func_name = name
self.own['name']['value'] = Js(name) | def _set_name(self, name):
'''name is py type'''
if self.own.get('name'):
self.func_name = name
self.own['name']['value'] = Js(name) | [
"name",
"is",
"py",
"type"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L1423-L1427 | [
"def",
"_set_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"own",
".",
"get",
"(",
"'name'",
")",
":",
"self",
".",
"func_name",
"=",
"name",
"self",
".",
"own",
"[",
"'name'",
"]",
"[",
"'value'",
"]",
"=",
"Js",
"(",
"name",
"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJsFunction.call | Calls this function and returns a result
(converted to PyJs type so func can return python types)
this must be a PyJs object and args must be a python tuple of PyJs objects.
arguments object is passed automatically and will be equal to Js(args)
(tuple converted to arguments object).You... | js2py/base.py | def call(self, this, args=()):
'''Calls this function and returns a result
(converted to PyJs type so func can return python types)
this must be a PyJs object and args must be a python tuple of PyJs objects.
arguments object is passed automatically and will be equal to Js(args)
... | def call(self, this, args=()):
'''Calls this function and returns a result
(converted to PyJs type so func can return python types)
this must be a PyJs object and args must be a python tuple of PyJs objects.
arguments object is passed automatically and will be equal to Js(args)
... | [
"Calls",
"this",
"function",
"and",
"returns",
"a",
"result",
"(",
"converted",
"to",
"PyJs",
"type",
"so",
"func",
"can",
"return",
"python",
"types",
")"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/base.py#L1437-L1469 | [
"def",
"call",
"(",
"self",
",",
"this",
",",
"args",
"=",
"(",
")",
")",
":",
"if",
"not",
"hasattr",
"(",
"args",
",",
"'__iter__'",
")",
":",
"#get rid of it later",
"args",
"=",
"(",
"args",
",",
")",
"args",
"=",
"tuple",
"(",
"Js",
"(",
"e"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | remove_functions | removes functions and returns new source, and 2 dicts.
first dict with removed hoisted(global) functions and second with replaced inline functions | js2py/legecy_translators/functions.py | def remove_functions(source, all_inline=False):
"""removes functions and returns new source, and 2 dicts.
first dict with removed hoisted(global) functions and second with replaced inline functions"""
global INLINE_COUNT
inline = {}
hoisted = {}
n = 0
limit = len(source) - 9 # 8 is leng... | def remove_functions(source, all_inline=False):
"""removes functions and returns new source, and 2 dicts.
first dict with removed hoisted(global) functions and second with replaced inline functions"""
global INLINE_COUNT
inline = {}
hoisted = {}
n = 0
limit = len(source) - 9 # 8 is leng... | [
"removes",
"functions",
"and",
"returns",
"new",
"source",
"and",
"2",
"dicts",
".",
"first",
"dict",
"with",
"removed",
"hoisted",
"(",
"global",
")",
"functions",
"and",
"second",
"with",
"replaced",
"inline",
"functions"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/functions.py#L19-L93 | [
"def",
"remove_functions",
"(",
"source",
",",
"all_inline",
"=",
"False",
")",
":",
"global",
"INLINE_COUNT",
"inline",
"=",
"{",
"}",
"hoisted",
"=",
"{",
"}",
"n",
"=",
"0",
"limit",
"=",
"len",
"(",
"source",
")",
"-",
"9",
"# 8 is length of 'functio... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | Space.ConstructArray | note py_arr elems are NOT converted to PyJs types! | js2py/internals/space.py | def ConstructArray(self, py_arr):
''' note py_arr elems are NOT converted to PyJs types!'''
arr = self.NewArray(len(py_arr))
arr._init(py_arr)
return arr | def ConstructArray(self, py_arr):
''' note py_arr elems are NOT converted to PyJs types!'''
arr = self.NewArray(len(py_arr))
arr._init(py_arr)
return arr | [
"note",
"py_arr",
"elems",
"are",
"NOT",
"converted",
"to",
"PyJs",
"types!"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/space.py#L81-L85 | [
"def",
"ConstructArray",
"(",
"self",
",",
"py_arr",
")",
":",
"arr",
"=",
"self",
".",
"NewArray",
"(",
"len",
"(",
"py_arr",
")",
")",
"arr",
".",
"_init",
"(",
"py_arr",
")",
"return",
"arr"
] | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | Space.ConstructObject | note py_obj items are NOT converted to PyJs types! | js2py/internals/space.py | def ConstructObject(self, py_obj):
''' note py_obj items are NOT converted to PyJs types! '''
obj = self.NewObject()
for k, v in py_obj.items():
obj.put(unicode(k), v)
return obj | def ConstructObject(self, py_obj):
''' note py_obj items are NOT converted to PyJs types! '''
obj = self.NewObject()
for k, v in py_obj.items():
obj.put(unicode(k), v)
return obj | [
"note",
"py_obj",
"items",
"are",
"NOT",
"converted",
"to",
"PyJs",
"types!"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/space.py#L87-L92 | [
"def",
"ConstructObject",
"(",
"self",
",",
"py_obj",
")",
":",
"obj",
"=",
"self",
".",
"NewObject",
"(",
")",
"for",
"k",
",",
"v",
"in",
"py_obj",
".",
"items",
"(",
")",
":",
"obj",
".",
"put",
"(",
"unicode",
"(",
"k",
")",
",",
"v",
")",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | Code.emit | Adds op_code with specified args to tape | js2py/internals/code.py | def emit(self, op_code, *args):
''' Adds op_code with specified args to tape '''
self.tape.append(OP_CODES[op_code](*args)) | def emit(self, op_code, *args):
''' Adds op_code with specified args to tape '''
self.tape.append(OP_CODES[op_code](*args)) | [
"Adds",
"op_code",
"with",
"specified",
"args",
"to",
"tape"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/code.py#L34-L36 | [
"def",
"emit",
"(",
"self",
",",
"op_code",
",",
"*",
"args",
")",
":",
"self",
".",
"tape",
".",
"append",
"(",
"OP_CODES",
"[",
"op_code",
"]",
"(",
"*",
"args",
")",
")"
] | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | Code.compile | Records locations of labels and compiles the code | js2py/internals/code.py | def compile(self, start_loc=0):
''' Records locations of labels and compiles the code '''
self.label_locs = {} if self.label_locs is None else self.label_locs
loc = start_loc
while loc < len(self.tape):
if type(self.tape[loc]) == LABEL:
self.label_locs[self.ta... | def compile(self, start_loc=0):
''' Records locations of labels and compiles the code '''
self.label_locs = {} if self.label_locs is None else self.label_locs
loc = start_loc
while loc < len(self.tape):
if type(self.tape[loc]) == LABEL:
self.label_locs[self.ta... | [
"Records",
"locations",
"of",
"labels",
"and",
"compiles",
"the",
"code"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/code.py#L38-L48 | [
"def",
"compile",
"(",
"self",
",",
"start_loc",
"=",
"0",
")",
":",
"self",
".",
"label_locs",
"=",
"{",
"}",
"if",
"self",
".",
"label_locs",
"is",
"None",
"else",
"self",
".",
"label_locs",
"loc",
"=",
"start_loc",
"while",
"loc",
"<",
"len",
"(",... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | Code._call | Calls a bytecode function func
NOTE: use !ONLY! when calling functions from native methods! | js2py/internals/code.py | def _call(self, func, this, args):
''' Calls a bytecode function func
NOTE: use !ONLY! when calling functions from native methods! '''
assert not func.is_native
# fake call - the the runner to return to the end of the file
old_contexts = self.contexts
old_return_locs... | def _call(self, func, this, args):
''' Calls a bytecode function func
NOTE: use !ONLY! when calling functions from native methods! '''
assert not func.is_native
# fake call - the the runner to return to the end of the file
old_contexts = self.contexts
old_return_locs... | [
"Calls",
"a",
"bytecode",
"function",
"func",
"NOTE",
":",
"use",
"!ONLY!",
"when",
"calling",
"functions",
"from",
"native",
"methods!"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/code.py#L50-L74 | [
"def",
"_call",
"(",
"self",
",",
"func",
",",
"this",
",",
"args",
")",
":",
"assert",
"not",
"func",
".",
"is_native",
"# fake call - the the runner to return to the end of the file",
"old_contexts",
"=",
"self",
".",
"contexts",
"old_return_locs",
"=",
"self",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | Code.execute_fragment_under_context | just like run but returns if moved outside of the specified fragment
# 4 different exectution results
# 0=normal, 1=return, 2=jump_outside, 3=errors
# execute_fragment_under_context returns:
# (return_value, typ, return_value/jump_loc/py_error)
# IMPARTANT: It... | js2py/internals/code.py | def execute_fragment_under_context(self, ctx, start_label, end_label):
''' just like run but returns if moved outside of the specified fragment
# 4 different exectution results
# 0=normal, 1=return, 2=jump_outside, 3=errors
# execute_fragment_under_context returns:
... | def execute_fragment_under_context(self, ctx, start_label, end_label):
''' just like run but returns if moved outside of the specified fragment
# 4 different exectution results
# 0=normal, 1=return, 2=jump_outside, 3=errors
# execute_fragment_under_context returns:
... | [
"just",
"like",
"run",
"but",
"returns",
"if",
"moved",
"outside",
"of",
"the",
"specified",
"fragment",
"#",
"4",
"different",
"exectution",
"results",
"#",
"0",
"=",
"normal",
"1",
"=",
"return",
"2",
"=",
"jump_outside",
"3",
"=",
"errors",
"#",
"exec... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/code.py#L76-L104 | [
"def",
"execute_fragment_under_context",
"(",
"self",
",",
"ctx",
",",
"start_label",
",",
"end_label",
")",
":",
"old_curr_ctx",
"=",
"self",
".",
"current_ctx",
"self",
".",
"ctx_depth",
"+=",
"1",
"old_stack_len",
"=",
"len",
"(",
"ctx",
".",
"stack",
")"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | pad | returns n digit string representation of the num | js2py/internals/constructors/jsdate.py | def pad(num, n=2, sign=False):
'''returns n digit string representation of the num'''
s = unicode(abs(num))
if len(s) < n:
s = '0' * (n - len(s)) + s
if not sign:
return s
if num >= 0:
return '+' + s
else:
return '-' + s | def pad(num, n=2, sign=False):
'''returns n digit string representation of the num'''
s = unicode(abs(num))
if len(s) < n:
s = '0' * (n - len(s)) + s
if not sign:
return s
if num >= 0:
return '+' + s
else:
return '-' + s | [
"returns",
"n",
"digit",
"string",
"representation",
"of",
"the",
"num"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/constructors/jsdate.py#L377-L387 | [
"def",
"pad",
"(",
"num",
",",
"n",
"=",
"2",
",",
"sign",
"=",
"False",
")",
":",
"s",
"=",
"unicode",
"(",
"abs",
"(",
"num",
")",
")",
"if",
"len",
"(",
"s",
")",
"<",
"n",
":",
"s",
"=",
"'0'",
"*",
"(",
"n",
"-",
"len",
"(",
"s",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | replacement_template | Takes the replacement template and some info about the match and returns filled template | js2py/internals/prototypes/jsstring.py | def replacement_template(rep, source, span, npar):
"""Takes the replacement template and some info about the match and returns filled template
"""
n = 0
res = ''
while n < len(rep) - 1:
char = rep[n]
if char == '$':
if rep[n + 1] == '$':
res += '$'
... | def replacement_template(rep, source, span, npar):
"""Takes the replacement template and some info about the match and returns filled template
"""
n = 0
res = ''
while n < len(rep) - 1:
char = rep[n]
if char == '$':
if rep[n + 1] == '$':
res += '$'
... | [
"Takes",
"the",
"replacement",
"template",
"and",
"some",
"info",
"about",
"the",
"match",
"and",
"returns",
"filled",
"template"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/prototypes/jsstring.py#L13-L52 | [
"def",
"replacement_template",
"(",
"rep",
",",
"source",
",",
"span",
",",
"npar",
")",
":",
"n",
"=",
"0",
"res",
"=",
"''",
"while",
"n",
"<",
"len",
"(",
"rep",
")",
"-",
"1",
":",
"char",
"=",
"rep",
"[",
"n",
"]",
"if",
"char",
"==",
"'... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | fix_js_args | Use this function when unsure whether func takes this and arguments as its last 2 args.
It will append 2 args if it does not. | js2py/utils/injector.py | def fix_js_args(func):
'''Use this function when unsure whether func takes this and arguments as its last 2 args.
It will append 2 args if it does not.'''
fcode = six.get_function_code(func)
fargs = fcode.co_varnames[fcode.co_argcount - 2:fcode.co_argcount]
if fargs == ('this', 'arguments') or fa... | def fix_js_args(func):
'''Use this function when unsure whether func takes this and arguments as its last 2 args.
It will append 2 args if it does not.'''
fcode = six.get_function_code(func)
fargs = fcode.co_varnames[fcode.co_argcount - 2:fcode.co_argcount]
if fargs == ('this', 'arguments') or fa... | [
"Use",
"this",
"function",
"when",
"unsure",
"whether",
"func",
"takes",
"this",
"and",
"arguments",
"as",
"its",
"last",
"2",
"args",
".",
"It",
"will",
"append",
"2",
"args",
"if",
"it",
"does",
"not",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/utils/injector.py#L20-L33 | [
"def",
"fix_js_args",
"(",
"func",
")",
":",
"fcode",
"=",
"six",
".",
"get_function_code",
"(",
"func",
")",
"fargs",
"=",
"fcode",
".",
"co_varnames",
"[",
"fcode",
".",
"co_argcount",
"-",
"2",
":",
"fcode",
".",
"co_argcount",
"]",
"if",
"fargs",
"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | ByteCodeGenerator.emit | what can be either name of the op, or node, or a list of statements. | js2py/internals/byte_trans.py | def emit(self, what, *args):
''' what can be either name of the op, or node, or a list of statements.'''
if isinstance(what, basestring):
return self.exe.emit(what, *args)
elif isinstance(what, list):
self._emit_statement_list(what)
else:
return getatt... | def emit(self, what, *args):
''' what can be either name of the op, or node, or a list of statements.'''
if isinstance(what, basestring):
return self.exe.emit(what, *args)
elif isinstance(what, list):
self._emit_statement_list(what)
else:
return getatt... | [
"what",
"can",
"be",
"either",
"name",
"of",
"the",
"op",
"or",
"node",
"or",
"a",
"list",
"of",
"statements",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/byte_trans.py#L680-L687 | [
"def",
"emit",
"(",
"self",
",",
"what",
",",
"*",
"args",
")",
":",
"if",
"isinstance",
"(",
"what",
",",
"basestring",
")",
":",
"return",
"self",
".",
"exe",
".",
"emit",
"(",
"what",
",",
"*",
"args",
")",
"elif",
"isinstance",
"(",
"what",
"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | to_key | returns string representation of this object | js2py/translators/translating_nodes.py | def to_key(literal_or_identifier):
''' returns string representation of this object'''
if literal_or_identifier['type'] == 'Identifier':
return literal_or_identifier['name']
elif literal_or_identifier['type'] == 'Literal':
k = literal_or_identifier['value']
if isinstance(k, float):
... | def to_key(literal_or_identifier):
''' returns string representation of this object'''
if literal_or_identifier['type'] == 'Identifier':
return literal_or_identifier['name']
elif literal_or_identifier['type'] == 'Literal':
k = literal_or_identifier['value']
if isinstance(k, float):
... | [
"returns",
"string",
"representation",
"of",
"this",
"object"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/translators/translating_nodes.py#L94-L109 | [
"def",
"to_key",
"(",
"literal_or_identifier",
")",
":",
"if",
"literal_or_identifier",
"[",
"'type'",
"]",
"==",
"'Identifier'",
":",
"return",
"literal_or_identifier",
"[",
"'name'",
"]",
"elif",
"literal_or_identifier",
"[",
"'type'",
"]",
"==",
"'Literal'",
":... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | trans | Translates esprima syntax tree to python by delegating to appropriate translating node | js2py/translators/translating_nodes.py | def trans(ele, standard=False):
"""Translates esprima syntax tree to python by delegating to appropriate translating node"""
try:
node = globals().get(ele['type'])
if not node:
raise NotImplementedError('%s is not supported!' % ele['type'])
if standard:
node = nod... | def trans(ele, standard=False):
"""Translates esprima syntax tree to python by delegating to appropriate translating node"""
try:
node = globals().get(ele['type'])
if not node:
raise NotImplementedError('%s is not supported!' % ele['type'])
if standard:
node = nod... | [
"Translates",
"esprima",
"syntax",
"tree",
"to",
"python",
"by",
"delegating",
"to",
"appropriate",
"translating",
"node"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/translators/translating_nodes.py#L112-L124 | [
"def",
"trans",
"(",
"ele",
",",
"standard",
"=",
"False",
")",
":",
"try",
":",
"node",
"=",
"globals",
"(",
")",
".",
"get",
"(",
"ele",
"[",
"'type'",
"]",
")",
"if",
"not",
"node",
":",
"raise",
"NotImplementedError",
"(",
"'%s is not supported!'",... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | limited | Decorator limiting resulting line length in order to avoid python parser stack overflow -
If expression longer than LINE_LEN_LIMIT characters then it will be moved to upper line
USE ONLY ON EXPRESSIONS!!! | js2py/translators/translating_nodes.py | def limited(func):
'''Decorator limiting resulting line length in order to avoid python parser stack overflow -
If expression longer than LINE_LEN_LIMIT characters then it will be moved to upper line
USE ONLY ON EXPRESSIONS!!! '''
def f(standard=False, **args):
insert_pos = len(
... | def limited(func):
'''Decorator limiting resulting line length in order to avoid python parser stack overflow -
If expression longer than LINE_LEN_LIMIT characters then it will be moved to upper line
USE ONLY ON EXPRESSIONS!!! '''
def f(standard=False, **args):
insert_pos = len(
... | [
"Decorator",
"limiting",
"resulting",
"line",
"length",
"in",
"order",
"to",
"avoid",
"python",
"parser",
"stack",
"overflow",
"-",
"If",
"expression",
"longer",
"than",
"LINE_LEN_LIMIT",
"characters",
"then",
"it",
"will",
"be",
"moved",
"to",
"upper",
"line",
... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/translators/translating_nodes.py#L127-L150 | [
"def",
"limited",
"(",
"func",
")",
":",
"def",
"f",
"(",
"standard",
"=",
"False",
",",
"*",
"*",
"args",
")",
":",
"insert_pos",
"=",
"len",
"(",
"inline_stack",
".",
"names",
")",
"# in case line is longer than limit we will have to insert the lval at current p... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | is_lval | Does not chceck whether t is not resticted or internal | js2py/legecy_translators/utils.py | def is_lval(t):
"""Does not chceck whether t is not resticted or internal"""
if not t:
return False
i = iter(t)
if i.next() not in IDENTIFIER_START:
return False
return all(e in IDENTIFIER_PART for e in i) | def is_lval(t):
"""Does not chceck whether t is not resticted or internal"""
if not t:
return False
i = iter(t)
if i.next() not in IDENTIFIER_START:
return False
return all(e in IDENTIFIER_PART for e in i) | [
"Does",
"not",
"chceck",
"whether",
"t",
"is",
"not",
"resticted",
"or",
"internal"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/utils.py#L6-L13 | [
"def",
"is_lval",
"(",
"t",
")",
":",
"if",
"not",
"t",
":",
"return",
"False",
"i",
"=",
"iter",
"(",
"t",
")",
"if",
"i",
".",
"next",
"(",
")",
"not",
"in",
"IDENTIFIER_START",
":",
"return",
"False",
"return",
"all",
"(",
"e",
"in",
"IDENTIFI... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | is_valid_lval | Checks whether t is valid JS identifier name (no keyword like var, function, if etc)
Also returns false on internal | js2py/legecy_translators/utils.py | def is_valid_lval(t):
"""Checks whether t is valid JS identifier name (no keyword like var, function, if etc)
Also returns false on internal"""
if not is_internal(t) and is_lval(t) and t not in RESERVED_NAMES:
return True
return False | def is_valid_lval(t):
"""Checks whether t is valid JS identifier name (no keyword like var, function, if etc)
Also returns false on internal"""
if not is_internal(t) and is_lval(t) and t not in RESERVED_NAMES:
return True
return False | [
"Checks",
"whether",
"t",
"is",
"valid",
"JS",
"identifier",
"name",
"(",
"no",
"keyword",
"like",
"var",
"function",
"if",
"etc",
")",
"Also",
"returns",
"false",
"on",
"internal"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/utils.py#L16-L21 | [
"def",
"is_valid_lval",
"(",
"t",
")",
":",
"if",
"not",
"is_internal",
"(",
"t",
")",
"and",
"is_lval",
"(",
"t",
")",
"and",
"t",
"not",
"in",
"RESERVED_NAMES",
":",
"return",
"True",
"return",
"False"
] | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | translate_js | js has to be a javascript source code.
returns equivalent python code. | js2py/translators/translator.py | def translate_js(js, HEADER=DEFAULT_HEADER, use_compilation_plan=False):
"""js has to be a javascript source code.
returns equivalent python code."""
if use_compilation_plan and not '//' in js and not '/*' in js:
return translate_js_with_compilation_plan(js, HEADER=HEADER)
parser = pyjsparser... | def translate_js(js, HEADER=DEFAULT_HEADER, use_compilation_plan=False):
"""js has to be a javascript source code.
returns equivalent python code."""
if use_compilation_plan and not '//' in js and not '/*' in js:
return translate_js_with_compilation_plan(js, HEADER=HEADER)
parser = pyjsparser... | [
"js",
"has",
"to",
"be",
"a",
"javascript",
"source",
"code",
".",
"returns",
"equivalent",
"python",
"code",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/translators/translator.py#L59-L70 | [
"def",
"translate_js",
"(",
"js",
",",
"HEADER",
"=",
"DEFAULT_HEADER",
",",
"use_compilation_plan",
"=",
"False",
")",
":",
"if",
"use_compilation_plan",
"and",
"not",
"'//'",
"in",
"js",
"and",
"not",
"'/*'",
"in",
"js",
":",
"return",
"translate_js_with_com... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | translate_js_with_compilation_plan | js has to be a javascript source code.
returns equivalent python code.
compile plans only work with the following restrictions:
- only enabled for oneliner expressions
- when there are comments in the js code string substitution is disabled
- when there nested escaped quotes string s... | js2py/translators/translator.py | def translate_js_with_compilation_plan(js, HEADER=DEFAULT_HEADER):
"""js has to be a javascript source code.
returns equivalent python code.
compile plans only work with the following restrictions:
- only enabled for oneliner expressions
- when there are comments in the js code string s... | def translate_js_with_compilation_plan(js, HEADER=DEFAULT_HEADER):
"""js has to be a javascript source code.
returns equivalent python code.
compile plans only work with the following restrictions:
- only enabled for oneliner expressions
- when there are comments in the js code string s... | [
"js",
"has",
"to",
"be",
"a",
"javascript",
"source",
"code",
".",
"returns",
"equivalent",
"python",
"code",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/translators/translator.py#L114-L158 | [
"def",
"translate_js_with_compilation_plan",
"(",
"js",
",",
"HEADER",
"=",
"DEFAULT_HEADER",
")",
":",
"match_increaser_str",
",",
"match_increaser_num",
",",
"compilation_plan",
"=",
"get_compilation_plan",
"(",
"js",
")",
"cp_hash",
"=",
"hashlib",
".",
"md5",
"(... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | import_js | Imports from javascript source file.
globals is your globals() | js2py/evaljs.py | def import_js(path, lib_name, globals):
"""Imports from javascript source file.
globals is your globals()"""
with codecs.open(path_as_local(path), "r", "utf-8") as f:
js = f.read()
e = EvalJs()
e.execute(js)
var = e.context['var']
globals[lib_name] = var.to_python() | def import_js(path, lib_name, globals):
"""Imports from javascript source file.
globals is your globals()"""
with codecs.open(path_as_local(path), "r", "utf-8") as f:
js = f.read()
e = EvalJs()
e.execute(js)
var = e.context['var']
globals[lib_name] = var.to_python() | [
"Imports",
"from",
"javascript",
"source",
"file",
".",
"globals",
"is",
"your",
"globals",
"()"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L32-L40 | [
"def",
"import_js",
"(",
"path",
",",
"lib_name",
",",
"globals",
")",
":",
"with",
"codecs",
".",
"open",
"(",
"path_as_local",
"(",
"path",
")",
",",
"\"r\"",
",",
"\"utf-8\"",
")",
"as",
"f",
":",
"js",
"=",
"f",
".",
"read",
"(",
")",
"e",
"=... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | translate_file | Translates input JS file to python and saves the it to the output path.
It appends some convenience code at the end so that it is easy to import JS objects.
For example we have a file 'example.js' with: var a = function(x) {return x}
translate_file('example.js', 'example.py')
Now example.py can be e... | js2py/evaljs.py | def translate_file(input_path, output_path):
'''
Translates input JS file to python and saves the it to the output path.
It appends some convenience code at the end so that it is easy to import JS objects.
For example we have a file 'example.js' with: var a = function(x) {return x}
translate_file... | def translate_file(input_path, output_path):
'''
Translates input JS file to python and saves the it to the output path.
It appends some convenience code at the end so that it is easy to import JS objects.
For example we have a file 'example.js' with: var a = function(x) {return x}
translate_file... | [
"Translates",
"input",
"JS",
"file",
"to",
"python",
"and",
"saves",
"the",
"it",
"to",
"the",
"output",
"path",
".",
"It",
"appends",
"some",
"convenience",
"code",
"at",
"the",
"end",
"so",
"that",
"it",
"is",
"easy",
"to",
"import",
"JS",
"objects",
... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L60-L81 | [
"def",
"translate_file",
"(",
"input_path",
",",
"output_path",
")",
":",
"js",
"=",
"get_file_contents",
"(",
"input_path",
")",
"py_code",
"=",
"translate_js",
"(",
"js",
")",
"lib_name",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"output_path",
")",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | run_file | Context must be EvalJS object. Runs given path as a JS program. Returns (eval_value, context). | js2py/evaljs.py | def run_file(path_or_file, context=None):
''' Context must be EvalJS object. Runs given path as a JS program. Returns (eval_value, context).
'''
if context is None:
context = EvalJs()
if not isinstance(context, EvalJs):
raise TypeError('context must be the instance of EvalJs')
eval_v... | def run_file(path_or_file, context=None):
''' Context must be EvalJS object. Runs given path as a JS program. Returns (eval_value, context).
'''
if context is None:
context = EvalJs()
if not isinstance(context, EvalJs):
raise TypeError('context must be the instance of EvalJs')
eval_v... | [
"Context",
"must",
"be",
"EvalJS",
"object",
".",
"Runs",
"given",
"path",
"as",
"a",
"JS",
"program",
".",
"Returns",
"(",
"eval_value",
"context",
")",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L84-L92 | [
"def",
"run_file",
"(",
"path_or_file",
",",
"context",
"=",
"None",
")",
":",
"if",
"context",
"is",
"None",
":",
"context",
"=",
"EvalJs",
"(",
")",
"if",
"not",
"isinstance",
"(",
"context",
",",
"EvalJs",
")",
":",
"raise",
"TypeError",
"(",
"'cont... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | EvalJs.execute | executes javascript js in current context
During initial execute() the converted js is cached for re-use. That means next time you
run the same javascript snippet you save many instructions needed to parse and convert the
js code to python code.
This cache causes minor overhead (a cach... | js2py/evaljs.py | def execute(self, js=None, use_compilation_plan=False):
"""executes javascript js in current context
During initial execute() the converted js is cached for re-use. That means next time you
run the same javascript snippet you save many instructions needed to parse and convert the
js cod... | def execute(self, js=None, use_compilation_plan=False):
"""executes javascript js in current context
During initial execute() the converted js is cached for re-use. That means next time you
run the same javascript snippet you save many instructions needed to parse and convert the
js cod... | [
"executes",
"javascript",
"js",
"in",
"current",
"context"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L160-L185 | [
"def",
"execute",
"(",
"self",
",",
"js",
"=",
"None",
",",
"use_compilation_plan",
"=",
"False",
")",
":",
"try",
":",
"cache",
"=",
"self",
".",
"__dict__",
"[",
"'cache'",
"]",
"except",
"KeyError",
":",
"cache",
"=",
"self",
".",
"__dict__",
"[",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | EvalJs.eval | evaluates expression in current context and returns its value | js2py/evaljs.py | def eval(self, expression, use_compilation_plan=False):
"""evaluates expression in current context and returns its value"""
code = 'PyJsEvalResult = eval(%s)' % json.dumps(expression)
self.execute(code, use_compilation_plan=use_compilation_plan)
return self['PyJsEvalResult'] | def eval(self, expression, use_compilation_plan=False):
"""evaluates expression in current context and returns its value"""
code = 'PyJsEvalResult = eval(%s)' % json.dumps(expression)
self.execute(code, use_compilation_plan=use_compilation_plan)
return self['PyJsEvalResult'] | [
"evaluates",
"expression",
"in",
"current",
"context",
"and",
"returns",
"its",
"value"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L187-L191 | [
"def",
"eval",
"(",
"self",
",",
"expression",
",",
"use_compilation_plan",
"=",
"False",
")",
":",
"code",
"=",
"'PyJsEvalResult = eval(%s)'",
"%",
"json",
".",
"dumps",
"(",
"expression",
")",
"self",
".",
"execute",
"(",
"code",
",",
"use_compilation_plan",... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | EvalJs.execute_debug | executes javascript js in current context
as opposed to the (faster) self.execute method, you can use your regular debugger
to set breakpoints and inspect the generated python code | js2py/evaljs.py | def execute_debug(self, js):
"""executes javascript js in current context
as opposed to the (faster) self.execute method, you can use your regular debugger
to set breakpoints and inspect the generated python code
"""
code = translate_js(js, '')
# make sure you have a temp... | def execute_debug(self, js):
"""executes javascript js in current context
as opposed to the (faster) self.execute method, you can use your regular debugger
to set breakpoints and inspect the generated python code
"""
code = translate_js(js, '')
# make sure you have a temp... | [
"executes",
"javascript",
"js",
"in",
"current",
"context",
"as",
"opposed",
"to",
"the",
"(",
"faster",
")",
"self",
".",
"execute",
"method",
"you",
"can",
"use",
"your",
"regular",
"debugger",
"to",
"set",
"breakpoints",
"and",
"inspect",
"the",
"generate... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L193-L216 | [
"def",
"execute_debug",
"(",
"self",
",",
"js",
")",
":",
"code",
"=",
"translate_js",
"(",
"js",
",",
"''",
")",
"# make sure you have a temp folder:",
"filename",
"=",
"'temp'",
"+",
"os",
".",
"sep",
"+",
"'_'",
"+",
"hashlib",
".",
"md5",
"(",
"code"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | EvalJs.eval_debug | evaluates expression in current context and returns its value
as opposed to the (faster) self.execute method, you can use your regular debugger
to set breakpoints and inspect the generated python code | js2py/evaljs.py | def eval_debug(self, expression):
"""evaluates expression in current context and returns its value
as opposed to the (faster) self.execute method, you can use your regular debugger
to set breakpoints and inspect the generated python code
"""
code = 'PyJsEvalResult = eval(%s)' % j... | def eval_debug(self, expression):
"""evaluates expression in current context and returns its value
as opposed to the (faster) self.execute method, you can use your regular debugger
to set breakpoints and inspect the generated python code
"""
code = 'PyJsEvalResult = eval(%s)' % j... | [
"evaluates",
"expression",
"in",
"current",
"context",
"and",
"returns",
"its",
"value",
"as",
"opposed",
"to",
"the",
"(",
"faster",
")",
"self",
".",
"execute",
"method",
"you",
"can",
"use",
"your",
"regular",
"debugger",
"to",
"set",
"breakpoints",
"and"... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L218-L225 | [
"def",
"eval_debug",
"(",
"self",
",",
"expression",
")",
":",
"code",
"=",
"'PyJsEvalResult = eval(%s)'",
"%",
"json",
".",
"dumps",
"(",
"expression",
")",
"self",
".",
"execute_debug",
"(",
"code",
")",
"return",
"self",
"[",
"'PyJsEvalResult'",
"]"
] | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | EvalJs.console | starts to interact (starts interactive console) Something like code.InteractiveConsole | js2py/evaljs.py | def console(self):
"""starts to interact (starts interactive console) Something like code.InteractiveConsole"""
while True:
if six.PY2:
code = raw_input('>>> ')
else:
code = input('>>>')
try:
print(self.eval(code))
... | def console(self):
"""starts to interact (starts interactive console) Something like code.InteractiveConsole"""
while True:
if six.PY2:
code = raw_input('>>> ')
else:
code = input('>>>')
try:
print(self.eval(code))
... | [
"starts",
"to",
"interact",
"(",
"starts",
"interactive",
"console",
")",
"Something",
"like",
"code",
".",
"InteractiveConsole"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/evaljs.py#L239-L256 | [
"def",
"console",
"(",
"self",
")",
":",
"while",
"True",
":",
"if",
"six",
".",
"PY2",
":",
"code",
"=",
"raw_input",
"(",
"'>>> '",
")",
"else",
":",
"code",
"=",
"input",
"(",
"'>>>'",
")",
"try",
":",
"print",
"(",
"self",
".",
"eval",
"(",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | to_key | returns string representation of this object | js2py/internals/trans_utils.py | def to_key(literal_or_identifier):
''' returns string representation of this object'''
if literal_or_identifier['type'] == 'Identifier':
return literal_or_identifier['name']
elif literal_or_identifier['type'] == 'Literal':
k = literal_or_identifier['value']
if isinstance(k, float):
... | def to_key(literal_or_identifier):
''' returns string representation of this object'''
if literal_or_identifier['type'] == 'Identifier':
return literal_or_identifier['name']
elif literal_or_identifier['type'] == 'Literal':
k = literal_or_identifier['value']
if isinstance(k, float):
... | [
"returns",
"string",
"representation",
"of",
"this",
"object"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/trans_utils.py#L8-L23 | [
"def",
"to_key",
"(",
"literal_or_identifier",
")",
":",
"if",
"literal_or_identifier",
"[",
"'type'",
"]",
"==",
"'Identifier'",
":",
"return",
"literal_or_identifier",
"[",
"'name'",
"]",
"elif",
"literal_or_identifier",
"[",
"'type'",
"]",
"==",
"'Literal'",
":... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | translate_js | js has to be a javascript source code.
returns equivalent python code. | js2py/legecy_translators/translator.py | def translate_js(js, top=TOP_GLOBAL):
"""js has to be a javascript source code.
returns equivalent python code."""
# Remove constant literals
no_const, constants = remove_constants(js)
#print 'const count', len(constants)
# Remove object literals
no_obj, objects, obj_count = remove_object... | def translate_js(js, top=TOP_GLOBAL):
"""js has to be a javascript source code.
returns equivalent python code."""
# Remove constant literals
no_const, constants = remove_constants(js)
#print 'const count', len(constants)
# Remove object literals
no_obj, objects, obj_count = remove_object... | [
"js",
"has",
"to",
"be",
"a",
"javascript",
"source",
"code",
".",
"returns",
"equivalent",
"python",
"code",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/translator.py#L10-L70 | [
"def",
"translate_js",
"(",
"js",
",",
"top",
"=",
"TOP_GLOBAL",
")",
":",
"# Remove constant literals",
"no_const",
",",
"constants",
"=",
"remove_constants",
"(",
"js",
")",
"#print 'const count', len(constants)",
"# Remove object literals",
"no_obj",
",",
"objects",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | translate_func | Translates functions and all nested functions to Python code.
name - name of that function (global functions will be available under var while
inline will be available directly under this name )
block - code of the function (*with* brackets {} )
args - arguments that this function take... | js2py/legecy_translators/translator.py | def translate_func(name, block, args):
"""Translates functions and all nested functions to Python code.
name - name of that function (global functions will be available under var while
inline will be available directly under this name )
block - code of the function (*with* brackets {} )
... | def translate_func(name, block, args):
"""Translates functions and all nested functions to Python code.
name - name of that function (global functions will be available under var while
inline will be available directly under this name )
block - code of the function (*with* brackets {} )
... | [
"Translates",
"functions",
"and",
"all",
"nested",
"functions",
"to",
"Python",
"code",
".",
"name",
"-",
"name",
"of",
"that",
"function",
"(",
"global",
"functions",
"will",
"be",
"available",
"under",
"var",
"while",
"inline",
"will",
"be",
"available",
"... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/translator.py#L73-L117 | [
"def",
"translate_func",
"(",
"name",
",",
"block",
",",
"args",
")",
":",
"inline",
"=",
"name",
".",
"startswith",
"(",
"'PyJsLvalInline'",
")",
"real_name",
"=",
"''",
"if",
"inline",
":",
"name",
",",
"real_name",
"=",
"name",
".",
"split",
"(",
"'... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | pass_bracket | Returns content of brackets with brackets and first pos after brackets
if source[start] is followed by some optional white space and brackets.
Otherwise None | js2py/legecy_translators/jsparser.py | def pass_bracket(source, start, bracket='()'):
"""Returns content of brackets with brackets and first pos after brackets
if source[start] is followed by some optional white space and brackets.
Otherwise None"""
e = bracket_split(source[start:], [bracket], False)
try:
cand = e.next()
ex... | def pass_bracket(source, start, bracket='()'):
"""Returns content of brackets with brackets and first pos after brackets
if source[start] is followed by some optional white space and brackets.
Otherwise None"""
e = bracket_split(source[start:], [bracket], False)
try:
cand = e.next()
ex... | [
"Returns",
"content",
"of",
"brackets",
"with",
"brackets",
"and",
"first",
"pos",
"after",
"brackets",
"if",
"source",
"[",
"start",
"]",
"is",
"followed",
"by",
"some",
"optional",
"white",
"space",
"and",
"brackets",
".",
"Otherwise",
"None"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L125-L143 | [
"def",
"pass_bracket",
"(",
"source",
",",
"start",
",",
"bracket",
"=",
"'()'",
")",
":",
"e",
"=",
"bracket_split",
"(",
"source",
"[",
"start",
":",
"]",
",",
"[",
"bracket",
"]",
",",
"False",
")",
"try",
":",
"cand",
"=",
"e",
".",
"next",
"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | except_token | Token can be only a single char. Returns position after token if found. Otherwise raises syntax error if throw
otherwise returns None | js2py/legecy_translators/jsparser.py | def except_token(source, start, token, throw=True):
"""Token can be only a single char. Returns position after token if found. Otherwise raises syntax error if throw
otherwise returns None"""
start = pass_white(source, start)
if start < len(source) and source[start] == token:
return start + 1
... | def except_token(source, start, token, throw=True):
"""Token can be only a single char. Returns position after token if found. Otherwise raises syntax error if throw
otherwise returns None"""
start = pass_white(source, start)
if start < len(source) and source[start] == token:
return start + 1
... | [
"Token",
"can",
"be",
"only",
"a",
"single",
"char",
".",
"Returns",
"position",
"after",
"token",
"if",
"found",
".",
"Otherwise",
"raises",
"syntax",
"error",
"if",
"throw",
"otherwise",
"returns",
"None"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L176-L184 | [
"def",
"except_token",
"(",
"source",
",",
"start",
",",
"token",
",",
"throw",
"=",
"True",
")",
":",
"start",
"=",
"pass_white",
"(",
"source",
",",
"start",
")",
"if",
"start",
"<",
"len",
"(",
"source",
")",
"and",
"source",
"[",
"start",
"]",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | except_keyword | Returns position after keyword if found else None
Note: skips white space | js2py/legecy_translators/jsparser.py | def except_keyword(source, start, keyword):
""" Returns position after keyword if found else None
Note: skips white space"""
start = pass_white(source, start)
kl = len(keyword) #keyword len
if kl + start > len(source):
return None
if source[start:start + kl] != keyword:
retu... | def except_keyword(source, start, keyword):
""" Returns position after keyword if found else None
Note: skips white space"""
start = pass_white(source, start)
kl = len(keyword) #keyword len
if kl + start > len(source):
return None
if source[start:start + kl] != keyword:
retu... | [
"Returns",
"position",
"after",
"keyword",
"if",
"found",
"else",
"None",
"Note",
":",
"skips",
"white",
"space"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L187-L198 | [
"def",
"except_keyword",
"(",
"source",
",",
"start",
",",
"keyword",
")",
":",
"start",
"=",
"pass_white",
"(",
"source",
",",
"start",
")",
"kl",
"=",
"len",
"(",
"keyword",
")",
"#keyword len",
"if",
"kl",
"+",
"start",
">",
"len",
"(",
"source",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | parse_identifier | passes white space from start and returns first identifier,
if identifier invalid and throw raises SyntaxError otherwise returns None | js2py/legecy_translators/jsparser.py | def parse_identifier(source, start, throw=True):
"""passes white space from start and returns first identifier,
if identifier invalid and throw raises SyntaxError otherwise returns None"""
start = pass_white(source, start)
end = start
if not end < len(source):
if throw:
raise ... | def parse_identifier(source, start, throw=True):
"""passes white space from start and returns first identifier,
if identifier invalid and throw raises SyntaxError otherwise returns None"""
start = pass_white(source, start)
end = start
if not end < len(source):
if throw:
raise ... | [
"passes",
"white",
"space",
"from",
"start",
"and",
"returns",
"first",
"identifier",
"if",
"identifier",
"invalid",
"and",
"throw",
"raises",
"SyntaxError",
"otherwise",
"returns",
"None"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L201-L222 | [
"def",
"parse_identifier",
"(",
"source",
",",
"start",
",",
"throw",
"=",
"True",
")",
":",
"start",
"=",
"pass_white",
"(",
"source",
",",
"start",
")",
"end",
"=",
"start",
"if",
"not",
"end",
"<",
"len",
"(",
"source",
")",
":",
"if",
"throw",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | argsplit | used to split JS args (it is not that simple as it seems because
sep can be inside brackets).
pass args *without* brackets!
Used also to parse array and object elements, and more | js2py/legecy_translators/jsparser.py | def argsplit(args, sep=','):
"""used to split JS args (it is not that simple as it seems because
sep can be inside brackets).
pass args *without* brackets!
Used also to parse array and object elements, and more"""
parsed_len = 0
last = 0
splits = []
for e in bracket_split(args... | def argsplit(args, sep=','):
"""used to split JS args (it is not that simple as it seems because
sep can be inside brackets).
pass args *without* brackets!
Used also to parse array and object elements, and more"""
parsed_len = 0
last = 0
splits = []
for e in bracket_split(args... | [
"used",
"to",
"split",
"JS",
"args",
"(",
"it",
"is",
"not",
"that",
"simple",
"as",
"it",
"seems",
"because",
"sep",
"can",
"be",
"inside",
"brackets",
")",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L225-L243 | [
"def",
"argsplit",
"(",
"args",
",",
"sep",
"=",
"','",
")",
":",
"parsed_len",
"=",
"0",
"last",
"=",
"0",
"splits",
"=",
"[",
"]",
"for",
"e",
"in",
"bracket_split",
"(",
"args",
",",
"brackets",
"=",
"[",
"'()'",
",",
"'[]'",
",",
"'{}'",
"]",... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | split_add_ops | Specialized function splitting text at add/sub operators.
Operands are *not* translated. Example result ['op1', '+', 'op2', '-', 'op3'] | js2py/legecy_translators/jsparser.py | def split_add_ops(text):
"""Specialized function splitting text at add/sub operators.
Operands are *not* translated. Example result ['op1', '+', 'op2', '-', 'op3']"""
n = 0
text = text.replace('++', '##').replace(
'--', '@@') #text does not normally contain any of these
spotted = False # s... | def split_add_ops(text):
"""Specialized function splitting text at add/sub operators.
Operands are *not* translated. Example result ['op1', '+', 'op2', '-', 'op3']"""
n = 0
text = text.replace('++', '##').replace(
'--', '@@') #text does not normally contain any of these
spotted = False # s... | [
"Specialized",
"function",
"splitting",
"text",
"at",
"add",
"/",
"sub",
"operators",
".",
"Operands",
"are",
"*",
"not",
"*",
"translated",
".",
"Example",
"result",
"[",
"op1",
"+",
"op2",
"-",
"op3",
"]"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L246-L267 | [
"def",
"split_add_ops",
"(",
"text",
")",
":",
"n",
"=",
"0",
"text",
"=",
"text",
".",
"replace",
"(",
"'++'",
",",
"'##'",
")",
".",
"replace",
"(",
"'--'",
",",
"'@@'",
")",
"#text does not normally contain any of these",
"spotted",
"=",
"False",
"# set... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | split_at_any | doc | js2py/legecy_translators/jsparser.py | def split_at_any(text,
lis,
translate=False,
not_before=[],
not_after=[],
validitate=None):
""" doc """
lis.sort(key=lambda x: len(x), reverse=True)
last = 0
n = 0
text_len = len(text)
while n < text_len:
... | def split_at_any(text,
lis,
translate=False,
not_before=[],
not_after=[],
validitate=None):
""" doc """
lis.sort(key=lambda x: len(x), reverse=True)
last = 0
n = 0
text_len = len(text)
while n < text_len:
... | [
"doc"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L270-L305 | [
"def",
"split_at_any",
"(",
"text",
",",
"lis",
",",
"translate",
"=",
"False",
",",
"not_before",
"=",
"[",
"]",
",",
"not_after",
"=",
"[",
"]",
",",
"validitate",
"=",
"None",
")",
":",
"lis",
".",
"sort",
"(",
"key",
"=",
"lambda",
"x",
":",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | split_at_single | Works like text.split(sep) but separated fragments
cant end with not_before or start with not_after | js2py/legecy_translators/jsparser.py | def split_at_single(text, sep, not_before=[], not_after=[]):
"""Works like text.split(sep) but separated fragments
cant end with not_before or start with not_after"""
n = 0
lt, s = len(text), len(sep)
last = 0
while n < lt:
if not s + n > lt:
if sep == text[n:n + s]:
... | def split_at_single(text, sep, not_before=[], not_after=[]):
"""Works like text.split(sep) but separated fragments
cant end with not_before or start with not_after"""
n = 0
lt, s = len(text), len(sep)
last = 0
while n < lt:
if not s + n > lt:
if sep == text[n:n + s]:
... | [
"Works",
"like",
"text",
".",
"split",
"(",
"sep",
")",
"but",
"separated",
"fragments",
"cant",
"end",
"with",
"not_before",
"or",
"start",
"with",
"not_after"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/jsparser.py#L308-L326 | [
"def",
"split_at_single",
"(",
"text",
",",
"sep",
",",
"not_before",
"=",
"[",
"]",
",",
"not_after",
"=",
"[",
"]",
")",
":",
"n",
"=",
"0",
"lt",
",",
"s",
"=",
"len",
"(",
"text",
")",
",",
"len",
"(",
"sep",
")",
"last",
"=",
"0",
"while... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | to_arr | Returns Python array from Js array | js2py/prototypes/jsarray.py | def to_arr(this):
"""Returns Python array from Js array"""
return [this.get(str(e)) for e in xrange(len(this))] | def to_arr(this):
"""Returns Python array from Js array"""
return [this.get(str(e)) for e in xrange(len(this))] | [
"Returns",
"Python",
"array",
"from",
"Js",
"array"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/prototypes/jsarray.py#L8-L10 | [
"def",
"to_arr",
"(",
"this",
")",
":",
"return",
"[",
"this",
".",
"get",
"(",
"str",
"(",
"e",
")",
")",
"for",
"e",
"in",
"xrange",
"(",
"len",
"(",
"this",
")",
")",
"]"
] | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | transform_crap | Transforms this ?: crap into if else python syntax | js2py/legecy_translators/nodevisitor.py | def transform_crap(code): #needs some more tests
"""Transforms this ?: crap into if else python syntax"""
ind = code.rfind('?')
if ind == -1:
return code
sep = code.find(':', ind)
if sep == -1:
raise SyntaxError('Invalid ?: syntax (probably missing ":" )')
beg = max(code.rfind('... | def transform_crap(code): #needs some more tests
"""Transforms this ?: crap into if else python syntax"""
ind = code.rfind('?')
if ind == -1:
return code
sep = code.find(':', ind)
if sep == -1:
raise SyntaxError('Invalid ?: syntax (probably missing ":" )')
beg = max(code.rfind('... | [
"Transforms",
"this",
"?",
":",
"crap",
"into",
"if",
"else",
"python",
"syntax"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/nodevisitor.py#L501-L514 | [
"def",
"transform_crap",
"(",
"code",
")",
":",
"#needs some more tests",
"ind",
"=",
"code",
".",
"rfind",
"(",
"'?'",
")",
"if",
"ind",
"==",
"-",
"1",
":",
"return",
"code",
"sep",
"=",
"code",
".",
"find",
"(",
"':'",
",",
"ind",
")",
"if",
"se... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | NodeVisitor.rl | performs this operation on a list from *right to left*
op must take 2 args
a,b,c => op(a, op(b, c)) | js2py/legecy_translators/nodevisitor.py | def rl(self, lis, op):
"""performs this operation on a list from *right to left*
op must take 2 args
a,b,c => op(a, op(b, c))"""
it = reversed(lis)
res = trans(it.next())
for e in it:
e = trans(e)
res = op(e, res)
return res | def rl(self, lis, op):
"""performs this operation on a list from *right to left*
op must take 2 args
a,b,c => op(a, op(b, c))"""
it = reversed(lis)
res = trans(it.next())
for e in it:
e = trans(e)
res = op(e, res)
return res | [
"performs",
"this",
"operation",
"on",
"a",
"list",
"from",
"*",
"right",
"to",
"left",
"*",
"op",
"must",
"take",
"2",
"args",
"a",
"b",
"c",
"=",
">",
"op",
"(",
"a",
"op",
"(",
"b",
"c",
"))"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/nodevisitor.py#L53-L62 | [
"def",
"rl",
"(",
"self",
",",
"lis",
",",
"op",
")",
":",
"it",
"=",
"reversed",
"(",
"lis",
")",
"res",
"=",
"trans",
"(",
"it",
".",
"next",
"(",
")",
")",
"for",
"e",
"in",
"it",
":",
"e",
"=",
"trans",
"(",
"e",
")",
"res",
"=",
"op"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | NodeVisitor.lr | performs this operation on a list from *left to right*
op must take 2 args
a,b,c => op(op(a, b), c) | js2py/legecy_translators/nodevisitor.py | def lr(self, lis, op):
"""performs this operation on a list from *left to right*
op must take 2 args
a,b,c => op(op(a, b), c)"""
it = iter(lis)
res = trans(it.next())
for e in it:
e = trans(e)
res = op(res, e)
return res | def lr(self, lis, op):
"""performs this operation on a list from *left to right*
op must take 2 args
a,b,c => op(op(a, b), c)"""
it = iter(lis)
res = trans(it.next())
for e in it:
e = trans(e)
res = op(res, e)
return res | [
"performs",
"this",
"operation",
"on",
"a",
"list",
"from",
"*",
"left",
"to",
"right",
"*",
"op",
"must",
"take",
"2",
"args",
"a",
"b",
"c",
"=",
">",
"op",
"(",
"op",
"(",
"a",
"b",
")",
"c",
")"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/nodevisitor.py#L64-L73 | [
"def",
"lr",
"(",
"self",
",",
"lis",
",",
"op",
")",
":",
"it",
"=",
"iter",
"(",
"lis",
")",
"res",
"=",
"trans",
"(",
"it",
".",
"next",
"(",
")",
")",
"for",
"e",
"in",
"it",
":",
"e",
"=",
"trans",
"(",
"e",
")",
"res",
"=",
"op",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | NodeVisitor.translate | Translates outer operation and calls translate on inner operation.
Returns fully translated code. | js2py/legecy_translators/nodevisitor.py | def translate(self):
"""Translates outer operation and calls translate on inner operation.
Returns fully translated code."""
if not self.code:
return ''
new = bracket_replace(self.code)
#Check comma operator:
cand = new.split(',') #every comma in new must ... | def translate(self):
"""Translates outer operation and calls translate on inner operation.
Returns fully translated code."""
if not self.code:
return ''
new = bracket_replace(self.code)
#Check comma operator:
cand = new.split(',') #every comma in new must ... | [
"Translates",
"outer",
"operation",
"and",
"calls",
"translate",
"on",
"inner",
"operation",
".",
"Returns",
"fully",
"translated",
"code",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/nodevisitor.py#L75-L261 | [
"def",
"translate",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"code",
":",
"return",
"''",
"new",
"=",
"bracket_replace",
"(",
"self",
".",
"code",
")",
"#Check comma operator:",
"cand",
"=",
"new",
".",
"split",
"(",
"','",
")",
"#every comma in ... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | do_statement | returns none if not found other functions that begin with 'do_' raise
also this do_ type function passes white space | js2py/legecy_translators/flow.py | def do_statement(source, start):
"""returns none if not found other functions that begin with 'do_' raise
also this do_ type function passes white space"""
start = pass_white(source, start)
# start is the fist position after initial start that is not a white space or \n
if not start < len(source): ... | def do_statement(source, start):
"""returns none if not found other functions that begin with 'do_' raise
also this do_ type function passes white space"""
start = pass_white(source, start)
# start is the fist position after initial start that is not a white space or \n
if not start < len(source): ... | [
"returns",
"none",
"if",
"not",
"found",
"other",
"functions",
"that",
"begin",
"with",
"do_",
"raise",
"also",
"this",
"do_",
"type",
"function",
"passes",
"white",
"space"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/flow.py#L74-L99 | [
"def",
"do_statement",
"(",
"source",
",",
"start",
")",
":",
"start",
"=",
"pass_white",
"(",
"source",
",",
"start",
")",
"# start is the fist position after initial start that is not a white space or \\n",
"if",
"not",
"start",
"<",
"len",
"(",
"source",
")",
":"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJsRegExp.match | string is of course a py string | js2py/internals/base.py | def match(self, string, pos):
'''string is of course a py string'''
return self.pat.match(string, int(pos)) | def match(self, string, pos):
'''string is of course a py string'''
return self.pat.match(string, int(pos)) | [
"string",
"is",
"of",
"course",
"a",
"py",
"string"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/base.py#L577-L579 | [
"def",
"match",
"(",
"self",
",",
"string",
",",
"pos",
")",
":",
"return",
"self",
".",
"pat",
".",
"match",
"(",
"string",
",",
"int",
"(",
"pos",
")",
")"
] | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | PyJsFunction.call | Dont use this method from inside bytecode to call other bytecode. | js2py/internals/base.py | def call(self, this, args=()):
''' Dont use this method from inside bytecode to call other bytecode. '''
if self.is_native:
_args = SpaceTuple(
args
) # we have to do that unfortunately to pass all the necessary info to the funcs
_args.space = self.sp... | def call(self, this, args=()):
''' Dont use this method from inside bytecode to call other bytecode. '''
if self.is_native:
_args = SpaceTuple(
args
) # we have to do that unfortunately to pass all the necessary info to the funcs
_args.space = self.sp... | [
"Dont",
"use",
"this",
"method",
"from",
"inside",
"bytecode",
"to",
"call",
"other",
"bytecode",
"."
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/base.py#L864-L876 | [
"def",
"call",
"(",
"self",
",",
"this",
",",
"args",
"=",
"(",
")",
")",
":",
"if",
"self",
".",
"is_native",
":",
"_args",
"=",
"SpaceTuple",
"(",
"args",
")",
"# we have to do that unfortunately to pass all the necessary info to the funcs",
"_args",
".",
"spa... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | is_empty_object | n may be the inside of block or object | js2py/legecy_translators/objects.py | def is_empty_object(n, last):
"""n may be the inside of block or object"""
if n.strip():
return False
# seems to be but can be empty code
last = last.strip()
markers = {
')',
';',
}
if not last or last[-1] in markers:
return False
return True | def is_empty_object(n, last):
"""n may be the inside of block or object"""
if n.strip():
return False
# seems to be but can be empty code
last = last.strip()
markers = {
')',
';',
}
if not last or last[-1] in markers:
return False
return True | [
"n",
"may",
"be",
"the",
"inside",
"of",
"block",
"or",
"object"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/objects.py#L23-L35 | [
"def",
"is_empty_object",
"(",
"n",
",",
"last",
")",
":",
"if",
"n",
".",
"strip",
"(",
")",
":",
"return",
"False",
"# seems to be but can be empty code",
"last",
"=",
"last",
".",
"strip",
"(",
")",
"markers",
"=",
"{",
"')'",
",",
"';'",
",",
"}",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | is_object | n may be the inside of block or object.
last is the code before object | js2py/legecy_translators/objects.py | def is_object(n, last):
"""n may be the inside of block or object.
last is the code before object"""
if is_empty_object(n, last):
return True
if not n.strip():
return False
#Object contains lines of code so it cant be an object
if len(argsplit(n, ';')) > 1:
return Fals... | def is_object(n, last):
"""n may be the inside of block or object.
last is the code before object"""
if is_empty_object(n, last):
return True
if not n.strip():
return False
#Object contains lines of code so it cant be an object
if len(argsplit(n, ';')) > 1:
return Fals... | [
"n",
"may",
"be",
"the",
"inside",
"of",
"block",
"or",
"object",
".",
"last",
"is",
"the",
"code",
"before",
"object"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/objects.py#L39-L79 | [
"def",
"is_object",
"(",
"n",
",",
"last",
")",
":",
"if",
"is_empty_object",
"(",
"n",
",",
"last",
")",
":",
"return",
"True",
"if",
"not",
"n",
".",
"strip",
"(",
")",
":",
"return",
"False",
"#Object contains lines of code so it cant be an object",
"if",... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | remove_objects | This function replaces objects with OBJECTS_LVALS, returns new code, replacement dict and count.
count arg is the number that should be added to the LVAL of the first replaced object | js2py/legecy_translators/objects.py | def remove_objects(code, count=1):
""" This function replaces objects with OBJECTS_LVALS, returns new code, replacement dict and count.
count arg is the number that should be added to the LVAL of the first replaced object
"""
replacements = {} #replacement dict
br = bracket_split(code, ['{}', '... | def remove_objects(code, count=1):
""" This function replaces objects with OBJECTS_LVALS, returns new code, replacement dict and count.
count arg is the number that should be added to the LVAL of the first replaced object
"""
replacements = {} #replacement dict
br = bracket_split(code, ['{}', '... | [
"This",
"function",
"replaces",
"objects",
"with",
"OBJECTS_LVALS",
"returns",
"new",
"code",
"replacement",
"dict",
"and",
"count",
".",
"count",
"arg",
"is",
"the",
"number",
"that",
"should",
"be",
"added",
"to",
"the",
"LVAL",
"of",
"the",
"first",
"repl... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/objects.py#L93-L126 | [
"def",
"remove_objects",
"(",
"code",
",",
"count",
"=",
"1",
")",
":",
"replacements",
"=",
"{",
"}",
"#replacement dict",
"br",
"=",
"bracket_split",
"(",
"code",
",",
"[",
"'{}'",
",",
"'[]'",
"]",
")",
"res",
"=",
"''",
"last",
"=",
"''",
"for",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | remove_arrays | removes arrays and replaces them with ARRAY_LVALS
returns new code and replacement dict
*NOTE* has to be called AFTER remove objects | js2py/legecy_translators/objects.py | def remove_arrays(code, count=1):
"""removes arrays and replaces them with ARRAY_LVALS
returns new code and replacement dict
*NOTE* has to be called AFTER remove objects"""
res = ''
last = ''
replacements = {}
for e in bracket_split(code, ['[]']):
if e[0] == '[':
if... | def remove_arrays(code, count=1):
"""removes arrays and replaces them with ARRAY_LVALS
returns new code and replacement dict
*NOTE* has to be called AFTER remove objects"""
res = ''
last = ''
replacements = {}
for e in bracket_split(code, ['[]']):
if e[0] == '[':
if... | [
"removes",
"arrays",
"and",
"replaces",
"them",
"with",
"ARRAY_LVALS",
"returns",
"new",
"code",
"and",
"replacement",
"dict",
"*",
"NOTE",
"*",
"has",
"to",
"be",
"called",
"AFTER",
"remove",
"objects"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/objects.py#L129-L150 | [
"def",
"remove_arrays",
"(",
"code",
",",
"count",
"=",
"1",
")",
":",
"res",
"=",
"''",
"last",
"=",
"''",
"replacements",
"=",
"{",
"}",
"for",
"e",
"in",
"bracket_split",
"(",
"code",
",",
"[",
"'[]'",
"]",
")",
":",
"if",
"e",
"[",
"0",
"]"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | translate_array | array has to be any js array for example [1,2,3]
lval has to be name of this array.
Returns python code that adds lval to the PY scope it should be put before lval | js2py/legecy_translators/objects.py | def translate_array(array, lval, obj_count=1, arr_count=1):
"""array has to be any js array for example [1,2,3]
lval has to be name of this array.
Returns python code that adds lval to the PY scope it should be put before lval"""
array = array[1:-1]
array, obj_rep, obj_count = remove_objects(a... | def translate_array(array, lval, obj_count=1, arr_count=1):
"""array has to be any js array for example [1,2,3]
lval has to be name of this array.
Returns python code that adds lval to the PY scope it should be put before lval"""
array = array[1:-1]
array, obj_rep, obj_count = remove_objects(a... | [
"array",
"has",
"to",
"be",
"any",
"js",
"array",
"for",
"example",
"[",
"1",
"2",
"3",
"]",
"lval",
"has",
"to",
"be",
"name",
"of",
"this",
"array",
".",
"Returns",
"python",
"code",
"that",
"adds",
"lval",
"to",
"the",
"PY",
"scope",
"it",
"shou... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/objects.py#L251-L288 | [
"def",
"translate_array",
"(",
"array",
",",
"lval",
",",
"obj_count",
"=",
"1",
",",
"arr_count",
"=",
"1",
")",
":",
"array",
"=",
"array",
"[",
"1",
":",
"-",
"1",
"]",
"array",
",",
"obj_rep",
",",
"obj_count",
"=",
"remove_objects",
"(",
"array"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | _ensure_regexp | returns True if regexp starts at n else returns False
checks whether it is not a division | js2py/legecy_translators/constants.py | def _ensure_regexp(source, n): #<- this function has to be improved
'''returns True if regexp starts at n else returns False
checks whether it is not a division '''
markers = '(+~"\'=[%:?!*^|&-,;/\\'
k = 0
while True:
k += 1
if n - k < 0:
return True
char = sou... | def _ensure_regexp(source, n): #<- this function has to be improved
'''returns True if regexp starts at n else returns False
checks whether it is not a division '''
markers = '(+~"\'=[%:?!*^|&-,;/\\'
k = 0
while True:
k += 1
if n - k < 0:
return True
char = sou... | [
"returns",
"True",
"if",
"regexp",
"starts",
"at",
"n",
"else",
"returns",
"False",
"checks",
"whether",
"it",
"is",
"not",
"a",
"division"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/constants.py#L28-L42 | [
"def",
"_ensure_regexp",
"(",
"source",
",",
"n",
")",
":",
"#<- this function has to be improved",
"markers",
"=",
"'(+~\"\\'=[%:?!*^|&-,;/\\\\'",
"k",
"=",
"0",
"while",
"True",
":",
"k",
"+=",
"1",
"if",
"n",
"-",
"k",
"<",
"0",
":",
"return",
"True",
"... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | parse_num | Returns a first index>=start of chat not in charset | js2py/legecy_translators/constants.py | def parse_num(source, start, charset):
"""Returns a first index>=start of chat not in charset"""
while start < len(source) and source[start] in charset:
start += 1
return start | def parse_num(source, start, charset):
"""Returns a first index>=start of chat not in charset"""
while start < len(source) and source[start] in charset:
start += 1
return start | [
"Returns",
"a",
"first",
"index",
">",
"=",
"start",
"of",
"chat",
"not",
"in",
"charset"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/constants.py#L45-L49 | [
"def",
"parse_num",
"(",
"source",
",",
"start",
",",
"charset",
")",
":",
"while",
"start",
"<",
"len",
"(",
"source",
")",
"and",
"source",
"[",
"start",
"]",
"in",
"charset",
":",
"start",
"+=",
"1",
"return",
"start"
] | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | parse_exponent | returns end of exponential, raises SyntaxError if failed | js2py/legecy_translators/constants.py | def parse_exponent(source, start):
"""returns end of exponential, raises SyntaxError if failed"""
if not source[start] in {'e', 'E'}:
if source[start] in IDENTIFIER_PART:
raise SyntaxError('Invalid number literal!')
return start
start += 1
if source[start] in {'-', '+'}:
... | def parse_exponent(source, start):
"""returns end of exponential, raises SyntaxError if failed"""
if not source[start] in {'e', 'E'}:
if source[start] in IDENTIFIER_PART:
raise SyntaxError('Invalid number literal!')
return start
start += 1
if source[start] in {'-', '+'}:
... | [
"returns",
"end",
"of",
"exponential",
"raises",
"SyntaxError",
"if",
"failed"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/constants.py#L52-L68 | [
"def",
"parse_exponent",
"(",
"source",
",",
"start",
")",
":",
"if",
"not",
"source",
"[",
"start",
"]",
"in",
"{",
"'e'",
",",
"'E'",
"}",
":",
"if",
"source",
"[",
"start",
"]",
"in",
"IDENTIFIER_PART",
":",
"raise",
"SyntaxError",
"(",
"'Invalid nu... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | remove_constants | Replaces Strings and Regexp literals in the source code with
identifiers and *removes comments*. Identifier is of the format:
PyJsStringConst(String const number)_ - for Strings
PyJsRegExpConst(RegExp const number)_ - for RegExps
Returns dict which relates identifier and replaced constant.... | js2py/legecy_translators/constants.py | def remove_constants(source):
'''Replaces Strings and Regexp literals in the source code with
identifiers and *removes comments*. Identifier is of the format:
PyJsStringConst(String const number)_ - for Strings
PyJsRegExpConst(RegExp const number)_ - for RegExps
Returns dict which rela... | def remove_constants(source):
'''Replaces Strings and Regexp literals in the source code with
identifiers and *removes comments*. Identifier is of the format:
PyJsStringConst(String const number)_ - for Strings
PyJsRegExpConst(RegExp const number)_ - for RegExps
Returns dict which rela... | [
"Replaces",
"Strings",
"and",
"Regexp",
"literals",
"in",
"the",
"source",
"code",
"with",
"identifiers",
"and",
"*",
"removes",
"comments",
"*",
".",
"Identifier",
"is",
"of",
"the",
"format",
":"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/constants.py#L71-L219 | [
"def",
"remove_constants",
"(",
"source",
")",
":",
"source",
"=",
"' '",
"+",
"source",
"+",
"'\\n'",
"comments",
"=",
"[",
"]",
"inside_comment",
",",
"single_comment",
"=",
"False",
",",
"False",
"inside_single",
",",
"inside_double",
"=",
"False",
",",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | recover_constants | Converts identifiers representing Js constants to the PyJs constants
PyJsNumberConst_1_ which has the true value of 5 will be converted to PyJsNumber(5) | js2py/legecy_translators/constants.py | def recover_constants(py_source,
replacements): #now has n^2 complexity. improve to n
'''Converts identifiers representing Js constants to the PyJs constants
PyJsNumberConst_1_ which has the true value of 5 will be converted to PyJsNumber(5)'''
for identifier, value in replacements.it... | def recover_constants(py_source,
replacements): #now has n^2 complexity. improve to n
'''Converts identifiers representing Js constants to the PyJs constants
PyJsNumberConst_1_ which has the true value of 5 will be converted to PyJsNumber(5)'''
for identifier, value in replacements.it... | [
"Converts",
"identifiers",
"representing",
"Js",
"constants",
"to",
"the",
"PyJs",
"constants",
"PyJsNumberConst_1_",
"which",
"has",
"the",
"true",
"value",
"of",
"5",
"will",
"be",
"converted",
"to",
"PyJsNumber",
"(",
"5",
")"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/constants.py#L222-L235 | [
"def",
"recover_constants",
"(",
"py_source",
",",
"replacements",
")",
":",
"#now has n^2 complexity. improve to n",
"for",
"identifier",
",",
"value",
"in",
"replacements",
".",
"iteritems",
"(",
")",
":",
"if",
"identifier",
".",
"startswith",
"(",
"'PyJsConstant... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | unify_string_literals | this function parses the string just like javascript
for example literal '\d' in JavaScript would be interpreted
as 'd' - backslash would be ignored and in Pyhon this
would be interpreted as '\\d' This function fixes this problem. | js2py/legecy_translators/constants.py | def unify_string_literals(js_string):
"""this function parses the string just like javascript
for example literal '\d' in JavaScript would be interpreted
as 'd' - backslash would be ignored and in Pyhon this
would be interpreted as '\\d' This function fixes this problem."""
n = 0
res = ... | def unify_string_literals(js_string):
"""this function parses the string just like javascript
for example literal '\d' in JavaScript would be interpreted
as 'd' - backslash would be ignored and in Pyhon this
would be interpreted as '\\d' This function fixes this problem."""
n = 0
res = ... | [
"this",
"function",
"parses",
"the",
"string",
"just",
"like",
"javascript",
"for",
"example",
"literal",
"\\",
"d",
"in",
"JavaScript",
"would",
"be",
"interpreted",
"as",
"d",
"-",
"backslash",
"would",
"be",
"ignored",
"and",
"in",
"Pyhon",
"this",
"would... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/constants.py#L238-L254 | [
"def",
"unify_string_literals",
"(",
"js_string",
")",
":",
"n",
"=",
"0",
"res",
"=",
"''",
"limit",
"=",
"len",
"(",
"js_string",
")",
"while",
"n",
"<",
"limit",
":",
"char",
"=",
"js_string",
"[",
"n",
"]",
"if",
"char",
"==",
"'\\\\'",
":",
"n... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | do_escape | Its actually quite complicated to cover every case :)
http://www.javascriptkit.com/jsref/escapesequence.shtml | js2py/legecy_translators/constants.py | def do_escape(source, n):
"""Its actually quite complicated to cover every case :)
http://www.javascriptkit.com/jsref/escapesequence.shtml"""
if not n + 1 < len(source):
return '' # not possible here but can be possible in general case.
if source[n + 1] in LINE_TERMINATOR:
if source[... | def do_escape(source, n):
"""Its actually quite complicated to cover every case :)
http://www.javascriptkit.com/jsref/escapesequence.shtml"""
if not n + 1 < len(source):
return '' # not possible here but can be possible in general case.
if source[n + 1] in LINE_TERMINATOR:
if source[... | [
"Its",
"actually",
"quite",
"complicated",
"to",
"cover",
"every",
"case",
":",
")",
"http",
":",
"//",
"www",
".",
"javascriptkit",
".",
"com",
"/",
"jsref",
"/",
"escapesequence",
".",
"shtml"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/legecy_translators/constants.py#L261-L298 | [
"def",
"do_escape",
"(",
"source",
",",
"n",
")",
":",
"if",
"not",
"n",
"+",
"1",
"<",
"len",
"(",
"source",
")",
":",
"return",
"''",
"# not possible here but can be possible in general case.",
"if",
"source",
"[",
"n",
"+",
"1",
"]",
"in",
"LINE_TERMINA... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | abstract_relational_comparison | self<other if self_first else other<self.
Returns the result of the question: is self smaller than other?
in case self_first is false it returns the answer of:
is other smaller than self.
result is PyJs type: bool or undefined | js2py/internals/operations.py | def abstract_relational_comparison(self, other,
self_first=True): # todo speed up!
''' self<other if self_first else other<self.
Returns the result of the question: is self smaller than other?
in case self_first is false it returns the answer of:
... | def abstract_relational_comparison(self, other,
self_first=True): # todo speed up!
''' self<other if self_first else other<self.
Returns the result of the question: is self smaller than other?
in case self_first is false it returns the answer of:
... | [
"self<other",
"if",
"self_first",
"else",
"other<self",
".",
"Returns",
"the",
"result",
"of",
"the",
"question",
":",
"is",
"self",
"smaller",
"than",
"other?",
"in",
"case",
"self_first",
"is",
"false",
"it",
"returns",
"the",
"answer",
"of",
":",
"is",
... | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/operations.py#L169-L189 | [
"def",
"abstract_relational_comparison",
"(",
"self",
",",
"other",
",",
"self_first",
"=",
"True",
")",
":",
"# todo speed up!",
"px",
"=",
"to_primitive",
"(",
"self",
",",
"'Number'",
")",
"py",
"=",
"to_primitive",
"(",
"other",
",",
"'Number'",
")",
"if... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | abstract_equality_op | returns the result of JS == compare.
result is PyJs type: bool | js2py/internals/operations.py | def abstract_equality_op(self, other):
''' returns the result of JS == compare.
result is PyJs type: bool'''
tx, ty = Type(self), Type(other)
if tx == ty:
if tx == 'Undefined' or tx == 'Null':
return True
if tx == 'Number' or tx == 'String' or tx == 'Boolean':
... | def abstract_equality_op(self, other):
''' returns the result of JS == compare.
result is PyJs type: bool'''
tx, ty = Type(self), Type(other)
if tx == ty:
if tx == 'Undefined' or tx == 'Null':
return True
if tx == 'Number' or tx == 'String' or tx == 'Boolean':
... | [
"returns",
"the",
"result",
"of",
"JS",
"==",
"compare",
".",
"result",
"is",
"PyJs",
"type",
":",
"bool"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/operations.py#L227-L253 | [
"def",
"abstract_equality_op",
"(",
"self",
",",
"other",
")",
":",
"tx",
",",
"ty",
"=",
"Type",
"(",
"self",
")",
",",
"Type",
"(",
"other",
")",
"if",
"tx",
"==",
"ty",
":",
"if",
"tx",
"==",
"'Undefined'",
"or",
"tx",
"==",
"'Null'",
":",
"re... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | in_op | checks if self is in other | js2py/internals/operations.py | def in_op(self, other):
'''checks if self is in other'''
if not is_object(other):
raise MakeError(
'TypeError',
"You can\'t use 'in' operator to search in non-objects")
return other.has_property(to_string(self)) | def in_op(self, other):
'''checks if self is in other'''
if not is_object(other):
raise MakeError(
'TypeError',
"You can\'t use 'in' operator to search in non-objects")
return other.has_property(to_string(self)) | [
"checks",
"if",
"self",
"is",
"in",
"other"
] | PiotrDabkowski/Js2Py | python | https://github.com/PiotrDabkowski/Js2Py/blob/c0fa43f5679cf91ca8986c5747fcb07a433dc584/js2py/internals/operations.py#L283-L289 | [
"def",
"in_op",
"(",
"self",
",",
"other",
")",
":",
"if",
"not",
"is_object",
"(",
"other",
")",
":",
"raise",
"MakeError",
"(",
"'TypeError'",
",",
"\"You can\\'t use 'in' operator to search in non-objects\"",
")",
"return",
"other",
".",
"has_property",
"(",
... | c0fa43f5679cf91ca8986c5747fcb07a433dc584 |
valid | maybe_download_and_extract | Download and extract processed data and embeddings. | examples/treelstm/main.py | def maybe_download_and_extract():
"""Download and extract processed data and embeddings."""
dest_directory = '.'
filename = DATA_URL.split('/')[-1]
filepath = os.path.join(dest_directory, filename)
if not os.path.exists(filepath):
def _progress(count, block_size, total_size):
sys.stdout.write('\r>> ... | def maybe_download_and_extract():
"""Download and extract processed data and embeddings."""
dest_directory = '.'
filename = DATA_URL.split('/')[-1]
filepath = os.path.join(dest_directory, filename)
if not os.path.exists(filepath):
def _progress(count, block_size, total_size):
sys.stdout.write('\r>> ... | [
"Download",
"and",
"extract",
"processed",
"data",
"and",
"embeddings",
"."
] | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/examples/treelstm/main.py#L24-L42 | [
"def",
"maybe_download_and_extract",
"(",
")",
":",
"dest_directory",
"=",
"'.'",
"filename",
"=",
"DATA_URL",
".",
"split",
"(",
"'/'",
")",
"[",
"-",
"1",
"]",
"filepath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dest_directory",
",",
"filename",
")"... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | make_network_graph | Make a network graph, represented as of nodes and a set of edges.
The nodes are represented as tuples: (name: string, input_dim: Dim, label: string, output_dim: Dim, children: set[name], features: string)
# The edges are represented as dict of children to sets of parents: (child: string) -> [(parent: string, feat... | python/dynet_viz.py | def make_network_graph(compact, expression_names, lookup_names):
"""
Make a network graph, represented as of nodes and a set of edges.
The nodes are represented as tuples: (name: string, input_dim: Dim, label: string, output_dim: Dim, children: set[name], features: string)
# The edges are represented as dict ... | def make_network_graph(compact, expression_names, lookup_names):
"""
Make a network graph, represented as of nodes and a set of edges.
The nodes are represented as tuples: (name: string, input_dim: Dim, label: string, output_dim: Dim, children: set[name], features: string)
# The edges are represented as dict ... | [
"Make",
"a",
"network",
"graph",
"represented",
"as",
"of",
"nodes",
"and",
"a",
"set",
"of",
"edges",
".",
"The",
"nodes",
"are",
"represented",
"as",
"tuples",
":",
"(",
"name",
":",
"string",
"input_dim",
":",
"Dim",
"label",
":",
"string",
"output_di... | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/python/dynet_viz.py#L775-L947 | [
"def",
"make_network_graph",
"(",
"compact",
",",
"expression_names",
",",
"lookup_names",
")",
":",
"nodes",
"=",
"set",
"(",
")",
"# edges = defaultdict(set) # parent -> (child, extra)",
"var_name_dict",
"=",
"dict",
"(",
")",
"if",
"expression_names",
":",
"for",... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | BiRNNBuilder.add_inputs | returns the list of state pairs (stateF, stateB) obtained by adding
inputs to both forward (stateF) and backward (stateB) RNNs.
@param es: a list of Expression
see also transduce(xs)
.transduce(xs) is different from .add_inputs(xs) in the following way:
.add_inputs(xs)... | python/dynet_viz.py | def add_inputs(self, es):
"""
returns the list of state pairs (stateF, stateB) obtained by adding
inputs to both forward (stateF) and backward (stateB) RNNs.
@param es: a list of Expression
see also transduce(xs)
.transduce(xs) is different from .add_inputs(xs) in t... | def add_inputs(self, es):
"""
returns the list of state pairs (stateF, stateB) obtained by adding
inputs to both forward (stateF) and backward (stateB) RNNs.
@param es: a list of Expression
see also transduce(xs)
.transduce(xs) is different from .add_inputs(xs) in t... | [
"returns",
"the",
"list",
"of",
"state",
"pairs",
"(",
"stateF",
"stateB",
")",
"obtained",
"by",
"adding",
"inputs",
"to",
"both",
"forward",
"(",
"stateF",
")",
"and",
"backward",
"(",
"stateB",
")",
"RNNs",
"."
] | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/python/dynet_viz.py#L566-L594 | [
"def",
"add_inputs",
"(",
"self",
",",
"es",
")",
":",
"for",
"e",
"in",
"es",
":",
"ensure_freshness",
"(",
"e",
")",
"for",
"(",
"fb",
",",
"bb",
")",
"in",
"self",
".",
"builder_layers",
"[",
":",
"-",
"1",
"]",
":",
"fs",
"=",
"fb",
".",
... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | BiRNNBuilder.transduce | returns the list of output Expressions obtained by adding the given inputs
to the current state, one by one, to both the forward and backward RNNs,
and concatenating.
@param es: a list of Expression
see also add_inputs(xs)
.transduce(xs) is different from .add_inputs(... | python/dynet_viz.py | def transduce(self, es):
"""
returns the list of output Expressions obtained by adding the given inputs
to the current state, one by one, to both the forward and backward RNNs,
and concatenating.
@param es: a list of Expression
see also add_inputs(xs)
... | def transduce(self, es):
"""
returns the list of output Expressions obtained by adding the given inputs
to the current state, one by one, to both the forward and backward RNNs,
and concatenating.
@param es: a list of Expression
see also add_inputs(xs)
... | [
"returns",
"the",
"list",
"of",
"output",
"Expressions",
"obtained",
"by",
"adding",
"the",
"given",
"inputs",
"to",
"the",
"current",
"state",
"one",
"by",
"one",
"to",
"both",
"the",
"forward",
"and",
"backward",
"RNNs",
"and",
"concatenating",
".",
"@para... | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/python/dynet_viz.py#L596-L622 | [
"def",
"transduce",
"(",
"self",
",",
"es",
")",
":",
"for",
"e",
"in",
"es",
":",
"ensure_freshness",
"(",
"e",
")",
"for",
"(",
"fb",
",",
"bb",
")",
"in",
"self",
".",
"builder_layers",
":",
"fs",
"=",
"fb",
".",
"initial_state",
"(",
")",
"."... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | StackedRNNState.add_inputs | returns the list of states obtained by adding the given inputs
to the current state, one by one. | python/dynet_viz.py | def add_inputs(self, xs):
"""
returns the list of states obtained by adding the given inputs
to the current state, one by one.
"""
states = []
cur = self
for x in xs:
cur = cur.add_input(x)
states.append(cur)
return states | def add_inputs(self, xs):
"""
returns the list of states obtained by adding the given inputs
to the current state, one by one.
"""
states = []
cur = self
for x in xs:
cur = cur.add_input(x)
states.append(cur)
return states | [
"returns",
"the",
"list",
"of",
"states",
"obtained",
"by",
"adding",
"the",
"given",
"inputs",
"to",
"the",
"current",
"state",
"one",
"by",
"one",
"."
] | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/python/dynet_viz.py#L681-L691 | [
"def",
"add_inputs",
"(",
"self",
",",
"xs",
")",
":",
"states",
"=",
"[",
"]",
"cur",
"=",
"self",
"for",
"x",
"in",
"xs",
":",
"cur",
"=",
"cur",
".",
"add_input",
"(",
"x",
")",
"states",
".",
"append",
"(",
"cur",
")",
"return",
"states"
] | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | load_mnist | wget -O - http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz | gunzip > train-images-idx3-ubyte
wget -O - http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz | gunzip > train-labels-idx1-ubyte
wget -O - http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz | gunzip > t10k-images-idx3-ubyte... | examples/variational-autoencoder/basic-image-recon/utils.py | def load_mnist(dataset, path):
"""
wget -O - http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz | gunzip > train-images-idx3-ubyte
wget -O - http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz | gunzip > train-labels-idx1-ubyte
wget -O - http://yann.lecun.com/exdb/mnist/t10k-images-idx3... | def load_mnist(dataset, path):
"""
wget -O - http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz | gunzip > train-images-idx3-ubyte
wget -O - http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz | gunzip > train-labels-idx1-ubyte
wget -O - http://yann.lecun.com/exdb/mnist/t10k-images-idx3... | [
"wget",
"-",
"O",
"-",
"http",
":",
"//",
"yann",
".",
"lecun",
".",
"com",
"/",
"exdb",
"/",
"mnist",
"/",
"train",
"-",
"images",
"-",
"idx3",
"-",
"ubyte",
".",
"gz",
"|",
"gunzip",
">",
"train",
"-",
"images",
"-",
"idx3",
"-",
"ubyte",
"wg... | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/examples/variational-autoencoder/basic-image-recon/utils.py#L7-L41 | [
"def",
"load_mnist",
"(",
"dataset",
",",
"path",
")",
":",
"if",
"dataset",
"is",
"\"training\"",
":",
"fname_img",
"=",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"\"train-images-idx3-ubyte\"",
")",
"fname_lbl",
"=",
"os",
".",
"path",
".",
"joi... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | make_grid | Make a grid of images, via numpy.
Args:
tensor (Tensor or list): 4D mini-batch Tensor of shape (B x C x H x W)
or a list of images all of the same size.
nrow (int, optional): Number of images displayed in each row of the grid.
The Final grid size is (B / nrow, nrow). Default... | examples/variational-autoencoder/basic-image-recon/utils.py | def make_grid(tensor, nrow=8, padding=2, pad_value=0):
"""Make a grid of images, via numpy.
Args:
tensor (Tensor or list): 4D mini-batch Tensor of shape (B x C x H x W)
or a list of images all of the same size.
nrow (int, optional): Number of images displayed in each row of the grid... | def make_grid(tensor, nrow=8, padding=2, pad_value=0):
"""Make a grid of images, via numpy.
Args:
tensor (Tensor or list): 4D mini-batch Tensor of shape (B x C x H x W)
or a list of images all of the same size.
nrow (int, optional): Number of images displayed in each row of the grid... | [
"Make",
"a",
"grid",
"of",
"images",
"via",
"numpy",
"."
] | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/examples/variational-autoencoder/basic-image-recon/utils.py#L44-L92 | [
"def",
"make_grid",
"(",
"tensor",
",",
"nrow",
"=",
"8",
",",
"padding",
"=",
"2",
",",
"pad_value",
"=",
"0",
")",
":",
"if",
"not",
"(",
"isinstance",
"(",
"tensor",
",",
"np",
".",
"ndarray",
")",
"or",
"(",
"isinstance",
"(",
"tensor",
",",
... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | save_image | Save a given Tensor into an image file.
Args:
tensor (Tensor or list): Image to be saved. If given a mini-batch tensor,
saves the tensor as a grid of images by calling ``make_grid``.
**kwargs: Other arguments are documented in ``make_grid``. | examples/variational-autoencoder/basic-image-recon/utils.py | def save_image(tensor, filename, nrow=8, padding=2, pad_value=0):
"""Save a given Tensor into an image file.
Args:
tensor (Tensor or list): Image to be saved. If given a mini-batch tensor,
saves the tensor as a grid of images by calling ``make_grid``.
**kwargs: Other arguments are d... | def save_image(tensor, filename, nrow=8, padding=2, pad_value=0):
"""Save a given Tensor into an image file.
Args:
tensor (Tensor or list): Image to be saved. If given a mini-batch tensor,
saves the tensor as a grid of images by calling ``make_grid``.
**kwargs: Other arguments are d... | [
"Save",
"a",
"given",
"Tensor",
"into",
"an",
"image",
"file",
"."
] | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/examples/variational-autoencoder/basic-image-recon/utils.py#L101-L112 | [
"def",
"save_image",
"(",
"tensor",
",",
"filename",
",",
"nrow",
"=",
"8",
",",
"padding",
"=",
"2",
",",
"pad_value",
"=",
"0",
")",
":",
"from",
"PIL",
"import",
"Image",
"grid",
"=",
"make_grid",
"(",
"tensor",
",",
"nrow",
"=",
"nrow",
",",
"p... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | pythonize_arguments | Remove types from function arguments in cython | doc/source/doc_util.py | def pythonize_arguments(arg_str):
"""
Remove types from function arguments in cython
"""
out_args = []
# If there aren't any arguments return the empty string
if arg_str is None:
return out_str
args = arg_str.split(',')
for arg in args:
components = arg.split('=')
... | def pythonize_arguments(arg_str):
"""
Remove types from function arguments in cython
"""
out_args = []
# If there aren't any arguments return the empty string
if arg_str is None:
return out_str
args = arg_str.split(',')
for arg in args:
components = arg.split('=')
... | [
"Remove",
"types",
"from",
"function",
"arguments",
"in",
"cython"
] | clab/dynet | python | https://github.com/clab/dynet/blob/21cc62606b74f81bb4b11a9989a6c2bd0caa09c5/doc/source/doc_util.py#L9-L31 | [
"def",
"pythonize_arguments",
"(",
"arg_str",
")",
":",
"out_args",
"=",
"[",
"]",
"# If there aren't any arguments return the empty string",
"if",
"arg_str",
"is",
"None",
":",
"return",
"out_str",
"args",
"=",
"arg_str",
".",
"split",
"(",
"','",
")",
"for",
"... | 21cc62606b74f81bb4b11a9989a6c2bd0caa09c5 |
valid | correspond | Communicate with the child process without closing stdin. | scripts/qemu.py | def correspond(text):
"""Communicate with the child process without closing stdin."""
if text:
subproc.stdin.write(text)
subproc.stdin.flush()
return get_lines() | def correspond(text):
"""Communicate with the child process without closing stdin."""
if text:
subproc.stdin.write(text)
subproc.stdin.flush()
return get_lines() | [
"Communicate",
"with",
"the",
"child",
"process",
"without",
"closing",
"stdin",
"."
] | trailofbits/manticore | python | https://github.com/trailofbits/manticore/blob/54c5a15b1119c523ae54c09972413e8b97f11629/scripts/qemu.py#L91-L96 | [
"def",
"correspond",
"(",
"text",
")",
":",
"if",
"text",
":",
"subproc",
".",
"stdin",
".",
"write",
"(",
"text",
")",
"subproc",
".",
"stdin",
".",
"flush",
"(",
")",
"return",
"get_lines",
"(",
")"
] | 54c5a15b1119c523ae54c09972413e8b97f11629 |
valid | _normalize | Convert a byte-like value into a canonical byte (a value of type 'bytes' of len 1)
:param c:
:return: | manticore/native/memory.py | def _normalize(c):
"""
Convert a byte-like value into a canonical byte (a value of type 'bytes' of len 1)
:param c:
:return:
"""
if isinstance(c, int):
return bytes([c])
elif isinstance(c, str):
return bytes([ord(c)])
else:
return c | def _normalize(c):
"""
Convert a byte-like value into a canonical byte (a value of type 'bytes' of len 1)
:param c:
:return:
"""
if isinstance(c, int):
return bytes([c])
elif isinstance(c, str):
return bytes([ord(c)])
else:
return c | [
"Convert",
"a",
"byte",
"-",
"like",
"value",
"into",
"a",
"canonical",
"byte",
"(",
"a",
"value",
"of",
"type",
"bytes",
"of",
"len",
"1",
")"
] | trailofbits/manticore | python | https://github.com/trailofbits/manticore/blob/54c5a15b1119c523ae54c09972413e8b97f11629/manticore/native/memory.py#L71-L83 | [
"def",
"_normalize",
"(",
"c",
")",
":",
"if",
"isinstance",
"(",
"c",
",",
"int",
")",
":",
"return",
"bytes",
"(",
"[",
"c",
"]",
")",
"elif",
"isinstance",
"(",
"c",
",",
"str",
")",
":",
"return",
"bytes",
"(",
"[",
"ord",
"(",
"c",
")",
... | 54c5a15b1119c523ae54c09972413e8b97f11629 |
valid | Map._set_perms | Sets the access permissions of the map.
:param perms: the new permissions. | manticore/native/memory.py | def _set_perms(self, perms):
"""
Sets the access permissions of the map.
:param perms: the new permissions.
"""
assert isinstance(perms, str) and len(perms) <= 3 and perms.strip() in ['', 'r', 'w', 'x', 'rw', 'r x', 'rx', 'rwx', 'wx', ]
self._perms = perms | def _set_perms(self, perms):
"""
Sets the access permissions of the map.
:param perms: the new permissions.
"""
assert isinstance(perms, str) and len(perms) <= 3 and perms.strip() in ['', 'r', 'w', 'x', 'rw', 'r x', 'rx', 'rwx', 'wx', ]
self._perms = perms | [
"Sets",
"the",
"access",
"permissions",
"of",
"the",
"map",
"."
] | trailofbits/manticore | python | https://github.com/trailofbits/manticore/blob/54c5a15b1119c523ae54c09972413e8b97f11629/manticore/native/memory.py#L120-L127 | [
"def",
"_set_perms",
"(",
"self",
",",
"perms",
")",
":",
"assert",
"isinstance",
"(",
"perms",
",",
"str",
")",
"and",
"len",
"(",
"perms",
")",
"<=",
"3",
"and",
"perms",
".",
"strip",
"(",
")",
"in",
"[",
"''",
",",
"'r'",
",",
"'w'",
",",
"... | 54c5a15b1119c523ae54c09972413e8b97f11629 |
valid | Map.access_ok | Check if there is enough permissions for access | manticore/native/memory.py | def access_ok(self, access):
""" Check if there is enough permissions for access """
for c in access:
if c not in self.perms:
return False
return True | def access_ok(self, access):
""" Check if there is enough permissions for access """
for c in access:
if c not in self.perms:
return False
return True | [
"Check",
"if",
"there",
"is",
"enough",
"permissions",
"for",
"access"
] | trailofbits/manticore | python | https://github.com/trailofbits/manticore/blob/54c5a15b1119c523ae54c09972413e8b97f11629/manticore/native/memory.py#L132-L137 | [
"def",
"access_ok",
"(",
"self",
",",
"access",
")",
":",
"for",
"c",
"in",
"access",
":",
"if",
"c",
"not",
"in",
"self",
".",
"perms",
":",
"return",
"False",
"return",
"True"
] | 54c5a15b1119c523ae54c09972413e8b97f11629 |
valid | Map._in_range | Returns True if index is in range | manticore/native/memory.py | def _in_range(self, index):
""" Returns True if index is in range """
if isinstance(index, slice):
in_range = index.start < index.stop and \
index.start >= self.start and \
index.stop <= self.end
else:
in_range = index >= self.start and \
... | def _in_range(self, index):
""" Returns True if index is in range """
if isinstance(index, slice):
in_range = index.start < index.stop and \
index.start >= self.start and \
index.stop <= self.end
else:
in_range = index >= self.start and \
... | [
"Returns",
"True",
"if",
"index",
"is",
"in",
"range"
] | trailofbits/manticore | python | https://github.com/trailofbits/manticore/blob/54c5a15b1119c523ae54c09972413e8b97f11629/manticore/native/memory.py#L188-L197 | [
"def",
"_in_range",
"(",
"self",
",",
"index",
")",
":",
"if",
"isinstance",
"(",
"index",
",",
"slice",
")",
":",
"in_range",
"=",
"index",
".",
"start",
"<",
"index",
".",
"stop",
"and",
"index",
".",
"start",
">=",
"self",
".",
"start",
"and",
"... | 54c5a15b1119c523ae54c09972413e8b97f11629 |
valid | Map._get_offset | Translates the index to the internal offsets.
self.start -> 0
self.start+1 -> 1
...
self.end -> len(self) | manticore/native/memory.py | def _get_offset(self, index):
"""
Translates the index to the internal offsets.
self.start -> 0
self.start+1 -> 1
...
self.end -> len(self)
"""
if not self._in_range(index):
raise IndexError('Map index out of range')
if isinstanc... | def _get_offset(self, index):
"""
Translates the index to the internal offsets.
self.start -> 0
self.start+1 -> 1
...
self.end -> len(self)
"""
if not self._in_range(index):
raise IndexError('Map index out of range')
if isinstanc... | [
"Translates",
"the",
"index",
"to",
"the",
"internal",
"offsets",
"."
] | trailofbits/manticore | python | https://github.com/trailofbits/manticore/blob/54c5a15b1119c523ae54c09972413e8b97f11629/manticore/native/memory.py#L199-L214 | [
"def",
"_get_offset",
"(",
"self",
",",
"index",
")",
":",
"if",
"not",
"self",
".",
"_in_range",
"(",
"index",
")",
":",
"raise",
"IndexError",
"(",
"'Map index out of range'",
")",
"if",
"isinstance",
"(",
"index",
",",
"slice",
")",
":",
"index",
"=",... | 54c5a15b1119c523ae54c09972413e8b97f11629 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.