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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | PluginManager.add_plugin_arguments | Add plugin arguments to argument parser.
Parameters
----------
parser : argparse.ArgumentParser
The main haas ArgumentParser. | haas/plugin_manager.py | def add_plugin_arguments(self, parser):
"""Add plugin arguments to argument parser.
Parameters
----------
parser : argparse.ArgumentParser
The main haas ArgumentParser.
"""
for manager in self.hook_managers.values():
if len(list(manager)) == 0:
... | def add_plugin_arguments(self, parser):
"""Add plugin arguments to argument parser.
Parameters
----------
parser : argparse.ArgumentParser
The main haas ArgumentParser.
"""
for manager in self.hook_managers.values():
if len(list(manager)) == 0:
... | [
"Add",
"plugin",
"arguments",
"to",
"argument",
"parser",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugin_manager.py#L105-L129 | [
"def",
"add_plugin_arguments",
"(",
"self",
",",
"parser",
")",
":",
"for",
"manager",
"in",
"self",
".",
"hook_managers",
".",
"values",
"(",
")",
":",
"if",
"len",
"(",
"list",
"(",
"manager",
")",
")",
"==",
"0",
":",
"continue",
"manager",
".",
"... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | PluginManager.get_enabled_hook_plugins | Get enabled plugins for specified hook name. | haas/plugin_manager.py | def get_enabled_hook_plugins(self, hook, args, **kwargs):
"""Get enabled plugins for specified hook name.
"""
manager = self.hook_managers[hook]
if len(list(manager)) == 0:
return []
return [
plugin for plugin in manager.map(
self._create_... | def get_enabled_hook_plugins(self, hook, args, **kwargs):
"""Get enabled plugins for specified hook name.
"""
manager = self.hook_managers[hook]
if len(list(manager)) == 0:
return []
return [
plugin for plugin in manager.map(
self._create_... | [
"Get",
"enabled",
"plugins",
"for",
"specified",
"hook",
"name",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugin_manager.py#L131-L142 | [
"def",
"get_enabled_hook_plugins",
"(",
"self",
",",
"hook",
",",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"manager",
"=",
"self",
".",
"hook_managers",
"[",
"hook",
"]",
"if",
"len",
"(",
"list",
"(",
"manager",
")",
")",
"==",
"0",
":",
"return",... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | PluginManager.get_driver | Get mutually-exlusive plugin for plugin namespace. | haas/plugin_manager.py | def get_driver(self, namespace, parsed_args, **kwargs):
"""Get mutually-exlusive plugin for plugin namespace.
"""
option, dest = self._namespace_to_option(namespace)
dest_prefix = '{0}_'.format(dest)
driver_name = getattr(parsed_args, dest, 'default')
driver_extension = ... | def get_driver(self, namespace, parsed_args, **kwargs):
"""Get mutually-exlusive plugin for plugin namespace.
"""
option, dest = self._namespace_to_option(namespace)
dest_prefix = '{0}_'.format(dest)
driver_name = getattr(parsed_args, dest, 'default')
driver_extension = ... | [
"Get",
"mutually",
"-",
"exlusive",
"plugin",
"for",
"plugin",
"namespace",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugin_manager.py#L144-L153 | [
"def",
"get_driver",
"(",
"self",
",",
"namespace",
",",
"parsed_args",
",",
"*",
"*",
"kwargs",
")",
":",
"option",
",",
"dest",
"=",
"self",
".",
"_namespace_to_option",
"(",
"namespace",
")",
"dest_prefix",
"=",
"'{0}_'",
".",
"format",
"(",
"dest",
"... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | Transaction.get_description | Get transaction description (for logging purposes) | bpc8583/transaction.py | def get_description(self):
"""
Get transaction description (for logging purposes)
"""
if self.card:
card_description = self.card.get_description()
else:
card_description = 'Cardless'
if card_description:
card_description += ' | '
... | def get_description(self):
"""
Get transaction description (for logging purposes)
"""
if self.card:
card_description = self.card.get_description()
else:
card_description = 'Cardless'
if card_description:
card_description += ' | '
... | [
"Get",
"transaction",
"description",
"(",
"for",
"logging",
"purposes",
")"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/transaction.py#L196-L208 | [
"def",
"get_description",
"(",
"self",
")",
":",
"if",
"self",
".",
"card",
":",
"card_description",
"=",
"self",
".",
"card",
".",
"get_description",
"(",
")",
"else",
":",
"card_description",
"=",
"'Cardless'",
"if",
"card_description",
":",
"card_descriptio... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | Transaction.set_amount | Set transaction amount | bpc8583/transaction.py | def set_amount(self, amount):
"""
Set transaction amount
"""
if amount:
try:
self.IsoMessage.FieldData(4, int(amount))
except ValueError:
self.IsoMessage.FieldData(4, 0)
self.rebuild() | def set_amount(self, amount):
"""
Set transaction amount
"""
if amount:
try:
self.IsoMessage.FieldData(4, int(amount))
except ValueError:
self.IsoMessage.FieldData(4, 0)
self.rebuild() | [
"Set",
"transaction",
"amount"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/transaction.py#L244-L253 | [
"def",
"set_amount",
"(",
"self",
",",
"amount",
")",
":",
"if",
"amount",
":",
"try",
":",
"self",
".",
"IsoMessage",
".",
"FieldData",
"(",
"4",
",",
"int",
"(",
"amount",
")",
")",
"except",
"ValueError",
":",
"self",
".",
"IsoMessage",
".",
"Fiel... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | Transaction.set_expected_action | Expected outcome of the transaction ('APPROVED' or 'DECLINED') | bpc8583/transaction.py | def set_expected_action(self, expected_response_action):
"""
Expected outcome of the transaction ('APPROVED' or 'DECLINED')
"""
if expected_response_action.upper() not in ['APPROVED', 'APPROVE', 'DECLINED', 'DECLINE']:
return False
self.expected_response_action = exp... | def set_expected_action(self, expected_response_action):
"""
Expected outcome of the transaction ('APPROVED' or 'DECLINED')
"""
if expected_response_action.upper() not in ['APPROVED', 'APPROVE', 'DECLINED', 'DECLINE']:
return False
self.expected_response_action = exp... | [
"Expected",
"outcome",
"of",
"the",
"transaction",
"(",
"APPROVED",
"or",
"DECLINED",
")"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/transaction.py#L263-L271 | [
"def",
"set_expected_action",
"(",
"self",
",",
"expected_response_action",
")",
":",
"if",
"expected_response_action",
".",
"upper",
"(",
")",
"not",
"in",
"[",
"'APPROVED'",
",",
"'APPROVE'",
",",
"'DECLINED'",
",",
"'DECLINE'",
"]",
":",
"return",
"False",
... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | Transaction.build_emv_data | TODO:
95 TVR
82 app_int_prof | bpc8583/transaction.py | def build_emv_data(self):
"""
TODO:
95 TVR
82 app_int_prof
"""
emv_data = ''
emv_data += self.TLV.build({'82': self._get_app_interchange_profile()})
emv_data += self.TLV.build({'9A': get_date()})
emv_data += self.TLV.build({'95': self.term.g... | def build_emv_data(self):
"""
TODO:
95 TVR
82 app_int_prof
"""
emv_data = ''
emv_data += self.TLV.build({'82': self._get_app_interchange_profile()})
emv_data += self.TLV.build({'9A': get_date()})
emv_data += self.TLV.build({'95': self.term.g... | [
"TODO",
":",
"95",
"TVR",
"82",
"app_int_prof"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/transaction.py#L302-L317 | [
"def",
"build_emv_data",
"(",
"self",
")",
":",
"emv_data",
"=",
"''",
"emv_data",
"+=",
"self",
".",
"TLV",
".",
"build",
"(",
"{",
"'82'",
":",
"self",
".",
"_get_app_interchange_profile",
"(",
")",
"}",
")",
"emv_data",
"+=",
"self",
".",
"TLV",
"."... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | Transaction.set_currency | Set transaction currency code from given currency id, e.g. set 840 from 'USD' | bpc8583/transaction.py | def set_currency(self, currency_id):
"""
Set transaction currency code from given currency id, e.g. set 840 from 'USD'
"""
try:
self.currency = currency_codes[currency_id]
self.IsoMessage.FieldData(49, self.currency)
self.rebuild()
except KeyEr... | def set_currency(self, currency_id):
"""
Set transaction currency code from given currency id, e.g. set 840 from 'USD'
"""
try:
self.currency = currency_codes[currency_id]
self.IsoMessage.FieldData(49, self.currency)
self.rebuild()
except KeyEr... | [
"Set",
"transaction",
"currency",
"code",
"from",
"given",
"currency",
"id",
"e",
".",
"g",
".",
"set",
"840",
"from",
"USD"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/transaction.py#L337-L346 | [
"def",
"set_currency",
"(",
"self",
",",
"currency_id",
")",
":",
"try",
":",
"self",
".",
"currency",
"=",
"currency_codes",
"[",
"currency_id",
"]",
"self",
".",
"IsoMessage",
".",
"FieldData",
"(",
"49",
",",
"self",
".",
"currency",
")",
"self",
".",... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | BlockCounts.finalize | Output the aggregate block count results. | hairball/plugins/blocks.py | def finalize(self):
"""Output the aggregate block count results."""
for name, count in sorted(self.blocks.items(), key=lambda x: x[1]):
print('{:3} {}'.format(count, name))
print('{:3} total'.format(sum(self.blocks.values()))) | def finalize(self):
"""Output the aggregate block count results."""
for name, count in sorted(self.blocks.items(), key=lambda x: x[1]):
print('{:3} {}'.format(count, name))
print('{:3} total'.format(sum(self.blocks.values()))) | [
"Output",
"the",
"aggregate",
"block",
"count",
"results",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/blocks.py#L17-L21 | [
"def",
"finalize",
"(",
"self",
")",
":",
"for",
"name",
",",
"count",
"in",
"sorted",
"(",
"self",
".",
"blocks",
".",
"items",
"(",
")",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
"[",
"1",
"]",
")",
":",
"print",
"(",
"'{:3} {}'",
".",
"forma... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | BlockCounts.analyze | Run and return the results from the BlockCounts plugin. | hairball/plugins/blocks.py | def analyze(self, scratch, **kwargs):
"""Run and return the results from the BlockCounts plugin."""
file_blocks = Counter()
for script in self.iter_scripts(scratch):
for name, _, _ in self.iter_blocks(script.blocks):
file_blocks[name] += 1
self.blocks.update(f... | def analyze(self, scratch, **kwargs):
"""Run and return the results from the BlockCounts plugin."""
file_blocks = Counter()
for script in self.iter_scripts(scratch):
for name, _, _ in self.iter_blocks(script.blocks):
file_blocks[name] += 1
self.blocks.update(f... | [
"Run",
"and",
"return",
"the",
"results",
"from",
"the",
"BlockCounts",
"plugin",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/blocks.py#L23-L30 | [
"def",
"analyze",
"(",
"self",
",",
"scratch",
",",
"*",
"*",
"kwargs",
")",
":",
"file_blocks",
"=",
"Counter",
"(",
")",
"for",
"script",
"in",
"self",
".",
"iter_scripts",
"(",
"scratch",
")",
":",
"for",
"name",
",",
"_",
",",
"_",
"in",
"self"... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | DeadCode.analyze | Run and return the results form the DeadCode plugin.
The variable_event indicates that the Scratch file contains at least
one instance of a broadcast event based on a variable. When
variable_event is True, dead code scripts reported by this plugin that
begin with a "when I receive" bloc... | hairball/plugins/blocks.py | def analyze(self, scratch, **kwargs):
"""Run and return the results form the DeadCode plugin.
The variable_event indicates that the Scratch file contains at least
one instance of a broadcast event based on a variable. When
variable_event is True, dead code scripts reported by this plugi... | def analyze(self, scratch, **kwargs):
"""Run and return the results form the DeadCode plugin.
The variable_event indicates that the Scratch file contains at least
one instance of a broadcast event based on a variable. When
variable_event is True, dead code scripts reported by this plugi... | [
"Run",
"and",
"return",
"the",
"results",
"form",
"the",
"DeadCode",
"plugin",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/blocks.py#L43-L65 | [
"def",
"analyze",
"(",
"self",
",",
"scratch",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"total_instances",
"+=",
"1",
"sprites",
"=",
"{",
"}",
"for",
"sprite",
",",
"script",
"in",
"self",
".",
"iter_sprite_scripts",
"(",
"scratch",
")",
":",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | DeadCode.finalize | Output the number of instances that contained dead code. | hairball/plugins/blocks.py | def finalize(self):
"""Output the number of instances that contained dead code."""
if self.total_instances > 1:
print('{} of {} instances contained dead code.'
.format(self.dead_code_instances, self.total_instances)) | def finalize(self):
"""Output the number of instances that contained dead code."""
if self.total_instances > 1:
print('{} of {} instances contained dead code.'
.format(self.dead_code_instances, self.total_instances)) | [
"Output",
"the",
"number",
"of",
"instances",
"that",
"contained",
"dead",
"code",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/blocks.py#L67-L71 | [
"def",
"finalize",
"(",
"self",
")",
":",
"if",
"self",
".",
"total_instances",
">",
"1",
":",
"print",
"(",
"'{} of {} instances contained dead code.'",
".",
"format",
"(",
"self",
".",
"dead_code_instances",
",",
"self",
".",
"total_instances",
")",
")"
] | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | show_help | Show help and basic usage | examples/isoClient.py | def show_help(name):
"""
Show help and basic usage
"""
print('Usage: python3 {} [OPTIONS]... '.format(name))
print('ISO8583 message client')
print(' -v, --verbose\t\tRun transactions verbosely')
print(' -p, --port=[PORT]\t\tTCP port to connect to, 1337 by default')
print(' -s, --serve... | def show_help(name):
"""
Show help and basic usage
"""
print('Usage: python3 {} [OPTIONS]... '.format(name))
print('ISO8583 message client')
print(' -v, --verbose\t\tRun transactions verbosely')
print(' -p, --port=[PORT]\t\tTCP port to connect to, 1337 by default')
print(' -s, --serve... | [
"Show",
"help",
"and",
"basic",
"usage"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/examples/isoClient.py#L301-L314 | [
"def",
"show_help",
"(",
"name",
")",
":",
"print",
"(",
"'Usage: python3 {} [OPTIONS]... '",
".",
"format",
"(",
"name",
")",
")",
"print",
"(",
"'ISO8583 message client'",
")",
"print",
"(",
"' -v, --verbose\\t\\tRun transactions verbosely'",
")",
"print",
"(",
"... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | isoClient._run_interactive | Run transactions interactively (by asking user which transaction to run) | examples/isoClient.py | def _run_interactive(self):
"""
Run transactions interactively (by asking user which transaction to run)
"""
self.term.connect()
self._show_available_transactions()
while True:
trxn_type = self._user_input('\nEnter transaction to send: ')
... | def _run_interactive(self):
"""
Run transactions interactively (by asking user which transaction to run)
"""
self.term.connect()
self._show_available_transactions()
while True:
trxn_type = self._user_input('\nEnter transaction to send: ')
... | [
"Run",
"transactions",
"interactively",
"(",
"by",
"asking",
"user",
"which",
"transaction",
"to",
"run",
")"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/examples/isoClient.py#L92-L138 | [
"def",
"_run_interactive",
"(",
"self",
")",
":",
"self",
".",
"term",
".",
"connect",
"(",
")",
"self",
".",
"_show_available_transactions",
"(",
")",
"while",
"True",
":",
"trxn_type",
"=",
"self",
".",
"_user_input",
"(",
"'\\nEnter transaction to send: '",
... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | find_top_level_directory | Finds the top-level directory of a project given a start directory
inside the project.
Parameters
----------
start_directory : str
The directory in which test discovery will start. | haas/plugins/discoverer.py | def find_top_level_directory(start_directory):
"""Finds the top-level directory of a project given a start directory
inside the project.
Parameters
----------
start_directory : str
The directory in which test discovery will start.
"""
top_level = start_directory
while os.path.i... | def find_top_level_directory(start_directory):
"""Finds the top-level directory of a project given a start directory
inside the project.
Parameters
----------
start_directory : str
The directory in which test discovery will start.
"""
top_level = start_directory
while os.path.i... | [
"Finds",
"the",
"top",
"-",
"level",
"directory",
"of",
"a",
"project",
"given",
"a",
"start",
"directory",
"inside",
"the",
"project",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugins/discoverer.py#L92-L107 | [
"def",
"find_top_level_directory",
"(",
"start_directory",
")",
":",
"top_level",
"=",
"start_directory",
"while",
"os",
".",
"path",
".",
"isfile",
"(",
"os",
".",
"path",
".",
"join",
"(",
"top_level",
",",
"'__init__.py'",
")",
")",
":",
"top_level",
"=",... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | Discoverer.discover | Do test case discovery.
This is the top-level entry-point for test discovery.
If the ``start`` argument is a drectory, then ``haas`` will
discover all tests in the package contained in that directory.
If the ``start`` argument is not a directory, it is assumed to
be a package ... | haas/plugins/discoverer.py | def discover(self, start, top_level_directory=None, pattern='test*.py'):
"""Do test case discovery.
This is the top-level entry-point for test discovery.
If the ``start`` argument is a drectory, then ``haas`` will
discover all tests in the package contained in that directory.
... | def discover(self, start, top_level_directory=None, pattern='test*.py'):
"""Do test case discovery.
This is the top-level entry-point for test discovery.
If the ``start`` argument is a drectory, then ``haas`` will
discover all tests in the package contained in that directory.
... | [
"Do",
"test",
"case",
"discovery",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugins/discoverer.py#L178-L219 | [
"def",
"discover",
"(",
"self",
",",
"start",
",",
"top_level_directory",
"=",
"None",
",",
"pattern",
"=",
"'test*.py'",
")",
":",
"logger",
".",
"debug",
"(",
"'Starting test discovery'",
")",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"start",
")",
"... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | Discoverer.discover_by_module | Find all tests in a package or module, or load a single test case if
a class or test inside a module was specified.
Parameters
----------
module_name : str
The dotted package name, module name or TestCase class and
test method.
top_level_directory : str
... | haas/plugins/discoverer.py | def discover_by_module(self, module_name, top_level_directory=None,
pattern='test*.py'):
"""Find all tests in a package or module, or load a single test case if
a class or test inside a module was specified.
Parameters
----------
module_name : str
... | def discover_by_module(self, module_name, top_level_directory=None,
pattern='test*.py'):
"""Find all tests in a package or module, or load a single test case if
a class or test inside a module was specified.
Parameters
----------
module_name : str
... | [
"Find",
"all",
"tests",
"in",
"a",
"package",
"or",
"module",
"or",
"load",
"a",
"single",
"test",
"case",
"if",
"a",
"class",
"or",
"test",
"inside",
"a",
"module",
"was",
"specified",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugins/discoverer.py#L221-L266 | [
"def",
"discover_by_module",
"(",
"self",
",",
"module_name",
",",
"top_level_directory",
"=",
"None",
",",
"pattern",
"=",
"'test*.py'",
")",
":",
"# If the top level directory is given, the module may only be",
"# importable with that in the path.",
"if",
"top_level_directory... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | Discoverer.discover_single_case | Find and load a single TestCase or TestCase method from a module.
Parameters
----------
module : module
The imported Python module containing the TestCase to be
loaded.
case_attributes : list
A list (length 1 or 2) of str. The first component must be... | haas/plugins/discoverer.py | def discover_single_case(self, module, case_attributes):
"""Find and load a single TestCase or TestCase method from a module.
Parameters
----------
module : module
The imported Python module containing the TestCase to be
loaded.
case_attributes : list
... | def discover_single_case(self, module, case_attributes):
"""Find and load a single TestCase or TestCase method from a module.
Parameters
----------
module : module
The imported Python module containing the TestCase to be
loaded.
case_attributes : list
... | [
"Find",
"and",
"load",
"a",
"single",
"TestCase",
"or",
"TestCase",
"method",
"from",
"a",
"module",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugins/discoverer.py#L268-L299 | [
"def",
"discover_single_case",
"(",
"self",
",",
"module",
",",
"case_attributes",
")",
":",
"# Find single case",
"case",
"=",
"module",
"loader",
"=",
"self",
".",
"_loader",
"for",
"index",
",",
"component",
"in",
"enumerate",
"(",
"case_attributes",
")",
"... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | Discoverer.discover_by_directory | Run test discovery in a directory.
Parameters
----------
start_directory : str
The package directory in which to start test discovery.
top_level_directory : str
The path to the top-level directoy of the project. This is
the parent directory of the pr... | haas/plugins/discoverer.py | def discover_by_directory(self, start_directory, top_level_directory=None,
pattern='test*.py'):
"""Run test discovery in a directory.
Parameters
----------
start_directory : str
The package directory in which to start test discovery.
top... | def discover_by_directory(self, start_directory, top_level_directory=None,
pattern='test*.py'):
"""Run test discovery in a directory.
Parameters
----------
start_directory : str
The package directory in which to start test discovery.
top... | [
"Run",
"test",
"discovery",
"in",
"a",
"directory",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugins/discoverer.py#L301-L332 | [
"def",
"discover_by_directory",
"(",
"self",
",",
"start_directory",
",",
"top_level_directory",
"=",
"None",
",",
"pattern",
"=",
"'test*.py'",
")",
":",
"start_directory",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"start_directory",
")",
"if",
"top_level_di... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | Discoverer.discover_by_file | Run test discovery on a single file.
Parameters
----------
start_filepath : str
The module file in which to start test discovery.
top_level_directory : str
The path to the top-level directoy of the project. This is
the parent directory of the project... | haas/plugins/discoverer.py | def discover_by_file(self, start_filepath, top_level_directory=None):
"""Run test discovery on a single file.
Parameters
----------
start_filepath : str
The module file in which to start test discovery.
top_level_directory : str
The path to the top-level ... | def discover_by_file(self, start_filepath, top_level_directory=None):
"""Run test discovery on a single file.
Parameters
----------
start_filepath : str
The module file in which to start test discovery.
top_level_directory : str
The path to the top-level ... | [
"Run",
"test",
"discovery",
"on",
"a",
"single",
"file",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/plugins/discoverer.py#L334-L362 | [
"def",
"discover_by_file",
"(",
"self",
",",
"start_filepath",
",",
"top_level_directory",
"=",
"None",
")",
":",
"start_filepath",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"start_filepath",
")",
"start_directory",
"=",
"os",
".",
"path",
".",
"dirname",
... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | OptionsViewMixin._set_options_headers | Set proper headers.
Sets following headers:
Allow
Access-Control-Allow-Methods
Access-Control-Allow-Headers
Arguments:
:methods: Sequence of HTTP method names that are value for
requested URI | nefertari/view_helpers.py | def _set_options_headers(self, methods):
""" Set proper headers.
Sets following headers:
Allow
Access-Control-Allow-Methods
Access-Control-Allow-Headers
Arguments:
:methods: Sequence of HTTP method names that are value for
request... | def _set_options_headers(self, methods):
""" Set proper headers.
Sets following headers:
Allow
Access-Control-Allow-Methods
Access-Control-Allow-Headers
Arguments:
:methods: Sequence of HTTP method names that are value for
request... | [
"Set",
"proper",
"headers",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L33-L58 | [
"def",
"_set_options_headers",
"(",
"self",
",",
"methods",
")",
":",
"request",
"=",
"self",
".",
"request",
"response",
"=",
"request",
".",
"response",
"response",
".",
"headers",
"[",
"'Allow'",
"]",
"=",
"', '",
".",
"join",
"(",
"sorted",
"(",
"met... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | OptionsViewMixin._get_handled_methods | Get names of HTTP methods that can be used at requested URI.
Arguments:
:actions_map: Map of actions. Must have the same structure as
self._item_actions and self._collection_actions | nefertari/view_helpers.py | def _get_handled_methods(self, actions_map):
""" Get names of HTTP methods that can be used at requested URI.
Arguments:
:actions_map: Map of actions. Must have the same structure as
self._item_actions and self._collection_actions
"""
methods = ('OPTIONS',)
... | def _get_handled_methods(self, actions_map):
""" Get names of HTTP methods that can be used at requested URI.
Arguments:
:actions_map: Map of actions. Must have the same structure as
self._item_actions and self._collection_actions
"""
methods = ('OPTIONS',)
... | [
"Get",
"names",
"of",
"HTTP",
"methods",
"that",
"can",
"be",
"used",
"at",
"requested",
"URI",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L60-L80 | [
"def",
"_get_handled_methods",
"(",
"self",
",",
"actions_map",
")",
":",
"methods",
"=",
"(",
"'OPTIONS'",
",",
")",
"defined_actions",
"=",
"[",
"]",
"for",
"action_name",
"in",
"actions_map",
".",
"keys",
"(",
")",
":",
"view_method",
"=",
"getattr",
"(... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | OptionsViewMixin.item_options | Handle collection OPTIONS request.
Singular route requests are handled a bit differently because
singular views may handle POST requests despite being registered
as item routes. | nefertari/view_helpers.py | def item_options(self, **kwargs):
""" Handle collection OPTIONS request.
Singular route requests are handled a bit differently because
singular views may handle POST requests despite being registered
as item routes.
"""
actions = self._item_actions.copy()
if self... | def item_options(self, **kwargs):
""" Handle collection OPTIONS request.
Singular route requests are handled a bit differently because
singular views may handle POST requests despite being registered
as item routes.
"""
actions = self._item_actions.copy()
if self... | [
"Handle",
"collection",
"OPTIONS",
"request",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L82-L93 | [
"def",
"item_options",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"actions",
"=",
"self",
".",
"_item_actions",
".",
"copy",
"(",
")",
"if",
"self",
".",
"_resource",
".",
"is_singular",
":",
"actions",
"[",
"'create'",
"]",
"=",
"(",
"'POST'",
... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | OptionsViewMixin.collection_options | Handle collection item OPTIONS request. | nefertari/view_helpers.py | def collection_options(self, **kwargs):
""" Handle collection item OPTIONS request. """
methods = self._get_handled_methods(self._collection_actions)
return self._set_options_headers(methods) | def collection_options(self, **kwargs):
""" Handle collection item OPTIONS request. """
methods = self._get_handled_methods(self._collection_actions)
return self._set_options_headers(methods) | [
"Handle",
"collection",
"item",
"OPTIONS",
"request",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L95-L98 | [
"def",
"collection_options",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"methods",
"=",
"self",
".",
"_get_handled_methods",
"(",
"self",
".",
"_collection_actions",
")",
"return",
"self",
".",
"_set_options_headers",
"(",
"methods",
")"
] | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | ESAggregator.wrap | Wrap :func: to perform aggregation on :func: call.
Should be called with view instance methods. | nefertari/view_helpers.py | def wrap(self, func):
""" Wrap :func: to perform aggregation on :func: call.
Should be called with view instance methods.
"""
@six.wraps(func)
def wrapper(*args, **kwargs):
try:
return self.aggregate()
except KeyError:
retu... | def wrap(self, func):
""" Wrap :func: to perform aggregation on :func: call.
Should be called with view instance methods.
"""
@six.wraps(func)
def wrapper(*args, **kwargs):
try:
return self.aggregate()
except KeyError:
retu... | [
"Wrap",
":",
"func",
":",
"to",
"perform",
"aggregation",
"on",
":",
"func",
":",
"call",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L129-L140 | [
"def",
"wrap",
"(",
"self",
",",
"func",
")",
":",
"@",
"six",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"self",
".",
"aggregate",
"(",
")",
"except",
"KeyError",
... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | ESAggregator.pop_aggregations_params | Pop and return aggregation params from query string params.
Aggregation params are expected to be prefixed(nested under) by
any of `self._aggregations_keys`. | nefertari/view_helpers.py | def pop_aggregations_params(self):
""" Pop and return aggregation params from query string params.
Aggregation params are expected to be prefixed(nested under) by
any of `self._aggregations_keys`.
"""
from nefertari.view import BaseView
self._query_params = BaseView.conv... | def pop_aggregations_params(self):
""" Pop and return aggregation params from query string params.
Aggregation params are expected to be prefixed(nested under) by
any of `self._aggregations_keys`.
"""
from nefertari.view import BaseView
self._query_params = BaseView.conv... | [
"Pop",
"and",
"return",
"aggregation",
"params",
"from",
"query",
"string",
"params",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L142-L155 | [
"def",
"pop_aggregations_params",
"(",
"self",
")",
":",
"from",
"nefertari",
".",
"view",
"import",
"BaseView",
"self",
".",
"_query_params",
"=",
"BaseView",
".",
"convert_dotted",
"(",
"self",
".",
"view",
".",
"_query_params",
")",
"for",
"key",
"in",
"s... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | ESAggregator.get_aggregations_fields | Recursively get values under the 'field' key.
Is used to get names of fields on which aggregations should be
performed. | nefertari/view_helpers.py | def get_aggregations_fields(cls, params):
""" Recursively get values under the 'field' key.
Is used to get names of fields on which aggregations should be
performed.
"""
fields = []
for key, val in params.items():
if isinstance(val, dict):
fie... | def get_aggregations_fields(cls, params):
""" Recursively get values under the 'field' key.
Is used to get names of fields on which aggregations should be
performed.
"""
fields = []
for key, val in params.items():
if isinstance(val, dict):
fie... | [
"Recursively",
"get",
"values",
"under",
"the",
"field",
"key",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L164-L176 | [
"def",
"get_aggregations_fields",
"(",
"cls",
",",
"params",
")",
":",
"fields",
"=",
"[",
"]",
"for",
"key",
",",
"val",
"in",
"params",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"val",
",",
"dict",
")",
":",
"fields",
"+=",
"cls",
"."... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | ESAggregator.check_aggregations_privacy | Check per-field privacy rules in aggregations.
Privacy is checked by making sure user has access to the fields
used in aggregations. | nefertari/view_helpers.py | def check_aggregations_privacy(self, aggregations_params):
""" Check per-field privacy rules in aggregations.
Privacy is checked by making sure user has access to the fields
used in aggregations.
"""
fields = self.get_aggregations_fields(aggregations_params)
fields_dict ... | def check_aggregations_privacy(self, aggregations_params):
""" Check per-field privacy rules in aggregations.
Privacy is checked by making sure user has access to the fields
used in aggregations.
"""
fields = self.get_aggregations_fields(aggregations_params)
fields_dict ... | [
"Check",
"per",
"-",
"field",
"privacy",
"rules",
"in",
"aggregations",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L178-L193 | [
"def",
"check_aggregations_privacy",
"(",
"self",
",",
"aggregations_params",
")",
":",
"fields",
"=",
"self",
".",
"get_aggregations_fields",
"(",
"aggregations_params",
")",
"fields_dict",
"=",
"dictset",
".",
"fromkeys",
"(",
"fields",
")",
"fields_dict",
"[",
... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | ESAggregator.aggregate | Perform aggregation and return response. | nefertari/view_helpers.py | def aggregate(self):
""" Perform aggregation and return response. """
from nefertari.elasticsearch import ES
aggregations_params = self.pop_aggregations_params()
if self.view._auth_enabled:
self.check_aggregations_privacy(aggregations_params)
self.stub_wrappers()
... | def aggregate(self):
""" Perform aggregation and return response. """
from nefertari.elasticsearch import ES
aggregations_params = self.pop_aggregations_params()
if self.view._auth_enabled:
self.check_aggregations_privacy(aggregations_params)
self.stub_wrappers()
... | [
"Perform",
"aggregation",
"and",
"return",
"response",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view_helpers.py#L195-L205 | [
"def",
"aggregate",
"(",
"self",
")",
":",
"from",
"nefertari",
".",
"elasticsearch",
"import",
"ES",
"aggregations_params",
"=",
"self",
".",
"pop_aggregations_params",
"(",
")",
"if",
"self",
".",
"view",
".",
"_auth_enabled",
":",
"self",
".",
"check_aggreg... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | dictset.asdict | Turn this 'a:2,b:blabla,c:True,a:'d' to
{a:[2, 'd'], b:'blabla', c:True} | nefertari/utils/dictset.py | def asdict(self, name, _type=None, _set=False):
"""
Turn this 'a:2,b:blabla,c:True,a:'d' to
{a:[2, 'd'], b:'blabla', c:True}
"""
if _type is None:
_type = lambda t: t
dict_str = self.pop(name, None)
if not dict_str:
return {}
_d... | def asdict(self, name, _type=None, _set=False):
"""
Turn this 'a:2,b:blabla,c:True,a:'d' to
{a:[2, 'd'], b:'blabla', c:True}
"""
if _type is None:
_type = lambda t: t
dict_str = self.pop(name, None)
if not dict_str:
return {}
_d... | [
"Turn",
"this",
"a",
":",
"2",
"b",
":",
"blabla",
"c",
":",
"True",
"a",
":",
"d",
"to",
"{",
"a",
":",
"[",
"2",
"d",
"]",
"b",
":",
"blabla",
"c",
":",
"True",
"}"
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/utils/dictset.py#L66-L95 | [
"def",
"asdict",
"(",
"self",
",",
"name",
",",
"_type",
"=",
"None",
",",
"_set",
"=",
"False",
")",
":",
"if",
"_type",
"is",
"None",
":",
"_type",
"=",
"lambda",
"t",
":",
"t",
"dict_str",
"=",
"self",
".",
"pop",
"(",
"name",
",",
"None",
"... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | get_random_hex | Return random hex string of a given length | bpc8583/tools.py | def get_random_hex(length):
"""
Return random hex string of a given length
"""
if length <= 0:
return ''
return hexify(random.randint(pow(2, length*2), pow(2, length*4)))[0:length] | def get_random_hex(length):
"""
Return random hex string of a given length
"""
if length <= 0:
return ''
return hexify(random.randint(pow(2, length*2), pow(2, length*4)))[0:length] | [
"Return",
"random",
"hex",
"string",
"of",
"a",
"given",
"length"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/tools.py#L59-L65 | [
"def",
"get_random_hex",
"(",
"length",
")",
":",
"if",
"length",
"<=",
"0",
":",
"return",
"''",
"return",
"hexify",
"(",
"random",
".",
"randint",
"(",
"pow",
"(",
"2",
",",
"length",
"*",
"2",
")",
",",
"pow",
"(",
"2",
",",
"length",
"*",
"4"... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | get_response | Return xx1x response for xx0x codes (e.g. 0810 for 0800) | bpc8583/tools.py | def get_response(_code):
"""
Return xx1x response for xx0x codes (e.g. 0810 for 0800)
"""
if _code:
code = str(_code)
return code[:-2] + str(int(code[-2:-1]) + 1) + code[-1]
else:
return None | def get_response(_code):
"""
Return xx1x response for xx0x codes (e.g. 0810 for 0800)
"""
if _code:
code = str(_code)
return code[:-2] + str(int(code[-2:-1]) + 1) + code[-1]
else:
return None | [
"Return",
"xx1x",
"response",
"for",
"xx0x",
"codes",
"(",
"e",
".",
"g",
".",
"0810",
"for",
"0800",
")"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/tools.py#L68-L76 | [
"def",
"get_response",
"(",
"_code",
")",
":",
"if",
"_code",
":",
"code",
"=",
"str",
"(",
"_code",
")",
"return",
"code",
"[",
":",
"-",
"2",
"]",
"+",
"str",
"(",
"int",
"(",
"code",
"[",
"-",
"2",
":",
"-",
"1",
"]",
")",
"+",
"1",
")",... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | Loader.load_case | Load a TestSuite containing all TestCase instances for all tests in
a TestCase subclass.
Parameters
----------
testcase : type
A subclass of :class:`unittest.TestCase` | haas/loader.py | def load_case(self, testcase):
"""Load a TestSuite containing all TestCase instances for all tests in
a TestCase subclass.
Parameters
----------
testcase : type
A subclass of :class:`unittest.TestCase`
"""
tests = [self.load_test(testcase, name)
... | def load_case(self, testcase):
"""Load a TestSuite containing all TestCase instances for all tests in
a TestCase subclass.
Parameters
----------
testcase : type
A subclass of :class:`unittest.TestCase`
"""
tests = [self.load_test(testcase, name)
... | [
"Load",
"a",
"TestSuite",
"containing",
"all",
"TestCase",
"instances",
"for",
"all",
"tests",
"in",
"a",
"TestCase",
"subclass",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/loader.py#L83-L95 | [
"def",
"load_case",
"(",
"self",
",",
"testcase",
")",
":",
"tests",
"=",
"[",
"self",
".",
"load_test",
"(",
"testcase",
",",
"name",
")",
"for",
"name",
"in",
"self",
".",
"find_test_method_names",
"(",
"testcase",
")",
"]",
"return",
"self",
".",
"c... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | Loader.load_module | Create and return a test suite containing all cases loaded from the
provided module.
Parameters
----------
module : module
A module object containing ``TestCases`` | haas/loader.py | def load_module(self, module):
"""Create and return a test suite containing all cases loaded from the
provided module.
Parameters
----------
module : module
A module object containing ``TestCases``
"""
cases = self.get_test_cases_from_module(module)
... | def load_module(self, module):
"""Create and return a test suite containing all cases loaded from the
provided module.
Parameters
----------
module : module
A module object containing ``TestCases``
"""
cases = self.get_test_cases_from_module(module)
... | [
"Create",
"and",
"return",
"a",
"test",
"suite",
"containing",
"all",
"cases",
"loaded",
"from",
"the",
"provided",
"module",
"."
] | scalative/haas | python | https://github.com/scalative/haas/blob/72c05216a2a80e5ee94d9cd8d05ed2b188725027/haas/loader.py#L112-L124 | [
"def",
"load_module",
"(",
"self",
",",
"module",
")",
":",
"cases",
"=",
"self",
".",
"get_test_cases_from_module",
"(",
"module",
")",
"suites",
"=",
"[",
"self",
".",
"load_case",
"(",
"case",
")",
"for",
"case",
"in",
"cases",
"]",
"return",
"self",
... | 72c05216a2a80e5ee94d9cd8d05ed2b188725027 |
train | ISO8583.Field | Add field to bitmap | bpc8583/ISO8583.py | def Field(self, field, Value = None):
'''
Add field to bitmap
'''
if Value == None:
try:
return self.__Bitmap[field]
except KeyError:
return None
elif Value == 1 or Value == 0:
self.__Bitmap[field] = Value
... | def Field(self, field, Value = None):
'''
Add field to bitmap
'''
if Value == None:
try:
return self.__Bitmap[field]
except KeyError:
return None
elif Value == 1 or Value == 0:
self.__Bitmap[field] = Value
... | [
"Add",
"field",
"to",
"bitmap"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/ISO8583.py#L396-L408 | [
"def",
"Field",
"(",
"self",
",",
"field",
",",
"Value",
"=",
"None",
")",
":",
"if",
"Value",
"==",
"None",
":",
"try",
":",
"return",
"self",
".",
"__Bitmap",
"[",
"field",
"]",
"except",
"KeyError",
":",
"return",
"None",
"elif",
"Value",
"==",
... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | ISO8583.FieldData | Add field data | bpc8583/ISO8583.py | def FieldData(self, field, Value = None):
'''
Add field data
'''
if Value == None:
try:
return self.__FieldData[field]
except KeyError:
return None
else:
if len(str(Value)) > self.__IsoSpec.MaxLength(field):
... | def FieldData(self, field, Value = None):
'''
Add field data
'''
if Value == None:
try:
return self.__FieldData[field]
except KeyError:
return None
else:
if len(str(Value)) > self.__IsoSpec.MaxLength(field):
... | [
"Add",
"field",
"data"
] | timgabets/bpc8583 | python | https://github.com/timgabets/bpc8583/blob/1b8e95d73ad273ad9d11bff40d1af3f06f0f3503/bpc8583/ISO8583.py#L419-L433 | [
"def",
"FieldData",
"(",
"self",
",",
"field",
",",
"Value",
"=",
"None",
")",
":",
"if",
"Value",
"==",
"None",
":",
"try",
":",
"return",
"self",
".",
"__FieldData",
"[",
"field",
"]",
"except",
"KeyError",
":",
"return",
"None",
"else",
":",
"if",... | 1b8e95d73ad273ad9d11bff40d1af3f06f0f3503 |
train | authenticated_userid | Helper function that can be used in ``db_key`` to support `self`
as a collection key. | nefertari/acl.py | def authenticated_userid(request):
"""Helper function that can be used in ``db_key`` to support `self`
as a collection key.
"""
user = getattr(request, 'user', None)
key = user.pk_field()
return getattr(user, key) | def authenticated_userid(request):
"""Helper function that can be used in ``db_key`` to support `self`
as a collection key.
"""
user = getattr(request, 'user', None)
key = user.pk_field()
return getattr(user, key) | [
"Helper",
"function",
"that",
"can",
"be",
"used",
"in",
"db_key",
"to",
"support",
"self",
"as",
"a",
"collection",
"key",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/acl.py#L68-L74 | [
"def",
"authenticated_userid",
"(",
"request",
")",
":",
"user",
"=",
"getattr",
"(",
"request",
",",
"'user'",
",",
"None",
")",
"key",
"=",
"user",
".",
"pk_field",
"(",
")",
"return",
"getattr",
"(",
"user",
",",
"key",
")"
] | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | HairballPlugin.iter_blocks | A generator for blocks contained in a block list.
Yields tuples containing the block name, the depth that the block was
found at, and finally a handle to the block itself. | hairball/plugins/__init__.py | def iter_blocks(block_list):
"""A generator for blocks contained in a block list.
Yields tuples containing the block name, the depth that the block was
found at, and finally a handle to the block itself.
"""
# queue the block and the depth of the block
queue = [(block, ... | def iter_blocks(block_list):
"""A generator for blocks contained in a block list.
Yields tuples containing the block name, the depth that the block was
found at, and finally a handle to the block itself.
"""
# queue the block and the depth of the block
queue = [(block, ... | [
"A",
"generator",
"for",
"blocks",
"contained",
"in",
"a",
"block",
"list",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L48-L67 | [
"def",
"iter_blocks",
"(",
"block_list",
")",
":",
"# queue the block and the depth of the block",
"queue",
"=",
"[",
"(",
"block",
",",
"0",
")",
"for",
"block",
"in",
"block_list",
"if",
"isinstance",
"(",
"block",
",",
"kurt",
".",
"Block",
")",
"]",
"whi... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | HairballPlugin.iter_scripts | A generator for all scripts contained in a scratch file.
yields stage scripts first, then scripts for each sprite | hairball/plugins/__init__.py | def iter_scripts(scratch):
"""A generator for all scripts contained in a scratch file.
yields stage scripts first, then scripts for each sprite
"""
for script in scratch.stage.scripts:
if not isinstance(script, kurt.Comment):
yield script
for sprite ... | def iter_scripts(scratch):
"""A generator for all scripts contained in a scratch file.
yields stage scripts first, then scripts for each sprite
"""
for script in scratch.stage.scripts:
if not isinstance(script, kurt.Comment):
yield script
for sprite ... | [
"A",
"generator",
"for",
"all",
"scripts",
"contained",
"in",
"a",
"scratch",
"file",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L70-L82 | [
"def",
"iter_scripts",
"(",
"scratch",
")",
":",
"for",
"script",
"in",
"scratch",
".",
"stage",
".",
"scripts",
":",
"if",
"not",
"isinstance",
"(",
"script",
",",
"kurt",
".",
"Comment",
")",
":",
"yield",
"script",
"for",
"sprite",
"in",
"scratch",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | HairballPlugin.iter_sprite_scripts | A generator for all scripts contained in a scratch file.
yields stage scripts first, then scripts for each sprite | hairball/plugins/__init__.py | def iter_sprite_scripts(scratch):
"""A generator for all scripts contained in a scratch file.
yields stage scripts first, then scripts for each sprite
"""
for script in scratch.stage.scripts:
if not isinstance(script, kurt.Comment):
yield ('Stage', script)
... | def iter_sprite_scripts(scratch):
"""A generator for all scripts contained in a scratch file.
yields stage scripts first, then scripts for each sprite
"""
for script in scratch.stage.scripts:
if not isinstance(script, kurt.Comment):
yield ('Stage', script)
... | [
"A",
"generator",
"for",
"all",
"scripts",
"contained",
"in",
"a",
"scratch",
"file",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L91-L103 | [
"def",
"iter_sprite_scripts",
"(",
"scratch",
")",
":",
"for",
"script",
"in",
"scratch",
".",
"stage",
".",
"scripts",
":",
"if",
"not",
"isinstance",
"(",
"script",
",",
"kurt",
".",
"Comment",
")",
":",
"yield",
"(",
"'Stage'",
",",
"script",
")",
"... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | HairballPlugin.script_start_type | Return the type of block the script begins with. | hairball/plugins/__init__.py | def script_start_type(script):
"""Return the type of block the script begins with."""
if script[0].type.text == 'when @greenFlag clicked':
return HairballPlugin.HAT_GREEN_FLAG
elif script[0].type.text == 'when I receive %s':
return HairballPlugin.HAT_WHEN_I_RECEIVE
... | def script_start_type(script):
"""Return the type of block the script begins with."""
if script[0].type.text == 'when @greenFlag clicked':
return HairballPlugin.HAT_GREEN_FLAG
elif script[0].type.text == 'when I receive %s':
return HairballPlugin.HAT_WHEN_I_RECEIVE
... | [
"Return",
"the",
"type",
"of",
"block",
"the",
"script",
"begins",
"with",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L106-L117 | [
"def",
"script_start_type",
"(",
"script",
")",
":",
"if",
"script",
"[",
"0",
"]",
".",
"type",
".",
"text",
"==",
"'when @greenFlag clicked'",
":",
"return",
"HairballPlugin",
".",
"HAT_GREEN_FLAG",
"elif",
"script",
"[",
"0",
"]",
".",
"type",
".",
"tex... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | HairballPlugin.get_broadcast_events | Return a Counter of event-names that were broadcast.
The Count will contain the key True if any of the broadcast blocks
contain a parameter that is a variable. | hairball/plugins/__init__.py | def get_broadcast_events(cls, script):
"""Return a Counter of event-names that were broadcast.
The Count will contain the key True if any of the broadcast blocks
contain a parameter that is a variable.
"""
events = Counter()
for name, _, block in cls.iter_blocks(script)... | def get_broadcast_events(cls, script):
"""Return a Counter of event-names that were broadcast.
The Count will contain the key True if any of the broadcast blocks
contain a parameter that is a variable.
"""
events = Counter()
for name, _, block in cls.iter_blocks(script)... | [
"Return",
"a",
"Counter",
"of",
"event",
"-",
"names",
"that",
"were",
"broadcast",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L120-L134 | [
"def",
"get_broadcast_events",
"(",
"cls",
",",
"script",
")",
":",
"events",
"=",
"Counter",
"(",
")",
"for",
"name",
",",
"_",
",",
"block",
"in",
"cls",
".",
"iter_blocks",
"(",
"script",
")",
":",
"if",
"'broadcast %s'",
"in",
"name",
":",
"if",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | HairballPlugin.tag_reachable_scripts | Tag each script with attribute reachable.
The reachable attribute will be set false for any script that does not
begin with a hat block. Additionally, any script that begins with a
'when I receive' block whose event-name doesn't appear in a
corresponding broadcast block is marked as unr... | hairball/plugins/__init__.py | def tag_reachable_scripts(cls, scratch):
"""Tag each script with attribute reachable.
The reachable attribute will be set false for any script that does not
begin with a hat block. Additionally, any script that begins with a
'when I receive' block whose event-name doesn't appear in a
... | def tag_reachable_scripts(cls, scratch):
"""Tag each script with attribute reachable.
The reachable attribute will be set false for any script that does not
begin with a hat block. Additionally, any script that begins with a
'when I receive' block whose event-name doesn't appear in a
... | [
"Tag",
"each",
"script",
"with",
"attribute",
"reachable",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L137-L172 | [
"def",
"tag_reachable_scripts",
"(",
"cls",
",",
"scratch",
")",
":",
"if",
"getattr",
"(",
"scratch",
",",
"'hairball_prepared'",
",",
"False",
")",
":",
"# Only process once",
"return",
"reachable",
"=",
"set",
"(",
")",
"untriggered_events",
"=",
"{",
"}",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | HairballPlugin.description | Attribute that returns the plugin description from its docstring. | hairball/plugins/__init__.py | def description(self):
"""Attribute that returns the plugin description from its docstring."""
lines = []
for line in self.__doc__.split('\n')[2:]:
line = line.strip()
if line:
lines.append(line)
return ' '.join(lines) | def description(self):
"""Attribute that returns the plugin description from its docstring."""
lines = []
for line in self.__doc__.split('\n')[2:]:
line = line.strip()
if line:
lines.append(line)
return ' '.join(lines) | [
"Attribute",
"that",
"returns",
"the",
"plugin",
"description",
"from",
"its",
"docstring",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L175-L182 | [
"def",
"description",
"(",
"self",
")",
":",
"lines",
"=",
"[",
"]",
"for",
"line",
"in",
"self",
".",
"__doc__",
".",
"split",
"(",
"'\\n'",
")",
"[",
"2",
":",
"]",
":",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"line",
":",
"lines",... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | HairballPlugin._process | Internal hook that marks reachable scripts before calling analyze.
Returns data exactly as returned by the analyze method. | hairball/plugins/__init__.py | def _process(self, scratch, filename, **kwargs):
"""Internal hook that marks reachable scripts before calling analyze.
Returns data exactly as returned by the analyze method.
"""
self.tag_reachable_scripts(scratch)
return self.analyze(scratch, filename=filename, **kwargs) | def _process(self, scratch, filename, **kwargs):
"""Internal hook that marks reachable scripts before calling analyze.
Returns data exactly as returned by the analyze method.
"""
self.tag_reachable_scripts(scratch)
return self.analyze(scratch, filename=filename, **kwargs) | [
"Internal",
"hook",
"that",
"marks",
"reachable",
"scripts",
"before",
"calling",
"analyze",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/__init__.py#L189-L196 | [
"def",
"_process",
"(",
"self",
",",
"scratch",
",",
"filename",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"tag_reachable_scripts",
"(",
"scratch",
")",
"return",
"self",
".",
"analyze",
"(",
"scratch",
",",
"filename",
"=",
"filename",
",",
"*",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | ODSWriter.close | Finalises the compressed version of the spreadsheet. If you aren't using the context manager ('with' statement,
you must call this manually, it is not triggered automatically like on a file object.
:return: Nothing. | odswriter/__init__.py | def close(self):
"""
Finalises the compressed version of the spreadsheet. If you aren't using the context manager ('with' statement,
you must call this manually, it is not triggered automatically like on a file object.
:return: Nothing.
"""
self.zipf.writestr("content.xml... | def close(self):
"""
Finalises the compressed version of the spreadsheet. If you aren't using the context manager ('with' statement,
you must call this manually, it is not triggered automatically like on a file object.
:return: Nothing.
"""
self.zipf.writestr("content.xml... | [
"Finalises",
"the",
"compressed",
"version",
"of",
"the",
"spreadsheet",
".",
"If",
"you",
"aren",
"t",
"using",
"the",
"context",
"manager",
"(",
"with",
"statement",
"you",
"must",
"call",
"this",
"manually",
"it",
"is",
"not",
"triggered",
"automatically",
... | mmulqueen/odswriter | python | https://github.com/mmulqueen/odswriter/blob/0bb038a60dd27bacd76d6b1ff3a200e2a7729651/odswriter/__init__.py#L49-L56 | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"zipf",
".",
"writestr",
"(",
"\"content.xml\"",
",",
"self",
".",
"dom",
".",
"toxml",
"(",
")",
".",
"encode",
"(",
"\"utf-8\"",
")",
")",
"self",
".",
"zipf",
".",
"close",
"(",
")"
] | 0bb038a60dd27bacd76d6b1ff3a200e2a7729651 |
train | ODSWriter.writerow | Write a row of cells into the default sheet of the spreadsheet.
:param cells: A list of cells (most basic Python types supported).
:return: Nothing. | odswriter/__init__.py | def writerow(self, cells):
"""
Write a row of cells into the default sheet of the spreadsheet.
:param cells: A list of cells (most basic Python types supported).
:return: Nothing.
"""
if self.default_sheet is None:
self.default_sheet = self.new_sheet()
... | def writerow(self, cells):
"""
Write a row of cells into the default sheet of the spreadsheet.
:param cells: A list of cells (most basic Python types supported).
:return: Nothing.
"""
if self.default_sheet is None:
self.default_sheet = self.new_sheet()
... | [
"Write",
"a",
"row",
"of",
"cells",
"into",
"the",
"default",
"sheet",
"of",
"the",
"spreadsheet",
".",
":",
"param",
"cells",
":",
"A",
"list",
"of",
"cells",
"(",
"most",
"basic",
"Python",
"types",
"supported",
")",
".",
":",
"return",
":",
"Nothing... | mmulqueen/odswriter | python | https://github.com/mmulqueen/odswriter/blob/0bb038a60dd27bacd76d6b1ff3a200e2a7729651/odswriter/__init__.py#L58-L66 | [
"def",
"writerow",
"(",
"self",
",",
"cells",
")",
":",
"if",
"self",
".",
"default_sheet",
"is",
"None",
":",
"self",
".",
"default_sheet",
"=",
"self",
".",
"new_sheet",
"(",
")",
"self",
".",
"default_sheet",
".",
"writerow",
"(",
"cells",
")"
] | 0bb038a60dd27bacd76d6b1ff3a200e2a7729651 |
train | ODSWriter.new_sheet | Create a new sheet in the spreadsheet and return it so content can be added.
:param name: Optional name for the sheet.
:param cols: Specify the number of columns, needed for compatibility in some cases
:return: Sheet object | odswriter/__init__.py | def new_sheet(self, name=None, cols=None):
"""
Create a new sheet in the spreadsheet and return it so content can be added.
:param name: Optional name for the sheet.
:param cols: Specify the number of columns, needed for compatibility in some cases
:return: Sheet object
"... | def new_sheet(self, name=None, cols=None):
"""
Create a new sheet in the spreadsheet and return it so content can be added.
:param name: Optional name for the sheet.
:param cols: Specify the number of columns, needed for compatibility in some cases
:return: Sheet object
"... | [
"Create",
"a",
"new",
"sheet",
"in",
"the",
"spreadsheet",
"and",
"return",
"it",
"so",
"content",
"can",
"be",
"added",
".",
":",
"param",
"name",
":",
"Optional",
"name",
"for",
"the",
"sheet",
".",
":",
"param",
"cols",
":",
"Specify",
"the",
"numbe... | mmulqueen/odswriter | python | https://github.com/mmulqueen/odswriter/blob/0bb038a60dd27bacd76d6b1ff3a200e2a7729651/odswriter/__init__.py#L77-L86 | [
"def",
"new_sheet",
"(",
"self",
",",
"name",
"=",
"None",
",",
"cols",
"=",
"None",
")",
":",
"sheet",
"=",
"Sheet",
"(",
"self",
".",
"dom",
",",
"name",
",",
"cols",
")",
"self",
".",
"sheets",
".",
"append",
"(",
"sheet",
")",
"return",
"shee... | 0bb038a60dd27bacd76d6b1ff3a200e2a7729651 |
train | _format_kwargs | Decorator to handle formatting kwargs to the proper names expected by
the associated function. The formats dictionary string keys will be used as
expected function kwargs and the value list of strings will be renamed to
the associated key string. | lib/qprompt.py | def _format_kwargs(func):
"""Decorator to handle formatting kwargs to the proper names expected by
the associated function. The formats dictionary string keys will be used as
expected function kwargs and the value list of strings will be renamed to
the associated key string."""
formats = {}
form... | def _format_kwargs(func):
"""Decorator to handle formatting kwargs to the proper names expected by
the associated function. The formats dictionary string keys will be used as
expected function kwargs and the value list of strings will be renamed to
the associated key string."""
formats = {}
form... | [
"Decorator",
"to",
"handle",
"formatting",
"kwargs",
"to",
"the",
"proper",
"names",
"expected",
"by",
"the",
"associated",
"function",
".",
"The",
"formats",
"dictionary",
"string",
"keys",
"will",
"be",
"used",
"as",
"expected",
"function",
"kwargs",
"and",
... | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L34-L55 | [
"def",
"_format_kwargs",
"(",
"func",
")",
":",
"formats",
"=",
"{",
"}",
"formats",
"[",
"'blk'",
"]",
"=",
"[",
"\"blank\"",
"]",
"formats",
"[",
"'dft'",
"]",
"=",
"[",
"\"default\"",
"]",
"formats",
"[",
"'hdr'",
"]",
"=",
"[",
"\"header\"",
"]",... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | show_limit | Shows a menu but limits the number of entries shown at a time.
Functionally equivalent to `show_menu()` with the `limit` parameter set. | lib/qprompt.py | def show_limit(entries, **kwargs):
"""Shows a menu but limits the number of entries shown at a time.
Functionally equivalent to `show_menu()` with the `limit` parameter set."""
limit = kwargs.pop('limit', 5)
if limit <= 0:
return show_menu(entries, **kwargs)
istart = 0 # Index of group start... | def show_limit(entries, **kwargs):
"""Shows a menu but limits the number of entries shown at a time.
Functionally equivalent to `show_menu()` with the `limit` parameter set."""
limit = kwargs.pop('limit', 5)
if limit <= 0:
return show_menu(entries, **kwargs)
istart = 0 # Index of group start... | [
"Shows",
"a",
"menu",
"but",
"limits",
"the",
"number",
"of",
"entries",
"shown",
"at",
"a",
"time",
".",
"Functionally",
"equivalent",
"to",
"show_menu",
"()",
"with",
"the",
"limit",
"parameter",
"set",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L258-L315 | [
"def",
"show_limit",
"(",
"entries",
",",
"*",
"*",
"kwargs",
")",
":",
"limit",
"=",
"kwargs",
".",
"pop",
"(",
"'limit'",
",",
"5",
")",
"if",
"limit",
"<=",
"0",
":",
"return",
"show_menu",
"(",
"entries",
",",
"*",
"*",
"kwargs",
")",
"istart",... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | show_menu | Shows a menu with the given list of `MenuEntry` items.
**Params**:
- header (str) - String to show above menu.
- note (str) - String to show as a note below menu.
- msg (str) - String to show below menu.
- dft (str) - Default value if input is left blank.
- compact (bool) - If true, t... | lib/qprompt.py | def show_menu(entries, **kwargs):
"""Shows a menu with the given list of `MenuEntry` items.
**Params**:
- header (str) - String to show above menu.
- note (str) - String to show as a note below menu.
- msg (str) - String to show below menu.
- dft (str) - Default value if input is left b... | def show_menu(entries, **kwargs):
"""Shows a menu with the given list of `MenuEntry` items.
**Params**:
- header (str) - String to show above menu.
- note (str) - String to show as a note below menu.
- msg (str) - String to show below menu.
- dft (str) - Default value if input is left b... | [
"Shows",
"a",
"menu",
"with",
"the",
"given",
"list",
"of",
"MenuEntry",
"items",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L318-L388 | [
"def",
"show_menu",
"(",
"entries",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"_AUTO",
"hdr",
"=",
"kwargs",
".",
"get",
"(",
"'hdr'",
",",
"\"\"",
")",
"note",
"=",
"kwargs",
".",
"get",
"(",
"'note'",
",",
"\"\"",
")",
"dft",
"=",
"kwargs",
... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | run_func | Runs the function associated with the given MenuEntry. | lib/qprompt.py | def run_func(entry):
"""Runs the function associated with the given MenuEntry."""
if entry.func:
if entry.args and entry.krgs:
return entry.func(*entry.args, **entry.krgs)
if entry.args:
return entry.func(*entry.args)
if entry.krgs:
return entry.func(*... | def run_func(entry):
"""Runs the function associated with the given MenuEntry."""
if entry.func:
if entry.args and entry.krgs:
return entry.func(*entry.args, **entry.krgs)
if entry.args:
return entry.func(*entry.args)
if entry.krgs:
return entry.func(*... | [
"Runs",
"the",
"function",
"associated",
"with",
"the",
"given",
"MenuEntry",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L390-L399 | [
"def",
"run_func",
"(",
"entry",
")",
":",
"if",
"entry",
".",
"func",
":",
"if",
"entry",
".",
"args",
"and",
"entry",
".",
"krgs",
":",
"return",
"entry",
".",
"func",
"(",
"*",
"entry",
".",
"args",
",",
"*",
"*",
"entry",
".",
"krgs",
")",
... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | enum_menu | Enumerates the given list of strings into returned menu.
**Params**:
- menu (Menu) - Existing menu to append. If not provided, a new menu will
be created. | lib/qprompt.py | def enum_menu(strs, menu=None, *args, **kwargs):
"""Enumerates the given list of strings into returned menu.
**Params**:
- menu (Menu) - Existing menu to append. If not provided, a new menu will
be created.
"""
if not menu:
menu = Menu(*args, **kwargs)
for s in strs:
m... | def enum_menu(strs, menu=None, *args, **kwargs):
"""Enumerates the given list of strings into returned menu.
**Params**:
- menu (Menu) - Existing menu to append. If not provided, a new menu will
be created.
"""
if not menu:
menu = Menu(*args, **kwargs)
for s in strs:
m... | [
"Enumerates",
"the",
"given",
"list",
"of",
"strings",
"into",
"returned",
"menu",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L401-L412 | [
"def",
"enum_menu",
"(",
"strs",
",",
"menu",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"menu",
":",
"menu",
"=",
"Menu",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"for",
"s",
"in",
"strs",
":",
"men... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | ask | Prompts the user for input and returns the given answer. Optionally
checks if answer is valid.
**Params**:
- msg (str) - Message to prompt the user with.
- fmt (func) - Function used to format user input.
- dft (int|float|str) - Default value if input is left blank.
- vld ([int|float|st... | lib/qprompt.py | def ask(msg="Enter input", fmt=None, dft=None, vld=None, shw=True, blk=False, hlp=None, qstr=True):
"""Prompts the user for input and returns the given answer. Optionally
checks if answer is valid.
**Params**:
- msg (str) - Message to prompt the user with.
- fmt (func) - Function used to format... | def ask(msg="Enter input", fmt=None, dft=None, vld=None, shw=True, blk=False, hlp=None, qstr=True):
"""Prompts the user for input and returns the given answer. Optionally
checks if answer is valid.
**Params**:
- msg (str) - Message to prompt the user with.
- fmt (func) - Function used to format... | [
"Prompts",
"the",
"user",
"for",
"input",
"and",
"returns",
"the",
"given",
"answer",
".",
"Optionally",
"checks",
"if",
"answer",
"is",
"valid",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L424-L516 | [
"def",
"ask",
"(",
"msg",
"=",
"\"Enter input\"",
",",
"fmt",
"=",
"None",
",",
"dft",
"=",
"None",
",",
"vld",
"=",
"None",
",",
"shw",
"=",
"True",
",",
"blk",
"=",
"False",
",",
"hlp",
"=",
"None",
",",
"qstr",
"=",
"True",
")",
":",
"global... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | ask_yesno | Prompts the user for a yes or no answer. Returns True for yes, False
for no. | lib/qprompt.py | def ask_yesno(msg="Proceed?", dft=None):
"""Prompts the user for a yes or no answer. Returns True for yes, False
for no."""
yes = ["y", "yes", "Y", "YES"]
no = ["n", "no", "N", "NO"]
if dft != None:
dft = yes[0] if (dft in yes or dft == True) else no[0]
return ask(msg, dft=dft, vld=yes+n... | def ask_yesno(msg="Proceed?", dft=None):
"""Prompts the user for a yes or no answer. Returns True for yes, False
for no."""
yes = ["y", "yes", "Y", "YES"]
no = ["n", "no", "N", "NO"]
if dft != None:
dft = yes[0] if (dft in yes or dft == True) else no[0]
return ask(msg, dft=dft, vld=yes+n... | [
"Prompts",
"the",
"user",
"for",
"a",
"yes",
"or",
"no",
"answer",
".",
"Returns",
"True",
"for",
"yes",
"False",
"for",
"no",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L519-L526 | [
"def",
"ask_yesno",
"(",
"msg",
"=",
"\"Proceed?\"",
",",
"dft",
"=",
"None",
")",
":",
"yes",
"=",
"[",
"\"y\"",
",",
"\"yes\"",
",",
"\"Y\"",
",",
"\"YES\"",
"]",
"no",
"=",
"[",
"\"n\"",
",",
"\"no\"",
",",
"\"N\"",
",",
"\"NO\"",
"]",
"if",
"... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | ask_int | Prompts the user for an integer. | lib/qprompt.py | def ask_int(msg="Enter an integer", dft=None, vld=None, hlp=None):
"""Prompts the user for an integer."""
vld = vld or [int]
return ask(msg, dft=dft, vld=vld, fmt=partial(cast, typ=int), hlp=hlp) | def ask_int(msg="Enter an integer", dft=None, vld=None, hlp=None):
"""Prompts the user for an integer."""
vld = vld or [int]
return ask(msg, dft=dft, vld=vld, fmt=partial(cast, typ=int), hlp=hlp) | [
"Prompts",
"the",
"user",
"for",
"an",
"integer",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L529-L532 | [
"def",
"ask_int",
"(",
"msg",
"=",
"\"Enter an integer\"",
",",
"dft",
"=",
"None",
",",
"vld",
"=",
"None",
",",
"hlp",
"=",
"None",
")",
":",
"vld",
"=",
"vld",
"or",
"[",
"int",
"]",
"return",
"ask",
"(",
"msg",
",",
"dft",
"=",
"dft",
",",
... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | ask_float | Prompts the user for a float. | lib/qprompt.py | def ask_float(msg="Enter a float", dft=None, vld=None, hlp=None):
"""Prompts the user for a float."""
vld = vld or [float]
return ask(msg, dft=dft, vld=vld, fmt=partial(cast, typ=float), hlp=hlp) | def ask_float(msg="Enter a float", dft=None, vld=None, hlp=None):
"""Prompts the user for a float."""
vld = vld or [float]
return ask(msg, dft=dft, vld=vld, fmt=partial(cast, typ=float), hlp=hlp) | [
"Prompts",
"the",
"user",
"for",
"a",
"float",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L535-L538 | [
"def",
"ask_float",
"(",
"msg",
"=",
"\"Enter a float\"",
",",
"dft",
"=",
"None",
",",
"vld",
"=",
"None",
",",
"hlp",
"=",
"None",
")",
":",
"vld",
"=",
"vld",
"or",
"[",
"float",
"]",
"return",
"ask",
"(",
"msg",
",",
"dft",
"=",
"dft",
",",
... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | ask_str | Prompts the user for a string. | lib/qprompt.py | def ask_str(msg="Enter a string", dft=None, vld=None, shw=True, blk=True, hlp=None):
"""Prompts the user for a string."""
vld = vld or [str]
return ask(msg, dft=dft, vld=vld, shw=shw, blk=blk, hlp=hlp) | def ask_str(msg="Enter a string", dft=None, vld=None, shw=True, blk=True, hlp=None):
"""Prompts the user for a string."""
vld = vld or [str]
return ask(msg, dft=dft, vld=vld, shw=shw, blk=blk, hlp=hlp) | [
"Prompts",
"the",
"user",
"for",
"a",
"string",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L541-L544 | [
"def",
"ask_str",
"(",
"msg",
"=",
"\"Enter a string\"",
",",
"dft",
"=",
"None",
",",
"vld",
"=",
"None",
",",
"shw",
"=",
"True",
",",
"blk",
"=",
"True",
",",
"hlp",
"=",
"None",
")",
":",
"vld",
"=",
"vld",
"or",
"[",
"str",
"]",
"return",
... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | ask_captcha | Prompts the user for a random string. | lib/qprompt.py | def ask_captcha(length=4):
"""Prompts the user for a random string."""
captcha = "".join(random.choice(string.ascii_lowercase) for _ in range(length))
ask_str('Enter the following letters, "%s"' % (captcha), vld=[captcha, captcha.upper()], blk=False) | def ask_captcha(length=4):
"""Prompts the user for a random string."""
captcha = "".join(random.choice(string.ascii_lowercase) for _ in range(length))
ask_str('Enter the following letters, "%s"' % (captcha), vld=[captcha, captcha.upper()], blk=False) | [
"Prompts",
"the",
"user",
"for",
"a",
"random",
"string",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L549-L552 | [
"def",
"ask_captcha",
"(",
"length",
"=",
"4",
")",
":",
"captcha",
"=",
"\"\"",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"string",
".",
"ascii_lowercase",
")",
"for",
"_",
"in",
"range",
"(",
"length",
")",
")",
"ask_str",
"(",
"'Enter the foll... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | clear | Clears the console. | lib/qprompt.py | def clear():
"""Clears the console."""
if sys.platform.startswith("win"):
call("cls", shell=True)
else:
call("clear", shell=True) | def clear():
"""Clears the console."""
if sys.platform.startswith("win"):
call("cls", shell=True)
else:
call("clear", shell=True) | [
"Clears",
"the",
"console",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L558-L563 | [
"def",
"clear",
"(",
")",
":",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"\"win\"",
")",
":",
"call",
"(",
"\"cls\"",
",",
"shell",
"=",
"True",
")",
"else",
":",
"call",
"(",
"\"clear\"",
",",
"shell",
"=",
"True",
")"
] | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | status | Prints a status message at the start and finish of an associated
function. Can be used as a function decorator or as a function that accepts
another function as the first parameter.
**Params**:
The following parameters are available when used as a decorator:
- msg (str) [args] - Message to prin... | lib/qprompt.py | def status(*args, **kwargs):
"""Prints a status message at the start and finish of an associated
function. Can be used as a function decorator or as a function that accepts
another function as the first parameter.
**Params**:
The following parameters are available when used as a decorator:
... | def status(*args, **kwargs):
"""Prints a status message at the start and finish of an associated
function. Can be used as a function decorator or as a function that accepts
another function as the first parameter.
**Params**:
The following parameters are available when used as a decorator:
... | [
"Prints",
"a",
"status",
"message",
"at",
"the",
"start",
"and",
"finish",
"of",
"an",
"associated",
"function",
".",
"Can",
"be",
"used",
"as",
"a",
"function",
"decorator",
"or",
"as",
"a",
"function",
"that",
"accepts",
"another",
"function",
"as",
"the... | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L565-L616 | [
"def",
"status",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"decor",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"krgs",
")",
":",
"echo",
"(",
"\"[!] \"",
"+",
"m... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | fatal | Prints a message then exits the program. Optionally pause before exit
with `pause=True` kwarg. | lib/qprompt.py | def fatal(msg, exitcode=1, **kwargs):
"""Prints a message then exits the program. Optionally pause before exit
with `pause=True` kwarg."""
# NOTE: Can't use normal arg named `pause` since function has same name.
pause_before_exit = kwargs.pop("pause") if "pause" in kwargs.keys() else False
echo("[FA... | def fatal(msg, exitcode=1, **kwargs):
"""Prints a message then exits the program. Optionally pause before exit
with `pause=True` kwarg."""
# NOTE: Can't use normal arg named `pause` since function has same name.
pause_before_exit = kwargs.pop("pause") if "pause" in kwargs.keys() else False
echo("[FA... | [
"Prints",
"a",
"message",
"then",
"exits",
"the",
"program",
".",
"Optionally",
"pause",
"before",
"exit",
"with",
"pause",
"=",
"True",
"kwarg",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L618-L626 | [
"def",
"fatal",
"(",
"msg",
",",
"exitcode",
"=",
"1",
",",
"*",
"*",
"kwargs",
")",
":",
"# NOTE: Can't use normal arg named `pause` since function has same name.",
"pause_before_exit",
"=",
"kwargs",
".",
"pop",
"(",
"\"pause\"",
")",
"if",
"\"pause\"",
"in",
"k... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | hrule | Outputs or returns a horizontal line of the given character and width.
Returns printed string. | lib/qprompt.py | def hrule(width=None, char=None):
"""Outputs or returns a horizontal line of the given character and width.
Returns printed string."""
width = width or HRWIDTH
char = char or HRCHAR
return echo(getline(char, width)) | def hrule(width=None, char=None):
"""Outputs or returns a horizontal line of the given character and width.
Returns printed string."""
width = width or HRWIDTH
char = char or HRCHAR
return echo(getline(char, width)) | [
"Outputs",
"or",
"returns",
"a",
"horizontal",
"line",
"of",
"the",
"given",
"character",
"and",
"width",
".",
"Returns",
"printed",
"string",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L644-L649 | [
"def",
"hrule",
"(",
"width",
"=",
"None",
",",
"char",
"=",
"None",
")",
":",
"width",
"=",
"width",
"or",
"HRWIDTH",
"char",
"=",
"char",
"or",
"HRCHAR",
"return",
"echo",
"(",
"getline",
"(",
"char",
",",
"width",
")",
")"
] | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | title | Sets the title of the console window. | lib/qprompt.py | def title(msg):
"""Sets the title of the console window."""
if sys.platform.startswith("win"):
ctypes.windll.kernel32.SetConsoleTitleW(tounicode(msg)) | def title(msg):
"""Sets the title of the console window."""
if sys.platform.startswith("win"):
ctypes.windll.kernel32.SetConsoleTitleW(tounicode(msg)) | [
"Sets",
"the",
"title",
"of",
"the",
"console",
"window",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L651-L654 | [
"def",
"title",
"(",
"msg",
")",
":",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"\"win\"",
")",
":",
"ctypes",
".",
"windll",
".",
"kernel32",
".",
"SetConsoleTitleW",
"(",
"tounicode",
"(",
"msg",
")",
")"
] | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | wrap | Wraps the given item content between horizontal lines. Item can be a
string or a function.
**Examples**:
::
qprompt.wrap("Hi, this will be wrapped.") # String item.
qprompt.wrap(myfunc, [arg1, arg2], {'krgk': krgv}) # Func item. | lib/qprompt.py | def wrap(item, args=None, krgs=None, **kwargs):
"""Wraps the given item content between horizontal lines. Item can be a
string or a function.
**Examples**:
::
qprompt.wrap("Hi, this will be wrapped.") # String item.
qprompt.wrap(myfunc, [arg1, arg2], {'krgk': krgv}) # Func item.
"... | def wrap(item, args=None, krgs=None, **kwargs):
"""Wraps the given item content between horizontal lines. Item can be a
string or a function.
**Examples**:
::
qprompt.wrap("Hi, this will be wrapped.") # String item.
qprompt.wrap(myfunc, [arg1, arg2], {'krgk': krgv}) # Func item.
"... | [
"Wraps",
"the",
"given",
"item",
"content",
"between",
"horizontal",
"lines",
".",
"Item",
"can",
"be",
"a",
"string",
"or",
"a",
"function",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L657-L672 | [
"def",
"wrap",
"(",
"item",
",",
"args",
"=",
"None",
",",
"krgs",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"Wrap",
"(",
"*",
"*",
"kwargs",
")",
":",
"if",
"callable",
"(",
"item",
")",
":",
"args",
"=",
"args",
"or",
"[",
"]"... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | _guess_name | Attempts to guess the menu entry name from the function name. | lib/qprompt.py | def _guess_name(desc, taken=None):
"""Attempts to guess the menu entry name from the function name."""
taken = taken or []
name = ""
# Try to find the shortest name based on the given description.
for word in desc.split():
c = word[0].lower()
if not c.isalnum():
continue
... | def _guess_name(desc, taken=None):
"""Attempts to guess the menu entry name from the function name."""
taken = taken or []
name = ""
# Try to find the shortest name based on the given description.
for word in desc.split():
c = word[0].lower()
if not c.isalnum():
continue
... | [
"Attempts",
"to",
"guess",
"the",
"menu",
"entry",
"name",
"from",
"the",
"function",
"name",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L674-L691 | [
"def",
"_guess_name",
"(",
"desc",
",",
"taken",
"=",
"None",
")",
":",
"taken",
"=",
"taken",
"or",
"[",
"]",
"name",
"=",
"\"\"",
"# Try to find the shortest name based on the given description.",
"for",
"word",
"in",
"desc",
".",
"split",
"(",
")",
":",
"... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | Menu.add | Add a menu entry. | lib/qprompt.py | def add(self, name, desc, func=None, args=None, krgs=None):
"""Add a menu entry."""
self.entries.append(MenuEntry(name, desc, func, args or [], krgs or {})) | def add(self, name, desc, func=None, args=None, krgs=None):
"""Add a menu entry."""
self.entries.append(MenuEntry(name, desc, func, args or [], krgs or {})) | [
"Add",
"a",
"menu",
"entry",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L141-L143 | [
"def",
"add",
"(",
"self",
",",
"name",
",",
"desc",
",",
"func",
"=",
"None",
",",
"args",
"=",
"None",
",",
"krgs",
"=",
"None",
")",
":",
"self",
".",
"entries",
".",
"append",
"(",
"MenuEntry",
"(",
"name",
",",
"desc",
",",
"func",
",",
"a... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | Menu.enum | Add a menu entry whose name will be an auto indexed number. | lib/qprompt.py | def enum(self, desc, func=None, args=None, krgs=None):
"""Add a menu entry whose name will be an auto indexed number."""
name = str(len(self.entries)+1)
self.entries.append(MenuEntry(name, desc, func, args or [], krgs or {})) | def enum(self, desc, func=None, args=None, krgs=None):
"""Add a menu entry whose name will be an auto indexed number."""
name = str(len(self.entries)+1)
self.entries.append(MenuEntry(name, desc, func, args or [], krgs or {})) | [
"Add",
"a",
"menu",
"entry",
"whose",
"name",
"will",
"be",
"an",
"auto",
"indexed",
"number",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L144-L147 | [
"def",
"enum",
"(",
"self",
",",
"desc",
",",
"func",
"=",
"None",
",",
"args",
"=",
"None",
",",
"krgs",
"=",
"None",
")",
":",
"name",
"=",
"str",
"(",
"len",
"(",
"self",
".",
"entries",
")",
"+",
"1",
")",
"self",
".",
"entries",
".",
"ap... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | Menu.show | Shows the menu. Any `kwargs` supplied will be passed to
`show_menu()`. | lib/qprompt.py | def show(self, **kwargs):
"""Shows the menu. Any `kwargs` supplied will be passed to
`show_menu()`."""
show_kwargs = copy.deepcopy(self._show_kwargs)
show_kwargs.update(kwargs)
return show_menu(self.entries, **show_kwargs) | def show(self, **kwargs):
"""Shows the menu. Any `kwargs` supplied will be passed to
`show_menu()`."""
show_kwargs = copy.deepcopy(self._show_kwargs)
show_kwargs.update(kwargs)
return show_menu(self.entries, **show_kwargs) | [
"Shows",
"the",
"menu",
".",
"Any",
"kwargs",
"supplied",
"will",
"be",
"passed",
"to",
"show_menu",
"()",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L148-L153 | [
"def",
"show",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"show_kwargs",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"_show_kwargs",
")",
"show_kwargs",
".",
"update",
"(",
"kwargs",
")",
"return",
"show_menu",
"(",
"self",
".",
"entries",
","... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | Menu.run | Runs the function associated with the given entry `name`. | lib/qprompt.py | def run(self, name):
"""Runs the function associated with the given entry `name`."""
for entry in self.entries:
if entry.name == name:
run_func(entry)
break | def run(self, name):
"""Runs the function associated with the given entry `name`."""
for entry in self.entries:
if entry.name == name:
run_func(entry)
break | [
"Runs",
"the",
"function",
"associated",
"with",
"the",
"given",
"entry",
"name",
"."
] | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L154-L159 | [
"def",
"run",
"(",
"self",
",",
"name",
")",
":",
"for",
"entry",
"in",
"self",
".",
"entries",
":",
"if",
"entry",
".",
"name",
"==",
"name",
":",
"run_func",
"(",
"entry",
")",
"break"
] | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | Menu.main | Runs the standard menu main logic. Any `kwargs` supplied will be
pass to `Menu.show()`. If `argv` is provided to the script, it will be
used as the `auto` parameter.
**Params**:
- auto ([str]) - If provided, the list of strings with be used as
input for the menu prompts.
... | lib/qprompt.py | def main(self, auto=None, loop=False, quit=("q", "Quit"), **kwargs):
"""Runs the standard menu main logic. Any `kwargs` supplied will be
pass to `Menu.show()`. If `argv` is provided to the script, it will be
used as the `auto` parameter.
**Params**:
- auto ([str]) - If provide... | def main(self, auto=None, loop=False, quit=("q", "Quit"), **kwargs):
"""Runs the standard menu main logic. Any `kwargs` supplied will be
pass to `Menu.show()`. If `argv` is provided to the script, it will be
used as the `auto` parameter.
**Params**:
- auto ([str]) - If provide... | [
"Runs",
"the",
"standard",
"menu",
"main",
"logic",
".",
"Any",
"kwargs",
"supplied",
"will",
"be",
"pass",
"to",
"Menu",
".",
"show",
"()",
".",
"If",
"argv",
"is",
"provided",
"to",
"the",
"script",
"it",
"will",
"be",
"used",
"as",
"the",
"auto",
... | jeffrimko/Qprompt | python | https://github.com/jeffrimko/Qprompt/blob/1887c53656dfecac49e0650e0f912328801cbb83/lib/qprompt.py#L160-L199 | [
"def",
"main",
"(",
"self",
",",
"auto",
"=",
"None",
",",
"loop",
"=",
"False",
",",
"quit",
"=",
"(",
"\"q\"",
",",
"\"Quit\"",
")",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"_main",
"(",
")",
":",
"global",
"_AUTO",
"if",
"quit",
":",
"if",... | 1887c53656dfecac49e0650e0f912328801cbb83 |
train | partition_scripts | Return two lists of scripts out of the original `scripts` list.
Scripts that begin with a `start_type1` or `start_type2` blocks
are returned first. All other scripts are returned second. | hairball/plugins/initialization.py | def partition_scripts(scripts, start_type1, start_type2):
"""Return two lists of scripts out of the original `scripts` list.
Scripts that begin with a `start_type1` or `start_type2` blocks
are returned first. All other scripts are returned second.
"""
match, other = [], []
for script in scrip... | def partition_scripts(scripts, start_type1, start_type2):
"""Return two lists of scripts out of the original `scripts` list.
Scripts that begin with a `start_type1` or `start_type2` blocks
are returned first. All other scripts are returned second.
"""
match, other = [], []
for script in scrip... | [
"Return",
"two",
"lists",
"of",
"scripts",
"out",
"of",
"the",
"original",
"scripts",
"list",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L7-L21 | [
"def",
"partition_scripts",
"(",
"scripts",
",",
"start_type1",
",",
"start_type2",
")",
":",
"match",
",",
"other",
"=",
"[",
"]",
",",
"[",
"]",
"for",
"script",
"in",
"scripts",
":",
"if",
"(",
"HairballPlugin",
".",
"script_start_type",
"(",
"script",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | AttributeInitialization.attribute_result | Return mapping of attributes to if they were initialized or not. | hairball/plugins/initialization.py | def attribute_result(cls, sprites):
"""Return mapping of attributes to if they were initialized or not."""
retval = dict((x, True) for x in cls.ATTRIBUTES)
for properties in sprites.values():
for attribute, state in properties.items():
retval[attribute] &= state != cl... | def attribute_result(cls, sprites):
"""Return mapping of attributes to if they were initialized or not."""
retval = dict((x, True) for x in cls.ATTRIBUTES)
for properties in sprites.values():
for attribute, state in properties.items():
retval[attribute] &= state != cl... | [
"Return",
"mapping",
"of",
"attributes",
"to",
"if",
"they",
"were",
"initialized",
"or",
"not",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L36-L42 | [
"def",
"attribute_result",
"(",
"cls",
",",
"sprites",
")",
":",
"retval",
"=",
"dict",
"(",
"(",
"x",
",",
"True",
")",
"for",
"x",
"in",
"cls",
".",
"ATTRIBUTES",
")",
"for",
"properties",
"in",
"sprites",
".",
"values",
"(",
")",
":",
"for",
"at... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | AttributeInitialization.attribute_state | Return the state of the scripts for the given attribute.
If there is more than one 'when green flag clicked' script and they
both modify the attribute, then the attribute is considered to not be
initialized. | hairball/plugins/initialization.py | def attribute_state(cls, scripts, attribute):
"""Return the state of the scripts for the given attribute.
If there is more than one 'when green flag clicked' script and they
both modify the attribute, then the attribute is considered to not be
initialized.
"""
green_fla... | def attribute_state(cls, scripts, attribute):
"""Return the state of the scripts for the given attribute.
If there is more than one 'when green flag clicked' script and they
both modify the attribute, then the attribute is considered to not be
initialized.
"""
green_fla... | [
"Return",
"the",
"state",
"of",
"the",
"scripts",
"for",
"the",
"given",
"attribute",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L45-L86 | [
"def",
"attribute_state",
"(",
"cls",
",",
"scripts",
",",
"attribute",
")",
":",
"green_flag",
",",
"other",
"=",
"partition_scripts",
"(",
"scripts",
",",
"cls",
".",
"HAT_GREEN_FLAG",
",",
"cls",
".",
"HAT_CLONE",
")",
"block_set",
"=",
"cls",
".",
"BLO... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | AttributeInitialization.output_results | Output whether or not each attribute was correctly initialized.
Attributes that were not modified at all are considered to be properly
initialized. | hairball/plugins/initialization.py | def output_results(cls, sprites):
"""Output whether or not each attribute was correctly initialized.
Attributes that were not modified at all are considered to be properly
initialized.
"""
print(' '.join(cls.ATTRIBUTES))
format_strs = ['{{{}!s:^{}}}'.format(x, len(x)) f... | def output_results(cls, sprites):
"""Output whether or not each attribute was correctly initialized.
Attributes that were not modified at all are considered to be properly
initialized.
"""
print(' '.join(cls.ATTRIBUTES))
format_strs = ['{{{}!s:^{}}}'.format(x, len(x)) f... | [
"Output",
"whether",
"or",
"not",
"each",
"attribute",
"was",
"correctly",
"initialized",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L89-L99 | [
"def",
"output_results",
"(",
"cls",
",",
"sprites",
")",
":",
"print",
"(",
"' '",
".",
"join",
"(",
"cls",
".",
"ATTRIBUTES",
")",
")",
"format_strs",
"=",
"[",
"'{{{}!s:^{}}}'",
".",
"format",
"(",
"x",
",",
"len",
"(",
"x",
")",
")",
"for",
"x"... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | AttributeInitialization.sprite_changes | Return a mapping of attributes to their initilization state. | hairball/plugins/initialization.py | def sprite_changes(cls, sprite):
"""Return a mapping of attributes to their initilization state."""
retval = dict((x, cls.attribute_state(sprite.scripts, x)) for x in
(x for x in cls.ATTRIBUTES if x != 'background'))
return retval | def sprite_changes(cls, sprite):
"""Return a mapping of attributes to their initilization state."""
retval = dict((x, cls.attribute_state(sprite.scripts, x)) for x in
(x for x in cls.ATTRIBUTES if x != 'background'))
return retval | [
"Return",
"a",
"mapping",
"of",
"attributes",
"to",
"their",
"initilization",
"state",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L102-L106 | [
"def",
"sprite_changes",
"(",
"cls",
",",
"sprite",
")",
":",
"retval",
"=",
"dict",
"(",
"(",
"x",
",",
"cls",
".",
"attribute_state",
"(",
"sprite",
".",
"scripts",
",",
"x",
")",
")",
"for",
"x",
"in",
"(",
"x",
"for",
"x",
"in",
"cls",
".",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | AttributeInitialization.analyze | Run and return the results of the AttributeInitialization plugin. | hairball/plugins/initialization.py | def analyze(self, scratch, **kwargs):
"""Run and return the results of the AttributeInitialization plugin."""
changes = dict((x.name, self.sprite_changes(x)) for x in
scratch.sprites)
changes['stage'] = {
'background': self.attribute_state(scratch.stage.scripts... | def analyze(self, scratch, **kwargs):
"""Run and return the results of the AttributeInitialization plugin."""
changes = dict((x.name, self.sprite_changes(x)) for x in
scratch.sprites)
changes['stage'] = {
'background': self.attribute_state(scratch.stage.scripts... | [
"Run",
"and",
"return",
"the",
"results",
"of",
"the",
"AttributeInitialization",
"plugin",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L108-L116 | [
"def",
"analyze",
"(",
"self",
",",
"scratch",
",",
"*",
"*",
"kwargs",
")",
":",
"changes",
"=",
"dict",
"(",
"(",
"x",
".",
"name",
",",
"self",
".",
"sprite_changes",
"(",
"x",
")",
")",
"for",
"x",
"in",
"scratch",
".",
"sprites",
")",
"chang... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | VariableInitialization.variable_state | Return the initialization state for each variable in variables.
The state is determined based on the scripts passed in via the scripts
parameter.
If there is more than one 'when green flag clicked' script and they
both modify the attribute, then the attribute is considered to not be
... | hairball/plugins/initialization.py | def variable_state(cls, scripts, variables):
"""Return the initialization state for each variable in variables.
The state is determined based on the scripts passed in via the scripts
parameter.
If there is more than one 'when green flag clicked' script and they
both modify the ... | def variable_state(cls, scripts, variables):
"""Return the initialization state for each variable in variables.
The state is determined based on the scripts passed in via the scripts
parameter.
If there is more than one 'when green flag clicked' script and they
both modify the ... | [
"Return",
"the",
"initialization",
"state",
"for",
"each",
"variable",
"in",
"variables",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L128-L175 | [
"def",
"variable_state",
"(",
"cls",
",",
"scripts",
",",
"variables",
")",
":",
"def",
"conditionally_set_not_modified",
"(",
")",
":",
"\"\"\"Set the variable to modified if it hasn't been altered.\"\"\"",
"state",
"=",
"variables",
".",
"get",
"(",
"block",
".",
"a... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | VariableInitialization.analyze | Run and return the results of the VariableInitialization plugin. | hairball/plugins/initialization.py | def analyze(self, scratch, **kwargs):
"""Run and return the results of the VariableInitialization plugin."""
variables = dict((x, self.variable_state(x.scripts, x.variables))
for x in scratch.sprites)
variables['global'] = self.variable_state(self.iter_scripts(scratch),
... | def analyze(self, scratch, **kwargs):
"""Run and return the results of the VariableInitialization plugin."""
variables = dict((x, self.variable_state(x.scripts, x.variables))
for x in scratch.sprites)
variables['global'] = self.variable_state(self.iter_scripts(scratch),
... | [
"Run",
"and",
"return",
"the",
"results",
"of",
"the",
"VariableInitialization",
"plugin",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/initialization.py#L177-L186 | [
"def",
"analyze",
"(",
"self",
",",
"scratch",
",",
"*",
"*",
"kwargs",
")",
":",
"variables",
"=",
"dict",
"(",
"(",
"x",
",",
"self",
".",
"variable_state",
"(",
"x",
".",
"scripts",
",",
"x",
".",
"variables",
")",
")",
"for",
"x",
"in",
"scra... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | SpriteNaming.finalize | Output the default sprite names found in the project. | hairball/plugins/convention.py | def finalize(self):
"""Output the default sprite names found in the project."""
print('{} default sprite names found:'.format(self.total_default))
for name in self.list_default:
print(name) | def finalize(self):
"""Output the default sprite names found in the project."""
print('{} default sprite names found:'.format(self.total_default))
for name in self.list_default:
print(name) | [
"Output",
"the",
"default",
"sprite",
"names",
"found",
"in",
"the",
"project",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/convention.py#L22-L26 | [
"def",
"finalize",
"(",
"self",
")",
":",
"print",
"(",
"'{} default sprite names found:'",
".",
"format",
"(",
"self",
".",
"total_default",
")",
")",
"for",
"name",
"in",
"self",
".",
"list_default",
":",
"print",
"(",
"name",
")"
] | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | SpriteNaming.analyze | Run and return the results from the SpriteNaming plugin. | hairball/plugins/convention.py | def analyze(self, scratch, **kwargs):
"""Run and return the results from the SpriteNaming plugin."""
for sprite in self.iter_sprites(scratch):
for default in self.default_names:
if default in sprite.name:
self.total_default += 1
self.li... | def analyze(self, scratch, **kwargs):
"""Run and return the results from the SpriteNaming plugin."""
for sprite in self.iter_sprites(scratch):
for default in self.default_names:
if default in sprite.name:
self.total_default += 1
self.li... | [
"Run",
"and",
"return",
"the",
"results",
"from",
"the",
"SpriteNaming",
"plugin",
"."
] | ucsb-cs-education/hairball | python | https://github.com/ucsb-cs-education/hairball/blob/c6da8971f8a34e88ce401d36b51431715e1dff5b/hairball/plugins/convention.py#L28-L34 | [
"def",
"analyze",
"(",
"self",
",",
"scratch",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"sprite",
"in",
"self",
".",
"iter_sprites",
"(",
"scratch",
")",
":",
"for",
"default",
"in",
"self",
".",
"default_names",
":",
"if",
"default",
"in",
"sprite",
... | c6da8971f8a34e88ce401d36b51431715e1dff5b |
train | get_tunneling | Allows all methods to be tunneled via GET for dev/debuging
purposes. | nefertari/tweens.py | def get_tunneling(handler, registry):
""" Allows all methods to be tunneled via GET for dev/debuging
purposes.
"""
log.info('get_tunneling enabled')
def get_tunneling(request):
if request.method == 'GET':
method = request.GET.pop('_m', 'GET')
request.method = method
... | def get_tunneling(handler, registry):
""" Allows all methods to be tunneled via GET for dev/debuging
purposes.
"""
log.info('get_tunneling enabled')
def get_tunneling(request):
if request.method == 'GET':
method = request.GET.pop('_m', 'GET')
request.method = method
... | [
"Allows",
"all",
"methods",
"to",
"be",
"tunneled",
"via",
"GET",
"for",
"dev",
"/",
"debuging",
"purposes",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/tweens.py#L34-L54 | [
"def",
"get_tunneling",
"(",
"handler",
",",
"registry",
")",
":",
"log",
".",
"info",
"(",
"'get_tunneling enabled'",
")",
"def",
"get_tunneling",
"(",
"request",
")",
":",
"if",
"request",
".",
"method",
"==",
"'GET'",
":",
"method",
"=",
"request",
".",... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | enable_selfalias | This allows replacing id_name with "self".
e.g. /users/joe/account == /users/self/account if joe is in the session
as an authorized user | nefertari/tweens.py | def enable_selfalias(config, id_name):
"""
This allows replacing id_name with "self".
e.g. /users/joe/account == /users/self/account if joe is in the session
as an authorized user
"""
def context_found_subscriber(event):
request = event.request
user = getattr(request, 'user', No... | def enable_selfalias(config, id_name):
"""
This allows replacing id_name with "self".
e.g. /users/joe/account == /users/self/account if joe is in the session
as an authorized user
"""
def context_found_subscriber(event):
request = event.request
user = getattr(request, 'user', No... | [
"This",
"allows",
"replacing",
"id_name",
"with",
"self",
".",
"e",
".",
"g",
".",
"/",
"users",
"/",
"joe",
"/",
"account",
"==",
"/",
"users",
"/",
"self",
"/",
"account",
"if",
"joe",
"is",
"in",
"the",
"session",
"as",
"an",
"authorized",
"user"
... | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/tweens.py#L136-L151 | [
"def",
"enable_selfalias",
"(",
"config",
",",
"id_name",
")",
":",
"def",
"context_found_subscriber",
"(",
"event",
")",
":",
"request",
"=",
"event",
".",
"request",
"user",
"=",
"getattr",
"(",
"request",
",",
"'user'",
",",
"None",
")",
"if",
"(",
"r... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.convert_dotted | Convert dotted keys in :params: dictset to a nested dictset.
E.g. {'settings.foo': 'bar'} -> {'settings': {'foo': 'bar'}} | nefertari/view.py | def convert_dotted(params):
""" Convert dotted keys in :params: dictset to a nested dictset.
E.g. {'settings.foo': 'bar'} -> {'settings': {'foo': 'bar'}}
"""
if not isinstance(params, dictset):
params = dictset(params)
dotted_items = {k: v for k, v in params.items()... | def convert_dotted(params):
""" Convert dotted keys in :params: dictset to a nested dictset.
E.g. {'settings.foo': 'bar'} -> {'settings': {'foo': 'bar'}}
"""
if not isinstance(params, dictset):
params = dictset(params)
dotted_items = {k: v for k, v in params.items()... | [
"Convert",
"dotted",
"keys",
"in",
":",
"params",
":",
"dictset",
"to",
"a",
"nested",
"dictset",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L79-L95 | [
"def",
"convert_dotted",
"(",
"params",
")",
":",
"if",
"not",
"isinstance",
"(",
"params",
",",
"dictset",
")",
":",
"params",
"=",
"dictset",
"(",
"params",
")",
"dotted_items",
"=",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"params",
".",
... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.prepare_request_params | Prepare query and update params. | nefertari/view.py | def prepare_request_params(self, _query_params, _json_params):
""" Prepare query and update params. """
self._query_params = dictset(
_query_params or self.request.params.mixed())
self._json_params = dictset(_json_params)
ctype = self.request.content_type
if self.req... | def prepare_request_params(self, _query_params, _json_params):
""" Prepare query and update params. """
self._query_params = dictset(
_query_params or self.request.params.mixed())
self._json_params = dictset(_json_params)
ctype = self.request.content_type
if self.req... | [
"Prepare",
"query",
"and",
"update",
"params",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L136-L158 | [
"def",
"prepare_request_params",
"(",
"self",
",",
"_query_params",
",",
"_json_params",
")",
":",
"self",
".",
"_query_params",
"=",
"dictset",
"(",
"_query_params",
"or",
"self",
".",
"request",
".",
"params",
".",
"mixed",
"(",
")",
")",
"self",
".",
"_... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.set_override_rendered | Set self.request.override_renderer if needed. | nefertari/view.py | def set_override_rendered(self):
""" Set self.request.override_renderer if needed. """
if '' in self.request.accept:
self.request.override_renderer = self._default_renderer
elif 'application/json' in self.request.accept:
self.request.override_renderer = 'nefertari_json'
... | def set_override_rendered(self):
""" Set self.request.override_renderer if needed. """
if '' in self.request.accept:
self.request.override_renderer = self._default_renderer
elif 'application/json' in self.request.accept:
self.request.override_renderer = 'nefertari_json'
... | [
"Set",
"self",
".",
"request",
".",
"override_renderer",
"if",
"needed",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L160-L167 | [
"def",
"set_override_rendered",
"(",
"self",
")",
":",
"if",
"''",
"in",
"self",
".",
"request",
".",
"accept",
":",
"self",
".",
"request",
".",
"override_renderer",
"=",
"self",
".",
"_default_renderer",
"elif",
"'application/json'",
"in",
"self",
".",
"re... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView._setup_aggregation | Wrap `self.index` method with ESAggregator.
This makes `self.index` to first try to run aggregation and only
on fail original method is run. Method is wrapped only if it is
defined and `elasticsearch.enable_aggregations` setting is true. | nefertari/view.py | def _setup_aggregation(self, aggregator=None):
""" Wrap `self.index` method with ESAggregator.
This makes `self.index` to first try to run aggregation and only
on fail original method is run. Method is wrapped only if it is
defined and `elasticsearch.enable_aggregations` setting is true... | def _setup_aggregation(self, aggregator=None):
""" Wrap `self.index` method with ESAggregator.
This makes `self.index` to first try to run aggregation and only
on fail original method is run. Method is wrapped only if it is
defined and `elasticsearch.enable_aggregations` setting is true... | [
"Wrap",
"self",
".",
"index",
"method",
"with",
"ESAggregator",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L169-L188 | [
"def",
"_setup_aggregation",
"(",
"self",
",",
"aggregator",
"=",
"None",
")",
":",
"from",
"nefertari",
".",
"elasticsearch",
"import",
"ES",
"if",
"aggregator",
"is",
"None",
":",
"aggregator",
"=",
"ESAggregator",
"aggregations_enabled",
"=",
"(",
"ES",
"."... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.get_collection_es | Query ES collection and return results.
This is default implementation of querying ES collection with
`self._query_params`. It must return found ES collection
results for default response renderers to work properly. | nefertari/view.py | def get_collection_es(self):
""" Query ES collection and return results.
This is default implementation of querying ES collection with
`self._query_params`. It must return found ES collection
results for default response renderers to work properly.
"""
from nefertari.ela... | def get_collection_es(self):
""" Query ES collection and return results.
This is default implementation of querying ES collection with
`self._query_params`. It must return found ES collection
results for default response renderers to work properly.
"""
from nefertari.ela... | [
"Query",
"ES",
"collection",
"and",
"return",
"results",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L190-L198 | [
"def",
"get_collection_es",
"(",
"self",
")",
":",
"from",
"nefertari",
".",
"elasticsearch",
"import",
"ES",
"return",
"ES",
"(",
"self",
".",
"Model",
".",
"__name__",
")",
".",
"get_collection",
"(",
"*",
"*",
"self",
".",
"_query_params",
")"
] | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.fill_null_values | Fill missing model fields in JSON with {key: null value}.
Only run for PUT requests. | nefertari/view.py | def fill_null_values(self):
""" Fill missing model fields in JSON with {key: null value}.
Only run for PUT requests.
"""
if not self.Model:
log.info("%s has no model defined" % self.__class__.__name__)
return
empty_values = self.Model.get_null_values()
... | def fill_null_values(self):
""" Fill missing model fields in JSON with {key: null value}.
Only run for PUT requests.
"""
if not self.Model:
log.info("%s has no model defined" % self.__class__.__name__)
return
empty_values = self.Model.get_null_values()
... | [
"Fill",
"missing",
"model",
"fields",
"in",
"JSON",
"with",
"{",
"key",
":",
"null",
"value",
"}",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L200-L212 | [
"def",
"fill_null_values",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"Model",
":",
"log",
".",
"info",
"(",
"\"%s has no model defined\"",
"%",
"self",
".",
"__class__",
".",
"__name__",
")",
"return",
"empty_values",
"=",
"self",
".",
"Model",
".",... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.set_public_limits | Set public limits if auth is enabled and user is not
authenticated.
Also sets default limit for GET, HEAD requests. | nefertari/view.py | def set_public_limits(self):
""" Set public limits if auth is enabled and user is not
authenticated.
Also sets default limit for GET, HEAD requests.
"""
if self.request.method.upper() in ['GET', 'HEAD']:
self._query_params.process_int_param('_limit', 20)
if s... | def set_public_limits(self):
""" Set public limits if auth is enabled and user is not
authenticated.
Also sets default limit for GET, HEAD requests.
"""
if self.request.method.upper() in ['GET', 'HEAD']:
self._query_params.process_int_param('_limit', 20)
if s... | [
"Set",
"public",
"limits",
"if",
"auth",
"is",
"enabled",
"and",
"user",
"is",
"not",
"authenticated",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L214-L223 | [
"def",
"set_public_limits",
"(",
"self",
")",
":",
"if",
"self",
".",
"request",
".",
"method",
".",
"upper",
"(",
")",
"in",
"[",
"'GET'",
",",
"'HEAD'",
"]",
":",
"self",
".",
"_query_params",
".",
"process_int_param",
"(",
"'_limit'",
",",
"20",
")"... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.convert_ids2objects | Convert object IDs from `self._json_params` to objects if needed.
Only IDs that belong to relationship field of `self.Model`
are converted. | nefertari/view.py | def convert_ids2objects(self):
""" Convert object IDs from `self._json_params` to objects if needed.
Only IDs that belong to relationship field of `self.Model`
are converted.
"""
if not self.Model:
log.info("%s has no model defined" % self.__class__.__name__)
... | def convert_ids2objects(self):
""" Convert object IDs from `self._json_params` to objects if needed.
Only IDs that belong to relationship field of `self.Model`
are converted.
"""
if not self.Model:
log.info("%s has no model defined" % self.__class__.__name__)
... | [
"Convert",
"object",
"IDs",
"from",
"self",
".",
"_json_params",
"to",
"objects",
"if",
"needed",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L225-L239 | [
"def",
"convert_ids2objects",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"Model",
":",
"log",
".",
"info",
"(",
"\"%s has no model defined\"",
"%",
"self",
".",
"__class__",
".",
"__name__",
")",
"return",
"for",
"field",
"in",
"self",
".",
"_json_pa... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | BaseView.setup_default_wrappers | Setup defaulf wrappers.
Wrappers are applied when view method does not return instance
of Response. In this case nefertari renderers call wrappers and
handle response generation. | nefertari/view.py | def setup_default_wrappers(self):
""" Setup defaulf wrappers.
Wrappers are applied when view method does not return instance
of Response. In this case nefertari renderers call wrappers and
handle response generation.
"""
# Index
self._after_calls['index'] = [
... | def setup_default_wrappers(self):
""" Setup defaulf wrappers.
Wrappers are applied when view method does not return instance
of Response. In this case nefertari renderers call wrappers and
handle response generation.
"""
# Index
self._after_calls['index'] = [
... | [
"Setup",
"defaulf",
"wrappers",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/view.py#L241-L293 | [
"def",
"setup_default_wrappers",
"(",
"self",
")",
":",
"# Index",
"self",
".",
"_after_calls",
"[",
"'index'",
"]",
"=",
"[",
"wrappers",
".",
"wrap_in_dict",
"(",
"self",
".",
"request",
")",
",",
"wrappers",
".",
"add_meta",
"(",
"self",
".",
"request",... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | migrate_codec | Migrate data from mongodict <= 0.2.1 to 0.3.0
`config_old` and `config_new` should be dictionaries with the keys
regarding to MongoDB server:
- `host`
- `port`
- `database`
- `collection` | migrate_data.py | def migrate_codec(config_old, config_new):
'''Migrate data from mongodict <= 0.2.1 to 0.3.0
`config_old` and `config_new` should be dictionaries with the keys
regarding to MongoDB server:
- `host`
- `port`
- `database`
- `collection`
'''
assert mongodict.__version__ i... | def migrate_codec(config_old, config_new):
'''Migrate data from mongodict <= 0.2.1 to 0.3.0
`config_old` and `config_new` should be dictionaries with the keys
regarding to MongoDB server:
- `host`
- `port`
- `database`
- `collection`
'''
assert mongodict.__version__ i... | [
"Migrate",
"data",
"from",
"mongodict",
"<",
"=",
"0",
".",
"2",
".",
"1",
"to",
"0",
".",
"3",
".",
"0",
"config_old",
"and",
"config_new",
"should",
"be",
"dictionaries",
"with",
"the",
"keys",
"regarding",
"to",
"MongoDB",
"server",
":",
"-",
"host"... | turicas/mongodict | python | https://github.com/turicas/mongodict/blob/596211a57f68cc0574eededc5cb2a4be8f9ce098/migrate_data.py#L40-L64 | [
"def",
"migrate_codec",
"(",
"config_old",
",",
"config_new",
")",
":",
"assert",
"mongodict",
".",
"__version__",
"in",
"[",
"(",
"0",
",",
"3",
",",
"0",
")",
",",
"(",
"0",
",",
"3",
",",
"1",
")",
"]",
"connection",
"=",
"pymongo",
".",
"Connec... | 596211a57f68cc0574eededc5cb2a4be8f9ce098 |
train | FieldData.from_dict | Generate map of `fieldName: clsInstance` from dict.
:param data: Dict where keys are field names and values are
new values of field.
:param model: Model class to which fields from :data: belong. | nefertari/utils/data.py | def from_dict(cls, data, model):
""" Generate map of `fieldName: clsInstance` from dict.
:param data: Dict where keys are field names and values are
new values of field.
:param model: Model class to which fields from :data: belong.
"""
model_provided = model is not N... | def from_dict(cls, data, model):
""" Generate map of `fieldName: clsInstance` from dict.
:param data: Dict where keys are field names and values are
new values of field.
:param model: Model class to which fields from :data: belong.
"""
model_provided = model is not N... | [
"Generate",
"map",
"of",
"fieldName",
":",
"clsInstance",
"from",
"dict",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/utils/data.py#L119-L136 | [
"def",
"from_dict",
"(",
"cls",
",",
"data",
",",
"model",
")",
":",
"model_provided",
"=",
"model",
"is",
"not",
"None",
"result",
"=",
"{",
"}",
"for",
"name",
",",
"new_value",
"in",
"data",
".",
"items",
"(",
")",
":",
"kwargs",
"=",
"{",
"'nam... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | TicketAuthViewMixin.register | Register new user by POSTing all required data. | nefertari/authentication/views.py | def register(self):
""" Register new user by POSTing all required data. """
user, created = self.Model.create_account(
self._json_params)
if not created:
raise JHTTPConflict('Looks like you already have an account.')
self.request._user = user
pk_field = ... | def register(self):
""" Register new user by POSTing all required data. """
user, created = self.Model.create_account(
self._json_params)
if not created:
raise JHTTPConflict('Looks like you already have an account.')
self.request._user = user
pk_field = ... | [
"Register",
"new",
"user",
"by",
"POSTing",
"all",
"required",
"data",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/authentication/views.py#L15-L26 | [
"def",
"register",
"(",
"self",
")",
":",
"user",
",",
"created",
"=",
"self",
".",
"Model",
".",
"create_account",
"(",
"self",
".",
"_json_params",
")",
"if",
"not",
"created",
":",
"raise",
"JHTTPConflict",
"(",
"'Looks like you already have an account.'",
... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | TokenAuthViewMixin.register | Register a new user by POSTing all required data.
User's `Authorization` header value is returned in `WWW-Authenticate`
header. | nefertari/authentication/views.py | def register(self):
""" Register a new user by POSTing all required data.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
user, created = self.Model.create_account(self._json_params)
if user.api_key is None:
raise JHTTPBadReq... | def register(self):
""" Register a new user by POSTing all required data.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
user, created = self.Model.create_account(self._json_params)
if user.api_key is None:
raise JHTTPBadReq... | [
"Register",
"a",
"new",
"user",
"by",
"POSTing",
"all",
"required",
"data",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/authentication/views.py#L109-L124 | [
"def",
"register",
"(",
"self",
")",
":",
"user",
",",
"created",
"=",
"self",
".",
"Model",
".",
"create_account",
"(",
"self",
".",
"_json_params",
")",
"if",
"user",
".",
"api_key",
"is",
"None",
":",
"raise",
"JHTTPBadRequest",
"(",
"'Failed to generat... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | TokenAuthViewMixin.claim_token | Claim current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header. | nefertari/authentication/views.py | def claim_token(self, **params):
"""Claim current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
self._json_params.update(params)
success, self.user = self.Model.authenticate_by_password(
... | def claim_token(self, **params):
"""Claim current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
self._json_params.update(params)
success, self.user = self.Model.authenticate_by_password(
... | [
"Claim",
"current",
"token",
"by",
"POSTing",
"login",
"and",
"password",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/authentication/views.py#L126-L142 | [
"def",
"claim_token",
"(",
"self",
",",
"*",
"*",
"params",
")",
":",
"self",
".",
"_json_params",
".",
"update",
"(",
"params",
")",
"success",
",",
"self",
".",
"user",
"=",
"self",
".",
"Model",
".",
"authenticate_by_password",
"(",
"self",
".",
"_j... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | TokenAuthViewMixin.reset_token | Reset current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header. | nefertari/authentication/views.py | def reset_token(self, **params):
""" Reset current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
response = self.claim_token(**params)
if not self.user:
return response
self... | def reset_token(self, **params):
""" Reset current token by POSTing 'login' and 'password'.
User's `Authorization` header value is returned in `WWW-Authenticate`
header.
"""
response = self.claim_token(**params)
if not self.user:
return response
self... | [
"Reset",
"current",
"token",
"by",
"POSTing",
"login",
"and",
"password",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/authentication/views.py#L144-L156 | [
"def",
"reset_token",
"(",
"self",
",",
"*",
"*",
"params",
")",
":",
"response",
"=",
"self",
".",
"claim_token",
"(",
"*",
"*",
"params",
")",
"if",
"not",
"self",
".",
"user",
":",
"return",
"response",
"self",
".",
"user",
".",
"api_key",
".",
... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | apply_privacy._apply_nested_privacy | Apply privacy to nested documents.
:param data: Dict of data to which privacy is already applied. | nefertari/wrappers.py | def _apply_nested_privacy(self, data):
""" Apply privacy to nested documents.
:param data: Dict of data to which privacy is already applied.
"""
kw = {
'is_admin': self.is_admin,
'drop_hidden': self.drop_hidden,
}
for key, val in data.items():
... | def _apply_nested_privacy(self, data):
""" Apply privacy to nested documents.
:param data: Dict of data to which privacy is already applied.
"""
kw = {
'is_admin': self.is_admin,
'drop_hidden': self.drop_hidden,
}
for key, val in data.items():
... | [
"Apply",
"privacy",
"to",
"nested",
"documents",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/wrappers.py#L191-L206 | [
"def",
"_apply_nested_privacy",
"(",
"self",
",",
"data",
")",
":",
"kw",
"=",
"{",
"'is_admin'",
":",
"self",
".",
"is_admin",
",",
"'drop_hidden'",
":",
"self",
".",
"drop_hidden",
",",
"}",
"for",
"key",
",",
"val",
"in",
"data",
".",
"items",
"(",
... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
train | add_object_url._set_object_self | Add '_self' key value to :obj: dict. | nefertari/wrappers.py | def _set_object_self(self, obj):
""" Add '_self' key value to :obj: dict. """
from nefertari.elasticsearch import ES
location = self.request.path_url
route_kwargs = {}
""" Check for parents """
if self.request.matchdict:
route_kwargs.update(self.request.match... | def _set_object_self(self, obj):
""" Add '_self' key value to :obj: dict. """
from nefertari.elasticsearch import ES
location = self.request.path_url
route_kwargs = {}
""" Check for parents """
if self.request.matchdict:
route_kwargs.update(self.request.match... | [
"Add",
"_self",
"key",
"value",
"to",
":",
"obj",
":",
"dict",
"."
] | ramses-tech/nefertari | python | https://github.com/ramses-tech/nefertari/blob/c7caffe11576c11aa111adbdbadeff70ce66b1dd/nefertari/wrappers.py#L300-L319 | [
"def",
"_set_object_self",
"(",
"self",
",",
"obj",
")",
":",
"from",
"nefertari",
".",
"elasticsearch",
"import",
"ES",
"location",
"=",
"self",
".",
"request",
".",
"path_url",
"route_kwargs",
"=",
"{",
"}",
"\"\"\" Check for parents \"\"\"",
"if",
"self",
"... | c7caffe11576c11aa111adbdbadeff70ce66b1dd |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.