repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ponty/psidialogs | psidialogs/api/easygui_api.py | fileopenbox | def fileopenbox(msg=None, title=None, argInitialFile=None):
"""Original doc: A dialog to get a file name.
Returns the name of a file, or None if user chose to cancel.
if argInitialFile contains a valid filename, the dialog will
be positioned at that file when it appears.
"""
ret... | python | def fileopenbox(msg=None, title=None, argInitialFile=None):
"""Original doc: A dialog to get a file name.
Returns the name of a file, or None if user chose to cancel.
if argInitialFile contains a valid filename, the dialog will
be positioned at that file when it appears.
"""
ret... | [
"def",
"fileopenbox",
"(",
"msg",
"=",
"None",
",",
"title",
"=",
"None",
",",
"argInitialFile",
"=",
"None",
")",
":",
"return",
"psidialogs",
".",
"ask_file",
"(",
"message",
"=",
"msg",
",",
"title",
"=",
"title",
",",
"default",
"=",
"argInitialFile"... | Original doc: A dialog to get a file name.
Returns the name of a file, or None if user chose to cancel.
if argInitialFile contains a valid filename, the dialog will
be positioned at that file when it appears. | [
"Original",
"doc",
":",
"A",
"dialog",
"to",
"get",
"a",
"file",
"name",
".",
"Returns",
"the",
"name",
"of",
"a",
"file",
"or",
"None",
"if",
"user",
"chose",
"to",
"cancel",
"."
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/easygui_api.py#L103-L110 | train | Original doc : A dialog to get a file name. |
ponty/psidialogs | psidialogs/api/easygui_api.py | integerbox | def integerbox(message='Enter something.', title='', argDefault=None, argLowerBound=0, argUpperBound=99):
"""Original doc: Show a box in which a user can enter an integer.
In addition to arguments for message and title, this function accepts
integer arguments for default_value, lowerbound, and upper... | python | def integerbox(message='Enter something.', title='', argDefault=None, argLowerBound=0, argUpperBound=99):
"""Original doc: Show a box in which a user can enter an integer.
In addition to arguments for message and title, this function accepts
integer arguments for default_value, lowerbound, and upper... | [
"def",
"integerbox",
"(",
"message",
"=",
"'Enter something.'",
",",
"title",
"=",
"''",
",",
"argDefault",
"=",
"None",
",",
"argLowerBound",
"=",
"0",
",",
"argUpperBound",
"=",
"99",
")",
":",
"return",
"psidialogs",
".",
"ask_string",
"(",
"message",
"... | Original doc: Show a box in which a user can enter an integer.
In addition to arguments for message and title, this function accepts
integer arguments for default_value, lowerbound, and upperbound.
The default_value argument may be None.
When the user enters some text, the text is chec... | [
"Original",
"doc",
":",
"Show",
"a",
"box",
"in",
"which",
"a",
"user",
"can",
"enter",
"an",
"integer",
".",
"In",
"addition",
"to",
"arguments",
"for",
"message",
"and",
"title",
"this",
"function",
"accepts",
"integer",
"arguments",
"for",
"default_value"... | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/easygui_api.py#L113-L130 | train | Original doc : Shows a box in which a user can enter an integer. |
ponty/psidialogs | psidialogs/api/easygui_api.py | ccbox | def ccbox(message="Shall I continue?", title=""):
"""
Original doc:
Display a message box with choices of Continue and Cancel.
The default is "Continue".
Returns returns 1 if "Continue" is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwise return... | python | def ccbox(message="Shall I continue?", title=""):
"""
Original doc:
Display a message box with choices of Continue and Cancel.
The default is "Continue".
Returns returns 1 if "Continue" is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwise return... | [
"def",
"ccbox",
"(",
"message",
"=",
"\"Shall I continue?\"",
",",
"title",
"=",
"\"\"",
")",
":",
"choices",
"=",
"[",
"\"Continue\"",
",",
"\"Cancel\"",
"]",
"if",
"title",
"==",
"None",
":",
"title",
"=",
"\"\"",
"return",
"boolbox",
"(",
"message",
"... | Original doc:
Display a message box with choices of Continue and Cancel.
The default is "Continue".
Returns returns 1 if "Continue" is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwise returns 0.
If invoked without a message parameter, displays a g... | [
"Original",
"doc",
":",
"Display",
"a",
"message",
"box",
"with",
"choices",
"of",
"Continue",
"and",
"Cancel",
".",
"The",
"default",
"is",
"Continue",
".",
"Returns",
"returns",
"1",
"if",
"Continue",
"is",
"chosen",
"or",
"if",
"the",
"dialog",
"is",
... | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/easygui_api.py#L151-L169 | train | Display a message box with choices of Continue and Cancel. |
ponty/psidialogs | psidialogs/api/easygui_api.py | boolbox | def boolbox(message="Shall I continue?", title="", choices=["Yes", "No"]):
"""
Original doc:
Display a boolean message box.
The default is the first choice.
Returns returns 1 if the first choice is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwi... | python | def boolbox(message="Shall I continue?", title="", choices=["Yes", "No"]):
"""
Original doc:
Display a boolean message box.
The default is the first choice.
Returns returns 1 if the first choice is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwi... | [
"def",
"boolbox",
"(",
"message",
"=",
"\"Shall I continue?\"",
",",
"title",
"=",
"\"\"",
",",
"choices",
"=",
"[",
"\"Yes\"",
",",
"\"No\"",
"]",
")",
":",
"if",
"title",
"==",
"None",
":",
"if",
"message",
"==",
"\"Shall I continue?\"",
":",
"title",
... | Original doc:
Display a boolean message box.
The default is the first choice.
Returns returns 1 if the first choice is chosen, or if
the dialog is cancelled (which is interpreted as
choosing the default). Otherwise returns 0. | [
"Original",
"doc",
":",
"Display",
"a",
"boolean",
"message",
"box",
".",
"The",
"default",
"is",
"the",
"first",
"choice",
".",
"Returns",
"returns",
"1",
"if",
"the",
"first",
"choice",
"is",
"chosen",
"or",
"if",
"the",
"dialog",
"is",
"cancelled",
"(... | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/easygui_api.py#L174-L193 | train | Display a boolean message box. |
ponty/psidialogs | psidialogs/api/easygui_api.py | indexbox | def indexbox(message="Shall I continue?", title="", choices=["Yes", "No"]):
"""
Original doc:
Display a buttonbox with the specified choices.
Return the index of the choice selected.
"""
reply = buttonbox(message, title, choices)
index = -1
for choice in choices:
index = index + ... | python | def indexbox(message="Shall I continue?", title="", choices=["Yes", "No"]):
"""
Original doc:
Display a buttonbox with the specified choices.
Return the index of the choice selected.
"""
reply = buttonbox(message, title, choices)
index = -1
for choice in choices:
index = index + ... | [
"def",
"indexbox",
"(",
"message",
"=",
"\"Shall I continue?\"",
",",
"title",
"=",
"\"\"",
",",
"choices",
"=",
"[",
"\"Yes\"",
",",
"\"No\"",
"]",
")",
":",
"reply",
"=",
"buttonbox",
"(",
"message",
",",
"title",
",",
"choices",
")",
"index",
"=",
"... | Original doc:
Display a buttonbox with the specified choices.
Return the index of the choice selected. | [
"Original",
"doc",
":",
"Display",
"a",
"buttonbox",
"with",
"the",
"specified",
"choices",
".",
"Return",
"the",
"index",
"of",
"the",
"choice",
"selected",
"."
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/easygui_api.py#L198-L209 | train | Display a buttonbox with the specified choices. |
spotify/gordon-gcp | src/gordon_gcp/clients/gcrm.py | GCRMClient.list_all_active_projects | async def list_all_active_projects(self, page_size=1000):
"""Get all active projects.
You can find the endpoint documentation `here <https://cloud.
google.com/resource-manager/reference/rest/v1/projects/list>`__.
Args:
page_size (int): hint for the client to only retrieve u... | python | async def list_all_active_projects(self, page_size=1000):
"""Get all active projects.
You can find the endpoint documentation `here <https://cloud.
google.com/resource-manager/reference/rest/v1/projects/list>`__.
Args:
page_size (int): hint for the client to only retrieve u... | [
"async",
"def",
"list_all_active_projects",
"(",
"self",
",",
"page_size",
"=",
"1000",
")",
":",
"url",
"=",
"f'{self.BASE_URL}/{self.api_version}/projects'",
"params",
"=",
"{",
"'pageSize'",
":",
"page_size",
"}",
"responses",
"=",
"await",
"self",
".",
"list_a... | Get all active projects.
You can find the endpoint documentation `here <https://cloud.
google.com/resource-manager/reference/rest/v1/projects/list>`__.
Args:
page_size (int): hint for the client to only retrieve up to
this number of results per API call.
Ret... | [
"Get",
"all",
"active",
"projects",
"."
] | 5ab19e3c2fe6ace72ee91e2ef1a1326f90b805da | https://github.com/spotify/gordon-gcp/blob/5ab19e3c2fe6ace72ee91e2ef1a1326f90b805da/src/gordon_gcp/clients/gcrm.py#L85-L105 | train | Get all active projects. |
dstanek/snake-guice | snakeguice/modules.py | Module.install | def install(self, binder, module):
"""Add another module's bindings to a binder."""
ModuleAdapter(module, self._injector).configure(binder) | python | def install(self, binder, module):
"""Add another module's bindings to a binder."""
ModuleAdapter(module, self._injector).configure(binder) | [
"def",
"install",
"(",
"self",
",",
"binder",
",",
"module",
")",
":",
"ModuleAdapter",
"(",
"module",
",",
"self",
".",
"_injector",
")",
".",
"configure",
"(",
"binder",
")"
] | Add another module's bindings to a binder. | [
"Add",
"another",
"module",
"s",
"bindings",
"to",
"a",
"binder",
"."
] | d20b62de3ee31e84119c801756398c35ed803fb3 | https://github.com/dstanek/snake-guice/blob/d20b62de3ee31e84119c801756398c35ed803fb3/snakeguice/modules.py#L23-L25 | train | Install another module s bindings. |
dstanek/snake-guice | snakeguice/modules.py | PrivateModule.expose | def expose(self, binder, interface, annotation=None):
"""Expose the child injector to the parent inject for a binding."""
private_module = self
class Provider(object):
def get(self):
return private_module.private_injector.get_instance(
interfac... | python | def expose(self, binder, interface, annotation=None):
"""Expose the child injector to the parent inject for a binding."""
private_module = self
class Provider(object):
def get(self):
return private_module.private_injector.get_instance(
interfac... | [
"def",
"expose",
"(",
"self",
",",
"binder",
",",
"interface",
",",
"annotation",
"=",
"None",
")",
":",
"private_module",
"=",
"self",
"class",
"Provider",
"(",
"object",
")",
":",
"def",
"get",
"(",
"self",
")",
":",
"return",
"private_module",
".",
... | Expose the child injector to the parent inject for a binding. | [
"Expose",
"the",
"child",
"injector",
"to",
"the",
"parent",
"inject",
"for",
"a",
"binding",
"."
] | d20b62de3ee31e84119c801756398c35ed803fb3 | https://github.com/dstanek/snake-guice/blob/d20b62de3ee31e84119c801756398c35ed803fb3/snakeguice/modules.py#L57-L66 | train | Exposes the child injector to the parent inject for a binding. |
spotify/gordon-gcp | src/gordon_gcp/plugins/service/enricher.py | GCEEnricherBuilder._call_validators | def _call_validators(self):
"""Actually run all the validations.
Returns:
list(str): Error messages from the validators.
"""
msg = []
msg.extend(self._validate_keyfile())
msg.extend(self._validate_dns_zone())
msg.extend(self._validate_retries())
... | python | def _call_validators(self):
"""Actually run all the validations.
Returns:
list(str): Error messages from the validators.
"""
msg = []
msg.extend(self._validate_keyfile())
msg.extend(self._validate_dns_zone())
msg.extend(self._validate_retries())
... | [
"def",
"_call_validators",
"(",
"self",
")",
":",
"msg",
"=",
"[",
"]",
"msg",
".",
"extend",
"(",
"self",
".",
"_validate_keyfile",
"(",
")",
")",
"msg",
".",
"extend",
"(",
"self",
".",
"_validate_dns_zone",
"(",
")",
")",
"msg",
".",
"extend",
"("... | Actually run all the validations.
Returns:
list(str): Error messages from the validators. | [
"Actually",
"run",
"all",
"the",
"validations",
"."
] | 5ab19e3c2fe6ace72ee91e2ef1a1326f90b805da | https://github.com/spotify/gordon-gcp/blob/5ab19e3c2fe6ace72ee91e2ef1a1326f90b805da/src/gordon_gcp/plugins/service/enricher.py#L93-L104 | train | Actually run all the validations. |
indietyp/django-automated-logging | automated_logging/admin.py | UserActionListFilter.lookups | def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
... | python | def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
... | [
"def",
"lookups",
"(",
"self",
",",
"request",
",",
"model_admin",
")",
":",
"User",
"=",
"get_user_model",
"(",
")",
"output",
"=",
"[",
"]",
"for",
"i",
"in",
"models",
".",
"Model",
".",
"objects",
".",
"values",
"(",
"'user__pk'",
")",
".",
"dist... | Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar. | [
"Returns",
"a",
"list",
"of",
"tuples",
".",
"The",
"first",
"element",
"in",
"each",
"tuple",
"is",
"the",
"coded",
"value",
"for",
"the",
"option",
"that",
"will",
"appear",
"in",
"the",
"URL",
"query",
".",
"The",
"second",
"element",
"is",
"the",
"... | 095dfc6df62dca45f7db4516bc35e52085d0a01c | https://github.com/indietyp/django-automated-logging/blob/095dfc6df62dca45f7db4516bc35e52085d0a01c/automated_logging/admin.py#L42-L59 | train | Returns a list of tuples that are used to lookup the user s entry - level attributes. |
indietyp/django-automated-logging | automated_logging/admin.py | UserActionListFilter.queryset | def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
if self.value() is not None:
return queryset.filter(user__pk=self.value())
else:
... | python | def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
if self.value() is not None:
return queryset.filter(user__pk=self.value())
else:
... | [
"def",
"queryset",
"(",
"self",
",",
"request",
",",
"queryset",
")",
":",
"if",
"self",
".",
"value",
"(",
")",
"is",
"not",
"None",
":",
"return",
"queryset",
".",
"filter",
"(",
"user__pk",
"=",
"self",
".",
"value",
"(",
")",
")",
"else",
":",
... | Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`. | [
"Returns",
"the",
"filtered",
"queryset",
"based",
"on",
"the",
"value",
"provided",
"in",
"the",
"query",
"string",
"and",
"retrievable",
"via",
"self",
".",
"value",
"()",
"."
] | 095dfc6df62dca45f7db4516bc35e52085d0a01c | https://github.com/indietyp/django-automated-logging/blob/095dfc6df62dca45f7db4516bc35e52085d0a01c/automated_logging/admin.py#L61-L70 | train | Returns the filtered queryset based on the value of the attribute. |
indietyp/django-automated-logging | automated_logging/admin.py | ContentTypeListFilter.lookups | def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
... | python | def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
... | [
"def",
"lookups",
"(",
"self",
",",
"request",
",",
"model_admin",
")",
":",
"output",
"=",
"[",
"]",
"for",
"i",
"in",
"models",
".",
"Model",
".",
"objects",
".",
"values",
"(",
"'information__type'",
")",
".",
"distinct",
"(",
")",
":",
"ct",
"=",... | Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar. | [
"Returns",
"a",
"list",
"of",
"tuples",
".",
"The",
"first",
"element",
"in",
"each",
"tuple",
"is",
"the",
"coded",
"value",
"for",
"the",
"option",
"that",
"will",
"appear",
"in",
"the",
"URL",
"query",
".",
"The",
"second",
"element",
"is",
"the",
"... | 095dfc6df62dca45f7db4516bc35e52085d0a01c | https://github.com/indietyp/django-automated-logging/blob/095dfc6df62dca45f7db4516bc35e52085d0a01c/automated_logging/admin.py#L77-L94 | train | Returns a list of tuples that are used to identify the items in the database that will appear in the right sidebar. |
indietyp/django-automated-logging | automated_logging/admin.py | ContentTypeListFilter.queryset | def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
if self.value() is not None:
return queryset.filter(information__type__pk=self.value())
els... | python | def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
if self.value() is not None:
return queryset.filter(information__type__pk=self.value())
els... | [
"def",
"queryset",
"(",
"self",
",",
"request",
",",
"queryset",
")",
":",
"if",
"self",
".",
"value",
"(",
")",
"is",
"not",
"None",
":",
"return",
"queryset",
".",
"filter",
"(",
"information__type__pk",
"=",
"self",
".",
"value",
"(",
")",
")",
"e... | Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`. | [
"Returns",
"the",
"filtered",
"queryset",
"based",
"on",
"the",
"value",
"provided",
"in",
"the",
"query",
"string",
"and",
"retrievable",
"via",
"self",
".",
"value",
"()",
"."
] | 095dfc6df62dca45f7db4516bc35e52085d0a01c | https://github.com/indietyp/django-automated-logging/blob/095dfc6df62dca45f7db4516bc35e52085d0a01c/automated_logging/admin.py#L96-L105 | train | Returns the filtered queryset based on the value of the information type. |
gitenberg-dev/gitberg | gitenberg/util/catalog.py | BookMetadata.parse_rdf | def parse_rdf(self):
""" Parses the relevant PG rdf file
"""
try:
self.metadata = pg_rdf_to_json(self.rdf_path)
except IOError as e:
raise NoRDFError(e)
if not self.authnames():
self.author = ''
elif len(self.authnames()) == 1:
... | python | def parse_rdf(self):
""" Parses the relevant PG rdf file
"""
try:
self.metadata = pg_rdf_to_json(self.rdf_path)
except IOError as e:
raise NoRDFError(e)
if not self.authnames():
self.author = ''
elif len(self.authnames()) == 1:
... | [
"def",
"parse_rdf",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"metadata",
"=",
"pg_rdf_to_json",
"(",
"self",
".",
"rdf_path",
")",
"except",
"IOError",
"as",
"e",
":",
"raise",
"NoRDFError",
"(",
"e",
")",
"if",
"not",
"self",
".",
"authnames",
... | Parses the relevant PG rdf file | [
"Parses",
"the",
"relevant",
"PG",
"rdf",
"file"
] | 3f6db8b5a22ccdd2110d3199223c30db4e558b5c | https://github.com/gitenberg-dev/gitberg/blob/3f6db8b5a22ccdd2110d3199223c30db4e558b5c/gitenberg/util/catalog.py#L93-L106 | train | Parses the relevant PG rdf file and sets the attributes of the object. |
gitenberg-dev/gitberg | gitenberg/util/catalog.py | Rdfcache.download_rdf | def download_rdf(self, force=False):
"""Ensures a fresh-enough RDF file is downloaded and extracted.
Returns True on error."""
if self.downloading:
return True
if not force and (os.path.exists(RDF_PATH) and
(time.time() - os.path.getmtime(RDF_PATH)) < RDF_MA... | python | def download_rdf(self, force=False):
"""Ensures a fresh-enough RDF file is downloaded and extracted.
Returns True on error."""
if self.downloading:
return True
if not force and (os.path.exists(RDF_PATH) and
(time.time() - os.path.getmtime(RDF_PATH)) < RDF_MA... | [
"def",
"download_rdf",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"self",
".",
"downloading",
":",
"return",
"True",
"if",
"not",
"force",
"and",
"(",
"os",
".",
"path",
".",
"exists",
"(",
"RDF_PATH",
")",
"and",
"(",
"time",
".",
"t... | Ensures a fresh-enough RDF file is downloaded and extracted.
Returns True on error. | [
"Ensures",
"a",
"fresh",
"-",
"enough",
"RDF",
"file",
"is",
"downloaded",
"and",
"extracted",
"."
] | 3f6db8b5a22ccdd2110d3199223c30db4e558b5c | https://github.com/gitenberg-dev/gitberg/blob/3f6db8b5a22ccdd2110d3199223c30db4e558b5c/gitenberg/util/catalog.py#L134-L172 | train | Downloads the RDF file and extracts it if necessary. Returns True on success. |
Scille/autobahn-sync | autobahn_sync/core.py | AutobahnSync.run_in_twisted | def run_in_twisted(self, url=DEFAULT_AUTOBAHN_ROUTER, realm=DEFAULT_AUTOBAHN_REALM,
authmethods=None, authid=None, authrole=None, authextra=None,
callback=None, **kwargs):
"""
Start the WAMP connection. Given we cannot run synchronous stuff inside the
... | python | def run_in_twisted(self, url=DEFAULT_AUTOBAHN_ROUTER, realm=DEFAULT_AUTOBAHN_REALM,
authmethods=None, authid=None, authrole=None, authextra=None,
callback=None, **kwargs):
"""
Start the WAMP connection. Given we cannot run synchronous stuff inside the
... | [
"def",
"run_in_twisted",
"(",
"self",
",",
"url",
"=",
"DEFAULT_AUTOBAHN_ROUTER",
",",
"realm",
"=",
"DEFAULT_AUTOBAHN_REALM",
",",
"authmethods",
"=",
"None",
",",
"authid",
"=",
"None",
",",
"authrole",
"=",
"None",
",",
"authextra",
"=",
"None",
",",
"cal... | Start the WAMP connection. Given we cannot run synchronous stuff inside the
twisted thread, use this function (which returns immediately) to do the
initialization from a spawned thread.
:param callback: function that will be called inside the spawned thread.
Put the rest of you init (or... | [
"Start",
"the",
"WAMP",
"connection",
".",
"Given",
"we",
"cannot",
"run",
"synchronous",
"stuff",
"inside",
"the",
"twisted",
"thread",
"use",
"this",
"function",
"(",
"which",
"returns",
"immediately",
")",
"to",
"do",
"the",
"initialization",
"from",
"a",
... | d75fceff0d1aee61fa6dd0168eb1cd40794ad827 | https://github.com/Scille/autobahn-sync/blob/d75fceff0d1aee61fa6dd0168eb1cd40794ad827/autobahn_sync/core.py#L55-L89 | train | Start the WAMP connection and run the callback in a twisted thread. |
Scille/autobahn-sync | autobahn_sync/core.py | AutobahnSync.run | def run(self, url=DEFAULT_AUTOBAHN_ROUTER, realm=DEFAULT_AUTOBAHN_REALM,
authmethods=None, authid=None, authrole=None, authextra=None,
blocking=False, callback=None, **kwargs):
"""
Start the background twisted thread and create the WAMP connection
:param blocking: If ``F... | python | def run(self, url=DEFAULT_AUTOBAHN_ROUTER, realm=DEFAULT_AUTOBAHN_REALM,
authmethods=None, authid=None, authrole=None, authextra=None,
blocking=False, callback=None, **kwargs):
"""
Start the background twisted thread and create the WAMP connection
:param blocking: If ``F... | [
"def",
"run",
"(",
"self",
",",
"url",
"=",
"DEFAULT_AUTOBAHN_ROUTER",
",",
"realm",
"=",
"DEFAULT_AUTOBAHN_REALM",
",",
"authmethods",
"=",
"None",
",",
"authid",
"=",
"None",
",",
"authrole",
"=",
"None",
",",
"authextra",
"=",
"None",
",",
"blocking",
"... | Start the background twisted thread and create the WAMP connection
:param blocking: If ``False`` (default) this method will spawn a new
thread that will be used to run the callback events (e.i. registered and
subscribed functions). If ``True`` this method will not returns and
use the cu... | [
"Start",
"the",
"background",
"twisted",
"thread",
"and",
"create",
"the",
"WAMP",
"connection"
] | d75fceff0d1aee61fa6dd0168eb1cd40794ad827 | https://github.com/Scille/autobahn-sync/blob/d75fceff0d1aee61fa6dd0168eb1cd40794ad827/autobahn_sync/core.py#L91-L110 | train | Start the WAMP connection and create the WAMP connection |
Scille/autobahn-sync | autobahn_sync/core.py | AutobahnSync.stop | def stop(self):
"""
Terminate the WAMP session
.. note::
If the :meth:`AutobahnSync.run` has been run with ``blocking=True``,
it will returns then.
"""
if not self._started:
raise NotRunningError("This AutobahnSync instance is not started")
... | python | def stop(self):
"""
Terminate the WAMP session
.. note::
If the :meth:`AutobahnSync.run` has been run with ``blocking=True``,
it will returns then.
"""
if not self._started:
raise NotRunningError("This AutobahnSync instance is not started")
... | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_started",
":",
"raise",
"NotRunningError",
"(",
"\"This AutobahnSync instance is not started\"",
")",
"self",
".",
"_callbacks_runner",
".",
"stop",
"(",
")",
"self",
".",
"_started",
"=",
"Fals... | Terminate the WAMP session
.. note::
If the :meth:`AutobahnSync.run` has been run with ``blocking=True``,
it will returns then. | [
"Terminate",
"the",
"WAMP",
"session"
] | d75fceff0d1aee61fa6dd0168eb1cd40794ad827 | https://github.com/Scille/autobahn-sync/blob/d75fceff0d1aee61fa6dd0168eb1cd40794ad827/autobahn_sync/core.py#L112-L123 | train | Terminate the WAMP session |
Scille/autobahn-sync | autobahn_sync/core.py | AutobahnSync._bootstrap | def _bootstrap(self, blocking, **kwargs):
"""Synchronous bootstrap (even if `blocking=False` is provided !)
Create the WAMP session and configure the `_callbacks_runner`.
"""
join_config = {}
for key in ('authid', 'authmethods', 'authrole', 'authextra'):
val = kwargs... | python | def _bootstrap(self, blocking, **kwargs):
"""Synchronous bootstrap (even if `blocking=False` is provided !)
Create the WAMP session and configure the `_callbacks_runner`.
"""
join_config = {}
for key in ('authid', 'authmethods', 'authrole', 'authextra'):
val = kwargs... | [
"def",
"_bootstrap",
"(",
"self",
",",
"blocking",
",",
"*",
"*",
"kwargs",
")",
":",
"join_config",
"=",
"{",
"}",
"for",
"key",
"in",
"(",
"'authid'",
",",
"'authmethods'",
",",
"'authrole'",
",",
"'authextra'",
")",
":",
"val",
"=",
"kwargs",
".",
... | Synchronous bootstrap (even if `blocking=False` is provided !)
Create the WAMP session and configure the `_callbacks_runner`. | [
"Synchronous",
"bootstrap",
"(",
"even",
"if",
"blocking",
"=",
"False",
"is",
"provided",
"!",
")"
] | d75fceff0d1aee61fa6dd0168eb1cd40794ad827 | https://github.com/Scille/autobahn-sync/blob/d75fceff0d1aee61fa6dd0168eb1cd40794ad827/autobahn_sync/core.py#L125-L185 | train | Create the WAMP session and configure the _callbacks_runner. |
Scille/autobahn-sync | autobahn_sync/core.py | AutobahnSync.register | def register(self, procedure=None, options=None):
"""Decorator for the :meth:`AutobahnSync.session.register`
.. note::
This decorator can be used before :meth:`AutobahnSync.run` is called.
In such case the actual registration will be done at ``run()`` time.
"""
... | python | def register(self, procedure=None, options=None):
"""Decorator for the :meth:`AutobahnSync.session.register`
.. note::
This decorator can be used before :meth:`AutobahnSync.run` is called.
In such case the actual registration will be done at ``run()`` time.
"""
... | [
"def",
"register",
"(",
"self",
",",
"procedure",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"if",
"self",
".",
"_started",
":",
"self",
".",
"session",
".",
"register",
"(",
"endpoint",
"=",
"func"... | Decorator for the :meth:`AutobahnSync.session.register`
.. note::
This decorator can be used before :meth:`AutobahnSync.run` is called.
In such case the actual registration will be done at ``run()`` time. | [
"Decorator",
"for",
"the",
":",
"meth",
":",
"AutobahnSync",
".",
"session",
".",
"register"
] | d75fceff0d1aee61fa6dd0168eb1cd40794ad827 | https://github.com/Scille/autobahn-sync/blob/d75fceff0d1aee61fa6dd0168eb1cd40794ad827/autobahn_sync/core.py#L187-L207 | train | Decorator for the AutobahnSync. session. register method. |
Scille/autobahn-sync | autobahn_sync/core.py | AutobahnSync.subscribe | def subscribe(self, topic, options=None):
"""Decorator for the :meth:`AutobahnSync.session.subscribe`
.. note::
This decorator can be used before :meth:`AutobahnSync.run` is called.
In such case the actual registration will be done at ``run()`` time.
"""
def dec... | python | def subscribe(self, topic, options=None):
"""Decorator for the :meth:`AutobahnSync.session.subscribe`
.. note::
This decorator can be used before :meth:`AutobahnSync.run` is called.
In such case the actual registration will be done at ``run()`` time.
"""
def dec... | [
"def",
"subscribe",
"(",
"self",
",",
"topic",
",",
"options",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"if",
"self",
".",
"_started",
":",
"self",
".",
"session",
".",
"subscribe",
"(",
"handler",
"=",
"func",
",",
"topic",
... | Decorator for the :meth:`AutobahnSync.session.subscribe`
.. note::
This decorator can be used before :meth:`AutobahnSync.run` is called.
In such case the actual registration will be done at ``run()`` time. | [
"Decorator",
"for",
"the",
":",
"meth",
":",
"AutobahnSync",
".",
"session",
".",
"subscribe"
] | d75fceff0d1aee61fa6dd0168eb1cd40794ad827 | https://github.com/Scille/autobahn-sync/blob/d75fceff0d1aee61fa6dd0168eb1cd40794ad827/autobahn_sync/core.py#L209-L229 | train | Decorator for the AutobahnSync. session. subscribe method. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | process_event | def process_event(self, event_id):
"""Process event in Celery."""
with db.session.begin_nested():
event = Event.query.get(event_id)
event._celery_task = self # internal binding to a Celery task
event.receiver.run(event) # call run directly to avoid circular calls
flag_modified(... | python | def process_event(self, event_id):
"""Process event in Celery."""
with db.session.begin_nested():
event = Event.query.get(event_id)
event._celery_task = self # internal binding to a Celery task
event.receiver.run(event) # call run directly to avoid circular calls
flag_modified(... | [
"def",
"process_event",
"(",
"self",
",",
"event_id",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"event",
"=",
"Event",
".",
"query",
".",
"get",
"(",
"event_id",
")",
"event",
".",
"_celery_task",
"=",
"self",
"# inter... | Process event in Celery. | [
"Process",
"event",
"in",
"Celery",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L143-L152 | train | Process an event in Celery. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | _json_column | def _json_column(**kwargs):
"""Return JSON column."""
return db.Column(
JSONType().with_variant(
postgresql.JSON(none_as_null=True),
'postgresql',
),
nullable=True,
**kwargs
) | python | def _json_column(**kwargs):
"""Return JSON column."""
return db.Column(
JSONType().with_variant(
postgresql.JSON(none_as_null=True),
'postgresql',
),
nullable=True,
**kwargs
) | [
"def",
"_json_column",
"(",
"*",
"*",
"kwargs",
")",
":",
"return",
"db",
".",
"Column",
"(",
"JSONType",
"(",
")",
".",
"with_variant",
"(",
"postgresql",
".",
"JSON",
"(",
"none_as_null",
"=",
"True",
")",
",",
"'postgresql'",
",",
")",
",",
"nullabl... | Return JSON column. | [
"Return",
"JSON",
"column",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L197-L206 | train | Return a JSON column. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Receiver.delete | def delete(self, event):
"""Mark event as deleted."""
assert self.receiver_id == event.receiver_id
event.response = {'status': 410, 'message': 'Gone.'}
event.response_code = 410 | python | def delete(self, event):
"""Mark event as deleted."""
assert self.receiver_id == event.receiver_id
event.response = {'status': 410, 'message': 'Gone.'}
event.response_code = 410 | [
"def",
"delete",
"(",
"self",
",",
"event",
")",
":",
"assert",
"self",
".",
"receiver_id",
"==",
"event",
".",
"receiver_id",
"event",
".",
"response",
"=",
"{",
"'status'",
":",
"410",
",",
"'message'",
":",
"'Gone.'",
"}",
"event",
".",
"response_code... | Mark event as deleted. | [
"Mark",
"event",
"as",
"deleted",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L81-L85 | train | Mark the event as deleted. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Receiver.get_hook_url | def get_hook_url(self, access_token):
"""Get URL for webhook.
In debug and testing mode the hook URL can be overwritten using
``WEBHOOKS_DEBUG_RECEIVER_URLS`` configuration variable to allow
testing webhooks via services such as e.g. Ultrahook.
.. code-block:: python
... | python | def get_hook_url(self, access_token):
"""Get URL for webhook.
In debug and testing mode the hook URL can be overwritten using
``WEBHOOKS_DEBUG_RECEIVER_URLS`` configuration variable to allow
testing webhooks via services such as e.g. Ultrahook.
.. code-block:: python
... | [
"def",
"get_hook_url",
"(",
"self",
",",
"access_token",
")",
":",
"# Allow overwriting hook URL in debug mode.",
"if",
"(",
"current_app",
".",
"debug",
"or",
"current_app",
".",
"testing",
")",
"and",
"current_app",
".",
"config",
".",
"get",
"(",
"'WEBHOOKS_DEB... | Get URL for webhook.
In debug and testing mode the hook URL can be overwritten using
``WEBHOOKS_DEBUG_RECEIVER_URLS`` configuration variable to allow
testing webhooks via services such as e.g. Ultrahook.
.. code-block:: python
WEBHOOKS_DEBUG_RECEIVER_URLS = dict(
... | [
"Get",
"URL",
"for",
"webhook",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L87-L112 | train | Get URL for webhook. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Receiver.check_signature | def check_signature(self):
"""Check signature of signed request."""
if not self.signature:
return True
signature_value = request.headers.get(self.signature, None)
if signature_value:
validator = 'check_' + re.sub(r'[-]', '_', self.signature).lower()
ch... | python | def check_signature(self):
"""Check signature of signed request."""
if not self.signature:
return True
signature_value = request.headers.get(self.signature, None)
if signature_value:
validator = 'check_' + re.sub(r'[-]', '_', self.signature).lower()
ch... | [
"def",
"check_signature",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"signature",
":",
"return",
"True",
"signature_value",
"=",
"request",
".",
"headers",
".",
"get",
"(",
"self",
".",
"signature",
",",
"None",
")",
"if",
"signature_value",
":",
"... | Check signature of signed request. | [
"Check",
"signature",
"of",
"signed",
"request",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L117-L127 | train | Check signature of signed request. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Receiver.extract_payload | def extract_payload(self):
"""Extract payload from request."""
if not self.check_signature():
raise InvalidSignature('Invalid Signature')
if request.is_json:
# Request.get_json() could be first called with silent=True.
delete_cached_json_for(request)
... | python | def extract_payload(self):
"""Extract payload from request."""
if not self.check_signature():
raise InvalidSignature('Invalid Signature')
if request.is_json:
# Request.get_json() could be first called with silent=True.
delete_cached_json_for(request)
... | [
"def",
"extract_payload",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"check_signature",
"(",
")",
":",
"raise",
"InvalidSignature",
"(",
"'Invalid Signature'",
")",
"if",
"request",
".",
"is_json",
":",
"# Request.get_json() could be first called with silent=Tru... | Extract payload from request. | [
"Extract",
"payload",
"from",
"request",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L129-L139 | train | Extract payload from request. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | CeleryReceiver.status | def status(self, event):
"""Return a tuple with current processing status code and message."""
result = AsyncResult(str(event.id))
return (
self.CELERY_STATES_TO_HTTP.get(result.state),
result.info.get('message')
if result.state in self.CELERY_RESULT_INFO_FOR ... | python | def status(self, event):
"""Return a tuple with current processing status code and message."""
result = AsyncResult(str(event.id))
return (
self.CELERY_STATES_TO_HTTP.get(result.state),
result.info.get('message')
if result.state in self.CELERY_RESULT_INFO_FOR ... | [
"def",
"status",
"(",
"self",
",",
"event",
")",
":",
"result",
"=",
"AsyncResult",
"(",
"str",
"(",
"event",
".",
"id",
")",
")",
"return",
"(",
"self",
".",
"CELERY_STATES_TO_HTTP",
".",
"get",
"(",
"result",
".",
"state",
")",
",",
"result",
".",
... | Return a tuple with current processing status code and message. | [
"Return",
"a",
"tuple",
"with",
"current",
"processing",
"status",
"code",
"and",
"message",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L181-L189 | train | Return a tuple with current processing status code and message. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | CeleryReceiver.delete | def delete(self, event):
"""Abort running task if it exists."""
super(CeleryReceiver, self).delete(event)
AsyncResult(event.id).revoke(terminate=True) | python | def delete(self, event):
"""Abort running task if it exists."""
super(CeleryReceiver, self).delete(event)
AsyncResult(event.id).revoke(terminate=True) | [
"def",
"delete",
"(",
"self",
",",
"event",
")",
":",
"super",
"(",
"CeleryReceiver",
",",
"self",
")",
".",
"delete",
"(",
"event",
")",
"AsyncResult",
"(",
"event",
".",
"id",
")",
".",
"revoke",
"(",
"terminate",
"=",
"True",
")"
] | Abort running task if it exists. | [
"Abort",
"running",
"task",
"if",
"it",
"exists",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L191-L194 | train | Abort running task if it exists. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Event.validate_receiver | def validate_receiver(self, key, value):
"""Validate receiver identifier."""
if value not in current_webhooks.receivers:
raise ReceiverDoesNotExist(self.receiver_id)
return value | python | def validate_receiver(self, key, value):
"""Validate receiver identifier."""
if value not in current_webhooks.receivers:
raise ReceiverDoesNotExist(self.receiver_id)
return value | [
"def",
"validate_receiver",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"if",
"value",
"not",
"in",
"current_webhooks",
".",
"receivers",
":",
"raise",
"ReceiverDoesNotExist",
"(",
"self",
".",
"receiver_id",
")",
"return",
"value"
] | Validate receiver identifier. | [
"Validate",
"receiver",
"identifier",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L251-L255 | train | Validate receiver identifier. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Event.create | def create(cls, receiver_id, user_id=None):
"""Create an event instance."""
event = cls(id=uuid.uuid4(), receiver_id=receiver_id, user_id=user_id)
event.payload = event.receiver.extract_payload()
return event | python | def create(cls, receiver_id, user_id=None):
"""Create an event instance."""
event = cls(id=uuid.uuid4(), receiver_id=receiver_id, user_id=user_id)
event.payload = event.receiver.extract_payload()
return event | [
"def",
"create",
"(",
"cls",
",",
"receiver_id",
",",
"user_id",
"=",
"None",
")",
":",
"event",
"=",
"cls",
"(",
"id",
"=",
"uuid",
".",
"uuid4",
"(",
")",
",",
"receiver_id",
"=",
"receiver_id",
",",
"user_id",
"=",
"user_id",
")",
"event",
".",
... | Create an event instance. | [
"Create",
"an",
"event",
"instance",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L258-L262 | train | Create an event instance. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Event.receiver | def receiver(self):
"""Return registered receiver."""
try:
return current_webhooks.receivers[self.receiver_id]
except KeyError:
raise ReceiverDoesNotExist(self.receiver_id) | python | def receiver(self):
"""Return registered receiver."""
try:
return current_webhooks.receivers[self.receiver_id]
except KeyError:
raise ReceiverDoesNotExist(self.receiver_id) | [
"def",
"receiver",
"(",
"self",
")",
":",
"try",
":",
"return",
"current_webhooks",
".",
"receivers",
"[",
"self",
".",
"receiver_id",
"]",
"except",
"KeyError",
":",
"raise",
"ReceiverDoesNotExist",
"(",
"self",
".",
"receiver_id",
")"
] | Return registered receiver. | [
"Return",
"registered",
"receiver",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L265-L270 | train | Return registered receiver. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Event.receiver | def receiver(self, value):
"""Set receiver instance."""
assert isinstance(value, Receiver)
self.receiver_id = value.receiver_id | python | def receiver(self, value):
"""Set receiver instance."""
assert isinstance(value, Receiver)
self.receiver_id = value.receiver_id | [
"def",
"receiver",
"(",
"self",
",",
"value",
")",
":",
"assert",
"isinstance",
"(",
"value",
",",
"Receiver",
")",
"self",
".",
"receiver_id",
"=",
"value",
".",
"receiver_id"
] | Set receiver instance. | [
"Set",
"receiver",
"instance",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L273-L276 | train | Set receiver instance. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Event.process | def process(self):
"""Process current event."""
try:
self.receiver(self)
# TODO RESTException
except Exception as e:
current_app.logger.exception('Could not process event.')
self.response_code = 500
self.response = dict(status=500, message=... | python | def process(self):
"""Process current event."""
try:
self.receiver(self)
# TODO RESTException
except Exception as e:
current_app.logger.exception('Could not process event.')
self.response_code = 500
self.response = dict(status=500, message=... | [
"def",
"process",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"receiver",
"(",
"self",
")",
"# TODO RESTException",
"except",
"Exception",
"as",
"e",
":",
"current_app",
".",
"logger",
".",
"exception",
"(",
"'Could not process event.'",
")",
"self",
"."... | Process current event. | [
"Process",
"current",
"event",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L278-L287 | train | Process current event. |
inveniosoftware/invenio-webhooks | invenio_webhooks/models.py | Event.status | def status(self):
"""Return a tuple with current processing status code and message."""
status = self.receiver.status(self)
return status if status else (
self.response_code, self.response.get('message')
) | python | def status(self):
"""Return a tuple with current processing status code and message."""
status = self.receiver.status(self)
return status if status else (
self.response_code, self.response.get('message')
) | [
"def",
"status",
"(",
"self",
")",
":",
"status",
"=",
"self",
".",
"receiver",
".",
"status",
"(",
"self",
")",
"return",
"status",
"if",
"status",
"else",
"(",
"self",
".",
"response_code",
",",
"self",
".",
"response",
".",
"get",
"(",
"'message'",
... | Return a tuple with current processing status code and message. | [
"Return",
"a",
"tuple",
"with",
"current",
"processing",
"status",
"code",
"and",
"message",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/models.py#L290-L295 | train | Return a tuple with current processing status code and message. |
GrahamDumpleton/autowrapt | src/bootstrap.py | register_bootstrap_functions | def register_bootstrap_functions():
'''Discover and register all post import hooks named in the
'AUTOWRAPT_BOOTSTRAP' environment variable. The value of the
environment variable must be a comma separated list.
'''
# This can be called twice if '.pth' file bootstrapping works and
# the 'autowra... | python | def register_bootstrap_functions():
'''Discover and register all post import hooks named in the
'AUTOWRAPT_BOOTSTRAP' environment variable. The value of the
environment variable must be a comma separated list.
'''
# This can be called twice if '.pth' file bootstrapping works and
# the 'autowra... | [
"def",
"register_bootstrap_functions",
"(",
")",
":",
"# This can be called twice if '.pth' file bootstrapping works and",
"# the 'autowrapt' wrapper script is still also used. We therefore",
"# protect ourselves just in case it is called a second time as we",
"# only want to force registration once... | Discover and register all post import hooks named in the
'AUTOWRAPT_BOOTSTRAP' environment variable. The value of the
environment variable must be a comma separated list. | [
"Discover",
"and",
"register",
"all",
"post",
"import",
"hooks",
"named",
"in",
"the",
"AUTOWRAPT_BOOTSTRAP",
"environment",
"variable",
".",
"The",
"value",
"of",
"the",
"environment",
"variable",
"must",
"be",
"a",
"comma",
"separated",
"list",
"."
] | d4770e4f511c19012055deaab68ef0ec8aa54ba4 | https://github.com/GrahamDumpleton/autowrapt/blob/d4770e4f511c19012055deaab68ef0ec8aa54ba4/src/bootstrap.py#L13-L39 | train | Discover and register all post import hooks named in the AUTOWRAPT_BOOTSTRAP environment variable. |
GrahamDumpleton/autowrapt | src/bootstrap.py | bootstrap | def bootstrap():
'''Patches the 'site' module such that the bootstrap functions for
registering the post import hook callback functions are called as
the last thing done when initialising the Python interpreter. This
function would normally be called from the special '.pth' file.
'''
global _p... | python | def bootstrap():
'''Patches the 'site' module such that the bootstrap functions for
registering the post import hook callback functions are called as
the last thing done when initialising the Python interpreter. This
function would normally be called from the special '.pth' file.
'''
global _p... | [
"def",
"bootstrap",
"(",
")",
":",
"global",
"_patched",
"if",
"_patched",
":",
"return",
"_patched",
"=",
"True",
"# We want to do our real work as the very last thing in the 'site'",
"# module when it is being imported so that the module search path is",
"# initialised properly. Wh... | Patches the 'site' module such that the bootstrap functions for
registering the post import hook callback functions are called as
the last thing done when initialising the Python interpreter. This
function would normally be called from the special '.pth' file. | [
"Patches",
"the",
"site",
"module",
"such",
"that",
"the",
"bootstrap",
"functions",
"for",
"registering",
"the",
"post",
"import",
"hook",
"callback",
"functions",
"are",
"called",
"as",
"the",
"last",
"thing",
"done",
"when",
"initialising",
"the",
"Python",
... | d4770e4f511c19012055deaab68ef0ec8aa54ba4 | https://github.com/GrahamDumpleton/autowrapt/blob/d4770e4f511c19012055deaab68ef0ec8aa54ba4/src/bootstrap.py#L67-L100 | train | Patches the site module so that the bootstrap functions for the user - defined modules are called as the last thing done when initialising the Python interpreter. |
Scille/autobahn-sync | autobahn_sync/extensions/flask.py | FlaskAutobahnSync.init_app | def init_app(self, app, router=None, realm=None, in_twisted=None):
"""Configure and call the :meth:`AutobahnSync.start` method
:param app: Flask app to configure
:param router: WAMP router to connect to
:param realm: WAMP realm to connect to
:param in_twisted: Is the code is goi... | python | def init_app(self, app, router=None, realm=None, in_twisted=None):
"""Configure and call the :meth:`AutobahnSync.start` method
:param app: Flask app to configure
:param router: WAMP router to connect to
:param realm: WAMP realm to connect to
:param in_twisted: Is the code is goi... | [
"def",
"init_app",
"(",
"self",
",",
"app",
",",
"router",
"=",
"None",
",",
"realm",
"=",
"None",
",",
"in_twisted",
"=",
"None",
")",
":",
"router",
"=",
"router",
"or",
"app",
".",
"config",
".",
"get",
"(",
"'AUTHOBAHN_ROUTER'",
")",
"realm",
"="... | Configure and call the :meth:`AutobahnSync.start` method
:param app: Flask app to configure
:param router: WAMP router to connect to
:param realm: WAMP realm to connect to
:param in_twisted: Is the code is going to run inside a Twisted application
.. Note:: The config provided ... | [
"Configure",
"and",
"call",
"the",
":",
"meth",
":",
"AutobahnSync",
".",
"start",
"method"
] | d75fceff0d1aee61fa6dd0168eb1cd40794ad827 | https://github.com/Scille/autobahn-sync/blob/d75fceff0d1aee61fa6dd0168eb1cd40794ad827/autobahn_sync/extensions/flask.py#L26-L46 | train | Configure and call the AutobahnSync. start method. |
ponty/psidialogs | psidialogs/api/tkmessagebox_api.py | askokcancel | def askokcancel(title=None, message=None, **options):
"""Original doc: Ask if operation should proceed; return true if the answer is ok"""
return psidialogs.ask_ok_cancel(title=title, message=message) | python | def askokcancel(title=None, message=None, **options):
"""Original doc: Ask if operation should proceed; return true if the answer is ok"""
return psidialogs.ask_ok_cancel(title=title, message=message) | [
"def",
"askokcancel",
"(",
"title",
"=",
"None",
",",
"message",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"return",
"psidialogs",
".",
"ask_ok_cancel",
"(",
"title",
"=",
"title",
",",
"message",
"=",
"message",
")"
] | Original doc: Ask if operation should proceed; return true if the answer is ok | [
"Original",
"doc",
":",
"Ask",
"if",
"operation",
"should",
"proceed",
";",
"return",
"true",
"if",
"the",
"answer",
"is",
"ok"
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/tkmessagebox_api.py#L4-L6 | train | Original doc : Ask if operation should proceed ; return true if the answer is ok |
ponty/psidialogs | psidialogs/api/tkmessagebox_api.py | showinfo | def showinfo(title=None, message=None, **options):
"""Original doc: Show an info message"""
return psidialogs.message(title=title, message=message) | python | def showinfo(title=None, message=None, **options):
"""Original doc: Show an info message"""
return psidialogs.message(title=title, message=message) | [
"def",
"showinfo",
"(",
"title",
"=",
"None",
",",
"message",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"return",
"psidialogs",
".",
"message",
"(",
"title",
"=",
"title",
",",
"message",
"=",
"message",
")"
] | Original doc: Show an info message | [
"Original",
"doc",
":",
"Show",
"an",
"info",
"message"
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/tkmessagebox_api.py#L9-L11 | train | Original doc : Show an info message |
ponty/psidialogs | psidialogs/api/tkmessagebox_api.py | askyesno | def askyesno(title=None, message=None, **options):
"""Original doc: Ask a question; return true if the answer is yes"""
return psidialogs.ask_yes_no(title=title, message=message) | python | def askyesno(title=None, message=None, **options):
"""Original doc: Ask a question; return true if the answer is yes"""
return psidialogs.ask_yes_no(title=title, message=message) | [
"def",
"askyesno",
"(",
"title",
"=",
"None",
",",
"message",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"return",
"psidialogs",
".",
"ask_yes_no",
"(",
"title",
"=",
"title",
",",
"message",
"=",
"message",
")"
] | Original doc: Ask a question; return true if the answer is yes | [
"Original",
"doc",
":",
"Ask",
"a",
"question",
";",
"return",
"true",
"if",
"the",
"answer",
"is",
"yes"
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/tkmessagebox_api.py#L14-L16 | train | Original doc : Ask a question ; return true if the answer is yes |
ponty/psidialogs | psidialogs/api/tkmessagebox_api.py | showwarning | def showwarning(title=None, message=None, **options):
"""Original doc: Show a warning message"""
return psidialogs.warning(title=title, message=message) | python | def showwarning(title=None, message=None, **options):
"""Original doc: Show a warning message"""
return psidialogs.warning(title=title, message=message) | [
"def",
"showwarning",
"(",
"title",
"=",
"None",
",",
"message",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"return",
"psidialogs",
".",
"warning",
"(",
"title",
"=",
"title",
",",
"message",
"=",
"message",
")"
] | Original doc: Show a warning message | [
"Original",
"doc",
":",
"Show",
"a",
"warning",
"message"
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/tkmessagebox_api.py#L19-L21 | train | Original doc : Show a warning message |
ponty/psidialogs | psidialogs/api/tkmessagebox_api.py | showerror | def showerror(title=None, message=None, **options):
"""Original doc: Show an error message"""
return psidialogs.error(title=title, message=message) | python | def showerror(title=None, message=None, **options):
"""Original doc: Show an error message"""
return psidialogs.error(title=title, message=message) | [
"def",
"showerror",
"(",
"title",
"=",
"None",
",",
"message",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"return",
"psidialogs",
".",
"error",
"(",
"title",
"=",
"title",
",",
"message",
"=",
"message",
")"
] | Original doc: Show an error message | [
"Original",
"doc",
":",
"Show",
"an",
"error",
"message"
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/tkmessagebox_api.py#L24-L26 | train | Original doc : Show an error message |
ponty/psidialogs | psidialogs/api/tkmessagebox_api.py | askretrycancel | def askretrycancel(title=None, message=None, **options):
"""Original doc: Ask if operation should be retried; return true if the answer is yes"""
return psidialogs.ask_ok_cancel(title=title, message=message, ok='Retry') | python | def askretrycancel(title=None, message=None, **options):
"""Original doc: Ask if operation should be retried; return true if the answer is yes"""
return psidialogs.ask_ok_cancel(title=title, message=message, ok='Retry') | [
"def",
"askretrycancel",
"(",
"title",
"=",
"None",
",",
"message",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"return",
"psidialogs",
".",
"ask_ok_cancel",
"(",
"title",
"=",
"title",
",",
"message",
"=",
"message",
",",
"ok",
"=",
"'Retry'",
")... | Original doc: Ask if operation should be retried; return true if the answer is yes | [
"Original",
"doc",
":",
"Ask",
"if",
"operation",
"should",
"be",
"retried",
";",
"return",
"true",
"if",
"the",
"answer",
"is",
"yes"
] | e385ab6b48cb43af52b810a1bf76a8135f4585b8 | https://github.com/ponty/psidialogs/blob/e385ab6b48cb43af52b810a1bf76a8135f4585b8/psidialogs/api/tkmessagebox_api.py#L29-L31 | train | Original doc : Ask if operation should be retried ; return true if the answer is yes |
architv/harvey | harvey/get_tldr.py | get_summary | def get_summary(content):
"""Gets the summary of a license from tldrlegal.com"""
soup = BeautifulSoup(content, "html.parser")
summary = soup.find_all(attrs={
'class': re.compile(r".*\bsummary-content\b.*")})
if summary[0].p.string is None:
return summary[0].p.p.getText()
return summary[0].p.getText... | python | def get_summary(content):
"""Gets the summary of a license from tldrlegal.com"""
soup = BeautifulSoup(content, "html.parser")
summary = soup.find_all(attrs={
'class': re.compile(r".*\bsummary-content\b.*")})
if summary[0].p.string is None:
return summary[0].p.p.getText()
return summary[0].p.getText... | [
"def",
"get_summary",
"(",
"content",
")",
":",
"soup",
"=",
"BeautifulSoup",
"(",
"content",
",",
"\"html.parser\"",
")",
"summary",
"=",
"soup",
".",
"find_all",
"(",
"attrs",
"=",
"{",
"'class'",
":",
"re",
".",
"compile",
"(",
"r\".*\\bsummary-content\\b... | Gets the summary of a license from tldrlegal.com | [
"Gets",
"the",
"summary",
"of",
"a",
"license",
"from",
"tldrlegal",
".",
"com"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/get_tldr.py#L15-L23 | train | Gets the summary of a license from tldrlegal. com |
architv/harvey | harvey/get_tldr.py | get_rules | def get_rules(license):
"""Gets can, cannot and must rules from github license API"""
can = []
cannot = []
must = []
req = requests.get("{base_url}/licenses/{license}".format(
base_url=BASE_URL, license=license), headers=_HEADERS)
if req.status_code == requests.codes.ok:
data = re... | python | def get_rules(license):
"""Gets can, cannot and must rules from github license API"""
can = []
cannot = []
must = []
req = requests.get("{base_url}/licenses/{license}".format(
base_url=BASE_URL, license=license), headers=_HEADERS)
if req.status_code == requests.codes.ok:
data = re... | [
"def",
"get_rules",
"(",
"license",
")",
":",
"can",
"=",
"[",
"]",
"cannot",
"=",
"[",
"]",
"must",
"=",
"[",
"]",
"req",
"=",
"requests",
".",
"get",
"(",
"\"{base_url}/licenses/{license}\"",
".",
"format",
"(",
"base_url",
"=",
"BASE_URL",
",",
"lic... | Gets can, cannot and must rules from github license API | [
"Gets",
"can",
"cannot",
"and",
"must",
"rules",
"from",
"github",
"license",
"API"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/get_tldr.py#L26-L41 | train | Gets can cannot and must rules from github license API |
architv/harvey | harvey/get_tldr.py | main | def main():
"""Gets all the license information and stores it in json format"""
all_summary = {}
for license in RESOURCES:
req = requests.get(RESOURCES[license])
if req.status_code == requests.codes.ok:
summary = get_summary(req.text)
can, cannot, must = get_rules(license)
all_summa... | python | def main():
"""Gets all the license information and stores it in json format"""
all_summary = {}
for license in RESOURCES:
req = requests.get(RESOURCES[license])
if req.status_code == requests.codes.ok:
summary = get_summary(req.text)
can, cannot, must = get_rules(license)
all_summa... | [
"def",
"main",
"(",
")",
":",
"all_summary",
"=",
"{",
"}",
"for",
"license",
"in",
"RESOURCES",
":",
"req",
"=",
"requests",
".",
"get",
"(",
"RESOURCES",
"[",
"license",
"]",
")",
"if",
"req",
".",
"status_code",
"==",
"requests",
".",
"codes",
"."... | Gets all the license information and stores it in json format | [
"Gets",
"all",
"the",
"license",
"information",
"and",
"stores",
"it",
"in",
"json",
"format"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/get_tldr.py#L44-L66 | train | Gets all the license information and stores it in json format |
costastf/toonlib | _CI/bin/bump.py | get_arguments | def get_arguments():
"""
This get us the cli arguments.
Returns the args as parsed from the argsparser.
"""
# https://docs.python.org/3/library/argparse.html
parser = argparse.ArgumentParser(
description='Handles bumping of the artifact version')
parser.add_argument('--log-config',
... | python | def get_arguments():
"""
This get us the cli arguments.
Returns the args as parsed from the argsparser.
"""
# https://docs.python.org/3/library/argparse.html
parser = argparse.ArgumentParser(
description='Handles bumping of the artifact version')
parser.add_argument('--log-config',
... | [
"def",
"get_arguments",
"(",
")",
":",
"# https://docs.python.org/3/library/argparse.html",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Handles bumping of the artifact version'",
")",
"parser",
".",
"add_argument",
"(",
"'--log-config'",
","... | This get us the cli arguments.
Returns the args as parsed from the argsparser. | [
"This",
"get",
"us",
"the",
"cli",
"arguments",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/_CI/bin/bump.py#L21-L68 | train | This function gets us the cli arguments. It returns the args as parsed from the argsparser. |
costastf/toonlib | _CI/bin/bump.py | setup_logging | def setup_logging(args):
"""
This sets up the logging.
Needs the args to get the log level supplied
:param args: The command line arguments
"""
handler = logging.StreamHandler()
handler.setLevel(args.log_level)
formatter = logging.Formatter(('%(asctime)s - '
... | python | def setup_logging(args):
"""
This sets up the logging.
Needs the args to get the log level supplied
:param args: The command line arguments
"""
handler = logging.StreamHandler()
handler.setLevel(args.log_level)
formatter = logging.Formatter(('%(asctime)s - '
... | [
"def",
"setup_logging",
"(",
"args",
")",
":",
"handler",
"=",
"logging",
".",
"StreamHandler",
"(",
")",
"handler",
".",
"setLevel",
"(",
"args",
".",
"log_level",
")",
"formatter",
"=",
"logging",
".",
"Formatter",
"(",
"(",
"'%(asctime)s - '",
"'%(name)s ... | This sets up the logging.
Needs the args to get the log level supplied
:param args: The command line arguments | [
"This",
"sets",
"up",
"the",
"logging",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/_CI/bin/bump.py#L71-L85 | train | This sets up the logging module. |
inveniosoftware/invenio-webhooks | invenio_webhooks/views.py | make_response | def make_response(event):
"""Make a response from webhook event."""
code, message = event.status
response = jsonify(**event.response)
response.headers['X-Hub-Event'] = event.receiver_id
response.headers['X-Hub-Delivery'] = event.id
if message:
response.headers['X-Hub-Info'] = message
... | python | def make_response(event):
"""Make a response from webhook event."""
code, message = event.status
response = jsonify(**event.response)
response.headers['X-Hub-Event'] = event.receiver_id
response.headers['X-Hub-Delivery'] = event.id
if message:
response.headers['X-Hub-Info'] = message
... | [
"def",
"make_response",
"(",
"event",
")",
":",
"code",
",",
"message",
"=",
"event",
".",
"status",
"response",
"=",
"jsonify",
"(",
"*",
"*",
"event",
".",
"response",
")",
"response",
".",
"headers",
"[",
"'X-Hub-Event'",
"]",
"=",
"event",
".",
"re... | Make a response from webhook event. | [
"Make",
"a",
"response",
"from",
"webhook",
"event",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/views.py#L69-L81 | train | Make a response from webhook event. |
inveniosoftware/invenio-webhooks | invenio_webhooks/views.py | error_handler | def error_handler(f):
"""Return a json payload and appropriate status code on expection."""
@wraps(f)
def inner(*args, **kwargs):
try:
return f(*args, **kwargs)
except ReceiverDoesNotExist:
return jsonify(
status=404,
description='Recei... | python | def error_handler(f):
"""Return a json payload and appropriate status code on expection."""
@wraps(f)
def inner(*args, **kwargs):
try:
return f(*args, **kwargs)
except ReceiverDoesNotExist:
return jsonify(
status=404,
description='Recei... | [
"def",
"error_handler",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"inner",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"except",
"ReceiverDoesNotExi... | Return a json payload and appropriate status code on expection. | [
"Return",
"a",
"json",
"payload",
"and",
"appropriate",
"status",
"code",
"on",
"expection",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/views.py#L87-L109 | train | Return a json payload and appropriate status code on expection. |
inveniosoftware/invenio-webhooks | invenio_webhooks/views.py | ReceiverEventListResource.post | def post(self, receiver_id=None):
"""Handle POST request."""
try:
user_id = request.oauth.access_token.user_id
except AttributeError:
user_id = current_user.get_id()
event = Event.create(
receiver_id=receiver_id,
user_id=user_id
)
... | python | def post(self, receiver_id=None):
"""Handle POST request."""
try:
user_id = request.oauth.access_token.user_id
except AttributeError:
user_id = current_user.get_id()
event = Event.create(
receiver_id=receiver_id,
user_id=user_id
)
... | [
"def",
"post",
"(",
"self",
",",
"receiver_id",
"=",
"None",
")",
":",
"try",
":",
"user_id",
"=",
"request",
".",
"oauth",
".",
"access_token",
".",
"user_id",
"except",
"AttributeError",
":",
"user_id",
"=",
"current_user",
".",
"get_id",
"(",
")",
"ev... | Handle POST request. | [
"Handle",
"POST",
"request",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/views.py#L121-L138 | train | Handle POST request. |
inveniosoftware/invenio-webhooks | invenio_webhooks/views.py | ReceiverEventResource._get_event | def _get_event(receiver_id, event_id):
"""Find event and check access rights."""
event = Event.query.filter_by(
receiver_id=receiver_id, id=event_id
).first_or_404()
try:
user_id = request.oauth.access_token.user_id
except AttributeError:
user... | python | def _get_event(receiver_id, event_id):
"""Find event and check access rights."""
event = Event.query.filter_by(
receiver_id=receiver_id, id=event_id
).first_or_404()
try:
user_id = request.oauth.access_token.user_id
except AttributeError:
user... | [
"def",
"_get_event",
"(",
"receiver_id",
",",
"event_id",
")",
":",
"event",
"=",
"Event",
".",
"query",
".",
"filter_by",
"(",
"receiver_id",
"=",
"receiver_id",
",",
"id",
"=",
"event_id",
")",
".",
"first_or_404",
"(",
")",
"try",
":",
"user_id",
"=",... | Find event and check access rights. | [
"Find",
"event",
"and",
"check",
"access",
"rights",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/views.py#L149-L163 | train | Find event and check access rights. |
inveniosoftware/invenio-webhooks | invenio_webhooks/views.py | ReceiverEventResource.get | def get(self, receiver_id=None, event_id=None):
"""Handle GET request."""
event = self._get_event(receiver_id, event_id)
return make_response(event) | python | def get(self, receiver_id=None, event_id=None):
"""Handle GET request."""
event = self._get_event(receiver_id, event_id)
return make_response(event) | [
"def",
"get",
"(",
"self",
",",
"receiver_id",
"=",
"None",
",",
"event_id",
"=",
"None",
")",
":",
"event",
"=",
"self",
".",
"_get_event",
"(",
"receiver_id",
",",
"event_id",
")",
"return",
"make_response",
"(",
"event",
")"
] | Handle GET request. | [
"Handle",
"GET",
"request",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/views.py#L168-L171 | train | Handle GET request. |
inveniosoftware/invenio-webhooks | invenio_webhooks/views.py | ReceiverEventResource.delete | def delete(self, receiver_id=None, event_id=None):
"""Handle DELETE request."""
event = self._get_event(receiver_id, event_id)
event.delete()
db.session.commit()
return make_response(event) | python | def delete(self, receiver_id=None, event_id=None):
"""Handle DELETE request."""
event = self._get_event(receiver_id, event_id)
event.delete()
db.session.commit()
return make_response(event) | [
"def",
"delete",
"(",
"self",
",",
"receiver_id",
"=",
"None",
",",
"event_id",
"=",
"None",
")",
":",
"event",
"=",
"self",
".",
"_get_event",
"(",
"receiver_id",
",",
"event_id",
")",
"event",
".",
"delete",
"(",
")",
"db",
".",
"session",
".",
"co... | Handle DELETE request. | [
"Handle",
"DELETE",
"request",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/views.py#L176-L181 | train | Handle DELETE request. |
architv/harvey | harvey/harvey.py | _stripslashes | def _stripslashes(s):
'''Removes trailing and leading backslashes from string'''
r = re.sub(r"\\(n|r)", "\n", s)
r = re.sub(r"\\", "", r)
return r | python | def _stripslashes(s):
'''Removes trailing and leading backslashes from string'''
r = re.sub(r"\\(n|r)", "\n", s)
r = re.sub(r"\\", "", r)
return r | [
"def",
"_stripslashes",
"(",
"s",
")",
":",
"r",
"=",
"re",
".",
"sub",
"(",
"r\"\\\\(n|r)\"",
",",
"\"\\n\"",
",",
"s",
")",
"r",
"=",
"re",
".",
"sub",
"(",
"r\"\\\\\"",
",",
"\"\"",
",",
"r",
")",
"return",
"r"
] | Removes trailing and leading backslashes from string | [
"Removes",
"trailing",
"and",
"leading",
"backslashes",
"from",
"string"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L46-L50 | train | Removes trailing and leading backslashes from string |
architv/harvey | harvey/harvey.py | _get_config_name | def _get_config_name():
'''Get git config user name'''
p = subprocess.Popen('git config --get user.name', shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.stdout.readlines()
return _stripslashes(output[0]) | python | def _get_config_name():
'''Get git config user name'''
p = subprocess.Popen('git config --get user.name', shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.stdout.readlines()
return _stripslashes(output[0]) | [
"def",
"_get_config_name",
"(",
")",
":",
"p",
"=",
"subprocess",
".",
"Popen",
"(",
"'git config --get user.name'",
",",
"shell",
"=",
"True",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"subprocess",
".",
"STDOUT",
")",
"output",
"... | Get git config user name | [
"Get",
"git",
"config",
"user",
"name"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L53-L58 | train | Get git config user name |
architv/harvey | harvey/harvey.py | _get_licences | def _get_licences():
""" Lists all the licenses on command line """
licenses = _LICENSES
for license in licenses:
print("{license_name} [{license_code}]".format(
license_name=licenses[license], license_code=license)) | python | def _get_licences():
""" Lists all the licenses on command line """
licenses = _LICENSES
for license in licenses:
print("{license_name} [{license_code}]".format(
license_name=licenses[license], license_code=license)) | [
"def",
"_get_licences",
"(",
")",
":",
"licenses",
"=",
"_LICENSES",
"for",
"license",
"in",
"licenses",
":",
"print",
"(",
"\"{license_name} [{license_code}]\"",
".",
"format",
"(",
"license_name",
"=",
"licenses",
"[",
"license",
"]",
",",
"license_code",
"=",... | Lists all the licenses on command line | [
"Lists",
"all",
"the",
"licenses",
"on",
"command",
"line"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L61-L67 | train | Lists all the licenses on command line |
architv/harvey | harvey/harvey.py | _get_license_description | def _get_license_description(license_code):
""" Gets the body for a license based on a license code """
req = requests.get("{base_url}/licenses/{license_code}".format(
base_url=BASE_URL, license_code=license_code), headers=_HEADERS)
if req.status_code == requests.codes.ok:
s = req.json()["body"]
se... | python | def _get_license_description(license_code):
""" Gets the body for a license based on a license code """
req = requests.get("{base_url}/licenses/{license_code}".format(
base_url=BASE_URL, license_code=license_code), headers=_HEADERS)
if req.status_code == requests.codes.ok:
s = req.json()["body"]
se... | [
"def",
"_get_license_description",
"(",
"license_code",
")",
":",
"req",
"=",
"requests",
".",
"get",
"(",
"\"{base_url}/licenses/{license_code}\"",
".",
"format",
"(",
"base_url",
"=",
"BASE_URL",
",",
"license_code",
"=",
"license_code",
")",
",",
"headers",
"="... | Gets the body for a license based on a license code | [
"Gets",
"the",
"body",
"for",
"a",
"license",
"based",
"on",
"a",
"license",
"code"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L70-L94 | train | Gets the body for a license based on a license code |
architv/harvey | harvey/harvey.py | get_license_summary | def get_license_summary(license_code):
""" Gets the license summary and permitted, forbidden and required
behaviour """
try:
abs_file = os.path.join(_ROOT, "summary.json")
with open(abs_file, 'r') as f:
summary_license = json.loads(f.read())[license_code]
# prints summary
print(Fore.YELLOW ... | python | def get_license_summary(license_code):
""" Gets the license summary and permitted, forbidden and required
behaviour """
try:
abs_file = os.path.join(_ROOT, "summary.json")
with open(abs_file, 'r') as f:
summary_license = json.loads(f.read())[license_code]
# prints summary
print(Fore.YELLOW ... | [
"def",
"get_license_summary",
"(",
"license_code",
")",
":",
"try",
":",
"abs_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"_ROOT",
",",
"\"summary.json\"",
")",
"with",
"open",
"(",
"abs_file",
",",
"'r'",
")",
"as",
"f",
":",
"summary_license",
"="... | Gets the license summary and permitted, forbidden and required
behaviour | [
"Gets",
"the",
"license",
"summary",
"and",
"permitted",
"forbidden",
"and",
"required",
"behaviour"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L97-L139 | train | Gets the license summary and permitted forbidden and required
|
architv/harvey | harvey/harvey.py | save_license | def save_license(license_code):
""" Grab license, save to LICENSE/LICENSE.txt file """
desc = _get_license_description(license_code)
fname = "LICENSE"
if sys.platform == "win32":
fname += ".txt" # Windows and file exts
with open(os.path.join(os.getcwd(), fname), "w") as afile:
afile.write(desc) | python | def save_license(license_code):
""" Grab license, save to LICENSE/LICENSE.txt file """
desc = _get_license_description(license_code)
fname = "LICENSE"
if sys.platform == "win32":
fname += ".txt" # Windows and file exts
with open(os.path.join(os.getcwd(), fname), "w") as afile:
afile.write(desc) | [
"def",
"save_license",
"(",
"license_code",
")",
":",
"desc",
"=",
"_get_license_description",
"(",
"license_code",
")",
"fname",
"=",
"\"LICENSE\"",
"if",
"sys",
".",
"platform",
"==",
"\"win32\"",
":",
"fname",
"+=",
"\".txt\"",
"# Windows and file exts",
"with"... | Grab license, save to LICENSE/LICENSE.txt file | [
"Grab",
"license",
"save",
"to",
"LICENSE",
"/",
"LICENSE",
".",
"txt",
"file"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L142-L149 | train | Save license to LICENSE. txt file |
architv/harvey | harvey/harvey.py | main | def main():
''' harvey helps you manage and add license from the command line '''
arguments = docopt(__doc__, version=__version__)
if arguments['ls'] or arguments['list']:
_get_licences()
elif arguments['--tldr'] and arguments['<NAME>']:
get_license_summary(arguments['<NAME>'].lower())
elif arguments... | python | def main():
''' harvey helps you manage and add license from the command line '''
arguments = docopt(__doc__, version=__version__)
if arguments['ls'] or arguments['list']:
_get_licences()
elif arguments['--tldr'] and arguments['<NAME>']:
get_license_summary(arguments['<NAME>'].lower())
elif arguments... | [
"def",
"main",
"(",
")",
":",
"arguments",
"=",
"docopt",
"(",
"__doc__",
",",
"version",
"=",
"__version__",
")",
"if",
"arguments",
"[",
"'ls'",
"]",
"or",
"arguments",
"[",
"'list'",
"]",
":",
"_get_licences",
"(",
")",
"elif",
"arguments",
"[",
"'-... | harvey helps you manage and add license from the command line | [
"harvey",
"helps",
"you",
"manage",
"and",
"add",
"license",
"from",
"the",
"command",
"line"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L152-L165 | train | Harvey helps you manage and add license from the command line |
rfverbruggen/rachiopy | rachiopy/person.py | Person.get | def get(self, user_id):
"""Retrieve the information for a person entity."""
path = '/'.join(['person', user_id])
return self.rachio.get(path) | python | def get(self, user_id):
"""Retrieve the information for a person entity."""
path = '/'.join(['person', user_id])
return self.rachio.get(path) | [
"def",
"get",
"(",
"self",
",",
"user_id",
")",
":",
"path",
"=",
"'/'",
".",
"join",
"(",
"[",
"'person'",
",",
"user_id",
"]",
")",
"return",
"self",
".",
"rachio",
".",
"get",
"(",
"path",
")"
] | Retrieve the information for a person entity. | [
"Retrieve",
"the",
"information",
"for",
"a",
"person",
"entity",
"."
] | c91abc9984f0f453e60fa905285c1b640c3390ae | https://github.com/rfverbruggen/rachiopy/blob/c91abc9984f0f453e60fa905285c1b640c3390ae/rachiopy/person.py#L16-L19 | train | Retrieve the information for a person entity. |
ptmcg/littletable | littletable.py | Table.copy_template | def copy_template(self, name=None):
"""Create empty copy of the current table, with copies of all
index definitions.
"""
ret = Table(self.table_name)
ret._indexes.update(dict((k, v.copy_template()) for k, v in self._indexes.items()))
ret(name)
return ret | python | def copy_template(self, name=None):
"""Create empty copy of the current table, with copies of all
index definitions.
"""
ret = Table(self.table_name)
ret._indexes.update(dict((k, v.copy_template()) for k, v in self._indexes.items()))
ret(name)
return ret | [
"def",
"copy_template",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"ret",
"=",
"Table",
"(",
"self",
".",
"table_name",
")",
"ret",
".",
"_indexes",
".",
"update",
"(",
"dict",
"(",
"(",
"k",
",",
"v",
".",
"copy_template",
"(",
")",
")",
"... | Create empty copy of the current table, with copies of all
index definitions. | [
"Create",
"empty",
"copy",
"of",
"the",
"current",
"table",
"with",
"copies",
"of",
"all",
"index",
"definitions",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L632-L639 | train | Create a copy of the current table with copies of all
index definitions. |
ptmcg/littletable | littletable.py | Table.clone | def clone(self, name=None):
"""Create full copy of the current table, including table contents
and index definitions.
"""
ret = self.copy_template().insert_many(self.obs)(name)
return ret | python | def clone(self, name=None):
"""Create full copy of the current table, including table contents
and index definitions.
"""
ret = self.copy_template().insert_many(self.obs)(name)
return ret | [
"def",
"clone",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"ret",
"=",
"self",
".",
"copy_template",
"(",
")",
".",
"insert_many",
"(",
"self",
".",
"obs",
")",
"(",
"name",
")",
"return",
"ret"
] | Create full copy of the current table, including table contents
and index definitions. | [
"Create",
"full",
"copy",
"of",
"the",
"current",
"table",
"including",
"table",
"contents",
"and",
"index",
"definitions",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L641-L646 | train | Create a full copy of the current table including table contents
and index definitions. |
ptmcg/littletable | littletable.py | Table.create_index | def create_index(self, attr, unique=False, accept_none=False):
"""Create a new index on a given attribute.
If C{unique} is True and records are found in the table with duplicate
attribute values, the index is deleted and C{KeyError} is raised.
If the table already has an index ... | python | def create_index(self, attr, unique=False, accept_none=False):
"""Create a new index on a given attribute.
If C{unique} is True and records are found in the table with duplicate
attribute values, the index is deleted and C{KeyError} is raised.
If the table already has an index ... | [
"def",
"create_index",
"(",
"self",
",",
"attr",
",",
"unique",
"=",
"False",
",",
"accept_none",
"=",
"False",
")",
":",
"if",
"attr",
"in",
"self",
".",
"_indexes",
":",
"raise",
"ValueError",
"(",
"'index %r already defined for table'",
"%",
"attr",
")",
... | Create a new index on a given attribute.
If C{unique} is True and records are found in the table with duplicate
attribute values, the index is deleted and C{KeyError} is raised.
If the table already has an index on the given attribute, then
ValueError is raised.
@... | [
"Create",
"a",
"new",
"index",
"on",
"a",
"given",
"attribute",
".",
"If",
"C",
"{",
"unique",
"}",
"is",
"True",
"and",
"records",
"are",
"found",
"in",
"the",
"table",
"with",
"duplicate",
"attribute",
"values",
"the",
"index",
"is",
"deleted",
"and",
... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L648-L687 | train | Create a new index on a given attribute. |
ptmcg/littletable | littletable.py | Table.delete_index | def delete_index(self, attr):
"""Deletes an index from the Table. Can be used to drop and rebuild an index,
or to convert a non-unique index to a unique index, or vice versa.
@param attr: name of an indexed attribute
@type attr: string
"""
if attr in self._index... | python | def delete_index(self, attr):
"""Deletes an index from the Table. Can be used to drop and rebuild an index,
or to convert a non-unique index to a unique index, or vice versa.
@param attr: name of an indexed attribute
@type attr: string
"""
if attr in self._index... | [
"def",
"delete_index",
"(",
"self",
",",
"attr",
")",
":",
"if",
"attr",
"in",
"self",
".",
"_indexes",
":",
"del",
"self",
".",
"_indexes",
"[",
"attr",
"]",
"self",
".",
"_uniqueIndexes",
"=",
"[",
"ind",
"for",
"ind",
"in",
"self",
".",
"_indexes"... | Deletes an index from the Table. Can be used to drop and rebuild an index,
or to convert a non-unique index to a unique index, or vice versa.
@param attr: name of an indexed attribute
@type attr: string | [
"Deletes",
"an",
"index",
"from",
"the",
"Table",
".",
"Can",
"be",
"used",
"to",
"drop",
"and",
"rebuild",
"an",
"index",
"or",
"to",
"convert",
"a",
"non",
"-",
"unique",
"index",
"to",
"a",
"unique",
"index",
"or",
"vice",
"versa",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L689-L698 | train | Deletes an index from the Table. |
ptmcg/littletable | littletable.py | Table.insert_many | def insert_many(self, it):
"""Inserts a collection of objects into the table."""
unique_indexes = self._uniqueIndexes # [ind for ind in self._indexes.values() if ind.is_unique]
NO_SUCH_ATTR = object()
new_objs = list(it)
if unique_indexes:
for ind in unique_indexes:
... | python | def insert_many(self, it):
"""Inserts a collection of objects into the table."""
unique_indexes = self._uniqueIndexes # [ind for ind in self._indexes.values() if ind.is_unique]
NO_SUCH_ATTR = object()
new_objs = list(it)
if unique_indexes:
for ind in unique_indexes:
... | [
"def",
"insert_many",
"(",
"self",
",",
"it",
")",
":",
"unique_indexes",
"=",
"self",
".",
"_uniqueIndexes",
"# [ind for ind in self._indexes.values() if ind.is_unique]",
"NO_SUCH_ATTR",
"=",
"object",
"(",
")",
"new_objs",
"=",
"list",
"(",
"it",
")",
"if",
"uni... | Inserts a collection of objects into the table. | [
"Inserts",
"a",
"collection",
"of",
"objects",
"into",
"the",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L720-L746 | train | Inserts a collection of objects into the table. |
ptmcg/littletable | littletable.py | Table.remove_many | def remove_many(self, it):
"""Removes a collection of objects from the table."""
# find indicies of objects in iterable
to_be_deleted = list(it)
del_indices = []
for i, ob in enumerate(self.obs):
try:
tbd_index = to_be_deleted.index(ob)
exc... | python | def remove_many(self, it):
"""Removes a collection of objects from the table."""
# find indicies of objects in iterable
to_be_deleted = list(it)
del_indices = []
for i, ob in enumerate(self.obs):
try:
tbd_index = to_be_deleted.index(ob)
exc... | [
"def",
"remove_many",
"(",
"self",
",",
"it",
")",
":",
"# find indicies of objects in iterable",
"to_be_deleted",
"=",
"list",
"(",
"it",
")",
"del_indices",
"=",
"[",
"]",
"for",
"i",
",",
"ob",
"in",
"enumerate",
"(",
"self",
".",
"obs",
")",
":",
"tr... | Removes a collection of objects from the table. | [
"Removes",
"a",
"collection",
"of",
"objects",
"from",
"the",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L753-L774 | train | Removes a collection of objects from the table. |
ptmcg/littletable | littletable.py | Table._query_attr_sort_fn | def _query_attr_sort_fn(self, attr_val):
"""Used to order where keys by most selective key first"""
attr, v = attr_val
if attr in self._indexes:
idx = self._indexes[attr]
if v in idx:
return len(idx[v])
else:
return 0
el... | python | def _query_attr_sort_fn(self, attr_val):
"""Used to order where keys by most selective key first"""
attr, v = attr_val
if attr in self._indexes:
idx = self._indexes[attr]
if v in idx:
return len(idx[v])
else:
return 0
el... | [
"def",
"_query_attr_sort_fn",
"(",
"self",
",",
"attr_val",
")",
":",
"attr",
",",
"v",
"=",
"attr_val",
"if",
"attr",
"in",
"self",
".",
"_indexes",
":",
"idx",
"=",
"self",
".",
"_indexes",
"[",
"attr",
"]",
"if",
"v",
"in",
"idx",
":",
"return",
... | Used to order where keys by most selective key first | [
"Used",
"to",
"order",
"where",
"keys",
"by",
"most",
"selective",
"key",
"first"
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L776-L786 | train | Used to sort keys by most selective key first |
ptmcg/littletable | littletable.py | Table.where | def where(self, wherefn=None, **kwargs):
"""
Retrieves matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be returned.
@param wherefn: a method or lambda... | python | def where(self, wherefn=None, **kwargs):
"""
Retrieves matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be returned.
@param wherefn: a method or lambda... | [
"def",
"where",
"(",
"self",
",",
"wherefn",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
":",
"# order query criteria in ascending order of number of matching items",
"# for each individual given attribute; this will minimize the number ",
"# of filtering re... | Retrieves matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be returned.
@param wherefn: a method or lambda that returns a boolean result, as in::
... | [
"Retrieves",
"matching",
"objects",
"from",
"the",
"table",
"based",
"on",
"given",
"named",
"parameters",
".",
"If",
"multiple",
"named",
"parameters",
"are",
"given",
"then",
"only",
"objects",
"that",
"satisfy",
"all",
"of",
"the",
"query",
"criteria",
"wil... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L788-L833 | train | Returns a new Table containing the matching objects from the table based on the given query criteria. |
ptmcg/littletable | littletable.py | Table.delete | def delete(self, **kwargs):
"""Deletes matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be removed.
@param kwargs: attributes for selecting records, given as a... | python | def delete(self, **kwargs):
"""Deletes matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be removed.
@param kwargs: attributes for selecting records, given as a... | [
"def",
"delete",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"kwargs",
":",
"return",
"0",
"affected",
"=",
"self",
".",
"where",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"remove_many",
"(",
"affected",
")",
"return",
"len",
"(",... | Deletes matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be removed.
@param kwargs: attributes for selecting records, given as additional
named argument... | [
"Deletes",
"matching",
"objects",
"from",
"the",
"table",
"based",
"on",
"given",
"named",
"parameters",
".",
"If",
"multiple",
"named",
"parameters",
"are",
"given",
"then",
"only",
"objects",
"that",
"satisfy",
"all",
"of",
"the",
"query",
"criteria",
"will"... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L835-L848 | train | Deletes matching objects from the table based on given
named parameters. |
ptmcg/littletable | littletable.py | Table.sort | def sort(self, key, reverse=False):
"""Sort Table in place, using given fields as sort key.
@param key: if this is a string, it is a comma-separated list of field names,
optionally followed by 'desc' to indicate descending sort instead of the
default ascending sort; if a ... | python | def sort(self, key, reverse=False):
"""Sort Table in place, using given fields as sort key.
@param key: if this is a string, it is a comma-separated list of field names,
optionally followed by 'desc' to indicate descending sort instead of the
default ascending sort; if a ... | [
"def",
"sort",
"(",
"self",
",",
"key",
",",
"reverse",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"(",
"basestring",
",",
"list",
",",
"tuple",
")",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"basestring",
")",
":",
"attrdefs... | Sort Table in place, using given fields as sort key.
@param key: if this is a string, it is a comma-separated list of field names,
optionally followed by 'desc' to indicate descending sort instead of the
default ascending sort; if a list or tuple, it is a list or tuple of field n... | [
"Sort",
"Table",
"in",
"place",
"using",
"given",
"fields",
"as",
"sort",
"key",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L857-L895 | train | Sort the object in place using given fields as sort key. |
ptmcg/littletable | littletable.py | Table.select | def select(self, fields, **exprs):
"""
Create a new table containing a subset of attributes, with optionally
newly-added fields computed from each rec in the original table.
@param fields: list of strings, or single space-delimited string, listing attribute name to be included in the
... | python | def select(self, fields, **exprs):
"""
Create a new table containing a subset of attributes, with optionally
newly-added fields computed from each rec in the original table.
@param fields: list of strings, or single space-delimited string, listing attribute name to be included in the
... | [
"def",
"select",
"(",
"self",
",",
"fields",
",",
"*",
"*",
"exprs",
")",
":",
"fields",
"=",
"self",
".",
"_parse_fields_string",
"(",
"fields",
")",
"def",
"_make_string_callable",
"(",
"expr",
")",
":",
"if",
"isinstance",
"(",
"expr",
",",
"basestrin... | Create a new table containing a subset of attributes, with optionally
newly-added fields computed from each rec in the original table.
@param fields: list of strings, or single space-delimited string, listing attribute name to be included in the
output
@type fields: list, or space-deli... | [
"Create",
"a",
"new",
"table",
"containing",
"a",
"subset",
"of",
"attributes",
"with",
"optionally",
"newly",
"-",
"added",
"fields",
"computed",
"from",
"each",
"rec",
"in",
"the",
"original",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L897-L931 | train | Create a new table containing a subset of attributes with optionally
added fields computed from each rec in the original table. |
ptmcg/littletable | littletable.py | Table.formatted_table | def formatted_table(self, *fields, **exprs):
"""
Create a new table with all string formatted attribute values, typically in preparation for
formatted output.
@param fields: one or more strings, each string is an attribute name to be included in the output
@type fields: string (m... | python | def formatted_table(self, *fields, **exprs):
"""
Create a new table with all string formatted attribute values, typically in preparation for
formatted output.
@param fields: one or more strings, each string is an attribute name to be included in the output
@type fields: string (m... | [
"def",
"formatted_table",
"(",
"self",
",",
"*",
"fields",
",",
"*",
"*",
"exprs",
")",
":",
"# select_exprs = {}",
"# for f in fields:",
"# select_exprs[f] = lambda r : str(getattr,f,None)",
"fields",
"=",
"set",
"(",
"fields",
")",
"select_exprs",
"=",
"ODict",
... | Create a new table with all string formatted attribute values, typically in preparation for
formatted output.
@param fields: one or more strings, each string is an attribute name to be included in the output
@type fields: string (multiple)
@param exprs: one or more named string arguments... | [
"Create",
"a",
"new",
"table",
"with",
"all",
"string",
"formatted",
"attribute",
"values",
"typically",
"in",
"preparation",
"for",
"formatted",
"output",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L933-L958 | train | Create a new table with all string formatted attribute values |
ptmcg/littletable | littletable.py | Table.join | def join(self, other, attrlist=None, auto_create_indexes=True, **kwargs):
"""
Join the objects of one table with the objects of another, based on the given
matching attributes in the named arguments. The attrlist specifies the attributes to
be copied from the source tables - if omitte... | python | def join(self, other, attrlist=None, auto_create_indexes=True, **kwargs):
"""
Join the objects of one table with the objects of another, based on the given
matching attributes in the named arguments. The attrlist specifies the attributes to
be copied from the source tables - if omitte... | [
"def",
"join",
"(",
"self",
",",
"other",
",",
"attrlist",
"=",
"None",
",",
"auto_create_indexes",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"kwargs",
":",
"raise",
"TypeError",
"(",
"\"must specify at least one join attribute as a named argu... | Join the objects of one table with the objects of another, based on the given
matching attributes in the named arguments. The attrlist specifies the attributes to
be copied from the source tables - if omitted, all attributes will be copied. Entries
in the attrlist may be single attribute na... | [
"Join",
"the",
"objects",
"of",
"one",
"table",
"with",
"the",
"objects",
"of",
"another",
"based",
"on",
"the",
"given",
"matching",
"attributes",
"in",
"the",
"named",
"arguments",
".",
"The",
"attrlist",
"specifies",
"the",
"attributes",
"to",
"be",
"copi... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L968-L1073 | train | Joins two tables and returns a new table containing the joined data. |
ptmcg/littletable | littletable.py | Table.join_on | def join_on(self, attr):
"""Creates a JoinTerm in preparation for joining with another table, to
indicate what attribute should be used in the join. Only indexed attributes
may be used in a join.
@param attr: attribute name to join from this table (may be different
... | python | def join_on(self, attr):
"""Creates a JoinTerm in preparation for joining with another table, to
indicate what attribute should be used in the join. Only indexed attributes
may be used in a join.
@param attr: attribute name to join from this table (may be different
... | [
"def",
"join_on",
"(",
"self",
",",
"attr",
")",
":",
"if",
"attr",
"not",
"in",
"self",
".",
"_indexes",
":",
"raise",
"ValueError",
"(",
"\"can only join on indexed attributes\"",
")",
"return",
"JoinTerm",
"(",
"self",
",",
"attr",
")"
] | Creates a JoinTerm in preparation for joining with another table, to
indicate what attribute should be used in the join. Only indexed attributes
may be used in a join.
@param attr: attribute name to join from this table (may be different
from the attribute name in the t... | [
"Creates",
"a",
"JoinTerm",
"in",
"preparation",
"for",
"joining",
"with",
"another",
"table",
"to",
"indicate",
"what",
"attribute",
"should",
"be",
"used",
"in",
"the",
"join",
".",
"Only",
"indexed",
"attributes",
"may",
"be",
"used",
"in",
"a",
"join",
... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1075-L1085 | train | Creates a JoinTerm in preparation for joining with another table. |
ptmcg/littletable | littletable.py | Table.pivot | def pivot(self, attrlist):
"""Pivots the data using the given attributes, returning a L{PivotTable}.
@param attrlist: list of attributes to be used to construct the pivot table
@type attrlist: list of strings, or string of space-delimited attribute names
"""
if isinstance... | python | def pivot(self, attrlist):
"""Pivots the data using the given attributes, returning a L{PivotTable}.
@param attrlist: list of attributes to be used to construct the pivot table
@type attrlist: list of strings, or string of space-delimited attribute names
"""
if isinstance... | [
"def",
"pivot",
"(",
"self",
",",
"attrlist",
")",
":",
"if",
"isinstance",
"(",
"attrlist",
",",
"basestring",
")",
":",
"attrlist",
"=",
"attrlist",
".",
"split",
"(",
")",
"if",
"all",
"(",
"a",
"in",
"self",
".",
"_indexes",
"for",
"a",
"in",
"... | Pivots the data using the given attributes, returning a L{PivotTable}.
@param attrlist: list of attributes to be used to construct the pivot table
@type attrlist: list of strings, or string of space-delimited attribute names | [
"Pivots",
"the",
"data",
"using",
"the",
"given",
"attributes",
"returning",
"a",
"L",
"{",
"PivotTable",
"}",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1087-L1097 | train | Pivots the data using the given attributes returning a PivotTable. |
ptmcg/littletable | littletable.py | Table.csv_import | def csv_import(self, csv_source, encoding='utf-8', transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a CSV-formatted file into this table.
@param csv_source: CSV file - if a string is given, the file with that name will be
opened, read, and closed; if a file ... | python | def csv_import(self, csv_source, encoding='utf-8', transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a CSV-formatted file into this table.
@param csv_source: CSV file - if a string is given, the file with that name will be
opened, read, and closed; if a file ... | [
"def",
"csv_import",
"(",
"self",
",",
"csv_source",
",",
"encoding",
"=",
"'utf-8'",
",",
"transforms",
"=",
"None",
",",
"row_class",
"=",
"DataObject",
",",
"*",
"*",
"kwargs",
")",
":",
"reader_args",
"=",
"dict",
"(",
"(",
"k",
",",
"v",
")",
"f... | Imports the contents of a CSV-formatted file into this table.
@param csv_source: CSV file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given, then that object
will be read as-is, and left for the caller to be closed.
... | [
"Imports",
"the",
"contents",
"of",
"a",
"CSV",
"-",
"formatted",
"file",
"into",
"this",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1136-L1161 | train | Imports the contents of a CSV - formatted file into this table. |
ptmcg/littletable | littletable.py | Table.tsv_import | def tsv_import(self, xsv_source, encoding="UTF-8", transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a tab-separated data file into this table.
@param xsv_source: tab-separated data file - if a string is given, the file with that name will be
opened, read, an... | python | def tsv_import(self, xsv_source, encoding="UTF-8", transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a tab-separated data file into this table.
@param xsv_source: tab-separated data file - if a string is given, the file with that name will be
opened, read, an... | [
"def",
"tsv_import",
"(",
"self",
",",
"xsv_source",
",",
"encoding",
"=",
"\"UTF-8\"",
",",
"transforms",
"=",
"None",
",",
"row_class",
"=",
"DataObject",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_xsv_import",
"(",
"xsv_source",
",",
... | Imports the contents of a tab-separated data file into this table.
@param xsv_source: tab-separated data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given, then that object
will be read as-is, and left for the caller... | [
"Imports",
"the",
"contents",
"of",
"a",
"tab",
"-",
"separated",
"data",
"file",
"into",
"this",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1171-L1185 | train | Imports the contents of a tab - separated data file into this table. |
ptmcg/littletable | littletable.py | Table.csv_export | def csv_export(self, csv_dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a CSV-formatted file.
@param csv_dest: CSV file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | python | def csv_export(self, csv_dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a CSV-formatted file.
@param csv_dest: CSV file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | [
"def",
"csv_export",
"(",
"self",
",",
"csv_dest",
",",
"fieldnames",
"=",
"None",
",",
"encoding",
"=",
"\"UTF-8\"",
")",
":",
"close_on_exit",
"=",
"False",
"if",
"isinstance",
"(",
"csv_dest",
",",
"basestring",
")",
":",
"if",
"PY_3",
":",
"csv_dest",
... | Exports the contents of the table to a CSV-formatted file.
@param csv_dest: CSV file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
will be written as-is, and left for the caller to be closed.
... | [
"Exports",
"the",
"contents",
"of",
"the",
"table",
"to",
"a",
"CSV",
"-",
"formatted",
"file",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1187-L1222 | train | Exports the contents of the table to a CSV - formatted file. |
ptmcg/littletable | littletable.py | Table.json_import | def json_import(self, source, encoding="UTF-8", transforms=None, row_class=DataObject):
"""Imports the contents of a JSON data file into this table.
@param source: JSON data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given... | python | def json_import(self, source, encoding="UTF-8", transforms=None, row_class=DataObject):
"""Imports the contents of a JSON data file into this table.
@param source: JSON data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given... | [
"def",
"json_import",
"(",
"self",
",",
"source",
",",
"encoding",
"=",
"\"UTF-8\"",
",",
"transforms",
"=",
"None",
",",
"row_class",
"=",
"DataObject",
")",
":",
"class",
"_JsonFileReader",
"(",
"object",
")",
":",
"def",
"__init__",
"(",
"self",
",",
... | Imports the contents of a JSON data file into this table.
@param source: JSON data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given, then that object
will be read as-is, and left for the caller to be closed.
... | [
"Imports",
"the",
"contents",
"of",
"a",
"JSON",
"data",
"file",
"into",
"this",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1224-L1252 | train | Imports the contents of a JSON data file into this table. |
ptmcg/littletable | littletable.py | Table.json_export | def json_export(self, dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a JSON-formatted file.
@param dest: output file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | python | def json_export(self, dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a JSON-formatted file.
@param dest: output file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | [
"def",
"json_export",
"(",
"self",
",",
"dest",
",",
"fieldnames",
"=",
"None",
",",
"encoding",
"=",
"\"UTF-8\"",
")",
":",
"close_on_exit",
"=",
"False",
"if",
"isinstance",
"(",
"dest",
",",
"basestring",
")",
":",
"if",
"PY_3",
":",
"dest",
"=",
"o... | Exports the contents of the table to a JSON-formatted file.
@param dest: output file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
will be written as-is, and left for the caller to be closed.
... | [
"Exports",
"the",
"contents",
"of",
"the",
"table",
"to",
"a",
"JSON",
"-",
"formatted",
"file",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1254-L1284 | train | Exports the contents of the table to a JSON - formatted file. |
ptmcg/littletable | littletable.py | Table.add_field | def add_field(self, attrname, fn, default=None):
"""Computes a new attribute for each object in table, or replaces an
existing attribute in each record with a computed value
@param attrname: attribute to compute for each object
@type attrname: string
@param fn: functi... | python | def add_field(self, attrname, fn, default=None):
"""Computes a new attribute for each object in table, or replaces an
existing attribute in each record with a computed value
@param attrname: attribute to compute for each object
@type attrname: string
@param fn: functi... | [
"def",
"add_field",
"(",
"self",
",",
"attrname",
",",
"fn",
",",
"default",
"=",
"None",
")",
":",
"# for rec in self:",
"def",
"_add_field_to_rec",
"(",
"rec_",
",",
"fn_",
"=",
"fn",
",",
"default_",
"=",
"default",
")",
":",
"try",
":",
"val",
"=",... | Computes a new attribute for each object in table, or replaces an
existing attribute in each record with a computed value
@param attrname: attribute to compute for each object
@type attrname: string
@param fn: function used to compute new attribute value, based on
... | [
"Computes",
"a",
"new",
"attribute",
"for",
"each",
"object",
"in",
"table",
"or",
"replaces",
"an",
"existing",
"attribute",
"in",
"each",
"record",
"with",
"a",
"computed",
"value"
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1286-L1314 | train | Adds a new attribute to each object in table or replaces an existing attribute in each record with a computed value. |
ptmcg/littletable | littletable.py | Table.groupby | def groupby(self, keyexpr, **outexprs):
"""simple prototype of group by, with support for expressions in the group-by clause
and outputs
@param keyexpr: grouping field and optional expression for computing the key value;
if a string is passed
@type keyexpr: stri... | python | def groupby(self, keyexpr, **outexprs):
"""simple prototype of group by, with support for expressions in the group-by clause
and outputs
@param keyexpr: grouping field and optional expression for computing the key value;
if a string is passed
@type keyexpr: stri... | [
"def",
"groupby",
"(",
"self",
",",
"keyexpr",
",",
"*",
"*",
"outexprs",
")",
":",
"if",
"isinstance",
"(",
"keyexpr",
",",
"basestring",
")",
":",
"keyattrs",
"=",
"keyexpr",
".",
"split",
"(",
")",
"keyfn",
"=",
"lambda",
"o",
":",
"tuple",
"(",
... | simple prototype of group by, with support for expressions in the group-by clause
and outputs
@param keyexpr: grouping field and optional expression for computing the key value;
if a string is passed
@type keyexpr: string or tuple
@param outexprs: named argum... | [
"simple",
"prototype",
"of",
"group",
"by",
"with",
"support",
"for",
"expressions",
"in",
"the",
"group",
"-",
"by",
"clause",
"and",
"outputs"
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1316-L1347 | train | simple prototype of group by with support for expressions in the group - by clause
and outputs
|
ptmcg/littletable | littletable.py | Table.unique | def unique(self, key=None):
"""
Create a new table of objects,containing no duplicate values.
@param key: (default=None) optional callable for computing a representative unique key for each
object in the table. If None, then a key will be composed as a tuple of all the values in the obj... | python | def unique(self, key=None):
"""
Create a new table of objects,containing no duplicate values.
@param key: (default=None) optional callable for computing a representative unique key for each
object in the table. If None, then a key will be composed as a tuple of all the values in the obj... | [
"def",
"unique",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"basestring",
")",
":",
"key",
"=",
"lambda",
"r",
",",
"attr",
"=",
"key",
":",
"getattr",
"(",
"r",
",",
"attr",
",",
"None",
")",
"ret",
"=... | Create a new table of objects,containing no duplicate values.
@param key: (default=None) optional callable for computing a representative unique key for each
object in the table. If None, then a key will be composed as a tuple of all the values in the object.
@type key: callable, takes the reco... | [
"Create",
"a",
"new",
"table",
"of",
"objects",
"containing",
"no",
"duplicate",
"values",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1349-L1374 | train | Create a new table of objects containing no duplicate values. |
ptmcg/littletable | littletable.py | Table.info | def info(self):
"""
Quick method to list informative table statistics
:return: dict listing table information and statistics
"""
unique_indexes = set(self._uniqueIndexes)
return {
'len': len(self),
'name': self.table_name,
'fields': lis... | python | def info(self):
"""
Quick method to list informative table statistics
:return: dict listing table information and statistics
"""
unique_indexes = set(self._uniqueIndexes)
return {
'len': len(self),
'name': self.table_name,
'fields': lis... | [
"def",
"info",
"(",
"self",
")",
":",
"unique_indexes",
"=",
"set",
"(",
"self",
".",
"_uniqueIndexes",
")",
"return",
"{",
"'len'",
":",
"len",
"(",
"self",
")",
",",
"'name'",
":",
"self",
".",
"table_name",
",",
"'fields'",
":",
"list",
"(",
"_obj... | Quick method to list informative table statistics
:return: dict listing table information and statistics | [
"Quick",
"method",
"to",
"list",
"informative",
"table",
"statistics",
":",
"return",
":",
"dict",
"listing",
"table",
"information",
"and",
"statistics"
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1376-L1387 | train | Quick method to list informative table information and statistics
|
ptmcg/littletable | littletable.py | Table._parse_fields_string | def _parse_fields_string(self, field_names):
"""
Convert raw string or list of names to actual column names:
- names starting with '-' indicate to suppress that field
- '*' means include all other field names
- if no fields are specifically included, then all fields are used
... | python | def _parse_fields_string(self, field_names):
"""
Convert raw string or list of names to actual column names:
- names starting with '-' indicate to suppress that field
- '*' means include all other field names
- if no fields are specifically included, then all fields are used
... | [
"def",
"_parse_fields_string",
"(",
"self",
",",
"field_names",
")",
":",
"if",
"isinstance",
"(",
"field_names",
",",
"basestring",
")",
":",
"field_names",
"=",
"field_names",
".",
"split",
"(",
")",
"if",
"not",
"self",
".",
"obs",
":",
"return",
"field... | Convert raw string or list of names to actual column names:
- names starting with '-' indicate to suppress that field
- '*' means include all other field names
- if no fields are specifically included, then all fields are used
:param field_names: str or list
:return: expanded lis... | [
"Convert",
"raw",
"string",
"or",
"list",
"of",
"names",
"to",
"actual",
"column",
"names",
":",
"-",
"names",
"starting",
"with",
"-",
"indicate",
"to",
"suppress",
"that",
"field",
"-",
"*",
"means",
"include",
"all",
"other",
"field",
"names",
"-",
"i... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1425-L1448 | train | Convert raw string or list of names to actual column names. |
ptmcg/littletable | littletable.py | Table.as_html | def as_html(self, fields='*'):
"""
Output the table as a rudimentary HTML table.
@param fields: fields in the table to be shown in the table
- listing '*' as a field will add all unnamed fields
- starting a field name with '-' will suppress that name... | python | def as_html(self, fields='*'):
"""
Output the table as a rudimentary HTML table.
@param fields: fields in the table to be shown in the table
- listing '*' as a field will add all unnamed fields
- starting a field name with '-' will suppress that name... | [
"def",
"as_html",
"(",
"self",
",",
"fields",
"=",
"'*'",
")",
":",
"fields",
"=",
"self",
".",
"_parse_fields_string",
"(",
"fields",
")",
"def",
"td_value",
"(",
"v",
")",
":",
"return",
"'<td><div align=\"{}\">{}</div></td>'",
".",
"format",
"(",
"(",
"... | Output the table as a rudimentary HTML table.
@param fields: fields in the table to be shown in the table
- listing '*' as a field will add all unnamed fields
- starting a field name with '-' will suppress that name
@type fields: list of strings or a single ... | [
"Output",
"the",
"table",
"as",
"a",
"rudimentary",
"HTML",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1450-L1469 | train | Output the table as a rudimentary HTML table. |
ptmcg/littletable | littletable.py | PivotTable.dump | def dump(self, out=sys.stdout, row_fn=repr, limit=-1, indent=0):
"""Dump out the contents of this table in a nested listing.
@param out: output stream to write to
@param row_fn: function to call to display individual rows
@param limit: number of records to show at deepest level ... | python | def dump(self, out=sys.stdout, row_fn=repr, limit=-1, indent=0):
"""Dump out the contents of this table in a nested listing.
@param out: output stream to write to
@param row_fn: function to call to display individual rows
@param limit: number of records to show at deepest level ... | [
"def",
"dump",
"(",
"self",
",",
"out",
"=",
"sys",
".",
"stdout",
",",
"row_fn",
"=",
"repr",
",",
"limit",
"=",
"-",
"1",
",",
"indent",
"=",
"0",
")",
":",
"NL",
"=",
"'\\n'",
"if",
"indent",
":",
"out",
".",
"write",
"(",
"\" \"",
"*",
"... | Dump out the contents of this table in a nested listing.
@param out: output stream to write to
@param row_fn: function to call to display individual rows
@param limit: number of records to show at deepest level of pivot (-1=show all)
@param indent: current nesting level | [
"Dump",
"out",
"the",
"contents",
"of",
"this",
"table",
"in",
"a",
"nested",
"listing",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1535-L1556 | train | Dump out the contents of this table in a nested listing. |
ptmcg/littletable | littletable.py | PivotTable.dump_counts | def dump_counts(self, out=sys.stdout, count_fn=len, colwidth=10):
"""Dump out the summary counts of entries in this pivot table as a tabular listing.
@param out: output stream to write to
@param count_fn: (default=len) function for computing value for each pivot cell
@param colw... | python | def dump_counts(self, out=sys.stdout, count_fn=len, colwidth=10):
"""Dump out the summary counts of entries in this pivot table as a tabular listing.
@param out: output stream to write to
@param count_fn: (default=len) function for computing value for each pivot cell
@param colw... | [
"def",
"dump_counts",
"(",
"self",
",",
"out",
"=",
"sys",
".",
"stdout",
",",
"count_fn",
"=",
"len",
",",
"colwidth",
"=",
"10",
")",
":",
"if",
"len",
"(",
"self",
".",
"_pivot_attrs",
")",
"==",
"1",
":",
"out",
".",
"write",
"(",
"\"Pivot: %s\... | Dump out the summary counts of entries in this pivot table as a tabular listing.
@param out: output stream to write to
@param count_fn: (default=len) function for computing value for each pivot cell
@param colwidth: (default=10) | [
"Dump",
"out",
"the",
"summary",
"counts",
"of",
"entries",
"in",
"this",
"pivot",
"table",
"as",
"a",
"tabular",
"listing",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1558-L1598 | train | Dump out the summary counts of entries in this pivot table as a tabular listing. |
ptmcg/littletable | littletable.py | PivotTable.as_table | def as_table(self, fn=None, col=None, col_label=None):
"""Dump out the summary counts of this pivot table as a Table.
"""
if col_label is None:
col_label = col
if fn is None:
fn = len
if col_label is None:
col_label = 'count'
re... | python | def as_table(self, fn=None, col=None, col_label=None):
"""Dump out the summary counts of this pivot table as a Table.
"""
if col_label is None:
col_label = col
if fn is None:
fn = len
if col_label is None:
col_label = 'count'
re... | [
"def",
"as_table",
"(",
"self",
",",
"fn",
"=",
"None",
",",
"col",
"=",
"None",
",",
"col_label",
"=",
"None",
")",
":",
"if",
"col_label",
"is",
"None",
":",
"col_label",
"=",
"col",
"if",
"fn",
"is",
"None",
":",
"fn",
"=",
"len",
"if",
"col_l... | Dump out the summary counts of this pivot table as a Table. | [
"Dump",
"out",
"the",
"summary",
"counts",
"of",
"this",
"pivot",
"table",
"as",
"a",
"Table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1600-L1642 | train | Dump out the summary counts of this pivot table as a Table. |
davidcarboni/Flask-Sleuth | sleuth/__init__.py | _python3_record_factory | def _python3_record_factory(*args, **kwargs):
"""Python 3 approach to custom logging, using `logging.getLogRecord(...)`
Inspireb by: https://docs.python.org/3/howto/logging-cookbook.html#customizing-logrecord
:return: A log record augmented with the values required by LOG_FORMAT, as per `_update_record(..... | python | def _python3_record_factory(*args, **kwargs):
"""Python 3 approach to custom logging, using `logging.getLogRecord(...)`
Inspireb by: https://docs.python.org/3/howto/logging-cookbook.html#customizing-logrecord
:return: A log record augmented with the values required by LOG_FORMAT, as per `_update_record(..... | [
"def",
"_python3_record_factory",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"record",
"=",
"_python_record_factory",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"_update_record",
"(",
"record",
")",
"return",
"record"
] | Python 3 approach to custom logging, using `logging.getLogRecord(...)`
Inspireb by: https://docs.python.org/3/howto/logging-cookbook.html#customizing-logrecord
:return: A log record augmented with the values required by LOG_FORMAT, as per `_update_record(...)` | [
"Python",
"3",
"approach",
"to",
"custom",
"logging",
"using",
"logging",
".",
"getLogRecord",
"(",
"...",
")"
] | 2191aa2a929ec43c0176ec51c7abef924b12d015 | https://github.com/davidcarboni/Flask-Sleuth/blob/2191aa2a929ec43c0176ec51c7abef924b12d015/sleuth/__init__.py#L13-L22 | train | Python 3 approach to custom logging using logging. getLogger. |
davidcarboni/Flask-Sleuth | sleuth/__init__.py | _update_record | def _update_record(record):
"""Collates values needed by LOG_FORMAT
This adds additional information to the log record to implement the logging standard.
:return: A log record augmented with the values required by LOG_FORMAT:
* springtime: LogRecord.asctime, but with a `.` instead of a `,` as the mil... | python | def _update_record(record):
"""Collates values needed by LOG_FORMAT
This adds additional information to the log record to implement the logging standard.
:return: A log record augmented with the values required by LOG_FORMAT:
* springtime: LogRecord.asctime, but with a `.` instead of a `,` as the mil... | [
"def",
"_update_record",
"(",
"record",
")",
":",
"# Standard fields",
"dt",
"=",
"datetime",
".",
"fromtimestamp",
"(",
"record",
".",
"created",
")",
"# Truncate microseconds to milliseconds",
"record",
".",
"springtime",
"=",
"str",
"(",
"dt",
")",
"[",
":",
... | Collates values needed by LOG_FORMAT
This adds additional information to the log record to implement the logging standard.
:return: A log record augmented with the values required by LOG_FORMAT:
* springtime: LogRecord.asctime, but with a `.` instead of a `,` as the millisecond separator
* levelname... | [
"Collates",
"values",
"needed",
"by",
"LOG_FORMAT"
] | 2191aa2a929ec43c0176ec51c7abef924b12d015 | https://github.com/davidcarboni/Flask-Sleuth/blob/2191aa2a929ec43c0176ec51c7abef924b12d015/sleuth/__init__.py#L41-L68 | train | Updates the log record with the values needed by LOG_FORMAT
|
davidcarboni/Flask-Sleuth | sleuth/__init__.py | _tracing_information | def _tracing_information():
"""Gets B3 distributed tracing information, if available.
This is returned as a list, ready to be formatted into Spring Cloud Sleuth compatible format.
"""
# We'll collate trace information if the B3 headers have been collected:
values = b3.values()
if values[b3.b3... | python | def _tracing_information():
"""Gets B3 distributed tracing information, if available.
This is returned as a list, ready to be formatted into Spring Cloud Sleuth compatible format.
"""
# We'll collate trace information if the B3 headers have been collected:
values = b3.values()
if values[b3.b3... | [
"def",
"_tracing_information",
"(",
")",
":",
"# We'll collate trace information if the B3 headers have been collected:",
"values",
"=",
"b3",
".",
"values",
"(",
")",
"if",
"values",
"[",
"b3",
".",
"b3_trace_id",
"]",
":",
"# Trace information would normally be sent to Zi... | Gets B3 distributed tracing information, if available.
This is returned as a list, ready to be formatted into Spring Cloud Sleuth compatible format. | [
"Gets",
"B3",
"distributed",
"tracing",
"information",
"if",
"available",
".",
"This",
"is",
"returned",
"as",
"a",
"list",
"ready",
"to",
"be",
"formatted",
"into",
"Spring",
"Cloud",
"Sleuth",
"compatible",
"format",
"."
] | 2191aa2a929ec43c0176ec51c7abef924b12d015 | https://github.com/davidcarboni/Flask-Sleuth/blob/2191aa2a929ec43c0176ec51c7abef924b12d015/sleuth/__init__.py#L71-L88 | train | Gets the B3 distributed tracing information if available. |
inveniosoftware/invenio-webhooks | invenio_webhooks/alembic/a095bd179f5c_create_webhooks_tables.py | upgrade | def upgrade():
"""Upgrade database."""
def json_column(name, **kwargs):
"""Return JSON column."""
return sa.Column(
name,
sqlalchemy_utils.types.JSONType().with_variant(
postgresql.JSON(none_as_null=True), 'postgresql',
),
**kwargs
... | python | def upgrade():
"""Upgrade database."""
def json_column(name, **kwargs):
"""Return JSON column."""
return sa.Column(
name,
sqlalchemy_utils.types.JSONType().with_variant(
postgresql.JSON(none_as_null=True), 'postgresql',
),
**kwargs
... | [
"def",
"upgrade",
"(",
")",
":",
"def",
"json_column",
"(",
"name",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Return JSON column.\"\"\"",
"return",
"sa",
".",
"Column",
"(",
"name",
",",
"sqlalchemy_utils",
".",
"types",
".",
"JSONType",
"(",
")",
".",
"... | Upgrade database. | [
"Upgrade",
"database",
"."
] | f407cb2245464543ee474a81189fb9d3978bdde5 | https://github.com/inveniosoftware/invenio-webhooks/blob/f407cb2245464543ee474a81189fb9d3978bdde5/invenio_webhooks/alembic/a095bd179f5c_create_webhooks_tables.py#L38-L71 | train | Upgrade database to version 1. 0. |
costastf/toonlib | toonlib/toonlib.py | Toon._authenticate | def _authenticate(self):
"""Authenticates to the api and sets up client information."""
data = {'username': self.username,
'password': self.password}
url = '{base}/client/login'.format(base=self.base_url)
response = self._session.get(url, params=data)
print(respon... | python | def _authenticate(self):
"""Authenticates to the api and sets up client information."""
data = {'username': self.username,
'password': self.password}
url = '{base}/client/login'.format(base=self.base_url)
response = self._session.get(url, params=data)
print(respon... | [
"def",
"_authenticate",
"(",
"self",
")",
":",
"data",
"=",
"{",
"'username'",
":",
"self",
".",
"username",
",",
"'password'",
":",
"self",
".",
"password",
"}",
"url",
"=",
"'{base}/client/login'",
".",
"format",
"(",
"base",
"=",
"self",
".",
"base_ur... | Authenticates to the api and sets up client information. | [
"Authenticates",
"to",
"the",
"api",
"and",
"sets",
"up",
"client",
"information",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L75-L85 | train | Authenticates to the api and sets up client information. |
costastf/toonlib | toonlib/toonlib.py | Toon._logout | def _logout(self, reset=True):
"""Log out of the API."""
url = '{base}/client/auth/logout'.format(base=self.base_url)
response = self._session.get(url, params=self._parameters)
if response.ok:
if reset:
self._reset()
return True
else:
... | python | def _logout(self, reset=True):
"""Log out of the API."""
url = '{base}/client/auth/logout'.format(base=self.base_url)
response = self._session.get(url, params=self._parameters)
if response.ok:
if reset:
self._reset()
return True
else:
... | [
"def",
"_logout",
"(",
"self",
",",
"reset",
"=",
"True",
")",
":",
"url",
"=",
"'{base}/client/auth/logout'",
".",
"format",
"(",
"base",
"=",
"self",
".",
"base_url",
")",
"response",
"=",
"self",
".",
"_session",
".",
"get",
"(",
"url",
",",
"params... | Log out of the API. | [
"Log",
"out",
"of",
"the",
"API",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L127-L136 | train | Log out of the API. |
costastf/toonlib | toonlib/toonlib.py | Toon._state | def _state(self):
"""The internal state of the object.
The api responses are not consistent so a retry is performed on every
call with information updating the internally saved state refreshing
the data. The info is cached for STATE_CACHING_SECONDS.
:return: The current state o... | python | def _state(self):
"""The internal state of the object.
The api responses are not consistent so a retry is performed on every
call with information updating the internally saved state refreshing
the data. The info is cached for STATE_CACHING_SECONDS.
:return: The current state o... | [
"def",
"_state",
"(",
"self",
")",
":",
"state",
"=",
"{",
"}",
"required_keys",
"=",
"(",
"'deviceStatusInfo'",
",",
"'gasUsage'",
",",
"'powerUsage'",
",",
"'thermostatInfo'",
",",
"'thermostatStates'",
")",
"try",
":",
"for",
"_",
"in",
"range",
"(",
"s... | The internal state of the object.
The api responses are not consistent so a retry is performed on every
call with information updating the internally saved state refreshing
the data. The info is cached for STATE_CACHING_SECONDS.
:return: The current state of the toons' information stat... | [
"The",
"internal",
"state",
"of",
"the",
"object",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L162-L188 | train | The internal state of the object. |
costastf/toonlib | toonlib/toonlib.py | Toon.smokedetectors | def smokedetectors(self):
""":return: A list of smokedetector objects modeled as named tuples"""
return [SmokeDetector(smokedetector.get('devUuid'),
smokedetector.get('name'),
smokedetector.get('lastConnectedChange'),
... | python | def smokedetectors(self):
""":return: A list of smokedetector objects modeled as named tuples"""
return [SmokeDetector(smokedetector.get('devUuid'),
smokedetector.get('name'),
smokedetector.get('lastConnectedChange'),
... | [
"def",
"smokedetectors",
"(",
"self",
")",
":",
"return",
"[",
"SmokeDetector",
"(",
"smokedetector",
".",
"get",
"(",
"'devUuid'",
")",
",",
"smokedetector",
".",
"get",
"(",
"'name'",
")",
",",
"smokedetector",
".",
"get",
"(",
"'lastConnectedChange'",
")"... | :return: A list of smokedetector objects modeled as named tuples | [
":",
"return",
":",
"A",
"list",
"of",
"smokedetector",
"objects",
"modeled",
"as",
"named",
"tuples"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L225-L234 | train | Returns a list of smokedetectors modeled as named tuples |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.