repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.process_value | def process_value(self, value):
"""Process publication value
"""
# UID -> SuperModel
if api.is_uid(value):
return self.to_super_model(value)
# Content -> SuperModel
elif api.is_object(value):
return self.to_super_model(value)
# String -> Un... | python | def process_value(self, value):
"""Process publication value
"""
# UID -> SuperModel
if api.is_uid(value):
return self.to_super_model(value)
# Content -> SuperModel
elif api.is_object(value):
return self.to_super_model(value)
# String -> Un... | [
"def",
"process_value",
"(",
"self",
",",
"value",
")",
":",
"# UID -> SuperModel",
"if",
"api",
".",
"is_uid",
"(",
"value",
")",
":",
"return",
"self",
".",
"to_super_model",
"(",
"value",
")",
"# Content -> SuperModel",
"elif",
"api",
".",
"is_object",
"(... | Process publication value | [
"Process",
"publication",
"value"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L200-L225 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.instance | def instance(self):
"""Content instance of the wrapped object
"""
if self._instance is None:
logger.debug("SuperModel::instance: *Wakup object*")
self._instance = api.get_object(self.brain)
return self._instance | python | def instance(self):
"""Content instance of the wrapped object
"""
if self._instance is None:
logger.debug("SuperModel::instance: *Wakup object*")
self._instance = api.get_object(self.brain)
return self._instance | [
"def",
"instance",
"(",
"self",
")",
":",
"if",
"self",
".",
"_instance",
"is",
"None",
":",
"logger",
".",
"debug",
"(",
"\"SuperModel::instance: *Wakup object*\"",
")",
"self",
".",
"_instance",
"=",
"api",
".",
"get_object",
"(",
"self",
".",
"brain",
"... | Content instance of the wrapped object | [
"Content",
"instance",
"of",
"the",
"wrapped",
"object"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L234-L240 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.brain | def brain(self):
"""Catalog brain of the wrapped object
"""
if self._brain is None:
logger.debug("SuperModel::brain: *Fetch catalog brain*")
self._brain = self.get_brain_by_uid(self.uid)
return self._brain | python | def brain(self):
"""Catalog brain of the wrapped object
"""
if self._brain is None:
logger.debug("SuperModel::brain: *Fetch catalog brain*")
self._brain = self.get_brain_by_uid(self.uid)
return self._brain | [
"def",
"brain",
"(",
"self",
")",
":",
"if",
"self",
".",
"_brain",
"is",
"None",
":",
"logger",
".",
"debug",
"(",
"\"SuperModel::brain: *Fetch catalog brain*\"",
")",
"self",
".",
"_brain",
"=",
"self",
".",
"get_brain_by_uid",
"(",
"self",
".",
"uid",
"... | Catalog brain of the wrapped object | [
"Catalog",
"brain",
"of",
"the",
"wrapped",
"object"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L243-L249 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.catalog | def catalog(self):
"""Primary registered catalog for the wrapped portal type
"""
if self._catalog is None:
logger.debug("SuperModel::catalog: *Fetch catalog*")
self._catalog = self.get_catalog_for(self.brain)
return self._catalog | python | def catalog(self):
"""Primary registered catalog for the wrapped portal type
"""
if self._catalog is None:
logger.debug("SuperModel::catalog: *Fetch catalog*")
self._catalog = self.get_catalog_for(self.brain)
return self._catalog | [
"def",
"catalog",
"(",
"self",
")",
":",
"if",
"self",
".",
"_catalog",
"is",
"None",
":",
"logger",
".",
"debug",
"(",
"\"SuperModel::catalog: *Fetch catalog*\"",
")",
"self",
".",
"_catalog",
"=",
"self",
".",
"get_catalog_for",
"(",
"self",
".",
"brain",
... | Primary registered catalog for the wrapped portal type | [
"Primary",
"registered",
"catalog",
"for",
"the",
"wrapped",
"portal",
"type"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L252-L258 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.get_catalog_for | def get_catalog_for(self, brain_or_object):
"""Return the primary catalog for the given brain or object
"""
if not api.is_object(brain_or_object):
raise TypeError("Invalid object type %r" % brain_or_object)
catalogs = api.get_catalogs_for(brain_or_object, default="uid_catalog... | python | def get_catalog_for(self, brain_or_object):
"""Return the primary catalog for the given brain or object
"""
if not api.is_object(brain_or_object):
raise TypeError("Invalid object type %r" % brain_or_object)
catalogs = api.get_catalogs_for(brain_or_object, default="uid_catalog... | [
"def",
"get_catalog_for",
"(",
"self",
",",
"brain_or_object",
")",
":",
"if",
"not",
"api",
".",
"is_object",
"(",
"brain_or_object",
")",
":",
"raise",
"TypeError",
"(",
"\"Invalid object type %r\"",
"%",
"brain_or_object",
")",
"catalogs",
"=",
"api",
".",
... | Return the primary catalog for the given brain or object | [
"Return",
"the",
"primary",
"catalog",
"for",
"the",
"given",
"brain",
"or",
"object"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L260-L266 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.get_brain_by_uid | def get_brain_by_uid(self, uid):
"""Lookup brain from the right catalog
"""
if uid == "0":
return api.get_portal()
# ensure we have the primary catalog
if self._catalog is None:
uid_catalog = api.get_tool("uid_catalog")
results = uid_catalog({... | python | def get_brain_by_uid(self, uid):
"""Lookup brain from the right catalog
"""
if uid == "0":
return api.get_portal()
# ensure we have the primary catalog
if self._catalog is None:
uid_catalog = api.get_tool("uid_catalog")
results = uid_catalog({... | [
"def",
"get_brain_by_uid",
"(",
"self",
",",
"uid",
")",
":",
"if",
"uid",
"==",
"\"0\"",
":",
"return",
"api",
".",
"get_portal",
"(",
")",
"# ensure we have the primary catalog",
"if",
"self",
".",
"_catalog",
"is",
"None",
":",
"uid_catalog",
"=",
"api",
... | Lookup brain from the right catalog | [
"Lookup",
"brain",
"from",
"the",
"right",
"catalog"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L268-L290 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.to_super_model | def to_super_model(self, thing):
"""Wraps an object into a Super Model
"""
if api.is_uid(thing):
return SuperModel(thing)
if not api.is_object(thing):
raise TypeError("Expected a portal object, got '{}'"
.format(type(thing)))
re... | python | def to_super_model(self, thing):
"""Wraps an object into a Super Model
"""
if api.is_uid(thing):
return SuperModel(thing)
if not api.is_object(thing):
raise TypeError("Expected a portal object, got '{}'"
.format(type(thing)))
re... | [
"def",
"to_super_model",
"(",
"self",
",",
"thing",
")",
":",
"if",
"api",
".",
"is_uid",
"(",
"thing",
")",
":",
"return",
"SuperModel",
"(",
"thing",
")",
"if",
"not",
"api",
".",
"is_object",
"(",
"thing",
")",
":",
"raise",
"TypeError",
"(",
"\"E... | Wraps an object into a Super Model | [
"Wraps",
"an",
"object",
"into",
"a",
"Super",
"Model"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L293-L301 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.stringify | def stringify(self, value):
"""Convert value to string
This method is used to generate a simple JSON representation of the
object (without dereferencing objects etc.)
"""
# SuperModel -> UID
if ISuperModel.providedBy(value):
return str(value)
# DateTi... | python | def stringify(self, value):
"""Convert value to string
This method is used to generate a simple JSON representation of the
object (without dereferencing objects etc.)
"""
# SuperModel -> UID
if ISuperModel.providedBy(value):
return str(value)
# DateTi... | [
"def",
"stringify",
"(",
"self",
",",
"value",
")",
":",
"# SuperModel -> UID",
"if",
"ISuperModel",
".",
"providedBy",
"(",
"value",
")",
":",
"return",
"str",
"(",
"value",
")",
"# DateTime -> ISO8601 format",
"elif",
"isinstance",
"(",
"value",
",",
"(",
... | Convert value to string
This method is used to generate a simple JSON representation of the
object (without dereferencing objects etc.) | [
"Convert",
"value",
"to",
"string"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L312-L342 |
senaite/senaite.core.supermodel | src/senaite/core/supermodel/model.py | SuperModel.to_dict | def to_dict(self, converter=None):
"""Returns a copy dict of the current object
If a converter function is given, pass each value to it.
Per default the values are converted by `self.stringify`.
"""
if converter is None:
converter = self.stringify
out = dict(... | python | def to_dict(self, converter=None):
"""Returns a copy dict of the current object
If a converter function is given, pass each value to it.
Per default the values are converted by `self.stringify`.
"""
if converter is None:
converter = self.stringify
out = dict(... | [
"def",
"to_dict",
"(",
"self",
",",
"converter",
"=",
"None",
")",
":",
"if",
"converter",
"is",
"None",
":",
"converter",
"=",
"self",
".",
"stringify",
"out",
"=",
"dict",
"(",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"iteritems",
"(",
")",
... | Returns a copy dict of the current object
If a converter function is given, pass each value to it.
Per default the values are converted by `self.stringify`. | [
"Returns",
"a",
"copy",
"dict",
"of",
"the",
"current",
"object"
] | train | https://github.com/senaite/senaite.core.supermodel/blob/1819154332b8776f187aa98a2e299701983a0119/src/senaite/core/supermodel/model.py#L344-L355 |
jbeluch/xbmcswift2 | xbmcswift2/module.py | Module.route | def route(self, url_rule, name=None, options=None):
'''A decorator to add a route to a view. name is used to
differentiate when there are multiple routes for a given view.'''
def decorator(func):
'''Adds a url rule for the provided function'''
view_name = name or func.__n... | python | def route(self, url_rule, name=None, options=None):
'''A decorator to add a route to a view. name is used to
differentiate when there are multiple routes for a given view.'''
def decorator(func):
'''Adds a url rule for the provided function'''
view_name = name or func.__n... | [
"def",
"route",
"(",
"self",
",",
"url_rule",
",",
"name",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"'''Adds a url rule for the provided function'''",
"view_name",
"=",
"name",
"or",
"func",
".",
"__name_... | A decorator to add a route to a view. name is used to
differentiate when there are multiple routes for a given view. | [
"A",
"decorator",
"to",
"add",
"a",
"route",
"to",
"a",
"view",
".",
"name",
"is",
"used",
"to",
"differentiate",
"when",
"there",
"are",
"multiple",
"routes",
"for",
"a",
"given",
"view",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/module.py#L85-L93 |
jbeluch/xbmcswift2 | xbmcswift2/module.py | Module.url_for | def url_for(self, endpoint, explicit=False, **items):
'''Returns a valid XBMC plugin URL for the given endpoint name.
endpoint can be the literal name of a function, or it can
correspond to the name keyword arguments passed to the route
decorator.
Currently, view names must be u... | python | def url_for(self, endpoint, explicit=False, **items):
'''Returns a valid XBMC plugin URL for the given endpoint name.
endpoint can be the literal name of a function, or it can
correspond to the name keyword arguments passed to the route
decorator.
Currently, view names must be u... | [
"def",
"url_for",
"(",
"self",
",",
"endpoint",
",",
"explicit",
"=",
"False",
",",
"*",
"*",
"items",
")",
":",
"# TODO: Enable items to be passed with keywords of other var names",
"# such as endpoing and explicit",
"# TODO: Figure out how to handle the case where a modul... | Returns a valid XBMC plugin URL for the given endpoint name.
endpoint can be the literal name of a function, or it can
correspond to the name keyword arguments passed to the route
decorator.
Currently, view names must be unique across all plugins and
modules. There are not names... | [
"Returns",
"a",
"valid",
"XBMC",
"plugin",
"URL",
"for",
"the",
"given",
"endpoint",
"name",
".",
"endpoint",
"can",
"be",
"the",
"literal",
"name",
"of",
"a",
"function",
"or",
"it",
"can",
"correspond",
"to",
"the",
"name",
"keyword",
"arguments",
"passe... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/module.py#L95-L110 |
jbeluch/xbmcswift2 | xbmcswift2/module.py | Module.add_url_rule | def add_url_rule(self, url_rule, view_func, name, options=None):
'''This method adds a URL rule for routing purposes. The
provided name can be different from the view function name if
desired. The provided name is what is used in url_for to build
a URL.
The route decorator provi... | python | def add_url_rule(self, url_rule, view_func, name, options=None):
'''This method adds a URL rule for routing purposes. The
provided name can be different from the view function name if
desired. The provided name is what is used in url_for to build
a URL.
The route decorator provi... | [
"def",
"add_url_rule",
"(",
"self",
",",
"url_rule",
",",
"view_func",
",",
"name",
",",
"options",
"=",
"None",
")",
":",
"name",
"=",
"'%s.%s'",
"%",
"(",
"self",
".",
"_namespace",
",",
"name",
")",
"def",
"register_rule",
"(",
"plugin",
",",
"url_p... | This method adds a URL rule for routing purposes. The
provided name can be different from the view function name if
desired. The provided name is what is used in url_for to build
a URL.
The route decorator provides the same functionality. | [
"This",
"method",
"adds",
"a",
"URL",
"rule",
"for",
"routing",
"purposes",
".",
"The",
"provided",
"name",
"can",
"be",
"different",
"from",
"the",
"view",
"function",
"name",
"if",
"desired",
".",
"The",
"provided",
"name",
"is",
"what",
"is",
"used",
... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/module.py#L112-L131 |
TurboGears/gearbox | gearbox/command.py | Command.get_parser | def get_parser(self, prog_name):
"""Override to add command options."""
parser = argparse.ArgumentParser(description=self.get_description(),
prog=prog_name, add_help=False)
return parser | python | def get_parser(self, prog_name):
"""Override to add command options."""
parser = argparse.ArgumentParser(description=self.get_description(),
prog=prog_name, add_help=False)
return parser | [
"def",
"get_parser",
"(",
"self",
",",
"prog_name",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"self",
".",
"get_description",
"(",
")",
",",
"prog",
"=",
"prog_name",
",",
"add_help",
"=",
"False",
")",
"return",
... | Override to add command options. | [
"Override",
"to",
"add",
"command",
"options",
"."
] | train | https://github.com/TurboGears/gearbox/blob/df496ab28050ce6a4cc4c502488f5c5812f2baff/gearbox/command.py#L20-L24 |
jbeluch/xbmcswift2 | xbmcswift2/cli/create.py | validate_pluginid | def validate_pluginid(value):
'''Returns True if the provided value is a valid pluglin id'''
valid = string.ascii_letters + string.digits + '.'
return all(c in valid for c in value) | python | def validate_pluginid(value):
'''Returns True if the provided value is a valid pluglin id'''
valid = string.ascii_letters + string.digits + '.'
return all(c in valid for c in value) | [
"def",
"validate_pluginid",
"(",
"value",
")",
":",
"valid",
"=",
"string",
".",
"ascii_letters",
"+",
"string",
".",
"digits",
"+",
"'.'",
"return",
"all",
"(",
"c",
"in",
"valid",
"for",
"c",
"in",
"value",
")"
] | Returns True if the provided value is a valid pluglin id | [
"Returns",
"True",
"if",
"the",
"provided",
"value",
"is",
"a",
"valid",
"pluglin",
"id"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/cli/create.py#L60-L63 |
jbeluch/xbmcswift2 | xbmcswift2/cli/create.py | get_valid_value | def get_valid_value(prompt, validator, default=None):
'''Displays the provided prompt and gets input from the user. This behavior
loops indefinitely until the provided validator returns True for the user
input. If a default value is provided, it will be used only if the user
hits Enter and does not prov... | python | def get_valid_value(prompt, validator, default=None):
'''Displays the provided prompt and gets input from the user. This behavior
loops indefinitely until the provided validator returns True for the user
input. If a default value is provided, it will be used only if the user
hits Enter and does not prov... | [
"def",
"get_valid_value",
"(",
"prompt",
",",
"validator",
",",
"default",
"=",
"None",
")",
":",
"ans",
"=",
"get_value",
"(",
"prompt",
",",
"default",
")",
"while",
"not",
"validator",
"(",
"ans",
")",
":",
"try",
":",
"print",
"validator",
".",
"er... | Displays the provided prompt and gets input from the user. This behavior
loops indefinitely until the provided validator returns True for the user
input. If a default value is provided, it will be used only if the user
hits Enter and does not provide a value.
If the validator callable has an error_mess... | [
"Displays",
"the",
"provided",
"prompt",
"and",
"gets",
"input",
"from",
"the",
"user",
".",
"This",
"behavior",
"loops",
"indefinitely",
"until",
"the",
"provided",
"validator",
"returns",
"True",
"for",
"the",
"user",
"input",
".",
"If",
"a",
"default",
"v... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/cli/create.py#L72-L89 |
jbeluch/xbmcswift2 | xbmcswift2/cli/create.py | get_value | def get_value(prompt, default=None, hidden=False):
'''Displays the provided prompt and returns the input from the user. If the
user hits Enter and there is a default value provided, the default is
returned.
'''
_prompt = '%s : ' % prompt
if default:
_prompt = '%s [%s]: ' % (prompt, defau... | python | def get_value(prompt, default=None, hidden=False):
'''Displays the provided prompt and returns the input from the user. If the
user hits Enter and there is a default value provided, the default is
returned.
'''
_prompt = '%s : ' % prompt
if default:
_prompt = '%s [%s]: ' % (prompt, defau... | [
"def",
"get_value",
"(",
"prompt",
",",
"default",
"=",
"None",
",",
"hidden",
"=",
"False",
")",
":",
"_prompt",
"=",
"'%s : '",
"%",
"prompt",
"if",
"default",
":",
"_prompt",
"=",
"'%s [%s]: '",
"%",
"(",
"prompt",
",",
"default",
")",
"if",
"hidden... | Displays the provided prompt and returns the input from the user. If the
user hits Enter and there is a default value provided, the default is
returned. | [
"Displays",
"the",
"provided",
"prompt",
"and",
"returns",
"the",
"input",
"from",
"the",
"user",
".",
"If",
"the",
"user",
"hits",
"Enter",
"and",
"there",
"is",
"a",
"default",
"value",
"provided",
"the",
"default",
"is",
"returned",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/cli/create.py#L92-L109 |
jbeluch/xbmcswift2 | xbmcswift2/cli/create.py | update_file | def update_file(filename, items):
'''Edits the given file in place, replacing any instances of {key} with the
appropriate value from the provided items dict. If the given filename ends
with ".xml" values will be quoted and escaped for XML.
'''
# TODO: Implement something in the templates to denote w... | python | def update_file(filename, items):
'''Edits the given file in place, replacing any instances of {key} with the
appropriate value from the provided items dict. If the given filename ends
with ".xml" values will be quoted and escaped for XML.
'''
# TODO: Implement something in the templates to denote w... | [
"def",
"update_file",
"(",
"filename",
",",
"items",
")",
":",
"# TODO: Implement something in the templates to denote whether the value",
"# being replaced is an XML attribute or a value. Perhaps move to dyanmic",
"# XML tree building rather than string replacement.",
"should_escape",
"=",
... | Edits the given file in place, replacing any instances of {key} with the
appropriate value from the provided items dict. If the given filename ends
with ".xml" values will be quoted and escaped for XML. | [
"Edits",
"the",
"given",
"file",
"in",
"place",
"replacing",
"any",
"instances",
"of",
"{",
"key",
"}",
"with",
"the",
"appropriate",
"value",
"from",
"the",
"provided",
"items",
"dict",
".",
"If",
"the",
"given",
"filename",
"ends",
"with",
".",
"xml",
... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/cli/create.py#L112-L132 |
jbeluch/xbmcswift2 | xbmcswift2/cli/create.py | create_new_project | def create_new_project():
'''Creates a new XBMC Addon directory based on user input'''
readline.parse_and_bind('tab: complete')
print \
'''
xbmcswift2 - A micro-framework for creating XBMC plugins.
[email protected]
--
'''
print 'I\'m going to ask you a few questions to get this proje... | python | def create_new_project():
'''Creates a new XBMC Addon directory based on user input'''
readline.parse_and_bind('tab: complete')
print \
'''
xbmcswift2 - A micro-framework for creating XBMC plugins.
[email protected]
--
'''
print 'I\'m going to ask you a few questions to get this proje... | [
"def",
"create_new_project",
"(",
")",
":",
"readline",
".",
"parse_and_bind",
"(",
"'tab: complete'",
")",
"print",
"'''\n xbmcswift2 - A micro-framework for creating XBMC plugins.\n [email protected]\n --\n'''",
"print",
"'I\\'m going to ask you a few questions to get th... | Creates a new XBMC Addon directory based on user input | [
"Creates",
"a",
"new",
"XBMC",
"Addon",
"directory",
"based",
"on",
"user",
"input"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/cli/create.py#L135-L189 |
mozilla/amo-validator | validator/json_parser.py | ManifestJsonParser.get_applications | def get_applications(self):
"""Return the list of supported applications."""
if ('applications' not in self.data or
'gecko' not in self.data['applications']):
return []
app = self.data['applications']['gecko']
min_version = app.get('strict_min_version', u'42.0... | python | def get_applications(self):
"""Return the list of supported applications."""
if ('applications' not in self.data or
'gecko' not in self.data['applications']):
return []
app = self.data['applications']['gecko']
min_version = app.get('strict_min_version', u'42.0... | [
"def",
"get_applications",
"(",
"self",
")",
":",
"if",
"(",
"'applications'",
"not",
"in",
"self",
".",
"data",
"or",
"'gecko'",
"not",
"in",
"self",
".",
"data",
"[",
"'applications'",
"]",
")",
":",
"return",
"[",
"]",
"app",
"=",
"self",
".",
"da... | Return the list of supported applications. | [
"Return",
"the",
"list",
"of",
"supported",
"applications",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/json_parser.py#L14-L24 |
mozilla/amo-validator | validator/chromemanifest.py | ChromeManifest.get_value | def get_value(self, subject=None, predicate=None, object_=None):
"""Returns the first triple value matching the given subject,
predicate, and/or object"""
for triple in self.triples:
# Filter out non-matches
if (subject and triple['subject'] != subject) or \
... | python | def get_value(self, subject=None, predicate=None, object_=None):
"""Returns the first triple value matching the given subject,
predicate, and/or object"""
for triple in self.triples:
# Filter out non-matches
if (subject and triple['subject'] != subject) or \
... | [
"def",
"get_value",
"(",
"self",
",",
"subject",
"=",
"None",
",",
"predicate",
"=",
"None",
",",
"object_",
"=",
"None",
")",
":",
"for",
"triple",
"in",
"self",
".",
"triples",
":",
"# Filter out non-matches",
"if",
"(",
"subject",
"and",
"triple",
"["... | Returns the first triple value matching the given subject,
predicate, and/or object | [
"Returns",
"the",
"first",
"triple",
"value",
"matching",
"the",
"given",
"subject",
"predicate",
"and",
"/",
"or",
"object"
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/chromemanifest.py#L44-L59 |
mozilla/amo-validator | validator/chromemanifest.py | ChromeManifest.get_objects | def get_objects(self, subject=None, predicate=None):
"""Returns a generator of objects that correspond to the
specified subjects and predicates."""
for triple in self.triples:
# Filter out non-matches
if ((subject and triple['subject'] != subject) or
(pr... | python | def get_objects(self, subject=None, predicate=None):
"""Returns a generator of objects that correspond to the
specified subjects and predicates."""
for triple in self.triples:
# Filter out non-matches
if ((subject and triple['subject'] != subject) or
(pr... | [
"def",
"get_objects",
"(",
"self",
",",
"subject",
"=",
"None",
",",
"predicate",
"=",
"None",
")",
":",
"for",
"triple",
"in",
"self",
".",
"triples",
":",
"# Filter out non-matches",
"if",
"(",
"(",
"subject",
"and",
"triple",
"[",
"'subject'",
"]",
"!... | Returns a generator of objects that correspond to the
specified subjects and predicates. | [
"Returns",
"a",
"generator",
"of",
"objects",
"that",
"correspond",
"to",
"the",
"specified",
"subjects",
"and",
"predicates",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/chromemanifest.py#L61-L72 |
mozilla/amo-validator | validator/chromemanifest.py | ChromeManifest.get_triples | def get_triples(self, subject=None, predicate=None, object_=None):
"""Returns triples that correspond to the specified subject,
predicates, and objects."""
for triple in self.triples:
# Filter out non-matches
if subject is not None and triple['subject'] != subject:
... | python | def get_triples(self, subject=None, predicate=None, object_=None):
"""Returns triples that correspond to the specified subject,
predicates, and objects."""
for triple in self.triples:
# Filter out non-matches
if subject is not None and triple['subject'] != subject:
... | [
"def",
"get_triples",
"(",
"self",
",",
"subject",
"=",
"None",
",",
"predicate",
"=",
"None",
",",
"object_",
"=",
"None",
")",
":",
"for",
"triple",
"in",
"self",
".",
"triples",
":",
"# Filter out non-matches",
"if",
"subject",
"is",
"not",
"None",
"a... | Returns triples that correspond to the specified subject,
predicates, and objects. | [
"Returns",
"triples",
"that",
"correspond",
"to",
"the",
"specified",
"subject",
"predicates",
"and",
"objects",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/chromemanifest.py#L74-L88 |
mozilla/amo-validator | validator/chromemanifest.py | ChromeManifest.get_applicable_overlays | def get_applicable_overlays(self, error_bundle):
"""
Given an error bundle, a list of overlays that are present in the
current package or subpackage are returned.
"""
content_paths = self.get_triples(subject='content')
if not content_paths:
return set()
... | python | def get_applicable_overlays(self, error_bundle):
"""
Given an error bundle, a list of overlays that are present in the
current package or subpackage are returned.
"""
content_paths = self.get_triples(subject='content')
if not content_paths:
return set()
... | [
"def",
"get_applicable_overlays",
"(",
"self",
",",
"error_bundle",
")",
":",
"content_paths",
"=",
"self",
".",
"get_triples",
"(",
"subject",
"=",
"'content'",
")",
"if",
"not",
"content_paths",
":",
"return",
"set",
"(",
")",
"# Create some variables that will ... | Given an error bundle, a list of overlays that are present in the
current package or subpackage are returned. | [
"Given",
"an",
"error",
"bundle",
"a",
"list",
"of",
"overlays",
"that",
"are",
"present",
"in",
"the",
"current",
"package",
"or",
"subpackage",
"are",
"returned",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/chromemanifest.py#L90-L170 |
mozilla/amo-validator | validator/chromemanifest.py | ChromeManifest.reverse_lookup | def reverse_lookup(self, state, path):
"""
Returns a chrome URL for a given path, given the current package depth
in an error bundle.
State may either be an error bundle or the actual package stack.
"""
# Make sure the path starts with a forward slash.
if not pa... | python | def reverse_lookup(self, state, path):
"""
Returns a chrome URL for a given path, given the current package depth
in an error bundle.
State may either be an error bundle or the actual package stack.
"""
# Make sure the path starts with a forward slash.
if not pa... | [
"def",
"reverse_lookup",
"(",
"self",
",",
"state",
",",
"path",
")",
":",
"# Make sure the path starts with a forward slash.",
"if",
"not",
"path",
".",
"startswith",
"(",
"'/'",
")",
":",
"path",
"=",
"'/%s'",
"%",
"path",
"# If the state is an error bundle, extra... | Returns a chrome URL for a given path, given the current package depth
in an error bundle.
State may either be an error bundle or the actual package stack. | [
"Returns",
"a",
"chrome",
"URL",
"for",
"a",
"given",
"path",
"given",
"the",
"current",
"package",
"depth",
"in",
"an",
"error",
"bundle",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/chromemanifest.py#L172-L227 |
mozilla/amo-validator | validator/chromemanifest.py | ChromeManifest._url_chunk_join | def _url_chunk_join(self, *args):
"""Join the arguments together to form a predictable URL chunk."""
# Strip slashes from either side of each path piece.
pathlets = map(lambda s: s.strip('/'), args)
# Remove empty pieces.
pathlets = filter(None, pathlets)
url = '/'.join(p... | python | def _url_chunk_join(self, *args):
"""Join the arguments together to form a predictable URL chunk."""
# Strip slashes from either side of each path piece.
pathlets = map(lambda s: s.strip('/'), args)
# Remove empty pieces.
pathlets = filter(None, pathlets)
url = '/'.join(p... | [
"def",
"_url_chunk_join",
"(",
"self",
",",
"*",
"args",
")",
":",
"# Strip slashes from either side of each path piece.",
"pathlets",
"=",
"map",
"(",
"lambda",
"s",
":",
"s",
".",
"strip",
"(",
"'/'",
")",
",",
"args",
")",
"# Remove empty pieces.",
"pathlets"... | Join the arguments together to form a predictable URL chunk. | [
"Join",
"the",
"arguments",
"together",
"to",
"form",
"a",
"predictable",
"URL",
"chunk",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/chromemanifest.py#L229-L239 |
TurboGears/gearbox | gearbox/main.py | GearBox.run | def run(self, argv):
"""Application entry point"""
try:
self.options, remainder = self.parser.parse_known_args(argv)
self._configure_logging()
if self.options.relative_plugins:
curdir = os.getcwd()
sys.path.insert(0, curdir)
... | python | def run(self, argv):
"""Application entry point"""
try:
self.options, remainder = self.parser.parse_known_args(argv)
self._configure_logging()
if self.options.relative_plugins:
curdir = os.getcwd()
sys.path.insert(0, curdir)
... | [
"def",
"run",
"(",
"self",
",",
"argv",
")",
":",
"try",
":",
"self",
".",
"options",
",",
"remainder",
"=",
"self",
".",
"parser",
".",
"parse_known_args",
"(",
"argv",
")",
"self",
".",
"_configure_logging",
"(",
")",
"if",
"self",
".",
"options",
... | Application entry point | [
"Application",
"entry",
"point"
] | train | https://github.com/TurboGears/gearbox/blob/df496ab28050ce6a4cc4c502488f5c5812f2baff/gearbox/main.py#L114-L150 |
mozilla/amo-validator | validator/rdf.py | RDFParser.uri | def uri(self, element, namespace=None):
'Returns a URIRef object for use with the RDF document.'
if namespace is None:
namespace = self.namespace
return URIRef('%s#%s' % (namespace, element)) | python | def uri(self, element, namespace=None):
'Returns a URIRef object for use with the RDF document.'
if namespace is None:
namespace = self.namespace
return URIRef('%s#%s' % (namespace, element)) | [
"def",
"uri",
"(",
"self",
",",
"element",
",",
"namespace",
"=",
"None",
")",
":",
"if",
"namespace",
"is",
"None",
":",
"namespace",
"=",
"self",
".",
"namespace",
"return",
"URIRef",
"(",
"'%s#%s'",
"%",
"(",
"namespace",
",",
"element",
")",
")"
] | Returns a URIRef object for use with the RDF document. | [
"Returns",
"a",
"URIRef",
"object",
"for",
"use",
"with",
"the",
"RDF",
"document",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/rdf.py#L123-L129 |
mozilla/amo-validator | validator/rdf.py | RDFParser.get_root_subject | def get_root_subject(self):
'Returns the BNode which describes the topmost subject of the graph.'
manifest = URIRef(self.manifest)
if list(self.rdf.triples((manifest, None, None))):
return manifest
else:
return self.rdf.subjects(None, self.manifest).next() | python | def get_root_subject(self):
'Returns the BNode which describes the topmost subject of the graph.'
manifest = URIRef(self.manifest)
if list(self.rdf.triples((manifest, None, None))):
return manifest
else:
return self.rdf.subjects(None, self.manifest).next() | [
"def",
"get_root_subject",
"(",
"self",
")",
":",
"manifest",
"=",
"URIRef",
"(",
"self",
".",
"manifest",
")",
"if",
"list",
"(",
"self",
".",
"rdf",
".",
"triples",
"(",
"(",
"manifest",
",",
"None",
",",
"None",
")",
")",
")",
":",
"return",
"ma... | Returns the BNode which describes the topmost subject of the graph. | [
"Returns",
"the",
"BNode",
"which",
"describes",
"the",
"topmost",
"subject",
"of",
"the",
"graph",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/rdf.py#L131-L139 |
mozilla/amo-validator | validator/rdf.py | RDFParser.get_object | def get_object(self, subject=None, predicate=None):
"""Eliminates some of the glue code for searching RDF. Pass
in a URIRef object (generated by the `uri` function above or
a BNode object (returned by this function) for either of the
parameters."""
# Get the result of the search... | python | def get_object(self, subject=None, predicate=None):
"""Eliminates some of the glue code for searching RDF. Pass
in a URIRef object (generated by the `uri` function above or
a BNode object (returned by this function) for either of the
parameters."""
# Get the result of the search... | [
"def",
"get_object",
"(",
"self",
",",
"subject",
"=",
"None",
",",
"predicate",
"=",
"None",
")",
":",
"# Get the result of the search",
"results",
"=",
"self",
".",
"rdf",
".",
"objects",
"(",
"subject",
",",
"predicate",
")",
"as_list",
"=",
"list",
"("... | Eliminates some of the glue code for searching RDF. Pass
in a URIRef object (generated by the `uri` function above or
a BNode object (returned by this function) for either of the
parameters. | [
"Eliminates",
"some",
"of",
"the",
"glue",
"code",
"for",
"searching",
"RDF",
".",
"Pass",
"in",
"a",
"URIRef",
"object",
"(",
"generated",
"by",
"the",
"uri",
"function",
"above",
"or",
"a",
"BNode",
"object",
"(",
"returned",
"by",
"this",
"function",
... | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/rdf.py#L141-L155 |
mozilla/amo-validator | validator/rdf.py | RDFParser.get_objects | def get_objects(self, subject=None, predicate=None):
"""Same as get_object, except returns a list of objects which
satisfy the query rather than a single result."""
# Get the result of the search
results = self.rdf.objects(subject, predicate)
return list(results) | python | def get_objects(self, subject=None, predicate=None):
"""Same as get_object, except returns a list of objects which
satisfy the query rather than a single result."""
# Get the result of the search
results = self.rdf.objects(subject, predicate)
return list(results) | [
"def",
"get_objects",
"(",
"self",
",",
"subject",
"=",
"None",
",",
"predicate",
"=",
"None",
")",
":",
"# Get the result of the search",
"results",
"=",
"self",
".",
"rdf",
".",
"objects",
"(",
"subject",
",",
"predicate",
")",
"return",
"list",
"(",
"re... | Same as get_object, except returns a list of objects which
satisfy the query rather than a single result. | [
"Same",
"as",
"get_object",
"except",
"returns",
"a",
"list",
"of",
"objects",
"which",
"satisfy",
"the",
"query",
"rather",
"than",
"a",
"single",
"result",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/rdf.py#L157-L163 |
mozilla/amo-validator | validator/rdf.py | RDFParser.get_applications | def get_applications(self):
"""Return the list of supported applications."""
applications = []
# Isolate all of the bnodes referring to target applications
for target_app in self.get_objects(None,
self.uri('targetApplication')):
app... | python | def get_applications(self):
"""Return the list of supported applications."""
applications = []
# Isolate all of the bnodes referring to target applications
for target_app in self.get_objects(None,
self.uri('targetApplication')):
app... | [
"def",
"get_applications",
"(",
"self",
")",
":",
"applications",
"=",
"[",
"]",
"# Isolate all of the bnodes referring to target applications",
"for",
"target_app",
"in",
"self",
".",
"get_objects",
"(",
"None",
",",
"self",
".",
"uri",
"(",
"'targetApplication'",
... | Return the list of supported applications. | [
"Return",
"the",
"list",
"of",
"supported",
"applications",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/rdf.py#L165-L178 |
jbeluch/xbmcswift2 | xbmcswift2/listitem.py | ListItem.add_context_menu_items | def add_context_menu_items(self, items, replace_items=False):
'''Adds context menu items. If replace_items is True all
previous context menu items will be removed.
'''
for label, action in items:
assert isinstance(label, basestring)
assert isinstance(action, bases... | python | def add_context_menu_items(self, items, replace_items=False):
'''Adds context menu items. If replace_items is True all
previous context menu items will be removed.
'''
for label, action in items:
assert isinstance(label, basestring)
assert isinstance(action, bases... | [
"def",
"add_context_menu_items",
"(",
"self",
",",
"items",
",",
"replace_items",
"=",
"False",
")",
":",
"for",
"label",
",",
"action",
"in",
"items",
":",
"assert",
"isinstance",
"(",
"label",
",",
"basestring",
")",
"assert",
"isinstance",
"(",
"action",
... | Adds context menu items. If replace_items is True all
previous context menu items will be removed. | [
"Adds",
"context",
"menu",
"items",
".",
"If",
"replace_items",
"is",
"True",
"all",
"previous",
"context",
"menu",
"items",
"will",
"be",
"removed",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/listitem.py#L55-L65 |
jbeluch/xbmcswift2 | xbmcswift2/listitem.py | ListItem.set_icon | def set_icon(self, icon):
'''Sets the listitem's icon image'''
self._icon = icon
return self._listitem.setIconImage(icon) | python | def set_icon(self, icon):
'''Sets the listitem's icon image'''
self._icon = icon
return self._listitem.setIconImage(icon) | [
"def",
"set_icon",
"(",
"self",
",",
"icon",
")",
":",
"self",
".",
"_icon",
"=",
"icon",
"return",
"self",
".",
"_listitem",
".",
"setIconImage",
"(",
"icon",
")"
] | Sets the listitem's icon image | [
"Sets",
"the",
"listitem",
"s",
"icon",
"image"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/listitem.py#L119-L122 |
jbeluch/xbmcswift2 | xbmcswift2/listitem.py | ListItem.set_thumbnail | def set_thumbnail(self, thumbnail):
'''Sets the listitem's thumbnail image'''
self._thumbnail = thumbnail
return self._listitem.setThumbnailImage(thumbnail) | python | def set_thumbnail(self, thumbnail):
'''Sets the listitem's thumbnail image'''
self._thumbnail = thumbnail
return self._listitem.setThumbnailImage(thumbnail) | [
"def",
"set_thumbnail",
"(",
"self",
",",
"thumbnail",
")",
":",
"self",
".",
"_thumbnail",
"=",
"thumbnail",
"return",
"self",
".",
"_listitem",
".",
"setThumbnailImage",
"(",
"thumbnail",
")"
] | Sets the listitem's thumbnail image | [
"Sets",
"the",
"listitem",
"s",
"thumbnail",
"image"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/listitem.py#L130-L133 |
jbeluch/xbmcswift2 | xbmcswift2/listitem.py | ListItem.set_path | def set_path(self, path):
'''Sets the listitem's path'''
self._path = path
return self._listitem.setPath(path) | python | def set_path(self, path):
'''Sets the listitem's path'''
self._path = path
return self._listitem.setPath(path) | [
"def",
"set_path",
"(",
"self",
",",
"path",
")",
":",
"self",
".",
"_path",
"=",
"path",
"return",
"self",
".",
"_listitem",
".",
"setPath",
"(",
"path",
")"
] | Sets the listitem's path | [
"Sets",
"the",
"listitem",
"s",
"path"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/listitem.py#L141-L144 |
jbeluch/xbmcswift2 | xbmcswift2/listitem.py | ListItem.set_is_playable | def set_is_playable(self, is_playable):
'''Sets the listitem's playable flag'''
value = 'false'
if is_playable:
value = 'true'
self.set_property('isPlayable', value)
self.is_folder = not is_playable | python | def set_is_playable(self, is_playable):
'''Sets the listitem's playable flag'''
value = 'false'
if is_playable:
value = 'true'
self.set_property('isPlayable', value)
self.is_folder = not is_playable | [
"def",
"set_is_playable",
"(",
"self",
",",
"is_playable",
")",
":",
"value",
"=",
"'false'",
"if",
"is_playable",
":",
"value",
"=",
"'true'",
"self",
".",
"set_property",
"(",
"'isPlayable'",
",",
"value",
")",
"self",
".",
"is_folder",
"=",
"not",
"is_p... | Sets the listitem's playable flag | [
"Sets",
"the",
"listitem",
"s",
"playable",
"flag"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/listitem.py#L154-L160 |
jbeluch/xbmcswift2 | xbmcswift2/listitem.py | ListItem.from_dict | def from_dict(cls, label=None, label2=None, icon=None, thumbnail=None,
path=None, selected=None, info=None, properties=None,
context_menu=None, replace_context_menu=False,
is_playable=None, info_type='video', stream_info=None):
'''A ListItem constructor for ... | python | def from_dict(cls, label=None, label2=None, icon=None, thumbnail=None,
path=None, selected=None, info=None, properties=None,
context_menu=None, replace_context_menu=False,
is_playable=None, info_type='video', stream_info=None):
'''A ListItem constructor for ... | [
"def",
"from_dict",
"(",
"cls",
",",
"label",
"=",
"None",
",",
"label2",
"=",
"None",
",",
"icon",
"=",
"None",
",",
"thumbnail",
"=",
"None",
",",
"path",
"=",
"None",
",",
"selected",
"=",
"None",
",",
"info",
"=",
"None",
",",
"properties",
"="... | A ListItem constructor for setting a lot of properties not
available in the regular __init__ method. Useful to collect all
the properties in a dict and then use the **dct to call this
method. | [
"A",
"ListItem",
"constructor",
"for",
"setting",
"a",
"lot",
"of",
"properties",
"not",
"available",
"in",
"the",
"regular",
"__init__",
"method",
".",
"Useful",
"to",
"collect",
"all",
"the",
"properties",
"in",
"a",
"dict",
"and",
"then",
"use",
"the",
... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/listitem.py#L186-L221 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.cached | def cached(self, TTL=60 * 24):
'''A decorator that will cache the output of the wrapped function. The
key used for the cache is the function name as well as the `*args` and
`**kwargs` passed to the function.
:param TTL: time to live in minutes
.. note:: For route caching, you s... | python | def cached(self, TTL=60 * 24):
'''A decorator that will cache the output of the wrapped function. The
key used for the cache is the function name as well as the `*args` and
`**kwargs` passed to the function.
:param TTL: time to live in minutes
.. note:: For route caching, you s... | [
"def",
"cached",
"(",
"self",
",",
"TTL",
"=",
"60",
"*",
"24",
")",
":",
"def",
"decorating_function",
"(",
"function",
")",
":",
"# TODO test this method",
"storage",
"=",
"self",
".",
"get_storage",
"(",
"self",
".",
"_function_cache_name",
",",
"file_for... | A decorator that will cache the output of the wrapped function. The
key used for the cache is the function name as well as the `*args` and
`**kwargs` passed to the function.
:param TTL: time to live in minutes
.. note:: For route caching, you should use
:meth:`xbmcswi... | [
"A",
"decorator",
"that",
"will",
"cache",
"the",
"output",
"of",
"the",
"wrapped",
"function",
".",
"The",
"key",
"used",
"for",
"the",
"cache",
"is",
"the",
"function",
"name",
"as",
"well",
"as",
"the",
"*",
"args",
"and",
"**",
"kwargs",
"passed",
... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L50-L86 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.list_storages | def list_storages(self):
'''Returns a list of existing stores. The returned names can then be
used to call get_storage().
'''
# Filter out any storages used by xbmcswift2 so caller doesn't corrupt
# them.
return [name for name in os.listdir(self.storage_path)
... | python | def list_storages(self):
'''Returns a list of existing stores. The returned names can then be
used to call get_storage().
'''
# Filter out any storages used by xbmcswift2 so caller doesn't corrupt
# them.
return [name for name in os.listdir(self.storage_path)
... | [
"def",
"list_storages",
"(",
"self",
")",
":",
"# Filter out any storages used by xbmcswift2 so caller doesn't corrupt",
"# them.",
"return",
"[",
"name",
"for",
"name",
"in",
"os",
".",
"listdir",
"(",
"self",
".",
"storage_path",
")",
"if",
"not",
"name",
".",
"... | Returns a list of existing stores. The returned names can then be
used to call get_storage(). | [
"Returns",
"a",
"list",
"of",
"existing",
"stores",
".",
"The",
"returned",
"names",
"can",
"then",
"be",
"used",
"to",
"call",
"get_storage",
"()",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L95-L102 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.get_storage | def get_storage(self, name='main', file_format='pickle', TTL=None):
'''Returns a storage for the given name. The returned storage is a
fully functioning python dictionary and is designed to be used that
way. It is usually not necessary for the caller to load or save the
storage manually.... | python | def get_storage(self, name='main', file_format='pickle', TTL=None):
'''Returns a storage for the given name. The returned storage is a
fully functioning python dictionary and is designed to be used that
way. It is usually not necessary for the caller to load or save the
storage manually.... | [
"def",
"get_storage",
"(",
"self",
",",
"name",
"=",
"'main'",
",",
"file_format",
"=",
"'pickle'",
",",
"TTL",
"=",
"None",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_unsynced_storages'",
")",
":",
"self",
".",
"_unsynced_storages",
"=",
"{"... | Returns a storage for the given name. The returned storage is a
fully functioning python dictionary and is designed to be used that
way. It is usually not necessary for the caller to load or save the
storage manually. If the storage does not already exist, it will be
created.
..... | [
"Returns",
"a",
"storage",
"for",
"the",
"given",
"name",
".",
"The",
"returned",
"storage",
"is",
"a",
"fully",
"functioning",
"python",
"dictionary",
"and",
"is",
"designed",
"to",
"be",
"used",
"that",
"way",
".",
"It",
"is",
"usually",
"not",
"necessar... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L104-L155 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.get_string | def get_string(self, stringid):
'''Returns the localized string from strings.xml for the given
stringid.
'''
stringid = int(stringid)
if not hasattr(self, '_strings'):
self._strings = {}
if not stringid in self._strings:
self._strings[stringid] = s... | python | def get_string(self, stringid):
'''Returns the localized string from strings.xml for the given
stringid.
'''
stringid = int(stringid)
if not hasattr(self, '_strings'):
self._strings = {}
if not stringid in self._strings:
self._strings[stringid] = s... | [
"def",
"get_string",
"(",
"self",
",",
"stringid",
")",
":",
"stringid",
"=",
"int",
"(",
"stringid",
")",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_strings'",
")",
":",
"self",
".",
"_strings",
"=",
"{",
"}",
"if",
"not",
"stringid",
"in",
"self"... | Returns the localized string from strings.xml for the given
stringid. | [
"Returns",
"the",
"localized",
"string",
"from",
"strings",
".",
"xml",
"for",
"the",
"given",
"stringid",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L160-L169 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.get_setting | def get_setting(self, key, converter=None, choices=None):
'''Returns the settings value for the provided key.
If converter is str, unicode, bool or int the settings value will be
returned converted to the provided type.
If choices is an instance of list or tuple its item at position of t... | python | def get_setting(self, key, converter=None, choices=None):
'''Returns the settings value for the provided key.
If converter is str, unicode, bool or int the settings value will be
returned converted to the provided type.
If choices is an instance of list or tuple its item at position of t... | [
"def",
"get_setting",
"(",
"self",
",",
"key",
",",
"converter",
"=",
"None",
",",
"choices",
"=",
"None",
")",
":",
"#TODO: allow pickling of settings items?",
"# TODO: STUB THIS OUT ON CLI",
"value",
"=",
"self",
".",
"addon",
".",
"getSetting",
"(",
"id",
"="... | Returns the settings value for the provided key.
If converter is str, unicode, bool or int the settings value will be
returned converted to the provided type.
If choices is an instance of list or tuple its item at position of the
settings value be returned.
.. note:: It is sugges... | [
"Returns",
"the",
"settings",
"value",
"for",
"the",
"provided",
"key",
".",
"If",
"converter",
"is",
"str",
"unicode",
"bool",
"or",
"int",
"the",
"settings",
"value",
"will",
"be",
"returned",
"converted",
"to",
"the",
"provided",
"type",
".",
"If",
"cho... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L181-L220 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.add_to_playlist | def add_to_playlist(self, items, playlist='video'):
'''Adds the provided list of items to the specified playlist.
Available playlists include *video* and *music*.
'''
playlists = {'music': 0, 'video': 1}
assert playlist in playlists.keys(), ('Playlist "%s" is invalid.' %
... | python | def add_to_playlist(self, items, playlist='video'):
'''Adds the provided list of items to the specified playlist.
Available playlists include *video* and *music*.
'''
playlists = {'music': 0, 'video': 1}
assert playlist in playlists.keys(), ('Playlist "%s" is invalid.' %
... | [
"def",
"add_to_playlist",
"(",
"self",
",",
"items",
",",
"playlist",
"=",
"'video'",
")",
":",
"playlists",
"=",
"{",
"'music'",
":",
"0",
",",
"'video'",
":",
"1",
"}",
"assert",
"playlist",
"in",
"playlists",
".",
"keys",
"(",
")",
",",
"(",
"'Pla... | Adds the provided list of items to the specified playlist.
Available playlists include *video* and *music*. | [
"Adds",
"the",
"provided",
"list",
"of",
"items",
"to",
"the",
"specified",
"playlist",
".",
"Available",
"playlists",
"include",
"*",
"video",
"*",
"and",
"*",
"music",
"*",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L230-L251 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.get_view_mode_id | def get_view_mode_id(self, view_mode):
'''Attempts to return a view_mode_id for a given view_mode
taking into account the current skin. If not view_mode_id can
be found, None is returned. 'thumbnail' is currently the only
suppported view_mode.
'''
view_mode_ids = VIEW_MOD... | python | def get_view_mode_id(self, view_mode):
'''Attempts to return a view_mode_id for a given view_mode
taking into account the current skin. If not view_mode_id can
be found, None is returned. 'thumbnail' is currently the only
suppported view_mode.
'''
view_mode_ids = VIEW_MOD... | [
"def",
"get_view_mode_id",
"(",
"self",
",",
"view_mode",
")",
":",
"view_mode_ids",
"=",
"VIEW_MODES",
".",
"get",
"(",
"view_mode",
".",
"lower",
"(",
")",
")",
"if",
"view_mode_ids",
":",
"return",
"view_mode_ids",
".",
"get",
"(",
"xbmc",
".",
"getSkin... | Attempts to return a view_mode_id for a given view_mode
taking into account the current skin. If not view_mode_id can
be found, None is returned. 'thumbnail' is currently the only
suppported view_mode. | [
"Attempts",
"to",
"return",
"a",
"view_mode_id",
"for",
"a",
"given",
"view_mode",
"taking",
"into",
"account",
"the",
"current",
"skin",
".",
"If",
"not",
"view_mode_id",
"can",
"be",
"found",
"None",
"is",
"returned",
".",
"thumbnail",
"is",
"currently",
"... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L253-L262 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.keyboard | def keyboard(self, default=None, heading=None, hidden=False):
'''Displays the keyboard input window to the user. If the user does not
cancel the modal, the value entered by the user will be returned.
:param default: The placeholder text used to prepopulate the input field.
:param headin... | python | def keyboard(self, default=None, heading=None, hidden=False):
'''Displays the keyboard input window to the user. If the user does not
cancel the modal, the value entered by the user will be returned.
:param default: The placeholder text used to prepopulate the input field.
:param headin... | [
"def",
"keyboard",
"(",
"self",
",",
"default",
"=",
"None",
",",
"heading",
"=",
"None",
",",
"hidden",
"=",
"False",
")",
":",
"if",
"heading",
"is",
"None",
":",
"heading",
"=",
"self",
".",
"addon",
".",
"getAddonInfo",
"(",
"'name'",
")",
"if",
... | Displays the keyboard input window to the user. If the user does not
cancel the modal, the value entered by the user will be returned.
:param default: The placeholder text used to prepopulate the input field.
:param heading: The heading for the window. Defaults to the current
... | [
"Displays",
"the",
"keyboard",
"input",
"window",
"to",
"the",
"user",
".",
"If",
"the",
"user",
"does",
"not",
"cancel",
"the",
"modal",
"the",
"value",
"entered",
"by",
"the",
"user",
"will",
"be",
"returned",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L269-L287 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.notify | def notify(self, msg='', title=None, delay=5000, image=''):
'''Displays a temporary notification message to the user. If
title is not provided, the plugin name will be used. To have a
blank title, pass '' for the title argument. The delay argument
is in milliseconds.
'''
... | python | def notify(self, msg='', title=None, delay=5000, image=''):
'''Displays a temporary notification message to the user. If
title is not provided, the plugin name will be used. To have a
blank title, pass '' for the title argument. The delay argument
is in milliseconds.
'''
... | [
"def",
"notify",
"(",
"self",
",",
"msg",
"=",
"''",
",",
"title",
"=",
"None",
",",
"delay",
"=",
"5000",
",",
"image",
"=",
"''",
")",
":",
"if",
"not",
"msg",
":",
"log",
".",
"warning",
"(",
"'Empty message for notification dialog'",
")",
"if",
"... | Displays a temporary notification message to the user. If
title is not provided, the plugin name will be used. To have a
blank title, pass '' for the title argument. The delay argument
is in milliseconds. | [
"Displays",
"a",
"temporary",
"notification",
"message",
"to",
"the",
"user",
".",
"If",
"title",
"is",
"not",
"provided",
"the",
"plugin",
"name",
"will",
"be",
"used",
".",
"To",
"have",
"a",
"blank",
"title",
"pass",
"for",
"the",
"title",
"argument",
... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L289-L300 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin._listitemify | def _listitemify(self, item):
'''Creates an xbmcswift2.ListItem if the provided value for item is a
dict. If item is already a valid xbmcswift2.ListItem, the item is
returned unmodified.
'''
info_type = self.info_type if hasattr(self, 'info_type') else 'video'
# Create L... | python | def _listitemify(self, item):
'''Creates an xbmcswift2.ListItem if the provided value for item is a
dict. If item is already a valid xbmcswift2.ListItem, the item is
returned unmodified.
'''
info_type = self.info_type if hasattr(self, 'info_type') else 'video'
# Create L... | [
"def",
"_listitemify",
"(",
"self",
",",
"item",
")",
":",
"info_type",
"=",
"self",
".",
"info_type",
"if",
"hasattr",
"(",
"self",
",",
"'info_type'",
")",
"else",
"'video'",
"# Create ListItems for anything that is not already an instance of",
"# ListItem",
"if",
... | Creates an xbmcswift2.ListItem if the provided value for item is a
dict. If item is already a valid xbmcswift2.ListItem, the item is
returned unmodified. | [
"Creates",
"an",
"xbmcswift2",
".",
"ListItem",
"if",
"the",
"provided",
"value",
"for",
"item",
"is",
"a",
"dict",
".",
"If",
"item",
"is",
"already",
"a",
"valid",
"xbmcswift2",
".",
"ListItem",
"the",
"item",
"is",
"returned",
"unmodified",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L302-L315 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin._add_subtitles | def _add_subtitles(self, subtitles):
'''Adds subtitles to playing video.
:param subtitles: A URL to a remote subtitles file or a local filename
for a subtitles file.
.. warning:: You must start playing a video before calling this method
or it will... | python | def _add_subtitles(self, subtitles):
'''Adds subtitles to playing video.
:param subtitles: A URL to a remote subtitles file or a local filename
for a subtitles file.
.. warning:: You must start playing a video before calling this method
or it will... | [
"def",
"_add_subtitles",
"(",
"self",
",",
"subtitles",
")",
":",
"# This method is named with an underscore to suggest that callers pass",
"# the subtitles argument to set_resolved_url instead of calling this",
"# method directly. This is to ensure a video is played before calling",
"# this m... | Adds subtitles to playing video.
:param subtitles: A URL to a remote subtitles file or a local filename
for a subtitles file.
.. warning:: You must start playing a video before calling this method
or it will loop for an indefinite length. | [
"Adds",
"subtitles",
"to",
"playing",
"video",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L317-L338 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.set_resolved_url | def set_resolved_url(self, item=None, subtitles=None):
'''Takes a url or a listitem to be played. Used in conjunction with a
playable list item with a path that calls back into your addon.
:param item: A playable list item or url. Pass None to alert XBMC of a
failure to res... | python | def set_resolved_url(self, item=None, subtitles=None):
'''Takes a url or a listitem to be played. Used in conjunction with a
playable list item with a path that calls back into your addon.
:param item: A playable list item or url. Pass None to alert XBMC of a
failure to res... | [
"def",
"set_resolved_url",
"(",
"self",
",",
"item",
"=",
"None",
",",
"subtitles",
"=",
"None",
")",
":",
"if",
"self",
".",
"_end_of_directory",
":",
"raise",
"Exception",
"(",
"'Current XBMC handle has been removed. Either '",
"'set_resolved_url(), end_of_directory()... | Takes a url or a listitem to be played. Used in conjunction with a
playable list item with a path that calls back into your addon.
:param item: A playable list item or url. Pass None to alert XBMC of a
failure to resolve the item.
.. warning:: When using set_r... | [
"Takes",
"a",
"url",
"or",
"a",
"listitem",
"to",
"be",
"played",
".",
"Used",
"in",
"conjunction",
"with",
"a",
"playable",
"list",
"item",
"with",
"a",
"path",
"that",
"calls",
"back",
"into",
"your",
"addon",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L340-L380 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.add_items | def add_items(self, items):
'''Adds ListItems to the XBMC interface. Each item in the
provided list should either be instances of xbmcswift2.ListItem,
or regular dictionaries that will be passed to
xbmcswift2.ListItem.from_dict. Returns the list of ListItems.
:param items: An it... | python | def add_items(self, items):
'''Adds ListItems to the XBMC interface. Each item in the
provided list should either be instances of xbmcswift2.ListItem,
or regular dictionaries that will be passed to
xbmcswift2.ListItem.from_dict. Returns the list of ListItems.
:param items: An it... | [
"def",
"add_items",
"(",
"self",
",",
"items",
")",
":",
"_items",
"=",
"[",
"self",
".",
"_listitemify",
"(",
"item",
")",
"for",
"item",
"in",
"items",
"]",
"tuples",
"=",
"[",
"item",
".",
"as_tuple",
"(",
")",
"for",
"item",
"in",
"_items",
"]"... | Adds ListItems to the XBMC interface. Each item in the
provided list should either be instances of xbmcswift2.ListItem,
or regular dictionaries that will be passed to
xbmcswift2.ListItem.from_dict. Returns the list of ListItems.
:param items: An iterable of items where each item is eith... | [
"Adds",
"ListItems",
"to",
"the",
"XBMC",
"interface",
".",
"Each",
"item",
"in",
"the",
"provided",
"list",
"should",
"either",
"be",
"instances",
"of",
"xbmcswift2",
".",
"ListItem",
"or",
"regular",
"dictionaries",
"that",
"will",
"be",
"passed",
"to",
"x... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L398-L418 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.end_of_directory | def end_of_directory(self, succeeded=True, update_listing=False,
cache_to_disc=True):
'''Wrapper for xbmcplugin.endOfDirectory. Records state in
self._end_of_directory.
Typically it is not necessary to call this method directly, as
calling :meth:`~xbmcswift2.Plu... | python | def end_of_directory(self, succeeded=True, update_listing=False,
cache_to_disc=True):
'''Wrapper for xbmcplugin.endOfDirectory. Records state in
self._end_of_directory.
Typically it is not necessary to call this method directly, as
calling :meth:`~xbmcswift2.Plu... | [
"def",
"end_of_directory",
"(",
"self",
",",
"succeeded",
"=",
"True",
",",
"update_listing",
"=",
"False",
",",
"cache_to_disc",
"=",
"True",
")",
":",
"self",
".",
"_update_listing",
"=",
"update_listing",
"if",
"not",
"self",
".",
"_end_of_directory",
":",
... | Wrapper for xbmcplugin.endOfDirectory. Records state in
self._end_of_directory.
Typically it is not necessary to call this method directly, as
calling :meth:`~xbmcswift2.Plugin.finish` will call this method. | [
"Wrapper",
"for",
"xbmcplugin",
".",
"endOfDirectory",
".",
"Records",
"state",
"in",
"self",
".",
"_end_of_directory",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L420-L434 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.add_sort_method | def add_sort_method(self, sort_method, label2_mask=None):
'''A wrapper for `xbmcplugin.addSortMethod()
<http://mirrors.xbmc.org/docs/python-docs/xbmcplugin.html#-addSortMethod>`_.
You can use ``dir(xbmcswift2.SortMethod)`` to list all available sort
methods.
:param sort_method: ... | python | def add_sort_method(self, sort_method, label2_mask=None):
'''A wrapper for `xbmcplugin.addSortMethod()
<http://mirrors.xbmc.org/docs/python-docs/xbmcplugin.html#-addSortMethod>`_.
You can use ``dir(xbmcswift2.SortMethod)`` to list all available sort
methods.
:param sort_method: ... | [
"def",
"add_sort_method",
"(",
"self",
",",
"sort_method",
",",
"label2_mask",
"=",
"None",
")",
":",
"try",
":",
"# Assume it's a string and we need to get the actual int value",
"sort_method",
"=",
"SortMethod",
".",
"from_string",
"(",
"sort_method",
")",
"except",
... | A wrapper for `xbmcplugin.addSortMethod()
<http://mirrors.xbmc.org/docs/python-docs/xbmcplugin.html#-addSortMethod>`_.
You can use ``dir(xbmcswift2.SortMethod)`` to list all available sort
methods.
:param sort_method: A valid sort method. You can provided the constant
... | [
"A",
"wrapper",
"for",
"xbmcplugin",
".",
"addSortMethod",
"()",
"<http",
":",
"//",
"mirrors",
".",
"xbmc",
".",
"org",
"/",
"docs",
"/",
"python",
"-",
"docs",
"/",
"xbmcplugin",
".",
"html#",
"-",
"addSortMethod",
">",
"_",
".",
"You",
"can",
"use",... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L436-L465 |
jbeluch/xbmcswift2 | xbmcswift2/xbmcmixin.py | XBMCMixin.finish | def finish(self, items=None, sort_methods=None, succeeded=True,
update_listing=False, cache_to_disc=True, view_mode=None):
'''Adds the provided items to the XBMC interface.
:param items: an iterable of items where each item is either a
dictionary with keys/values suitable for... | python | def finish(self, items=None, sort_methods=None, succeeded=True,
update_listing=False, cache_to_disc=True, view_mode=None):
'''Adds the provided items to the XBMC interface.
:param items: an iterable of items where each item is either a
dictionary with keys/values suitable for... | [
"def",
"finish",
"(",
"self",
",",
"items",
"=",
"None",
",",
"sort_methods",
"=",
"None",
",",
"succeeded",
"=",
"True",
",",
"update_listing",
"=",
"False",
",",
"cache_to_disc",
"=",
"True",
",",
"view_mode",
"=",
"None",
")",
":",
"# If we have any ite... | Adds the provided items to the XBMC interface.
:param items: an iterable of items where each item is either a
dictionary with keys/values suitable for passing to
:meth:`xbmcswift2.ListItem.from_dict` or an instance of
:class:`xbmcswift2.ListItem`.
:param sort_methods... | [
"Adds",
"the",
"provided",
"items",
"to",
"the",
"XBMC",
"interface",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/xbmcmixin.py#L467-L517 |
mozilla/amo-validator | validator/decorator.py | register_cleanup | def register_cleanup(cleanup):
"""Register a cleanup function to be called at the end of every validation
task. Takes either a callable (including a class with a __call_ method),
or a class with a `cleanup` class method."""
if not callable(cleanup):
# Allow decorating a class with a `cleanup` c... | python | def register_cleanup(cleanup):
"""Register a cleanup function to be called at the end of every validation
task. Takes either a callable (including a class with a __call_ method),
or a class with a `cleanup` class method."""
if not callable(cleanup):
# Allow decorating a class with a `cleanup` c... | [
"def",
"register_cleanup",
"(",
"cleanup",
")",
":",
"if",
"not",
"callable",
"(",
"cleanup",
")",
":",
"# Allow decorating a class with a `cleanup` classm ethod.",
"cleanup",
"=",
"cleanup",
".",
"cleanup",
"CLEANUP_FUNCTIONS",
".",
"append",
"(",
"cleanup",
".",
"... | Register a cleanup function to be called at the end of every validation
task. Takes either a callable (including a class with a __call_ method),
or a class with a `cleanup` class method. | [
"Register",
"a",
"cleanup",
"function",
"to",
"be",
"called",
"at",
"the",
"end",
"of",
"every",
"validation",
"task",
".",
"Takes",
"either",
"a",
"callable",
"(",
"including",
"a",
"class",
"with",
"a",
"__call_",
"method",
")",
"or",
"a",
"class",
"wi... | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/decorator.py#L37-L47 |
mozilla/amo-validator | validator/decorator.py | version_range | def version_range(guid, version, before=None, app_versions=None):
"""Returns all values after (and including) `version` for the app `guid`"""
if app_versions is None:
app_versions = validator.constants.APPROVED_APPLICATIONS
app_key = None
# Support for shorthand instead of full GUIDs.
for ... | python | def version_range(guid, version, before=None, app_versions=None):
"""Returns all values after (and including) `version` for the app `guid`"""
if app_versions is None:
app_versions = validator.constants.APPROVED_APPLICATIONS
app_key = None
# Support for shorthand instead of full GUIDs.
for ... | [
"def",
"version_range",
"(",
"guid",
",",
"version",
",",
"before",
"=",
"None",
",",
"app_versions",
"=",
"None",
")",
":",
"if",
"app_versions",
"is",
"None",
":",
"app_versions",
"=",
"validator",
".",
"constants",
".",
"APPROVED_APPLICATIONS",
"app_key",
... | Returns all values after (and including) `version` for the app `guid` | [
"Returns",
"all",
"values",
"after",
"(",
"and",
"including",
")",
"version",
"for",
"the",
"app",
"guid"
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/decorator.py#L79-L107 |
jbeluch/xbmcswift2 | xbmcswift2/urls.py | UrlRule.match | def match(self, path):
'''Attempts to match a url to the given path. If successful, a tuple is
returned. The first item is the matchd function and the second item is
a dictionary containing items to be passed to the function parsed from
the provided path.
If the provided path do... | python | def match(self, path):
'''Attempts to match a url to the given path. If successful, a tuple is
returned. The first item is the matchd function and the second item is
a dictionary containing items to be passed to the function parsed from
the provided path.
If the provided path do... | [
"def",
"match",
"(",
"self",
",",
"path",
")",
":",
"m",
"=",
"self",
".",
"_regex",
".",
"search",
"(",
"path",
")",
"if",
"not",
"m",
":",
"raise",
"NotFoundException",
"# urlunencode the values",
"items",
"=",
"dict",
"(",
"(",
"key",
",",
"unquote_... | Attempts to match a url to the given path. If successful, a tuple is
returned. The first item is the matchd function and the second item is
a dictionary containing items to be passed to the function parsed from
the provided path.
If the provided path does not match this url rule then a
... | [
"Attempts",
"to",
"match",
"a",
"url",
"to",
"the",
"given",
"path",
".",
"If",
"successful",
"a",
"tuple",
"is",
"returned",
".",
"The",
"first",
"item",
"is",
"the",
"matchd",
"function",
"and",
"the",
"second",
"item",
"is",
"a",
"dictionary",
"contai... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/urls.py#L75-L98 |
jbeluch/xbmcswift2 | xbmcswift2/urls.py | UrlRule._make_path | def _make_path(self, items):
'''Returns a relative path for the given dictionary of items.
Uses this url rule's url pattern and replaces instances of <var_name>
with the appropriate value from the items dict.
'''
for key, val in items.items():
if not isinstance(val, ... | python | def _make_path(self, items):
'''Returns a relative path for the given dictionary of items.
Uses this url rule's url pattern and replaces instances of <var_name>
with the appropriate value from the items dict.
'''
for key, val in items.items():
if not isinstance(val, ... | [
"def",
"_make_path",
"(",
"self",
",",
"items",
")",
":",
"for",
"key",
",",
"val",
"in",
"items",
".",
"items",
"(",
")",
":",
"if",
"not",
"isinstance",
"(",
"val",
",",
"basestring",
")",
":",
"raise",
"TypeError",
",",
"(",
"'Value \"%s\" for key \... | Returns a relative path for the given dictionary of items.
Uses this url rule's url pattern and replaces instances of <var_name>
with the appropriate value from the items dict. | [
"Returns",
"a",
"relative",
"path",
"for",
"the",
"given",
"dictionary",
"of",
"items",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/urls.py#L100-L119 |
jbeluch/xbmcswift2 | xbmcswift2/urls.py | UrlRule.make_path_qs | def make_path_qs(self, items):
'''Returns a relative path complete with query string for the given
dictionary of items.
Any items with keys matching this rule's url pattern will be inserted
into the path. Any remaining items will be appended as query string
parameters.
... | python | def make_path_qs(self, items):
'''Returns a relative path complete with query string for the given
dictionary of items.
Any items with keys matching this rule's url pattern will be inserted
into the path. Any remaining items will be appended as query string
parameters.
... | [
"def",
"make_path_qs",
"(",
"self",
",",
"items",
")",
":",
"# Convert any ints and longs to strings",
"for",
"key",
",",
"val",
"in",
"items",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"val",
",",
"(",
"int",
",",
"long",
")",
")",
":",
"i... | Returns a relative path complete with query string for the given
dictionary of items.
Any items with keys matching this rule's url pattern will be inserted
into the path. Any remaining items will be appended as query string
parameters.
All items will be urlencoded. Any items wh... | [
"Returns",
"a",
"relative",
"path",
"complete",
"with",
"query",
"string",
"for",
"the",
"given",
"dictionary",
"of",
"items",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/urls.py#L128-L169 |
jbeluch/xbmcswift2 | xbmcswift2/storage.py | _PersistentDictMixin.sync | def sync(self):
'''Write the dict to disk'''
if self.flag == 'r':
return
filename = self.filename
tempname = filename + '.tmp'
fileobj = open(tempname, 'wb' if self.file_format == 'pickle' else 'w')
try:
self.dump(fileobj)
except Exception:... | python | def sync(self):
'''Write the dict to disk'''
if self.flag == 'r':
return
filename = self.filename
tempname = filename + '.tmp'
fileobj = open(tempname, 'wb' if self.file_format == 'pickle' else 'w')
try:
self.dump(fileobj)
except Exception:... | [
"def",
"sync",
"(",
"self",
")",
":",
"if",
"self",
".",
"flag",
"==",
"'r'",
":",
"return",
"filename",
"=",
"self",
".",
"filename",
"tempname",
"=",
"filename",
"+",
"'.tmp'",
"fileobj",
"=",
"open",
"(",
"tempname",
",",
"'wb'",
"if",
"self",
"."... | Write the dict to disk | [
"Write",
"the",
"dict",
"to",
"disk"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/storage.py#L49-L65 |
jbeluch/xbmcswift2 | xbmcswift2/storage.py | _PersistentDictMixin.dump | def dump(self, fileobj):
'''Handles the writing of the dict to the file object'''
if self.file_format == 'csv':
csv.writer(fileobj).writerows(self.raw_dict().items())
elif self.file_format == 'json':
json.dump(self.raw_dict(), fileobj, separators=(',', ':'))
elif ... | python | def dump(self, fileobj):
'''Handles the writing of the dict to the file object'''
if self.file_format == 'csv':
csv.writer(fileobj).writerows(self.raw_dict().items())
elif self.file_format == 'json':
json.dump(self.raw_dict(), fileobj, separators=(',', ':'))
elif ... | [
"def",
"dump",
"(",
"self",
",",
"fileobj",
")",
":",
"if",
"self",
".",
"file_format",
"==",
"'csv'",
":",
"csv",
".",
"writer",
"(",
"fileobj",
")",
".",
"writerows",
"(",
"self",
".",
"raw_dict",
"(",
")",
".",
"items",
"(",
")",
")",
"elif",
... | Handles the writing of the dict to the file object | [
"Handles",
"the",
"writing",
"of",
"the",
"dict",
"to",
"the",
"file",
"object"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/storage.py#L77-L87 |
jbeluch/xbmcswift2 | xbmcswift2/storage.py | _PersistentDictMixin.load | def load(self, fileobj):
'''Load the dict from the file object'''
# try formats from most restrictive to least restrictive
for loader in (pickle.load, json.load, csv.reader):
fileobj.seek(0)
try:
return self.initial_update(loader(fileobj))
exce... | python | def load(self, fileobj):
'''Load the dict from the file object'''
# try formats from most restrictive to least restrictive
for loader in (pickle.load, json.load, csv.reader):
fileobj.seek(0)
try:
return self.initial_update(loader(fileobj))
exce... | [
"def",
"load",
"(",
"self",
",",
"fileobj",
")",
":",
"# try formats from most restrictive to least restrictive",
"for",
"loader",
"in",
"(",
"pickle",
".",
"load",
",",
"json",
".",
"load",
",",
"csv",
".",
"reader",
")",
":",
"fileobj",
".",
"seek",
"(",
... | Load the dict from the file object | [
"Load",
"the",
"dict",
"from",
"the",
"file",
"object"
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/storage.py#L89-L98 |
jbeluch/xbmcswift2 | xbmcswift2/storage.py | TimedStorage.initial_update | def initial_update(self, mapping):
'''Initially fills the underlying dictionary with keys, values and
timestamps.
'''
for key, val in mapping.items():
_, timestamp = val
if not self.TTL or (datetime.utcnow() -
datetime.utcfromtimestamp(timestamp) <... | python | def initial_update(self, mapping):
'''Initially fills the underlying dictionary with keys, values and
timestamps.
'''
for key, val in mapping.items():
_, timestamp = val
if not self.TTL or (datetime.utcnow() -
datetime.utcfromtimestamp(timestamp) <... | [
"def",
"initial_update",
"(",
"self",
",",
"mapping",
")",
":",
"for",
"key",
",",
"val",
"in",
"mapping",
".",
"items",
"(",
")",
":",
"_",
",",
"timestamp",
"=",
"val",
"if",
"not",
"self",
".",
"TTL",
"or",
"(",
"datetime",
".",
"utcnow",
"(",
... | Initially fills the underlying dictionary with keys, values and
timestamps. | [
"Initially",
"fills",
"the",
"underlying",
"dictionary",
"with",
"keys",
"values",
"and",
"timestamps",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/storage.py#L176-L184 |
jbeluch/xbmcswift2 | xbmcswift2/logger.py | setup_log | def setup_log(name):
'''Returns a logging instance for the provided name. The returned
object is an instance of logging.Logger. Logged messages will be
printed to stderr when running in the CLI, or forwarded to XBMC's
log when running in XBMC mode.
'''
_log = logging.getLogger(name)
_log.set... | python | def setup_log(name):
'''Returns a logging instance for the provided name. The returned
object is an instance of logging.Logger. Logged messages will be
printed to stderr when running in the CLI, or forwarded to XBMC's
log when running in XBMC mode.
'''
_log = logging.getLogger(name)
_log.set... | [
"def",
"setup_log",
"(",
"name",
")",
":",
"_log",
"=",
"logging",
".",
"getLogger",
"(",
"name",
")",
"_log",
".",
"setLevel",
"(",
"GLOBAL_LOG_LEVEL",
")",
"handler",
"=",
"logging",
".",
"StreamHandler",
"(",
")",
"formatter",
"=",
"logging",
".",
"Fo... | Returns a logging instance for the provided name. The returned
object is an instance of logging.Logger. Logged messages will be
printed to stderr when running in the CLI, or forwarded to XBMC's
log when running in XBMC mode. | [
"Returns",
"a",
"logging",
"instance",
"for",
"the",
"provided",
"name",
".",
"The",
"returned",
"object",
"is",
"an",
"instance",
"of",
"logging",
".",
"Logger",
".",
"Logged",
"messages",
"will",
"be",
"printed",
"to",
"stderr",
"when",
"running",
"in",
... | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/logger.py#L80-L94 |
jbeluch/xbmcswift2 | xbmcswift2/logger.py | XBMCFilter.filter | def filter(self, record):
'''Returns True for all records if running in the CLI, else returns
True.
When running inside XBMC it calls the xbmc.log() method and prevents
the message from being double printed to STDOUT.
'''
# When running in XBMC, any logged statements wi... | python | def filter(self, record):
'''Returns True for all records if running in the CLI, else returns
True.
When running inside XBMC it calls the xbmc.log() method and prevents
the message from being double printed to STDOUT.
'''
# When running in XBMC, any logged statements wi... | [
"def",
"filter",
"(",
"self",
",",
"record",
")",
":",
"# When running in XBMC, any logged statements will be double printed",
"# since we are calling xbmc.log() explicitly. Therefore we return False",
"# so every log message is filtered out and not printed again.",
"if",
"CLI_MODE",
":",
... | Returns True for all records if running in the CLI, else returns
True.
When running inside XBMC it calls the xbmc.log() method and prevents
the message from being double printed to STDOUT. | [
"Returns",
"True",
"for",
"all",
"records",
"if",
"running",
"in",
"the",
"CLI",
"else",
"returns",
"True",
"."
] | train | https://github.com/jbeluch/xbmcswift2/blob/0e7a3642499554edc8265fdf1ba6c5ee567daa78/xbmcswift2/logger.py#L51-L71 |
mozilla/amo-validator | validator/metadata_helpers.py | validate_name | def validate_name(err, value, source):
'Tests a manifest name value for trademarks.'
ff_pattern = re.compile('(mozilla|firefox)', re.I)
err.metadata['name'] = value
if ff_pattern.search(value):
err.warning(
('metadata_helpers', '_test_name', 'trademark'),
'Add-on has p... | python | def validate_name(err, value, source):
'Tests a manifest name value for trademarks.'
ff_pattern = re.compile('(mozilla|firefox)', re.I)
err.metadata['name'] = value
if ff_pattern.search(value):
err.warning(
('metadata_helpers', '_test_name', 'trademark'),
'Add-on has p... | [
"def",
"validate_name",
"(",
"err",
",",
"value",
",",
"source",
")",
":",
"ff_pattern",
"=",
"re",
".",
"compile",
"(",
"'(mozilla|firefox)'",
",",
"re",
".",
"I",
")",
"err",
".",
"metadata",
"[",
"'name'",
"]",
"=",
"value",
"if",
"ff_pattern",
".",... | Tests a manifest name value for trademarks. | [
"Tests",
"a",
"manifest",
"name",
"value",
"for",
"trademarks",
"."
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/metadata_helpers.py#L6-L20 |
mozilla/amo-validator | validator/metadata_helpers.py | validate_id | def validate_id(err, value, source):
'Tests a manifest UUID value'
field_name = '<em:id>' if source == 'install.rdf' else 'id'
id_pattern = re.compile(
'('
# UUID format.
'\{[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\}'
'|'
# "email" format.
'[a-z0-9-\.\+_]*\... | python | def validate_id(err, value, source):
'Tests a manifest UUID value'
field_name = '<em:id>' if source == 'install.rdf' else 'id'
id_pattern = re.compile(
'('
# UUID format.
'\{[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\}'
'|'
# "email" format.
'[a-z0-9-\.\+_]*\... | [
"def",
"validate_id",
"(",
"err",
",",
"value",
",",
"source",
")",
":",
"field_name",
"=",
"'<em:id>'",
"if",
"source",
"==",
"'install.rdf'",
"else",
"'id'",
"id_pattern",
"=",
"re",
".",
"compile",
"(",
"'('",
"# UUID format.",
"'\\{[0-9a-f]{8}-([0-9a-f]{4}-)... | Tests a manifest UUID value | [
"Tests",
"a",
"manifest",
"UUID",
"value"
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/metadata_helpers.py#L23-L50 |
mozilla/amo-validator | validator/metadata_helpers.py | validate_version | def validate_version(err, value, source):
'Tests a manifest version number'
field_name = '<em:version>' if source == 'install.rdf' else 'version'
err.metadata['version'] = value
# May not be longer than 32 characters
if len(value) > 32:
err.error(
('metadata_helpers', '_test_... | python | def validate_version(err, value, source):
'Tests a manifest version number'
field_name = '<em:version>' if source == 'install.rdf' else 'version'
err.metadata['version'] = value
# May not be longer than 32 characters
if len(value) > 32:
err.error(
('metadata_helpers', '_test_... | [
"def",
"validate_version",
"(",
"err",
",",
"value",
",",
"source",
")",
":",
"field_name",
"=",
"'<em:version>'",
"if",
"source",
"==",
"'install.rdf'",
"else",
"'version'",
"err",
".",
"metadata",
"[",
"'version'",
"]",
"=",
"value",
"# May not be longer than ... | Tests a manifest version number | [
"Tests",
"a",
"manifest",
"version",
"number"
] | train | https://github.com/mozilla/amo-validator/blob/0251bfbd7d93106e01ecdb6de5fcd1dc1a180664/validator/metadata_helpers.py#L53-L78 |
konnected-io/konnected-py | konnected/__init__.py | Client.get_device | def get_device(self, pin=None):
""" Query the status of a specific pin (or all configured pins if pin is ommitted) """
url = self.base_url + '/device'
try:
r = requests.get(url, params={'pin': pin}, timeout=10)
return r.json()
except RequestException as err:
... | python | def get_device(self, pin=None):
""" Query the status of a specific pin (or all configured pins if pin is ommitted) """
url = self.base_url + '/device'
try:
r = requests.get(url, params={'pin': pin}, timeout=10)
return r.json()
except RequestException as err:
... | [
"def",
"get_device",
"(",
"self",
",",
"pin",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"base_url",
"+",
"'/device'",
"try",
":",
"r",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"params",
"=",
"{",
"'pin'",
":",
"pin",
"}",
",",
"timeout... | Query the status of a specific pin (or all configured pins if pin is ommitted) | [
"Query",
"the",
"status",
"of",
"a",
"specific",
"pin",
"(",
"or",
"all",
"configured",
"pins",
"if",
"pin",
"is",
"ommitted",
")"
] | train | https://github.com/konnected-io/konnected-py/blob/0a3f2d0cfe23deb222ed92e43dee96f27b0f664c/konnected/__init__.py#L20-L27 |
konnected-io/konnected-py | konnected/__init__.py | Client.get_status | def get_status(self):
""" Query the device status. Returns JSON of the device internal state """
url = self.base_url + '/status'
try:
r = requests.get(url, timeout=10)
return r.json()
except RequestException as err:
raise Client.ClientError(err) | python | def get_status(self):
""" Query the device status. Returns JSON of the device internal state """
url = self.base_url + '/status'
try:
r = requests.get(url, timeout=10)
return r.json()
except RequestException as err:
raise Client.ClientError(err) | [
"def",
"get_status",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"base_url",
"+",
"'/status'",
"try",
":",
"r",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"timeout",
"=",
"10",
")",
"return",
"r",
".",
"json",
"(",
")",
"except",
"RequestExc... | Query the device status. Returns JSON of the device internal state | [
"Query",
"the",
"device",
"status",
".",
"Returns",
"JSON",
"of",
"the",
"device",
"internal",
"state"
] | train | https://github.com/konnected-io/konnected-py/blob/0a3f2d0cfe23deb222ed92e43dee96f27b0f664c/konnected/__init__.py#L29-L36 |
konnected-io/konnected-py | konnected/__init__.py | Client.put_device | def put_device(self, pin, state, momentary=None, times=None, pause=None):
""" Actuate a device pin """
url = self.base_url + '/device'
payload = {
"pin": pin,
"state": state
}
if momentary is not None:
payload["momentary"] = momentary
... | python | def put_device(self, pin, state, momentary=None, times=None, pause=None):
""" Actuate a device pin """
url = self.base_url + '/device'
payload = {
"pin": pin,
"state": state
}
if momentary is not None:
payload["momentary"] = momentary
... | [
"def",
"put_device",
"(",
"self",
",",
"pin",
",",
"state",
",",
"momentary",
"=",
"None",
",",
"times",
"=",
"None",
",",
"pause",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"base_url",
"+",
"'/device'",
"payload",
"=",
"{",
"\"pin\"",
":",
"... | Actuate a device pin | [
"Actuate",
"a",
"device",
"pin"
] | train | https://github.com/konnected-io/konnected-py/blob/0a3f2d0cfe23deb222ed92e43dee96f27b0f664c/konnected/__init__.py#L38-L60 |
konnected-io/konnected-py | konnected/__init__.py | Client.put_settings | def put_settings(self, sensors=[], actuators=[], auth_token=None,
endpoint=None, blink=None, discovery=None,
dht_sensors=[], ds18b20_sensors=[]):
""" Sync settings to the Konnected device """
url = self.base_url + '/settings'
payload = {
"se... | python | def put_settings(self, sensors=[], actuators=[], auth_token=None,
endpoint=None, blink=None, discovery=None,
dht_sensors=[], ds18b20_sensors=[]):
""" Sync settings to the Konnected device """
url = self.base_url + '/settings'
payload = {
"se... | [
"def",
"put_settings",
"(",
"self",
",",
"sensors",
"=",
"[",
"]",
",",
"actuators",
"=",
"[",
"]",
",",
"auth_token",
"=",
"None",
",",
"endpoint",
"=",
"None",
",",
"blink",
"=",
"None",
",",
"discovery",
"=",
"None",
",",
"dht_sensors",
"=",
"[",
... | Sync settings to the Konnected device | [
"Sync",
"settings",
"to",
"the",
"Konnected",
"device"
] | train | https://github.com/konnected-io/konnected-py/blob/0a3f2d0cfe23deb222ed92e43dee96f27b0f664c/konnected/__init__.py#L62-L87 |
dbtsai/python-mimeparse | mimeparse.py | parse_mime_type | def parse_mime_type(mime_type):
"""Parses a mime-type into its component parts.
Carves up a mime-type and returns a tuple of the (type, subtype, params)
where 'params' is a dictionary of all the parameters for the media range.
For example, the media range 'application/xhtml;q=0.5' would get parsed
... | python | def parse_mime_type(mime_type):
"""Parses a mime-type into its component parts.
Carves up a mime-type and returns a tuple of the (type, subtype, params)
where 'params' is a dictionary of all the parameters for the media range.
For example, the media range 'application/xhtml;q=0.5' would get parsed
... | [
"def",
"parse_mime_type",
"(",
"mime_type",
")",
":",
"full_type",
",",
"params",
"=",
"cgi",
".",
"parse_header",
"(",
"mime_type",
")",
"# Java URLConnection class sends an Accept header that includes a",
"# single '*'. Turn it into a legal wildcard.",
"if",
"full_type",
"=... | Parses a mime-type into its component parts.
Carves up a mime-type and returns a tuple of the (type, subtype, params)
where 'params' is a dictionary of all the parameters for the media range.
For example, the media range 'application/xhtml;q=0.5' would get parsed
into:
('application', 'xhtml', ... | [
"Parses",
"a",
"mime",
"-",
"type",
"into",
"its",
"component",
"parts",
"."
] | train | https://github.com/dbtsai/python-mimeparse/blob/cf605c0994149b1a1936b3a8a597203fe3fbb62e/mimeparse.py#L14-L39 |
dbtsai/python-mimeparse | mimeparse.py | parse_media_range | def parse_media_range(range):
"""Parse a media-range into its component parts.
Carves up a media range and returns a tuple of the (type, subtype,
params) where 'params' is a dictionary of all the parameters for the media
range. For example, the media range 'application/*;q=0.5' would get parsed
in... | python | def parse_media_range(range):
"""Parse a media-range into its component parts.
Carves up a media range and returns a tuple of the (type, subtype,
params) where 'params' is a dictionary of all the parameters for the media
range. For example, the media range 'application/*;q=0.5' would get parsed
in... | [
"def",
"parse_media_range",
"(",
"range",
")",
":",
"(",
"type",
",",
"subtype",
",",
"params",
")",
"=",
"parse_mime_type",
"(",
"range",
")",
"params",
".",
"setdefault",
"(",
"'q'",
",",
"params",
".",
"pop",
"(",
"'Q'",
",",
"None",
")",
")",
"# ... | Parse a media-range into its component parts.
Carves up a media range and returns a tuple of the (type, subtype,
params) where 'params' is a dictionary of all the parameters for the media
range. For example, the media range 'application/*;q=0.5' would get parsed
into:
('application', '*', {'q'... | [
"Parse",
"a",
"media",
"-",
"range",
"into",
"its",
"component",
"parts",
"."
] | train | https://github.com/dbtsai/python-mimeparse/blob/cf605c0994149b1a1936b3a8a597203fe3fbb62e/mimeparse.py#L42-L66 |
dbtsai/python-mimeparse | mimeparse.py | quality_and_fitness_parsed | def quality_and_fitness_parsed(mime_type, parsed_ranges):
"""Find the best match for a mime-type amongst parsed media-ranges.
Find the best match for a given mime-type against a list of media_ranges
that have already been parsed by parse_media_range(). Returns a tuple of
the fitness value and the value... | python | def quality_and_fitness_parsed(mime_type, parsed_ranges):
"""Find the best match for a mime-type amongst parsed media-ranges.
Find the best match for a given mime-type against a list of media_ranges
that have already been parsed by parse_media_range(). Returns a tuple of
the fitness value and the value... | [
"def",
"quality_and_fitness_parsed",
"(",
"mime_type",
",",
"parsed_ranges",
")",
":",
"best_fitness",
"=",
"-",
"1",
"best_fit_q",
"=",
"0",
"(",
"target_type",
",",
"target_subtype",
",",
"target_params",
")",
"=",
"parse_media_range",
"(",
"mime_type",
")",
"... | Find the best match for a mime-type amongst parsed media-ranges.
Find the best match for a given mime-type against a list of media_ranges
that have already been parsed by parse_media_range(). Returns a tuple of
the fitness value and the value of the 'q' quality parameter of the best
match, or (-1, 0) i... | [
"Find",
"the",
"best",
"match",
"for",
"a",
"mime",
"-",
"type",
"amongst",
"parsed",
"media",
"-",
"ranges",
"."
] | train | https://github.com/dbtsai/python-mimeparse/blob/cf605c0994149b1a1936b3a8a597203fe3fbb62e/mimeparse.py#L69-L120 |
dbtsai/python-mimeparse | mimeparse.py | quality | def quality(mime_type, ranges):
"""Return the quality ('q') of a mime-type against a list of media-ranges.
Returns the quality 'q' of a mime-type when compared against the
media-ranges in ranges. For example:
>>> quality('text/html','text/*;q=0.3, text/html;q=0.7,
text/html;level=1, ... | python | def quality(mime_type, ranges):
"""Return the quality ('q') of a mime-type against a list of media-ranges.
Returns the quality 'q' of a mime-type when compared against the
media-ranges in ranges. For example:
>>> quality('text/html','text/*;q=0.3, text/html;q=0.7,
text/html;level=1, ... | [
"def",
"quality",
"(",
"mime_type",
",",
"ranges",
")",
":",
"parsed_ranges",
"=",
"[",
"parse_media_range",
"(",
"r",
")",
"for",
"r",
"in",
"ranges",
".",
"split",
"(",
"','",
")",
"]",
"return",
"quality_parsed",
"(",
"mime_type",
",",
"parsed_ranges",
... | Return the quality ('q') of a mime-type against a list of media-ranges.
Returns the quality 'q' of a mime-type when compared against the
media-ranges in ranges. For example:
>>> quality('text/html','text/*;q=0.3, text/html;q=0.7,
text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5')
... | [
"Return",
"the",
"quality",
"(",
"q",
")",
"of",
"a",
"mime",
"-",
"type",
"against",
"a",
"list",
"of",
"media",
"-",
"ranges",
"."
] | train | https://github.com/dbtsai/python-mimeparse/blob/cf605c0994149b1a1936b3a8a597203fe3fbb62e/mimeparse.py#L138-L152 |
dbtsai/python-mimeparse | mimeparse.py | best_match | def best_match(supported, header):
"""Return mime-type with the highest quality ('q') from list of candidates.
Takes a list of supported mime-types and finds the best match for all the
media-ranges listed in header. The value of header must be a string that
conforms to the format of the HTTP Accept: he... | python | def best_match(supported, header):
"""Return mime-type with the highest quality ('q') from list of candidates.
Takes a list of supported mime-types and finds the best match for all the
media-ranges listed in header. The value of header must be a string that
conforms to the format of the HTTP Accept: he... | [
"def",
"best_match",
"(",
"supported",
",",
"header",
")",
":",
"split_header",
"=",
"_filter_blank",
"(",
"header",
".",
"split",
"(",
"','",
")",
")",
"parsed_header",
"=",
"[",
"parse_media_range",
"(",
"r",
")",
"for",
"r",
"in",
"split_header",
"]",
... | Return mime-type with the highest quality ('q') from list of candidates.
Takes a list of supported mime-types and finds the best match for all the
media-ranges listed in header. The value of header must be a string that
conforms to the format of the HTTP Accept: header. The value of 'supported'
is a li... | [
"Return",
"mime",
"-",
"type",
"with",
"the",
"highest",
"quality",
"(",
"q",
")",
"from",
"list",
"of",
"candidates",
"."
] | train | https://github.com/dbtsai/python-mimeparse/blob/cf605c0994149b1a1936b3a8a597203fe3fbb62e/mimeparse.py#L155-L184 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/xml2xhtml.py | makeXsl | def makeXsl(filename):
""" Helper that creates a XSLT stylesheet """
pkg = 'cnxml2html'
package = ''.join(['.' + x for x in __name__.split('.')[:-1]])[1:]
if package != '':
pkg = package + '.' + pkg
path = pkg_resources.resource_filename(pkg, filename)
xml = etree.parse(path)
return etree.XSLT(xml) | python | def makeXsl(filename):
""" Helper that creates a XSLT stylesheet """
pkg = 'cnxml2html'
package = ''.join(['.' + x for x in __name__.split('.')[:-1]])[1:]
if package != '':
pkg = package + '.' + pkg
path = pkg_resources.resource_filename(pkg, filename)
xml = etree.parse(path)
return etree.XSLT(xml) | [
"def",
"makeXsl",
"(",
"filename",
")",
":",
"pkg",
"=",
"'cnxml2html'",
"package",
"=",
"''",
".",
"join",
"(",
"[",
"'.'",
"+",
"x",
"for",
"x",
"in",
"__name__",
".",
"split",
"(",
"'.'",
")",
"[",
":",
"-",
"1",
"]",
"]",
")",
"[",
"1",
"... | Helper that creates a XSLT stylesheet | [
"Helper",
"that",
"creates",
"a",
"XSLT",
"stylesheet"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/xml2xhtml.py#L27-L35 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/xml2xhtml.py | transform_collxml | def transform_collxml(collxml_file):
""" Given a collxml file (collection.xml) this returns an HTML version of it
(including "include" anchor links to the modules) """
xml = etree.parse(collxml_file)
xslt = makeXsl('collxml2xhtml.xsl')
xml = xslt(xml)
return xml | python | def transform_collxml(collxml_file):
""" Given a collxml file (collection.xml) this returns an HTML version of it
(including "include" anchor links to the modules) """
xml = etree.parse(collxml_file)
xslt = makeXsl('collxml2xhtml.xsl')
xml = xslt(xml)
return xml | [
"def",
"transform_collxml",
"(",
"collxml_file",
")",
":",
"xml",
"=",
"etree",
".",
"parse",
"(",
"collxml_file",
")",
"xslt",
"=",
"makeXsl",
"(",
"'collxml2xhtml.xsl'",
")",
"xml",
"=",
"xslt",
"(",
"xml",
")",
"return",
"xml"
] | Given a collxml file (collection.xml) this returns an HTML version of it
(including "include" anchor links to the modules) | [
"Given",
"a",
"collxml",
"file",
"(",
"collection",
".",
"xml",
")",
"this",
"returns",
"an",
"HTML",
"version",
"of",
"it",
"(",
"including",
"include",
"anchor",
"links",
"to",
"the",
"modules",
")"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/xml2xhtml.py#L37-L44 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/xml2xhtml.py | transform_cnxml | def transform_cnxml(cnxml_file):
""" Given a module cnxml file (index.cnxml) this returns an HTML version of it """
xml = etree.parse(cnxml_file)
xslt = makeXsl('cnxml2xhtml.xsl')
xml = xslt(xml)
return xml | python | def transform_cnxml(cnxml_file):
""" Given a module cnxml file (index.cnxml) this returns an HTML version of it """
xml = etree.parse(cnxml_file)
xslt = makeXsl('cnxml2xhtml.xsl')
xml = xslt(xml)
return xml | [
"def",
"transform_cnxml",
"(",
"cnxml_file",
")",
":",
"xml",
"=",
"etree",
".",
"parse",
"(",
"cnxml_file",
")",
"xslt",
"=",
"makeXsl",
"(",
"'cnxml2xhtml.xsl'",
")",
"xml",
"=",
"xslt",
"(",
"xml",
")",
"return",
"xml"
] | Given a module cnxml file (index.cnxml) this returns an HTML version of it | [
"Given",
"a",
"module",
"cnxml",
"file",
"(",
"index",
".",
"cnxml",
")",
"this",
"returns",
"an",
"HTML",
"version",
"of",
"it"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/xml2xhtml.py#L46-L52 |
openstax/rhaptos.cnxmlutils | rhaptos/cnxmlutils/xml2xhtml.py | transform_collection | def transform_collection(collection_dir):
""" Given an unzipped collection generate a giant HTML file representing
the entire collection (including loading and converting individual modules) """
collxml_file = open(os.path.join(collection_dir, 'collection.xml'))
collxml_html = transform_collxml(col... | python | def transform_collection(collection_dir):
""" Given an unzipped collection generate a giant HTML file representing
the entire collection (including loading and converting individual modules) """
collxml_file = open(os.path.join(collection_dir, 'collection.xml'))
collxml_html = transform_collxml(col... | [
"def",
"transform_collection",
"(",
"collection_dir",
")",
":",
"collxml_file",
"=",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"collection_dir",
",",
"'collection.xml'",
")",
")",
"collxml_html",
"=",
"transform_collxml",
"(",
"collxml_file",
")",
"# For... | Given an unzipped collection generate a giant HTML file representing
the entire collection (including loading and converting individual modules) | [
"Given",
"an",
"unzipped",
"collection",
"generate",
"a",
"giant",
"HTML",
"file",
"representing",
"the",
"entire",
"collection",
"(",
"including",
"loading",
"and",
"converting",
"individual",
"modules",
")"
] | train | https://github.com/openstax/rhaptos.cnxmlutils/blob/c32b1a7428dc652e8cd745f3fdf4019a20543649/rhaptos/cnxmlutils/xml2xhtml.py#L54-L79 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_dict | def from_dict(cls, d: dict, force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> T:
"""From dict to instance
:param d: Dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
... | python | def from_dict(cls, d: dict, force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> T:
"""From dict to instance
:param d: Dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
... | [
"def",
"from_dict",
"(",
"cls",
",",
"d",
":",
"dict",
",",
"force_snake_case",
":",
"bool",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"T",
":",
"if",
"isinstance",
"(",
"d",
",... | From dict to instance
:param d: Dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: Instance
Usage:
>>> from... | [
"From",
"dict",
"to",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L93-L259 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_optional_dict | def from_optional_dict(cls, d: Optional[dict],
force_snake_case: bool=True,force_cast: bool=False, restrict: bool=True) -> TOption[T]:
"""From dict to optional instance.
:param d: Dict
:param force_snake_case: Keys are transformed to snake case in order to compliant P... | python | def from_optional_dict(cls, d: Optional[dict],
force_snake_case: bool=True,force_cast: bool=False, restrict: bool=True) -> TOption[T]:
"""From dict to optional instance.
:param d: Dict
:param force_snake_case: Keys are transformed to snake case in order to compliant P... | [
"def",
"from_optional_dict",
"(",
"cls",
",",
"d",
":",
"Optional",
"[",
"dict",
"]",
",",
"force_snake_case",
":",
"bool",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"TOption",
"[",... | From dict to optional instance.
:param d: Dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: Instance
Usage:
... | [
"From",
"dict",
"to",
"optional",
"instance",
"."
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L262-L298 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_dicts | def from_dicts(cls, ds: List[dict],
force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> TList[T]:
"""From list of dict to list of instance
:param ds: List of dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 i... | python | def from_dicts(cls, ds: List[dict],
force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> TList[T]:
"""From list of dict to list of instance
:param ds: List of dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 i... | [
"def",
"from_dicts",
"(",
"cls",
",",
"ds",
":",
"List",
"[",
"dict",
"]",
",",
"force_snake_case",
":",
"bool",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"TList",
"[",
"T",
"]"... | From list of dict to list of instance
:param ds: List of dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: List of instance
... | [
"From",
"list",
"of",
"dict",
"to",
"list",
"of",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L301-L326 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_optional_dicts | def from_optional_dicts(cls, ds: Optional[List[dict]],
force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> TOption[TList[T]]:
"""From list of dict to optional list of instance.
:param ds: List of dict
:param force_snake_case: Keys are transfo... | python | def from_optional_dicts(cls, ds: Optional[List[dict]],
force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> TOption[TList[T]]:
"""From list of dict to optional list of instance.
:param ds: List of dict
:param force_snake_case: Keys are transfo... | [
"def",
"from_optional_dicts",
"(",
"cls",
",",
"ds",
":",
"Optional",
"[",
"List",
"[",
"dict",
"]",
"]",
",",
"force_snake_case",
":",
"bool",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
... | From list of dict to optional list of instance.
:param ds: List of dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: List of ins... | [
"From",
"list",
"of",
"dict",
"to",
"optional",
"list",
"of",
"instance",
"."
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L329-L350 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_dicts_by_key | def from_dicts_by_key(cls, ds: dict,
force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> TDict[T]:
"""From dict of dict to dict of instance
:param ds: Dict of dict
:param force_snake_case: Keys are transformed to snake case in order to complian... | python | def from_dicts_by_key(cls, ds: dict,
force_snake_case: bool=True, force_cast: bool=False, restrict: bool=True) -> TDict[T]:
"""From dict of dict to dict of instance
:param ds: Dict of dict
:param force_snake_case: Keys are transformed to snake case in order to complian... | [
"def",
"from_dicts_by_key",
"(",
"cls",
",",
"ds",
":",
"dict",
",",
"force_snake_case",
":",
"bool",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"TDict",
"[",
"T",
"]",
":",
"retur... | From dict of dict to dict of instance
:param ds: Dict of dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: Dict of instance
... | [
"From",
"dict",
"of",
"dict",
"to",
"dict",
"of",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L353-L378 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_optional_dicts_by_key | def from_optional_dicts_by_key(cls, ds: Optional[dict],
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> TOption[TDict[T]]:
"""From dict of dict to optional dict of instance.
:param ds: Dict of dict
:param force_snake_case: Keys are trans... | python | def from_optional_dicts_by_key(cls, ds: Optional[dict],
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> TOption[TDict[T]]:
"""From dict of dict to optional dict of instance.
:param ds: Dict of dict
:param force_snake_case: Keys are trans... | [
"def",
"from_optional_dicts_by_key",
"(",
"cls",
",",
"ds",
":",
"Optional",
"[",
"dict",
"]",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"TOption",
"[",
"TDic... | From dict of dict to optional dict of instance.
:param ds: Dict of dict
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: Dict of ins... | [
"From",
"dict",
"of",
"dict",
"to",
"optional",
"dict",
"of",
"instance",
"."
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L381-L402 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_json | def from_json(cls, data: str, force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> T:
"""From json string to instance
:param data: Json string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcib... | python | def from_json(cls, data: str, force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> T:
"""From json string to instance
:param data: Json string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcib... | [
"def",
"from_json",
"(",
"cls",
",",
"data",
":",
"str",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"False",
")",
"->",
"T",
":",
"return",
"cls",
".",
"from_dict",
"(",
"uti... | From json string to instance
:param data: Json string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: Instance
Usage:
... | [
"From",
"json",
"string",
"to",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L405-L435 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_jsonf | def from_jsonf(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> T:
"""From json file path to instance
:param fpath: Json file path
:param encoding: Json file encoding
:param force_snake_case: Keys are trans... | python | def from_jsonf(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> T:
"""From json file path to instance
:param fpath: Json file path
:param encoding: Json file encoding
:param force_snake_case: Keys are trans... | [
"def",
"from_jsonf",
"(",
"cls",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"False",
")",
"->",
"T",
":"... | From json file path to instance
:param fpath: Json file path
:param encoding: Json file encoding
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if ... | [
"From",
"json",
"file",
"path",
"to",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L438-L452 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_json_to_list | def from_json_to_list(cls, data: str,
force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> TList[T]:
"""From json string to list of instance
:param data: Json string
:param force_snake_case: Keys are transformed to snake case in order to compliant PE... | python | def from_json_to_list(cls, data: str,
force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> TList[T]:
"""From json string to list of instance
:param data: Json string
:param force_snake_case: Keys are transformed to snake case in order to compliant PE... | [
"def",
"from_json_to_list",
"(",
"cls",
",",
"data",
":",
"str",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"False",
")",
"->",
"TList",
"[",
"T",
"]",
":",
"return",
"cls",
... | From json string to list of instance
:param data: Json string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: List of instance
... | [
"From",
"json",
"string",
"to",
"list",
"of",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L455-L480 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_jsonf_to_list | def from_jsonf_to_list(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> TList[T]:
"""From json file path to list of instance
:param fpath: Json file path
:param encoding: Json file encoding
:param f... | python | def from_jsonf_to_list(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> TList[T]:
"""From json file path to list of instance
:param fpath: Json file path
:param encoding: Json file encoding
:param f... | [
"def",
"from_jsonf_to_list",
"(",
"cls",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"False",
")",
"->",
"T... | From json file path to list of instance
:param fpath: Json file path
:param encoding: Json file encoding
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parame... | [
"From",
"json",
"file",
"path",
"to",
"list",
"of",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L483-L497 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_yaml | def from_yaml(cls, data: str, force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> T:
"""From yaml string to instance
:param data: Yaml string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibl... | python | def from_yaml(cls, data: str, force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> T:
"""From yaml string to instance
:param data: Yaml string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibl... | [
"def",
"from_yaml",
"(",
"cls",
",",
"data",
":",
"str",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"T",
":",
"return",
"cls",
".",
"from_dict",
"(",
"util... | From yaml string to instance
:param data: Yaml string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: Instance
Usage:
... | [
"From",
"yaml",
"string",
"to",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L500-L532 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_yamlf | def from_yamlf(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> T:
"""From yaml file path to instance
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:param force_snake_case: Keys are transf... | python | def from_yamlf(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> T:
"""From yaml file path to instance
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:param force_snake_case: Keys are transf... | [
"def",
"from_yamlf",
"(",
"cls",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"T",
":",... | From yaml file path to instance
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if ... | [
"From",
"yaml",
"file",
"path",
"to",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L535-L549 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_yaml_to_list | def from_yaml_to_list(cls, data: str,
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> TList[T]:
"""From yaml string to list of instance
:param data: Yaml string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP... | python | def from_yaml_to_list(cls, data: str,
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> TList[T]:
"""From yaml string to list of instance
:param data: Yaml string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP... | [
"def",
"from_yaml_to_list",
"(",
"cls",
",",
"data",
":",
"str",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"TList",
"[",
"T",
"]",
":",
"return",
"cls",
"... | From yaml string to list of instance
:param data: Yaml string
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: List of instance
... | [
"From",
"yaml",
"string",
"to",
"list",
"of",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L552-L585 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_yamlf_to_list | def from_yamlf_to_list(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> TList[T]:
"""From yaml file path to list of instance
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:param fo... | python | def from_yamlf_to_list(cls, fpath: str, encoding: str='utf8',
force_snake_case=True, force_cast: bool=False, restrict: bool=True) -> TList[T]:
"""From yaml file path to list of instance
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:param fo... | [
"def",
"from_yamlf_to_list",
"(",
"cls",
",",
"fpath",
":",
"str",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"True",
")",
"->",
"TL... | From yaml file path to list of instance
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parame... | [
"From",
"yaml",
"file",
"path",
"to",
"list",
"of",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L588-L602 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_csvf | def from_csvf(cls, fpath: str, fieldnames: Optional[Sequence[str]]=None, encoding: str='utf8',
force_snake_case: bool=True, restrict: bool=True) -> TList[T]:
"""From csv file path to list of instance
:param fpath: Csv file path
:param fieldnames: Specify csv header names if no... | python | def from_csvf(cls, fpath: str, fieldnames: Optional[Sequence[str]]=None, encoding: str='utf8',
force_snake_case: bool=True, restrict: bool=True) -> TList[T]:
"""From csv file path to list of instance
:param fpath: Csv file path
:param fieldnames: Specify csv header names if no... | [
"def",
"from_csvf",
"(",
"cls",
",",
"fpath",
":",
"str",
",",
"fieldnames",
":",
"Optional",
"[",
"Sequence",
"[",
"str",
"]",
"]",
"=",
"None",
",",
"encoding",
":",
"str",
"=",
"'utf8'",
",",
"force_snake_case",
":",
"bool",
"=",
"True",
",",
"res... | From csv file path to list of instance
:param fpath: Csv file path
:param fieldnames: Specify csv header names if not included in the file
:param encoding: Csv file encoding
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param res... | [
"From",
"csv",
"file",
"path",
"to",
"list",
"of",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L605-L619 |
tadashi-aikawa/owlmixin | owlmixin/__init__.py | OwlMixin.from_json_url | def from_json_url(cls, url: str, force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> T:
"""From url which returns json to instance
:param url: Url which returns json
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param... | python | def from_json_url(cls, url: str, force_snake_case=True, force_cast: bool=False, restrict: bool=False) -> T:
"""From url which returns json to instance
:param url: Url which returns json
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param... | [
"def",
"from_json_url",
"(",
"cls",
",",
"url",
":",
"str",
",",
"force_snake_case",
"=",
"True",
",",
"force_cast",
":",
"bool",
"=",
"False",
",",
"restrict",
":",
"bool",
"=",
"False",
")",
"->",
"T",
":",
"return",
"cls",
".",
"from_dict",
"(",
"... | From url which returns json to instance
:param url: Url which returns json
:param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
:param force_cast: Cast forcibly if True
:param restrict: Prohibit extra parameters if True
:return: Instance | [
"From",
"url",
"which",
"returns",
"json",
"to",
"instance"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/__init__.py#L622-L634 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.get | def get(self, index: int) -> TOption[T]:
"""
:param index:
Usage:
>>> TList([1, 2, 3, 4, 5]).get(3)
Option --> 4
>>> TList([1, 2, 3, 4, 5]).get(5)
Option --> None
"""
return TOption(self[index]) if len(self) > index else TOption(N... | python | def get(self, index: int) -> TOption[T]:
"""
:param index:
Usage:
>>> TList([1, 2, 3, 4, 5]).get(3)
Option --> 4
>>> TList([1, 2, 3, 4, 5]).get(5)
Option --> None
"""
return TOption(self[index]) if len(self) > index else TOption(N... | [
"def",
"get",
"(",
"self",
",",
"index",
":",
"int",
")",
"->",
"TOption",
"[",
"T",
"]",
":",
"return",
"TOption",
"(",
"self",
"[",
"index",
"]",
")",
"if",
"len",
"(",
"self",
")",
">",
"index",
"else",
"TOption",
"(",
"None",
")"
] | :param index:
Usage:
>>> TList([1, 2, 3, 4, 5]).get(3)
Option --> 4
>>> TList([1, 2, 3, 4, 5]).get(5)
Option --> None | [
":",
"param",
"index",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L24-L35 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.emap | def emap(self, func):
"""
:param func:
:type func: T, int -> U
:rtype: TList[U]
Usage:
>>> TList([10, 20, 30, 40, 50]).emap(lambda x, i: (x+1, i))
[(11, 0), (21, 1), (31, 2), (41, 3), (51, 4)]
"""
return TList([func(x, i) for i, x in enum... | python | def emap(self, func):
"""
:param func:
:type func: T, int -> U
:rtype: TList[U]
Usage:
>>> TList([10, 20, 30, 40, 50]).emap(lambda x, i: (x+1, i))
[(11, 0), (21, 1), (31, 2), (41, 3), (51, 4)]
"""
return TList([func(x, i) for i, x in enum... | [
"def",
"emap",
"(",
"self",
",",
"func",
")",
":",
"return",
"TList",
"(",
"[",
"func",
"(",
"x",
",",
"i",
")",
"for",
"i",
",",
"x",
"in",
"enumerate",
"(",
"self",
")",
"]",
")"
] | :param func:
:type func: T, int -> U
:rtype: TList[U]
Usage:
>>> TList([10, 20, 30, 40, 50]).emap(lambda x, i: (x+1, i))
[(11, 0), (21, 1), (31, 2), (41, 3), (51, 4)] | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"T",
"int",
"-",
">",
"U",
":",
"rtype",
":",
"TList",
"[",
"U",
"]"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L50-L61 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.head_while | def head_while(self, func: Callable[[T], bool]) -> 'TList[T]':
"""
:param func:
:type func: T -> bool
Usage:
>>> TList([1, 2, 30, 4, 50]).head_while(lambda x: x < 10)
[1, 2]
"""
r = TList()
for x in self:
if not func(x):
... | python | def head_while(self, func: Callable[[T], bool]) -> 'TList[T]':
"""
:param func:
:type func: T -> bool
Usage:
>>> TList([1, 2, 30, 4, 50]).head_while(lambda x: x < 10)
[1, 2]
"""
r = TList()
for x in self:
if not func(x):
... | [
"def",
"head_while",
"(",
"self",
",",
"func",
":",
"Callable",
"[",
"[",
"T",
"]",
",",
"bool",
"]",
")",
"->",
"'TList[T]'",
":",
"r",
"=",
"TList",
"(",
")",
"for",
"x",
"in",
"self",
":",
"if",
"not",
"func",
"(",
"x",
")",
":",
"return",
... | :param func:
:type func: T -> bool
Usage:
>>> TList([1, 2, 30, 4, 50]).head_while(lambda x: x < 10)
[1, 2] | [
":",
"param",
"func",
":",
":",
"type",
"func",
":",
"T",
"-",
">",
"bool"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L124-L140 |
tadashi-aikawa/owlmixin | owlmixin/owlcollections.py | TList.uniq | def uniq(self) -> 'TList[T]':
"""
Usage:
>>> TList([1, 2, 3, 2, 1]).uniq()
[1, 2, 3]
"""
rs = TList()
for e in self:
if e not in rs:
rs.append(e)
return rs | python | def uniq(self) -> 'TList[T]':
"""
Usage:
>>> TList([1, 2, 3, 2, 1]).uniq()
[1, 2, 3]
"""
rs = TList()
for e in self:
if e not in rs:
rs.append(e)
return rs | [
"def",
"uniq",
"(",
"self",
")",
"->",
"'TList[T]'",
":",
"rs",
"=",
"TList",
"(",
")",
"for",
"e",
"in",
"self",
":",
"if",
"e",
"not",
"in",
"rs",
":",
"rs",
".",
"append",
"(",
"e",
")",
"return",
"rs"
] | Usage:
>>> TList([1, 2, 3, 2, 1]).uniq()
[1, 2, 3] | [
"Usage",
":"
] | train | https://github.com/tadashi-aikawa/owlmixin/blob/7c4a042c3008abddc56a8e8e55ae930d276071f5/owlmixin/owlcollections.py#L151-L162 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.