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 |
|---|---|---|---|---|---|---|---|---|---|---|
InfoAgeTech/django-core | django_core/utils/random_utils.py | random_alphanum | def random_alphanum(length=10, lower_only=False):
"""
Gets a random alphanumeric value using both letters and numbers.
:param length: size of the random alphanumeric string.
:param lower_only: boolean indicating if only lower case letters should be
used.
:return: alphanumeric string size of... | python | def random_alphanum(length=10, lower_only=False):
"""
Gets a random alphanumeric value using both letters and numbers.
:param length: size of the random alphanumeric string.
:param lower_only: boolean indicating if only lower case letters should be
used.
:return: alphanumeric string size of... | [
"def",
"random_alphanum",
"(",
"length",
"=",
"10",
",",
"lower_only",
"=",
"False",
")",
":",
"character_set",
"=",
"ALPHANUM_LOWER",
"if",
"lower_only",
"else",
"ALPHANUM",
"sample_size",
"=",
"5",
"chars",
"=",
"random",
".",
"sample",
"(",
"character_set",... | Gets a random alphanumeric value using both letters and numbers.
:param length: size of the random alphanumeric string.
:param lower_only: boolean indicating if only lower case letters should be
used.
:return: alphanumeric string size of length
This function uses all number except for:
* ... | [
"Gets",
"a",
"random",
"alphanumeric",
"value",
"using",
"both",
"letters",
"and",
"numbers",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/random_utils.py#L20-L98 |
InfoAgeTech/django-core | django_core/utils/random_utils.py | generate_key | def generate_key(low=7, high=10, lower_only=False):
"""Gets a random alphanumeric key between low and high characters in
length.
"""
return random_alphanum(length=randint(7, 10), lower_only=lower_only) | python | def generate_key(low=7, high=10, lower_only=False):
"""Gets a random alphanumeric key between low and high characters in
length.
"""
return random_alphanum(length=randint(7, 10), lower_only=lower_only) | [
"def",
"generate_key",
"(",
"low",
"=",
"7",
",",
"high",
"=",
"10",
",",
"lower_only",
"=",
"False",
")",
":",
"return",
"random_alphanum",
"(",
"length",
"=",
"randint",
"(",
"7",
",",
"10",
")",
",",
"lower_only",
"=",
"lower_only",
")"
] | Gets a random alphanumeric key between low and high characters in
length. | [
"Gets",
"a",
"random",
"alphanumeric",
"key",
"between",
"low",
"and",
"high",
"characters",
"in",
"length",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/random_utils.py#L101-L105 |
InfoAgeTech/django-core | django_core/db/models/mixins/urls.py | AbstractUrlLinkModelMixin.get_absolute_url_link | def get_absolute_url_link(self, text=None, cls=None, icon_class=None,
**attrs):
"""Gets the html link for the object."""
if text is None:
text = self.get_link_text()
return build_link(href=self.get_absolute_url(),
text=text,
... | python | def get_absolute_url_link(self, text=None, cls=None, icon_class=None,
**attrs):
"""Gets the html link for the object."""
if text is None:
text = self.get_link_text()
return build_link(href=self.get_absolute_url(),
text=text,
... | [
"def",
"get_absolute_url_link",
"(",
"self",
",",
"text",
"=",
"None",
",",
"cls",
"=",
"None",
",",
"icon_class",
"=",
"None",
",",
"*",
"*",
"attrs",
")",
":",
"if",
"text",
"is",
"None",
":",
"text",
"=",
"self",
".",
"get_link_text",
"(",
")",
... | Gets the html link for the object. | [
"Gets",
"the",
"html",
"link",
"for",
"the",
"object",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/db/models/mixins/urls.py#L26-L36 |
InfoAgeTech/django-core | django_core/db/models/mixins/urls.py | AbstractUrlLinkModelMixin.get_edit_url_link | def get_edit_url_link(self, text=None, cls=None, icon_class=None,
**attrs):
"""Gets the html edit link for the object."""
if text is None:
text = 'Edit'
return build_link(href=self.get_edit_url(),
text=text,
... | python | def get_edit_url_link(self, text=None, cls=None, icon_class=None,
**attrs):
"""Gets the html edit link for the object."""
if text is None:
text = 'Edit'
return build_link(href=self.get_edit_url(),
text=text,
... | [
"def",
"get_edit_url_link",
"(",
"self",
",",
"text",
"=",
"None",
",",
"cls",
"=",
"None",
",",
"icon_class",
"=",
"None",
",",
"*",
"*",
"attrs",
")",
":",
"if",
"text",
"is",
"None",
":",
"text",
"=",
"'Edit'",
"return",
"build_link",
"(",
"href",... | Gets the html edit link for the object. | [
"Gets",
"the",
"html",
"edit",
"link",
"for",
"the",
"object",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/db/models/mixins/urls.py#L38-L48 |
InfoAgeTech/django-core | django_core/db/models/mixins/urls.py | AbstractUrlLinkModelMixin.get_delete_url_link | def get_delete_url_link(self, text=None, cls=None, icon_class=None,
**attrs):
"""Gets the html delete link for the object."""
if text is None:
text = 'Delete'
return build_link(href=self.get_delete_url(),
text=text,
... | python | def get_delete_url_link(self, text=None, cls=None, icon_class=None,
**attrs):
"""Gets the html delete link for the object."""
if text is None:
text = 'Delete'
return build_link(href=self.get_delete_url(),
text=text,
... | [
"def",
"get_delete_url_link",
"(",
"self",
",",
"text",
"=",
"None",
",",
"cls",
"=",
"None",
",",
"icon_class",
"=",
"None",
",",
"*",
"*",
"attrs",
")",
":",
"if",
"text",
"is",
"None",
":",
"text",
"=",
"'Delete'",
"return",
"build_link",
"(",
"hr... | Gets the html delete link for the object. | [
"Gets",
"the",
"html",
"delete",
"link",
"for",
"the",
"object",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/db/models/mixins/urls.py#L50-L60 |
InfoAgeTech/django-core | django_core/managers.py | TokenAuthorizationManager.expire_by_email | def expire_by_email(self, email_address, **kwargs):
"""Expires tokens for an email address or email addresses.
:param email_address: the string email address or emails addresses to
expire tokens for.
:param reason: the codified reason for the tokens. If explicitly set
t... | python | def expire_by_email(self, email_address, **kwargs):
"""Expires tokens for an email address or email addresses.
:param email_address: the string email address or emails addresses to
expire tokens for.
:param reason: the codified reason for the tokens. If explicitly set
t... | [
"def",
"expire_by_email",
"(",
"self",
",",
"email_address",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"email_address",
":",
"# no email(s) provided. Nothing to do.",
"return",
"None",
"if",
"isinstance",
"(",
"email_address",
",",
"(",
"set",
",",
"list"... | Expires tokens for an email address or email addresses.
:param email_address: the string email address or emails addresses to
expire tokens for.
:param reason: the codified reason for the tokens. If explicitly set
to None, this will expire all tokens for the email provided. | [
"Expires",
"tokens",
"for",
"an",
"email",
"address",
"or",
"email",
"addresses",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/managers.py#L12-L47 |
InfoAgeTech/django-core | django_core/views/mixins/query.py | QueryStringAliasViewMixin.map_query_string | def map_query_string(self):
"""Maps the GET query string params the the query_key_mapper dict and
updates the request's GET QueryDict with the mapped keys.
"""
if (not self.query_key_mapper or
self.request.method == 'POST'):
# Nothing to map, don't do anything.
... | python | def map_query_string(self):
"""Maps the GET query string params the the query_key_mapper dict and
updates the request's GET QueryDict with the mapped keys.
"""
if (not self.query_key_mapper or
self.request.method == 'POST'):
# Nothing to map, don't do anything.
... | [
"def",
"map_query_string",
"(",
"self",
")",
":",
"if",
"(",
"not",
"self",
".",
"query_key_mapper",
"or",
"self",
".",
"request",
".",
"method",
"==",
"'POST'",
")",
":",
"# Nothing to map, don't do anything.",
"# return self.request.POST",
"return",
"{",
"}",
... | Maps the GET query string params the the query_key_mapper dict and
updates the request's GET QueryDict with the mapped keys. | [
"Maps",
"the",
"GET",
"query",
"string",
"params",
"the",
"the",
"query_key_mapper",
"dict",
"and",
"updates",
"the",
"request",
"s",
"GET",
"QueryDict",
"with",
"the",
"mapped",
"keys",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/views/mixins/query.py#L40-L53 |
edx/edx-django-release-util | scripts/update_repos_version.py | bump_repos_version | def bump_repos_version(module_name, new_version, local_only):
"""
Changes the pinned version number in the requirements files of all repos
which have the specified Python module as a dependency.
This script assumes that GITHUB_TOKEN is set for GitHub authentication.
"""
# Make the cloning direc... | python | def bump_repos_version(module_name, new_version, local_only):
"""
Changes the pinned version number in the requirements files of all repos
which have the specified Python module as a dependency.
This script assumes that GITHUB_TOKEN is set for GitHub authentication.
"""
# Make the cloning direc... | [
"def",
"bump_repos_version",
"(",
"module_name",
",",
"new_version",
",",
"local_only",
")",
":",
"# Make the cloning directory and change directories into it.",
"tmp_dir",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"dir",
"=",
"os",
".",
"getcwd",
"(",
")",
")",
"# Iter... | Changes the pinned version number in the requirements files of all repos
which have the specified Python module as a dependency.
This script assumes that GITHUB_TOKEN is set for GitHub authentication. | [
"Changes",
"the",
"pinned",
"version",
"number",
"in",
"the",
"requirements",
"files",
"of",
"all",
"repos",
"which",
"have",
"the",
"specified",
"Python",
"module",
"as",
"a",
"dependency",
"."
] | train | https://github.com/edx/edx-django-release-util/blob/de0fde41d6a19885ab7dc309472b94fd0fccbc1d/scripts/update_repos_version.py#L55-L153 |
txomon/abot | abot/slack.py | SlackAPI.call | async def call(self, method, **params):
"""
Call an Slack Web API method
:param method: Slack Web API method to call
:param params: {str: object} parameters to method
:return: dict()
"""
url = self.SLACK_RPC_PREFIX + method
data = FormData()
data.... | python | async def call(self, method, **params):
"""
Call an Slack Web API method
:param method: Slack Web API method to call
:param params: {str: object} parameters to method
:return: dict()
"""
url = self.SLACK_RPC_PREFIX + method
data = FormData()
data.... | [
"async",
"def",
"call",
"(",
"self",
",",
"method",
",",
"*",
"*",
"params",
")",
":",
"url",
"=",
"self",
".",
"SLACK_RPC_PREFIX",
"+",
"method",
"data",
"=",
"FormData",
"(",
")",
"data",
".",
"add_fields",
"(",
"MultiDict",
"(",
"token",
"=",
"sel... | Call an Slack Web API method
:param method: Slack Web API method to call
:param params: {str: object} parameters to method
:return: dict() | [
"Call",
"an",
"Slack",
"Web",
"API",
"method"
] | train | https://github.com/txomon/abot/blob/3ac23c6d14965d4608ed13c284ae1a886b462252/abot/slack.py#L83-L107 |
txomon/abot | abot/slack.py | SlackAPI.rtm_handler | def rtm_handler(self, ws_message):
"""
Handle a message, processing it internally if required. If it's a message that should go outside the bot,
this function will return True
:param message:
:return: Boolean if message should be yielded
"""
message = json.loads(... | python | def rtm_handler(self, ws_message):
"""
Handle a message, processing it internally if required. If it's a message that should go outside the bot,
this function will return True
:param message:
:return: Boolean if message should be yielded
"""
message = json.loads(... | [
"def",
"rtm_handler",
"(",
"self",
",",
"ws_message",
")",
":",
"message",
"=",
"json",
".",
"loads",
"(",
"ws_message",
".",
"data",
")",
"if",
"'reply_to'",
"in",
"message",
":",
"reply_to",
"=",
"message",
"[",
"'reply_to'",
"]",
"future",
"=",
"self"... | Handle a message, processing it internally if required. If it's a message that should go outside the bot,
this function will return True
:param message:
:return: Boolean if message should be yielded | [
"Handle",
"a",
"message",
"processing",
"it",
"internally",
"if",
"required",
".",
"If",
"it",
"s",
"a",
"message",
"that",
"should",
"go",
"outside",
"the",
"bot",
"this",
"function",
"will",
"return",
"True"
] | train | https://github.com/txomon/abot/blob/3ac23c6d14965d4608ed13c284ae1a886b462252/abot/slack.py#L591-L621 |
MarcoFavorito/flloat | flloat/parser/ltlf.py | LTLfLexer.t_ATOM | def t_ATOM(self, t):
r'[a-zA-Z_][a-zA-Z_0-9]*'
t.type = LTLfLexer.reserved.get(t.value, 'ATOM') # Check for reserved words
return t | python | def t_ATOM(self, t):
r'[a-zA-Z_][a-zA-Z_0-9]*'
t.type = LTLfLexer.reserved.get(t.value, 'ATOM') # Check for reserved words
return t | [
"def",
"t_ATOM",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"type",
"=",
"LTLfLexer",
".",
"reserved",
".",
"get",
"(",
"t",
".",
"value",
",",
"'ATOM'",
")",
"# Check for reserved words",
"return",
"t"
] | r'[a-zA-Z_][a-zA-Z_0-9]* | [
"r",
"[",
"a",
"-",
"zA",
"-",
"Z_",
"]",
"[",
"a",
"-",
"zA",
"-",
"Z_0",
"-",
"9",
"]",
"*"
] | train | https://github.com/MarcoFavorito/flloat/blob/5e6de1bea444b68d46d288834031860a8b2f8c2d/flloat/parser/ltlf.py#L54-L57 |
MarcoFavorito/flloat | flloat/parser/ltlf.py | LTLfParser.p_formula | def p_formula(self, p):
"""formula : formula EQUIVALENCE formula
| formula IMPLIES formula
| formula OR formula
| formula AND formula
| formula UNTIL formula
| formula RELEASE formula
| EVENTUALLY f... | python | def p_formula(self, p):
"""formula : formula EQUIVALENCE formula
| formula IMPLIES formula
| formula OR formula
| formula AND formula
| formula UNTIL formula
| formula RELEASE formula
| EVENTUALLY f... | [
"def",
"p_formula",
"(",
"self",
",",
"p",
")",
":",
"if",
"len",
"(",
"p",
")",
"==",
"2",
":",
"if",
"p",
"[",
"1",
"]",
"==",
"Symbols",
".",
"TRUE",
".",
"value",
":",
"p",
"[",
"0",
"]",
"=",
"LTLfTrue",
"(",
")",
"elif",
"p",
"[",
"... | formula : formula EQUIVALENCE formula
| formula IMPLIES formula
| formula OR formula
| formula AND formula
| formula UNTIL formula
| formula RELEASE formula
| EVENTUALLY formula
| ALWAYS ... | [
"formula",
":",
"formula",
"EQUIVALENCE",
"formula",
"|",
"formula",
"IMPLIES",
"formula",
"|",
"formula",
"OR",
"formula",
"|",
"formula",
"AND",
"formula",
"|",
"formula",
"UNTIL",
"formula",
"|",
"formula",
"RELEASE",
"formula",
"|",
"EVENTUALLY",
"formula",
... | train | https://github.com/MarcoFavorito/flloat/blob/5e6de1bea444b68d46d288834031860a8b2f8c2d/flloat/parser/ltlf.py#L77-L127 |
InfoAgeTech/django-core | django_core/forms/mixins/common.py | PrefixFormMixin.get_default_prefix | def get_default_prefix(self, instance=None):
"""Gets the prefix for this form.
:param instance: the form model instance. When calling this method
directly this should almost always stay None so it looks for
self.instance.
"""
if instance is None and hasattr(self... | python | def get_default_prefix(self, instance=None):
"""Gets the prefix for this form.
:param instance: the form model instance. When calling this method
directly this should almost always stay None so it looks for
self.instance.
"""
if instance is None and hasattr(self... | [
"def",
"get_default_prefix",
"(",
"self",
",",
"instance",
"=",
"None",
")",
":",
"if",
"instance",
"is",
"None",
"and",
"hasattr",
"(",
"self",
",",
"'instance'",
")",
":",
"instance",
"=",
"self",
".",
"instance",
"if",
"instance",
"and",
"instance",
"... | Gets the prefix for this form.
:param instance: the form model instance. When calling this method
directly this should almost always stay None so it looks for
self.instance. | [
"Gets",
"the",
"prefix",
"for",
"this",
"form",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/forms/mixins/common.py#L36-L58 |
InfoAgeTech/django-core | django_core/contrib/auth/backends.py | EmailOrUsernameBackend.authenticate | def authenticate(self, username, password):
"""
:param username: this is the email or username to check
"""
# If username is an email address, then try to pull it up
user = self.get_by_username_or_email(username)
if not user:
return None
if user.chec... | python | def authenticate(self, username, password):
"""
:param username: this is the email or username to check
"""
# If username is an email address, then try to pull it up
user = self.get_by_username_or_email(username)
if not user:
return None
if user.chec... | [
"def",
"authenticate",
"(",
"self",
",",
"username",
",",
"password",
")",
":",
"# If username is an email address, then try to pull it up",
"user",
"=",
"self",
".",
"get_by_username_or_email",
"(",
"username",
")",
"if",
"not",
"user",
":",
"return",
"None",
"if",... | :param username: this is the email or username to check | [
":",
"param",
"username",
":",
"this",
"is",
"the",
"email",
"or",
"username",
"to",
"check"
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/contrib/auth/backends.py#L13-L26 |
MarcoFavorito/flloat | flloat/utils.py | powerset | def powerset(iterable) -> FrozenSet:
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
combs = _powerset(iterable)
res = frozenset(frozenset(x) for x in combs)
# res = map(frozenset, combs)
return res | python | def powerset(iterable) -> FrozenSet:
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
combs = _powerset(iterable)
res = frozenset(frozenset(x) for x in combs)
# res = map(frozenset, combs)
return res | [
"def",
"powerset",
"(",
"iterable",
")",
"->",
"FrozenSet",
":",
"combs",
"=",
"_powerset",
"(",
"iterable",
")",
"res",
"=",
"frozenset",
"(",
"frozenset",
"(",
"x",
")",
"for",
"x",
"in",
"combs",
")",
"# res = map(frozenset, combs)",
"return",
"res"
] | powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3) | [
"powerset",
"(",
"[",
"1",
"2",
"3",
"]",
")",
"--",
">",
"()",
"(",
"1",
")",
"(",
"2",
")",
"(",
"3",
")",
"(",
"1",
"2",
")",
"(",
"1",
"3",
")",
"(",
"2",
"3",
")",
"(",
"1",
"2",
"3",
")"
] | train | https://github.com/MarcoFavorito/flloat/blob/5e6de1bea444b68d46d288834031860a8b2f8c2d/flloat/utils.py#L13-L18 |
InfoAgeTech/django-core | django_core/templatetags/url_tags.py | edit_url_link | def edit_url_link(obj, **kwargs):
"""This method assumes that the "get_delete_url_link" method has been
implemented on the obj.
"""
if hasattr(obj, 'get_edit_url_link'):
return obj.get_edit_url_link(**kwargs)
edit_url = obj.get_edit_url()
return build_link(href=edit_url, **kwargs) | python | def edit_url_link(obj, **kwargs):
"""This method assumes that the "get_delete_url_link" method has been
implemented on the obj.
"""
if hasattr(obj, 'get_edit_url_link'):
return obj.get_edit_url_link(**kwargs)
edit_url = obj.get_edit_url()
return build_link(href=edit_url, **kwargs) | [
"def",
"edit_url_link",
"(",
"obj",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'get_edit_url_link'",
")",
":",
"return",
"obj",
".",
"get_edit_url_link",
"(",
"*",
"*",
"kwargs",
")",
"edit_url",
"=",
"obj",
".",
"get_edit_url"... | This method assumes that the "get_delete_url_link" method has been
implemented on the obj. | [
"This",
"method",
"assumes",
"that",
"the",
"get_delete_url_link",
"method",
"has",
"been",
"implemented",
"on",
"the",
"obj",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/templatetags/url_tags.py#L49-L57 |
InfoAgeTech/django-core | django_core/templatetags/url_tags.py | delete_url_link | def delete_url_link(obj, **kwargs):
"""This method assumes that the "get_delete_url_link" method has been
implemented on the obj.
"""
if hasattr(obj, 'get_delete_url_link'):
return obj.get_delete_url_link(**kwargs)
delete_url = obj.get_delete_url()
return build_link(href=delete_url, **k... | python | def delete_url_link(obj, **kwargs):
"""This method assumes that the "get_delete_url_link" method has been
implemented on the obj.
"""
if hasattr(obj, 'get_delete_url_link'):
return obj.get_delete_url_link(**kwargs)
delete_url = obj.get_delete_url()
return build_link(href=delete_url, **k... | [
"def",
"delete_url_link",
"(",
"obj",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'get_delete_url_link'",
")",
":",
"return",
"obj",
".",
"get_delete_url_link",
"(",
"*",
"*",
"kwargs",
")",
"delete_url",
"=",
"obj",
".",
"get_d... | This method assumes that the "get_delete_url_link" method has been
implemented on the obj. | [
"This",
"method",
"assumes",
"that",
"the",
"get_delete_url_link",
"method",
"has",
"been",
"implemented",
"on",
"the",
"obj",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/templatetags/url_tags.py#L68-L76 |
InfoAgeTech/django-core | django_core/db/models/fields.py | ListField.formfield | def formfield(self, form_class=None, choices_form_class=None, **kwargs):
"""Make the default formfield a CommaSeparatedListField."""
defaults = {
'form_class': form_class or self.get_form_class()
}
defaults.update(kwargs)
return super(ListField, self).formfield(**def... | python | def formfield(self, form_class=None, choices_form_class=None, **kwargs):
"""Make the default formfield a CommaSeparatedListField."""
defaults = {
'form_class': form_class or self.get_form_class()
}
defaults.update(kwargs)
return super(ListField, self).formfield(**def... | [
"def",
"formfield",
"(",
"self",
",",
"form_class",
"=",
"None",
",",
"choices_form_class",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"defaults",
"=",
"{",
"'form_class'",
":",
"form_class",
"or",
"self",
".",
"get_form_class",
"(",
")",
"}",
"defa... | Make the default formfield a CommaSeparatedListField. | [
"Make",
"the",
"default",
"formfield",
"a",
"CommaSeparatedListField",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/db/models/fields.py#L94-L101 |
InfoAgeTech/django-core | django_core/db/models/fields.py | ListField.validate | def validate(self, value, model_instance, **kwargs):
"""This follows the validate rules for choices_form_class field used.
"""
self.get_choices_form_class().validate(value, model_instance, **kwargs) | python | def validate(self, value, model_instance, **kwargs):
"""This follows the validate rules for choices_form_class field used.
"""
self.get_choices_form_class().validate(value, model_instance, **kwargs) | [
"def",
"validate",
"(",
"self",
",",
"value",
",",
"model_instance",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"get_choices_form_class",
"(",
")",
".",
"validate",
"(",
"value",
",",
"model_instance",
",",
"*",
"*",
"kwargs",
")"
] | This follows the validate rules for choices_form_class field used. | [
"This",
"follows",
"the",
"validate",
"rules",
"for",
"choices_form_class",
"field",
"used",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/db/models/fields.py#L110-L113 |
InfoAgeTech/django-core | django_core/db/models/fields.py | JSONField.to_python | def to_python(self, value):
"""
Convert the input JSON value into python structures, raises
django.core.exceptions.ValidationError if the data can't be converted.
"""
if isinstance(value, dict):
return value
if self.blank and not value:
return Non... | python | def to_python(self, value):
"""
Convert the input JSON value into python structures, raises
django.core.exceptions.ValidationError if the data can't be converted.
"""
if isinstance(value, dict):
return value
if self.blank and not value:
return Non... | [
"def",
"to_python",
"(",
"self",
",",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"return",
"value",
"if",
"self",
".",
"blank",
"and",
"not",
"value",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"str... | Convert the input JSON value into python structures, raises
django.core.exceptions.ValidationError if the data can't be converted. | [
"Convert",
"the",
"input",
"JSON",
"value",
"into",
"python",
"structures",
"raises",
"django",
".",
"core",
".",
"exceptions",
".",
"ValidationError",
"if",
"the",
"data",
"can",
"t",
"be",
"converted",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/db/models/fields.py#L197-L214 |
InfoAgeTech/django-core | django_core/db/models/fields.py | JSONField.get_prep_value | def get_prep_value(self, value):
"""Convert value to JSON string before save"""
try:
return json.dumps(value, cls=DjangoJSONEncoder)
except Exception as e:
raise ValidationError(str(e)) | python | def get_prep_value(self, value):
"""Convert value to JSON string before save"""
try:
return json.dumps(value, cls=DjangoJSONEncoder)
except Exception as e:
raise ValidationError(str(e)) | [
"def",
"get_prep_value",
"(",
"self",
",",
"value",
")",
":",
"try",
":",
"return",
"json",
".",
"dumps",
"(",
"value",
",",
"cls",
"=",
"DjangoJSONEncoder",
")",
"except",
"Exception",
"as",
"e",
":",
"raise",
"ValidationError",
"(",
"str",
"(",
"e",
... | Convert value to JSON string before save | [
"Convert",
"value",
"to",
"JSON",
"string",
"before",
"save"
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/db/models/fields.py#L226-L231 |
dls-controls/annotypes | annotypes/_fake_typing.py | _gorg | def _gorg(a):
"""Return the farthest origin of a generic class (internal helper)."""
assert isinstance(a, GenericMeta)
while a.__origin__ is not None:
a = a.__origin__
return a | python | def _gorg(a):
"""Return the farthest origin of a generic class (internal helper)."""
assert isinstance(a, GenericMeta)
while a.__origin__ is not None:
a = a.__origin__
return a | [
"def",
"_gorg",
"(",
"a",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"GenericMeta",
")",
"while",
"a",
".",
"__origin__",
"is",
"not",
"None",
":",
"a",
"=",
"a",
".",
"__origin__",
"return",
"a"
] | Return the farthest origin of a generic class (internal helper). | [
"Return",
"the",
"farthest",
"origin",
"of",
"a",
"generic",
"class",
"(",
"internal",
"helper",
")",
"."
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_fake_typing.py#L135-L140 |
dls-controls/annotypes | annotypes/_fake_typing.py | _next_in_mro | def _next_in_mro(cls):
"""Helper for Generic.__new__.
Returns the class after the last occurrence of Generic or
Generic[...] in cls.__mro__.
"""
next_in_mro = object
# Look for the last occurrence of Generic or Generic[...].
for i, c in enumerate(cls.__mro__[:-1]):
if isinstance(c, ... | python | def _next_in_mro(cls):
"""Helper for Generic.__new__.
Returns the class after the last occurrence of Generic or
Generic[...] in cls.__mro__.
"""
next_in_mro = object
# Look for the last occurrence of Generic or Generic[...].
for i, c in enumerate(cls.__mro__[:-1]):
if isinstance(c, ... | [
"def",
"_next_in_mro",
"(",
"cls",
")",
":",
"next_in_mro",
"=",
"object",
"# Look for the last occurrence of Generic or Generic[...].",
"for",
"i",
",",
"c",
"in",
"enumerate",
"(",
"cls",
".",
"__mro__",
"[",
":",
"-",
"1",
"]",
")",
":",
"if",
"isinstance",... | Helper for Generic.__new__.
Returns the class after the last occurrence of Generic or
Generic[...] in cls.__mro__. | [
"Helper",
"for",
"Generic",
".",
"__new__",
"."
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_fake_typing.py#L143-L154 |
dls-controls/annotypes | annotypes/_fake_typing.py | _make_subclasshook | def _make_subclasshook(cls):
"""Construct a __subclasshook__ callable that incorporates
the associated __extra__ class in subclass checks performed
against cls.
"""
if isinstance(cls.__extra__, abc.ABCMeta):
# The logic mirrors that of ABCMeta.__subclasscheck__.
# Registered classes ... | python | def _make_subclasshook(cls):
"""Construct a __subclasshook__ callable that incorporates
the associated __extra__ class in subclass checks performed
against cls.
"""
if isinstance(cls.__extra__, abc.ABCMeta):
# The logic mirrors that of ABCMeta.__subclasscheck__.
# Registered classes ... | [
"def",
"_make_subclasshook",
"(",
"cls",
")",
":",
"if",
"isinstance",
"(",
"cls",
".",
"__extra__",
",",
"abc",
".",
"ABCMeta",
")",
":",
"# The logic mirrors that of ABCMeta.__subclasscheck__.",
"# Registered classes need not be checked here because",
"# cls and its extra s... | Construct a __subclasshook__ callable that incorporates
the associated __extra__ class in subclass checks performed
against cls. | [
"Construct",
"a",
"__subclasshook__",
"callable",
"that",
"incorporates",
"the",
"associated",
"__extra__",
"class",
"in",
"subclass",
"checks",
"performed",
"against",
"cls",
"."
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_fake_typing.py#L157-L187 |
InfoAgeTech/django-core | django_core/auth/views.py | AuthorizationTokenRequiredViewMixin.get_authorization | def get_authorization(self, **kwargs):
"""Gets the authorization object for the view."""
if self.authorization is not None:
return self.authorization
auth_class = self.get_authorization_class()
auth_user = self.get_authorization_user()
auth_kwargs = {
'to... | python | def get_authorization(self, **kwargs):
"""Gets the authorization object for the view."""
if self.authorization is not None:
return self.authorization
auth_class = self.get_authorization_class()
auth_user = self.get_authorization_user()
auth_kwargs = {
'to... | [
"def",
"get_authorization",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"authorization",
"is",
"not",
"None",
":",
"return",
"self",
".",
"authorization",
"auth_class",
"=",
"self",
".",
"get_authorization_class",
"(",
")",
"auth_user"... | Gets the authorization object for the view. | [
"Gets",
"the",
"authorization",
"object",
"for",
"the",
"view",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/auth/views.py#L31-L48 |
InfoAgeTech/django-core | django_core/auth/views.py | AuthorizationTokenRequiredViewMixin.get_authorization_user | def get_authorization_user(self, **kwargs):
"""Gets the user the authorization object is for."""
if self.authorization_user is not None:
return self.authorization_user
self.authorization_user = self.request.user
return self.request.user | python | def get_authorization_user(self, **kwargs):
"""Gets the user the authorization object is for."""
if self.authorization_user is not None:
return self.authorization_user
self.authorization_user = self.request.user
return self.request.user | [
"def",
"get_authorization_user",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"authorization_user",
"is",
"not",
"None",
":",
"return",
"self",
".",
"authorization_user",
"self",
".",
"authorization_user",
"=",
"self",
".",
"request",
"... | Gets the user the authorization object is for. | [
"Gets",
"the",
"user",
"the",
"authorization",
"object",
"is",
"for",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/auth/views.py#L54-L60 |
dls-controls/annotypes | annotypes/_serializable.py | Serializable.to_dict | def to_dict(self, dict_cls=FrozenOrderedDict):
# type: (Type[dict]) -> Dict[str, Any]
"""Create a dictionary representation of object attributes
Returns:
OrderedDict serialised version of self
"""
pairs = tuple((k, serialize_object(getattr(self, k), dict_cls))
... | python | def to_dict(self, dict_cls=FrozenOrderedDict):
# type: (Type[dict]) -> Dict[str, Any]
"""Create a dictionary representation of object attributes
Returns:
OrderedDict serialised version of self
"""
pairs = tuple((k, serialize_object(getattr(self, k), dict_cls))
... | [
"def",
"to_dict",
"(",
"self",
",",
"dict_cls",
"=",
"FrozenOrderedDict",
")",
":",
"# type: (Type[dict]) -> Dict[str, Any]",
"pairs",
"=",
"tuple",
"(",
"(",
"k",
",",
"serialize_object",
"(",
"getattr",
"(",
"self",
",",
"k",
")",
",",
"dict_cls",
")",
")"... | Create a dictionary representation of object attributes
Returns:
OrderedDict serialised version of self | [
"Create",
"a",
"dictionary",
"representation",
"of",
"object",
"attributes"
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_serializable.py#L125-L138 |
InfoAgeTech/django-core | django_core/utils/urls.py | safe_redirect | def safe_redirect(next_url, default=None):
"""Makes sure it's a legit site to redirect to.
:param default: this is the default url or named url to redirect to in the
event where next_url is not legit.
"""
if is_legit_next_url(next_url):
return redirect(next_url)
if default:
... | python | def safe_redirect(next_url, default=None):
"""Makes sure it's a legit site to redirect to.
:param default: this is the default url or named url to redirect to in the
event where next_url is not legit.
"""
if is_legit_next_url(next_url):
return redirect(next_url)
if default:
... | [
"def",
"safe_redirect",
"(",
"next_url",
",",
"default",
"=",
"None",
")",
":",
"if",
"is_legit_next_url",
"(",
"next_url",
")",
":",
"return",
"redirect",
"(",
"next_url",
")",
"if",
"default",
":",
"return",
"redirect",
"(",
"default",
")",
"return",
"re... | Makes sure it's a legit site to redirect to.
:param default: this is the default url or named url to redirect to in the
event where next_url is not legit. | [
"Makes",
"sure",
"it",
"s",
"a",
"legit",
"site",
"to",
"redirect",
"to",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/urls.py#L53-L66 |
InfoAgeTech/django-core | django_core/utils/urls.py | replace_url_query_values | def replace_url_query_values(url, replace_vals):
"""Replace querystring values in a url string.
>>> url = 'http://helloworld.com/some/path?test=5'
>>> replace_vals = {'test': 10}
>>> replace_url_query_values(url=url, replace_vals=replace_vals)
'http://helloworld.com/some/path?test=10'
"""
i... | python | def replace_url_query_values(url, replace_vals):
"""Replace querystring values in a url string.
>>> url = 'http://helloworld.com/some/path?test=5'
>>> replace_vals = {'test': 10}
>>> replace_url_query_values(url=url, replace_vals=replace_vals)
'http://helloworld.com/some/path?test=10'
"""
i... | [
"def",
"replace_url_query_values",
"(",
"url",
",",
"replace_vals",
")",
":",
"if",
"'?'",
"not",
"in",
"url",
":",
"return",
"url",
"parsed_url",
"=",
"urlparse",
"(",
"url",
")",
"query",
"=",
"dict",
"(",
"parse_qsl",
"(",
"parsed_url",
".",
"query",
... | Replace querystring values in a url string.
>>> url = 'http://helloworld.com/some/path?test=5'
>>> replace_vals = {'test': 10}
>>> replace_url_query_values(url=url, replace_vals=replace_vals)
'http://helloworld.com/some/path?test=10' | [
"Replace",
"querystring",
"values",
"in",
"a",
"url",
"string",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/urls.py#L82-L96 |
InfoAgeTech/django-core | django_core/utils/urls.py | get_query_values_from_url | def get_query_values_from_url(url, keys=None):
"""Gets query string values from a url.
if a list of keys are provided, then a dict will be returned. If only a
single string key is provided, then only a single value will be returned.
>>> url = 'http://helloworld.com/some/path?test=5&hello=world&john=d... | python | def get_query_values_from_url(url, keys=None):
"""Gets query string values from a url.
if a list of keys are provided, then a dict will be returned. If only a
single string key is provided, then only a single value will be returned.
>>> url = 'http://helloworld.com/some/path?test=5&hello=world&john=d... | [
"def",
"get_query_values_from_url",
"(",
"url",
",",
"keys",
"=",
"None",
")",
":",
"if",
"not",
"url",
"or",
"'?'",
"not",
"in",
"url",
":",
"# no query params",
"return",
"None",
"parsed_url",
"=",
"urlparse",
"(",
"url",
")",
"query",
"=",
"dict",
"("... | Gets query string values from a url.
if a list of keys are provided, then a dict will be returned. If only a
single string key is provided, then only a single value will be returned.
>>> url = 'http://helloworld.com/some/path?test=5&hello=world&john=doe'
>>> get_query_values_from_url(url=url, keys='t... | [
"Gets",
"query",
"string",
"values",
"from",
"a",
"url",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/urls.py#L99-L128 |
InfoAgeTech/django-core | django_core/views/response.py | JSONResponseMixin.get_json_response | def get_json_response(self, content, **kwargs):
"""Returns a json response object."""
# Don't care to return a django form or view in the response here.
# Remove those from the context.
if isinstance(content, dict):
response_content = {k: deepcopy(v) for k, v in content.item... | python | def get_json_response(self, content, **kwargs):
"""Returns a json response object."""
# Don't care to return a django form or view in the response here.
# Remove those from the context.
if isinstance(content, dict):
response_content = {k: deepcopy(v) for k, v in content.item... | [
"def",
"get_json_response",
"(",
"self",
",",
"content",
",",
"*",
"*",
"kwargs",
")",
":",
"# Don't care to return a django form or view in the response here.",
"# Remove those from the context.",
"if",
"isinstance",
"(",
"content",
",",
"dict",
")",
":",
"response_conte... | Returns a json response object. | [
"Returns",
"a",
"json",
"response",
"object",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/views/response.py#L23-L37 |
InfoAgeTech/django-core | django_core/views/response.py | JSONHybridDeleteView.delete | def delete(self, request, *args, **kwargs):
"""
Calls the delete() method on the fetched object and then
redirects to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
if self.request.is_ajax():... | python | def delete(self, request, *args, **kwargs):
"""
Calls the delete() method on the fetched object and then
redirects to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
if self.request.is_ajax():... | [
"def",
"delete",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
... | Calls the delete() method on the fetched object and then
redirects to the success URL. | [
"Calls",
"the",
"delete",
"()",
"method",
"on",
"the",
"fetched",
"object",
"and",
"then",
"redirects",
"to",
"the",
"success",
"URL",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/views/response.py#L166-L178 |
MarcoFavorito/flloat | flloat/flloat.py | find_atomics | def find_atomics(formula: Formula) -> Set[PLAtomic]:
"""Finds all the atomic formulas"""
f = formula
res = set()
if isinstance(formula, PLFormula):
res = formula.find_atomics()
# elif isinstance(f, PLNot):
# res = res.union(find_atomics(f.f))
# elif isinstance(f, PLBinaryOperator... | python | def find_atomics(formula: Formula) -> Set[PLAtomic]:
"""Finds all the atomic formulas"""
f = formula
res = set()
if isinstance(formula, PLFormula):
res = formula.find_atomics()
# elif isinstance(f, PLNot):
# res = res.union(find_atomics(f.f))
# elif isinstance(f, PLBinaryOperator... | [
"def",
"find_atomics",
"(",
"formula",
":",
"Formula",
")",
"->",
"Set",
"[",
"PLAtomic",
"]",
":",
"f",
"=",
"formula",
"res",
"=",
"set",
"(",
")",
"if",
"isinstance",
"(",
"formula",
",",
"PLFormula",
")",
":",
"res",
"=",
"formula",
".",
"find_at... | Finds all the atomic formulas | [
"Finds",
"all",
"the",
"atomic",
"formulas"
] | train | https://github.com/MarcoFavorito/flloat/blob/5e6de1bea444b68d46d288834031860a8b2f8c2d/flloat/flloat.py#L18-L31 |
MarcoFavorito/flloat | flloat/flloat.py | _transform_delta | def _transform_delta(f:Formula, formula2AtomicFormula):
"""From a Propositional Formula to a Propositional Formula
with non-propositional subformulas replaced with a "freezed" atomic formula."""
t = type(f)
if t == PLNot:
return PLNot(_transform_delta(f, formula2AtomicFormula))
# elif isinst... | python | def _transform_delta(f:Formula, formula2AtomicFormula):
"""From a Propositional Formula to a Propositional Formula
with non-propositional subformulas replaced with a "freezed" atomic formula."""
t = type(f)
if t == PLNot:
return PLNot(_transform_delta(f, formula2AtomicFormula))
# elif isinst... | [
"def",
"_transform_delta",
"(",
"f",
":",
"Formula",
",",
"formula2AtomicFormula",
")",
":",
"t",
"=",
"type",
"(",
"f",
")",
"if",
"t",
"==",
"PLNot",
":",
"return",
"PLNot",
"(",
"_transform_delta",
"(",
"f",
",",
"formula2AtomicFormula",
")",
")",
"# ... | From a Propositional Formula to a Propositional Formula
with non-propositional subformulas replaced with a "freezed" atomic formula. | [
"From",
"a",
"Propositional",
"Formula",
"to",
"a",
"Propositional",
"Formula",
"with",
"non",
"-",
"propositional",
"subformulas",
"replaced",
"with",
"a",
"freezed",
"atomic",
"formula",
"."
] | train | https://github.com/MarcoFavorito/flloat/blob/5e6de1bea444b68d46d288834031860a8b2f8c2d/flloat/flloat.py#L33-L45 |
MarcoFavorito/flloat | flloat/flloat.py | to_automaton_ | def to_automaton_(f, labels:Set[Symbol]=None):
"""
DEPRECATED
From a LDLfFormula, build the automaton.
:param f: a LDLfFormula;
:param labels: a set of Symbol, the fluents of our domain. If None, retrieve them from the formula;
:param determinize: True if you need to d... | python | def to_automaton_(f, labels:Set[Symbol]=None):
"""
DEPRECATED
From a LDLfFormula, build the automaton.
:param f: a LDLfFormula;
:param labels: a set of Symbol, the fluents of our domain. If None, retrieve them from the formula;
:param determinize: True if you need to d... | [
"def",
"to_automaton_",
"(",
"f",
",",
"labels",
":",
"Set",
"[",
"Symbol",
"]",
"=",
"None",
")",
":",
"nnf",
"=",
"f",
".",
"to_nnf",
"(",
")",
"if",
"labels",
"is",
"None",
":",
"# if the labels of the formula are not specified in input,",
"# retrieve them ... | DEPRECATED
From a LDLfFormula, build the automaton.
:param f: a LDLfFormula;
:param labels: a set of Symbol, the fluents of our domain. If None, retrieve them from the formula;
:param determinize: True if you need to determinize the NFA, obtaining a DFA;
:param minimize: ... | [
"DEPRECATED",
"From",
"a",
"LDLfFormula",
"build",
"the",
"automaton",
".",
":",
"param",
"f",
":",
"a",
"LDLfFormula",
";",
":",
"param",
"labels",
":",
"a",
"set",
"of",
"Symbol",
"the",
"fluents",
"of",
"our",
"domain",
".",
"If",
"None",
"retrieve",
... | train | https://github.com/MarcoFavorito/flloat/blob/5e6de1bea444b68d46d288834031860a8b2f8c2d/flloat/flloat.py#L48-L161 |
InfoAgeTech/django-core | django_core/utils/loading.py | get_setting | def get_setting(key, **kwargs):
"""Gets a settings key or raises an improperly configured error.
:param key: the settings key to get.
:param default: the default value to return if no value is found
"""
has_default = 'default' in kwargs
default_val = kwargs.get('default')
try:
if h... | python | def get_setting(key, **kwargs):
"""Gets a settings key or raises an improperly configured error.
:param key: the settings key to get.
:param default: the default value to return if no value is found
"""
has_default = 'default' in kwargs
default_val = kwargs.get('default')
try:
if h... | [
"def",
"get_setting",
"(",
"key",
",",
"*",
"*",
"kwargs",
")",
":",
"has_default",
"=",
"'default'",
"in",
"kwargs",
"default_val",
"=",
"kwargs",
".",
"get",
"(",
"'default'",
")",
"try",
":",
"if",
"has_default",
":",
"return",
"getattr",
"(",
"settin... | Gets a settings key or raises an improperly configured error.
:param key: the settings key to get.
:param default: the default value to return if no value is found | [
"Gets",
"a",
"settings",
"key",
"or",
"raises",
"an",
"improperly",
"configured",
"error",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/loading.py#L12-L29 |
InfoAgeTech/django-core | django_core/utils/loading.py | get_class_from_settings | def get_class_from_settings(settings_key):
"""Gets a class from a setting key. This will first check loaded models,
then look in installed apps, then fallback to import from lib.
:param settings_key: the key defined in settings to the value for
"""
cls_path = getattr(settings, settings_key, None)
... | python | def get_class_from_settings(settings_key):
"""Gets a class from a setting key. This will first check loaded models,
then look in installed apps, then fallback to import from lib.
:param settings_key: the key defined in settings to the value for
"""
cls_path = getattr(settings, settings_key, None)
... | [
"def",
"get_class_from_settings",
"(",
"settings_key",
")",
":",
"cls_path",
"=",
"getattr",
"(",
"settings",
",",
"settings_key",
",",
"None",
")",
"if",
"not",
"cls_path",
":",
"raise",
"NotImplementedError",
"(",
")",
"try",
":",
"# First check to see if it's a... | Gets a class from a setting key. This will first check loaded models,
then look in installed apps, then fallback to import from lib.
:param settings_key: the key defined in settings to the value for | [
"Gets",
"a",
"class",
"from",
"a",
"setting",
"key",
".",
"This",
"will",
"first",
"check",
"loaded",
"models",
"then",
"look",
"in",
"installed",
"apps",
"then",
"fallback",
"to",
"import",
"from",
"lib",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/loading.py#L32-L51 |
InfoAgeTech/django-core | django_core/utils/loading.py | get_model_from_settings | def get_model_from_settings(settings_key):
"""Return the django model from a settings key.
This is the same pattern user for django's "get_user_model()" method. To
allow you to set the model instance to a different model subclass.
:param settings_key: the key defined in settings to the value for
... | python | def get_model_from_settings(settings_key):
"""Return the django model from a settings key.
This is the same pattern user for django's "get_user_model()" method. To
allow you to set the model instance to a different model subclass.
:param settings_key: the key defined in settings to the value for
... | [
"def",
"get_model_from_settings",
"(",
"settings_key",
")",
":",
"cls_path",
"=",
"getattr",
"(",
"settings",
",",
"settings_key",
",",
"None",
")",
"if",
"not",
"cls_path",
":",
"raise",
"NotImplementedError",
"(",
")",
"try",
":",
"app_label",
",",
"model_na... | Return the django model from a settings key.
This is the same pattern user for django's "get_user_model()" method. To
allow you to set the model instance to a different model subclass.
:param settings_key: the key defined in settings to the value for | [
"Return",
"the",
"django",
"model",
"from",
"a",
"settings",
"key",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/loading.py#L54-L79 |
InfoAgeTech/django-core | django_core/utils/loading.py | get_class_from_settings_from_apps | def get_class_from_settings_from_apps(settings_key):
"""Try and get a class from a settings path by lookin in installed apps.
"""
cls_path = getattr(settings, settings_key, None)
if not cls_path:
raise NotImplementedError()
try:
app_label = cls_path.split('.')[-2]
model_nam... | python | def get_class_from_settings_from_apps(settings_key):
"""Try and get a class from a settings path by lookin in installed apps.
"""
cls_path = getattr(settings, settings_key, None)
if not cls_path:
raise NotImplementedError()
try:
app_label = cls_path.split('.')[-2]
model_nam... | [
"def",
"get_class_from_settings_from_apps",
"(",
"settings_key",
")",
":",
"cls_path",
"=",
"getattr",
"(",
"settings",
",",
"settings_key",
",",
"None",
")",
"if",
"not",
"cls_path",
":",
"raise",
"NotImplementedError",
"(",
")",
"try",
":",
"app_label",
"=",
... | Try and get a class from a settings path by lookin in installed apps. | [
"Try",
"and",
"get",
"a",
"class",
"from",
"a",
"settings",
"path",
"by",
"lookin",
"in",
"installed",
"apps",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/loading.py#L82-L104 |
InfoAgeTech/django-core | django_core/utils/loading.py | get_class_from_settings_full_path | def get_class_from_settings_full_path(settings_key):
"""Get a class from it's full path.
Example:
some.path.module.MyClass
"""
cls_path = getattr(settings, settings_key, None)
if not cls_path:
raise NotImplementedError()
try:
module_name, class_name = cls_path.rsplit('.',... | python | def get_class_from_settings_full_path(settings_key):
"""Get a class from it's full path.
Example:
some.path.module.MyClass
"""
cls_path = getattr(settings, settings_key, None)
if not cls_path:
raise NotImplementedError()
try:
module_name, class_name = cls_path.rsplit('.',... | [
"def",
"get_class_from_settings_full_path",
"(",
"settings_key",
")",
":",
"cls_path",
"=",
"getattr",
"(",
"settings",
",",
"settings_key",
",",
"None",
")",
"if",
"not",
"cls_path",
":",
"raise",
"NotImplementedError",
"(",
")",
"try",
":",
"module_name",
",",... | Get a class from it's full path.
Example:
some.path.module.MyClass | [
"Get",
"a",
"class",
"from",
"it",
"s",
"full",
"path",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/loading.py#L107-L132 |
InfoAgeTech/django-core | django_core/utils/loading.py | get_function_from_settings | def get_function_from_settings(settings_key):
"""Gets a function from the string path defined in a settings file.
Example:
# my_app/my_file.py
def some_function():
# do something
pass
# settings.py
SOME_FUNCTION = 'my_app.my_file.some_function'
> get_function_from_setting... | python | def get_function_from_settings(settings_key):
"""Gets a function from the string path defined in a settings file.
Example:
# my_app/my_file.py
def some_function():
# do something
pass
# settings.py
SOME_FUNCTION = 'my_app.my_file.some_function'
> get_function_from_setting... | [
"def",
"get_function_from_settings",
"(",
"settings_key",
")",
":",
"renderer_func_str",
"=",
"getattr",
"(",
"settings",
",",
"settings_key",
",",
"None",
")",
"if",
"not",
"renderer_func_str",
":",
"return",
"None",
"module_str",
",",
"renderer_func_name",
"=",
... | Gets a function from the string path defined in a settings file.
Example:
# my_app/my_file.py
def some_function():
# do something
pass
# settings.py
SOME_FUNCTION = 'my_app.my_file.some_function'
> get_function_from_settings('SOME_FUNCTION')
<function my_app.my_file.some_... | [
"Gets",
"a",
"function",
"from",
"the",
"string",
"path",
"defined",
"in",
"a",
"settings",
"file",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/loading.py#L135-L162 |
dls-controls/annotypes | annotypes/_anno.py | caller_locals | def caller_locals():
# type: () -> Dict
"""Return the frame object for the caller's stack frame."""
try:
raise ValueError
except ValueError:
_, _, tb = sys.exc_info()
assert tb, "Can't get traceback, this shouldn't happen"
caller_frame = tb.tb_frame.f_back.f_back
... | python | def caller_locals():
# type: () -> Dict
"""Return the frame object for the caller's stack frame."""
try:
raise ValueError
except ValueError:
_, _, tb = sys.exc_info()
assert tb, "Can't get traceback, this shouldn't happen"
caller_frame = tb.tb_frame.f_back.f_back
... | [
"def",
"caller_locals",
"(",
")",
":",
"# type: () -> Dict",
"try",
":",
"raise",
"ValueError",
"except",
"ValueError",
":",
"_",
",",
"_",
",",
"tb",
"=",
"sys",
".",
"exc_info",
"(",
")",
"assert",
"tb",
",",
"\"Can't get traceback, this shouldn't happen\"",
... | Return the frame object for the caller's stack frame. | [
"Return",
"the",
"frame",
"object",
"for",
"the",
"caller",
"s",
"stack",
"frame",
"."
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_anno.py#L43-L52 |
dls-controls/annotypes | annotypes/_anno.py | make_repr | def make_repr(inst, attrs):
# type: (object, Sequence[str]) -> str
"""Create a repr from an instance of a class
Args:
inst: The class instance we are generating a repr of
attrs: The attributes that should appear in the repr
"""
arg_str = ", ".join(
"%s=%r" % (a, getattr(inst... | python | def make_repr(inst, attrs):
# type: (object, Sequence[str]) -> str
"""Create a repr from an instance of a class
Args:
inst: The class instance we are generating a repr of
attrs: The attributes that should appear in the repr
"""
arg_str = ", ".join(
"%s=%r" % (a, getattr(inst... | [
"def",
"make_repr",
"(",
"inst",
",",
"attrs",
")",
":",
"# type: (object, Sequence[str]) -> str",
"arg_str",
"=",
"\", \"",
".",
"join",
"(",
"\"%s=%r\"",
"%",
"(",
"a",
",",
"getattr",
"(",
"inst",
",",
"a",
")",
")",
"for",
"a",
"in",
"attrs",
"if",
... | Create a repr from an instance of a class
Args:
inst: The class instance we are generating a repr of
attrs: The attributes that should appear in the repr | [
"Create",
"a",
"repr",
"from",
"an",
"instance",
"of",
"a",
"class"
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_anno.py#L55-L66 |
openstack/pymod2pkg | pymod2pkg/__init__.py | default_rdo_tr | def default_rdo_tr(mod):
"""
Default translation function for Fedora/RDO based systems
"""
pkg = mod.rsplit('-python')[0]
pkg = pkg.replace('_', '-').replace('.', '-').lower()
if not pkg.startswith('python-'):
pkg = 'python-' + pkg
py2pkg = pkg
py3pkg = re.sub('python', 'python3'... | python | def default_rdo_tr(mod):
"""
Default translation function for Fedora/RDO based systems
"""
pkg = mod.rsplit('-python')[0]
pkg = pkg.replace('_', '-').replace('.', '-').lower()
if not pkg.startswith('python-'):
pkg = 'python-' + pkg
py2pkg = pkg
py3pkg = re.sub('python', 'python3'... | [
"def",
"default_rdo_tr",
"(",
"mod",
")",
":",
"pkg",
"=",
"mod",
".",
"rsplit",
"(",
"'-python'",
")",
"[",
"0",
"]",
"pkg",
"=",
"pkg",
".",
"replace",
"(",
"'_'",
",",
"'-'",
")",
".",
"replace",
"(",
"'.'",
",",
"'-'",
")",
".",
"lower",
"(... | Default translation function for Fedora/RDO based systems | [
"Default",
"translation",
"function",
"for",
"Fedora",
"/",
"RDO",
"based",
"systems"
] | train | https://github.com/openstack/pymod2pkg/blob/f9a2f02fbfa0b2cfcdb4a7494c9ddbd10859065a/pymod2pkg/__init__.py#L74-L84 |
openstack/pymod2pkg | pymod2pkg/__init__.py | default_ubuntu_tr | def default_ubuntu_tr(mod):
"""
Default translation function for Ubuntu based systems
"""
pkg = 'python-%s' % mod.lower()
py2pkg = pkg
py3pkg = 'python3-%s' % mod.lower()
return (pkg, py2pkg, py3pkg) | python | def default_ubuntu_tr(mod):
"""
Default translation function for Ubuntu based systems
"""
pkg = 'python-%s' % mod.lower()
py2pkg = pkg
py3pkg = 'python3-%s' % mod.lower()
return (pkg, py2pkg, py3pkg) | [
"def",
"default_ubuntu_tr",
"(",
"mod",
")",
":",
"pkg",
"=",
"'python-%s'",
"%",
"mod",
".",
"lower",
"(",
")",
"py2pkg",
"=",
"pkg",
"py3pkg",
"=",
"'python3-%s'",
"%",
"mod",
".",
"lower",
"(",
")",
"return",
"(",
"pkg",
",",
"py2pkg",
",",
"py3pk... | Default translation function for Ubuntu based systems | [
"Default",
"translation",
"function",
"for",
"Ubuntu",
"based",
"systems"
] | train | https://github.com/openstack/pymod2pkg/blob/f9a2f02fbfa0b2cfcdb4a7494c9ddbd10859065a/pymod2pkg/__init__.py#L87-L94 |
openstack/pymod2pkg | pymod2pkg/__init__.py | default_suse_tr | def default_suse_tr(mod):
"""
Default translation function for openSUSE, SLES, and other
SUSE based systems
Returns a tuple of 3 elements - the unversioned name, the python2 versioned
name and the python3 versioned name.
"""
pkg = 'python-%s' % mod
py2pkg = 'python2-%s' % mod
py3pkg... | python | def default_suse_tr(mod):
"""
Default translation function for openSUSE, SLES, and other
SUSE based systems
Returns a tuple of 3 elements - the unversioned name, the python2 versioned
name and the python3 versioned name.
"""
pkg = 'python-%s' % mod
py2pkg = 'python2-%s' % mod
py3pkg... | [
"def",
"default_suse_tr",
"(",
"mod",
")",
":",
"pkg",
"=",
"'python-%s'",
"%",
"mod",
"py2pkg",
"=",
"'python2-%s'",
"%",
"mod",
"py3pkg",
"=",
"'python3-%s'",
"%",
"mod",
"return",
"(",
"pkg",
",",
"py2pkg",
",",
"py3pkg",
")"
] | Default translation function for openSUSE, SLES, and other
SUSE based systems
Returns a tuple of 3 elements - the unversioned name, the python2 versioned
name and the python3 versioned name. | [
"Default",
"translation",
"function",
"for",
"openSUSE",
"SLES",
"and",
"other",
"SUSE",
"based",
"systems"
] | train | https://github.com/openstack/pymod2pkg/blob/f9a2f02fbfa0b2cfcdb4a7494c9ddbd10859065a/pymod2pkg/__init__.py#L97-L108 |
openstack/pymod2pkg | pymod2pkg/__init__.py | module2package | def module2package(mod, dist, pkg_map=None, py_vers=('py',)):
"""Return a corresponding package name for a python module.
mod: python module name
dist: a linux distribution as returned by
`platform.linux_distribution()[0]`
pkg_map: a custom package mapping. None means autodetected based on th... | python | def module2package(mod, dist, pkg_map=None, py_vers=('py',)):
"""Return a corresponding package name for a python module.
mod: python module name
dist: a linux distribution as returned by
`platform.linux_distribution()[0]`
pkg_map: a custom package mapping. None means autodetected based on th... | [
"def",
"module2package",
"(",
"mod",
",",
"dist",
",",
"pkg_map",
"=",
"None",
",",
"py_vers",
"=",
"(",
"'py'",
",",
")",
")",
":",
"if",
"not",
"pkg_map",
":",
"pkg_map",
"=",
"get_pkg_map",
"(",
"dist",
")",
"for",
"rule",
"in",
"pkg_map",
":",
... | Return a corresponding package name for a python module.
mod: python module name
dist: a linux distribution as returned by
`platform.linux_distribution()[0]`
pkg_map: a custom package mapping. None means autodetected based on the
given dist parameter
py_vers: a list of python ver... | [
"Return",
"a",
"corresponding",
"package",
"name",
"for",
"a",
"python",
"module",
"."
] | train | https://github.com/openstack/pymod2pkg/blob/f9a2f02fbfa0b2cfcdb4a7494c9ddbd10859065a/pymod2pkg/__init__.py#L359-L396 |
openstack/pymod2pkg | pymod2pkg/__init__.py | module2upstream | def module2upstream(mod):
"""Return a corresponding OpenStack upstream name for a python module.
mod -- python module name
"""
for rule in OPENSTACK_UPSTREAM_PKG_MAP:
pkglist = rule(mod, dist=None)
if pkglist:
return pkglist[0]
return mod | python | def module2upstream(mod):
"""Return a corresponding OpenStack upstream name for a python module.
mod -- python module name
"""
for rule in OPENSTACK_UPSTREAM_PKG_MAP:
pkglist = rule(mod, dist=None)
if pkglist:
return pkglist[0]
return mod | [
"def",
"module2upstream",
"(",
"mod",
")",
":",
"for",
"rule",
"in",
"OPENSTACK_UPSTREAM_PKG_MAP",
":",
"pkglist",
"=",
"rule",
"(",
"mod",
",",
"dist",
"=",
"None",
")",
"if",
"pkglist",
":",
"return",
"pkglist",
"[",
"0",
"]",
"return",
"mod"
] | Return a corresponding OpenStack upstream name for a python module.
mod -- python module name | [
"Return",
"a",
"corresponding",
"OpenStack",
"upstream",
"name",
"for",
"a",
"python",
"module",
"."
] | train | https://github.com/openstack/pymod2pkg/blob/f9a2f02fbfa0b2cfcdb4a7494c9ddbd10859065a/pymod2pkg/__init__.py#L399-L408 |
openstack/pymod2pkg | pymod2pkg/__init__.py | main | def main():
"""for resolving names from command line"""
parser = argparse.ArgumentParser(description='Python module name to'
'package name')
group = parser.add_mutually_exclusive_group()
group.add_argument('--dist', help='distribution style '
'... | python | def main():
"""for resolving names from command line"""
parser = argparse.ArgumentParser(description='Python module name to'
'package name')
group = parser.add_mutually_exclusive_group()
group.add_argument('--dist', help='distribution style '
'... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Python module name to'",
"'package name'",
")",
"group",
"=",
"parser",
".",
"add_mutually_exclusive_group",
"(",
")",
"group",
".",
"add_argument",
"(",
"... | for resolving names from command line | [
"for",
"resolving",
"names",
"from",
"command",
"line"
] | train | https://github.com/openstack/pymod2pkg/blob/f9a2f02fbfa0b2cfcdb4a7494c9ddbd10859065a/pymod2pkg/__init__.py#L411-L440 |
InfoAgeTech/django-core | django_core/views/mixins/paging.py | PagingViewMixin.get_paging | def get_paging(self):
"""Gets the paging values passed through the query string params.
* "p" for "page number" and
* "ps" for "page size".
:returns: tuple with the page being the first part and the page size
being the second part.
"""
orig_page_num ... | python | def get_paging(self):
"""Gets the paging values passed through the query string params.
* "p" for "page number" and
* "ps" for "page size".
:returns: tuple with the page being the first part and the page size
being the second part.
"""
orig_page_num ... | [
"def",
"get_paging",
"(",
"self",
")",
":",
"orig_page_num",
"=",
"self",
".",
"page_num",
"orig_page_size",
"=",
"self",
".",
"page_size",
"try",
":",
"page_num",
"=",
"int",
"(",
"self",
".",
"request",
".",
"GET",
".",
"get",
"(",
"self",
".",
"page... | Gets the paging values passed through the query string params.
* "p" for "page number" and
* "ps" for "page size".
:returns: tuple with the page being the first part and the page size
being the second part. | [
"Gets",
"the",
"paging",
"values",
"passed",
"through",
"the",
"query",
"string",
"params",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/views/mixins/paging.py#L38-L68 |
dls-controls/annotypes | annotypes/_calltypes.py | make_call_types | def make_call_types(f, globals_d):
# type: (Callable, Dict) -> Tuple[Dict[str, Anno], Anno]
"""Make a call_types dictionary that describes what arguments to pass to f
Args:
f: The function to inspect for argument names (without self)
globals_d: A dictionary of globals to lookup annotation d... | python | def make_call_types(f, globals_d):
# type: (Callable, Dict) -> Tuple[Dict[str, Anno], Anno]
"""Make a call_types dictionary that describes what arguments to pass to f
Args:
f: The function to inspect for argument names (without self)
globals_d: A dictionary of globals to lookup annotation d... | [
"def",
"make_call_types",
"(",
"f",
",",
"globals_d",
")",
":",
"# type: (Callable, Dict) -> Tuple[Dict[str, Anno], Anno]",
"arg_spec",
"=",
"getargspec",
"(",
"f",
")",
"args",
"=",
"[",
"k",
"for",
"k",
"in",
"arg_spec",
".",
"args",
"if",
"k",
"!=",
"\"self... | Make a call_types dictionary that describes what arguments to pass to f
Args:
f: The function to inspect for argument names (without self)
globals_d: A dictionary of globals to lookup annotation definitions in | [
"Make",
"a",
"call_types",
"dictionary",
"that",
"describes",
"what",
"arguments",
"to",
"pass",
"to",
"f"
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_calltypes.py#L44-L80 |
dls-controls/annotypes | annotypes/_calltypes.py | make_annotations | def make_annotations(f, globals_d=None):
# type: (Callable, Dict) -> Dict[str, Any]
"""Create an annotations dictionary from Python2 type comments
http://mypy.readthedocs.io/en/latest/python2.html
Args:
f: The function to examine for type comments
globals_d: The globals dictionary to g... | python | def make_annotations(f, globals_d=None):
# type: (Callable, Dict) -> Dict[str, Any]
"""Create an annotations dictionary from Python2 type comments
http://mypy.readthedocs.io/en/latest/python2.html
Args:
f: The function to examine for type comments
globals_d: The globals dictionary to g... | [
"def",
"make_annotations",
"(",
"f",
",",
"globals_d",
"=",
"None",
")",
":",
"# type: (Callable, Dict) -> Dict[str, Any]",
"locals_d",
"=",
"{",
"}",
"# type: Dict[str, Any]",
"if",
"globals_d",
"is",
"None",
":",
"# If not given a globals_d then we should just populate an... | Create an annotations dictionary from Python2 type comments
http://mypy.readthedocs.io/en/latest/python2.html
Args:
f: The function to examine for type comments
globals_d: The globals dictionary to get type idents from. If not
specified then make the annotations dict contain string... | [
"Create",
"an",
"annotations",
"dictionary",
"from",
"Python2",
"type",
"comments"
] | train | https://github.com/dls-controls/annotypes/blob/31ab68a0367bb70ebd9898e8b9fa9405423465bd/annotypes/_calltypes.py#L106-L178 |
InfoAgeTech/django-core | django_core/views/mixins/common.py | CommonSingleObjectViewMixin.get_object | def get_object(self, **kwargs):
"""Sometimes preprocessing of a view need to happen before the object
attribute has been set for a view. In this case, just return the
object if it has already been set when it's called down the road since
there's no need to make another query.
""... | python | def get_object(self, **kwargs):
"""Sometimes preprocessing of a view need to happen before the object
attribute has been set for a view. In this case, just return the
object if it has already been set when it's called down the road since
there's no need to make another query.
""... | [
"def",
"get_object",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'object'",
")",
"and",
"self",
".",
"object",
":",
"return",
"self",
".",
"object",
"obj",
"=",
"super",
"(",
"CommonSingleObjectViewMixin",
",",
"... | Sometimes preprocessing of a view need to happen before the object
attribute has been set for a view. In this case, just return the
object if it has already been set when it's called down the road since
there's no need to make another query. | [
"Sometimes",
"preprocessing",
"of",
"a",
"view",
"need",
"to",
"happen",
"before",
"the",
"object",
"attribute",
"has",
"been",
"set",
"for",
"a",
"view",
".",
"In",
"this",
"case",
"just",
"return",
"the",
"object",
"if",
"it",
"has",
"already",
"been",
... | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/views/mixins/common.py#L6-L17 |
InfoAgeTech/django-core | django_core/utils/date_parsers.py | hex_timestamp_to_datetime | def hex_timestamp_to_datetime(hex_timestamp):
"""Converts hex timestamp to a datetime object.
>>> hex_timestamp_to_datetime('558BBCF9')
datetime.datetime(2015, 6, 25, 8, 34, 1)
>>> hex_timestamp_to_datetime('0x558BBCF9')
datetime.datetime(2015, 6, 25, 8, 34, 1)
>>> datetime.fromtimestamp(0x558B... | python | def hex_timestamp_to_datetime(hex_timestamp):
"""Converts hex timestamp to a datetime object.
>>> hex_timestamp_to_datetime('558BBCF9')
datetime.datetime(2015, 6, 25, 8, 34, 1)
>>> hex_timestamp_to_datetime('0x558BBCF9')
datetime.datetime(2015, 6, 25, 8, 34, 1)
>>> datetime.fromtimestamp(0x558B... | [
"def",
"hex_timestamp_to_datetime",
"(",
"hex_timestamp",
")",
":",
"if",
"not",
"hex_timestamp",
".",
"startswith",
"(",
"'0x'",
")",
":",
"hex_timestamp",
"=",
"'0x{0}'",
".",
"format",
"(",
"hex_timestamp",
")",
"return",
"datetime",
".",
"fromtimestamp",
"("... | Converts hex timestamp to a datetime object.
>>> hex_timestamp_to_datetime('558BBCF9')
datetime.datetime(2015, 6, 25, 8, 34, 1)
>>> hex_timestamp_to_datetime('0x558BBCF9')
datetime.datetime(2015, 6, 25, 8, 34, 1)
>>> datetime.fromtimestamp(0x558BBCF9)
datetime.datetime(2015, 6, 25, 8, 34, 1) | [
"Converts",
"hex",
"timestamp",
"to",
"a",
"datetime",
"object",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/date_parsers.py#L10-L23 |
InfoAgeTech/django-core | django_core/utils/date_parsers.py | now_by_tz | def now_by_tz(tz='US/Central', ignoretz=True):
"""Gets the current datetime object by timezone.
:param tz: is the timezone to get the date for. tz can be passed as a
string or as a timezone object. (i.e. 'US/Central' or
pytz.timezone('US/Central'), etc)
:param ignoretz: will ignore the tim... | python | def now_by_tz(tz='US/Central', ignoretz=True):
"""Gets the current datetime object by timezone.
:param tz: is the timezone to get the date for. tz can be passed as a
string or as a timezone object. (i.e. 'US/Central' or
pytz.timezone('US/Central'), etc)
:param ignoretz: will ignore the tim... | [
"def",
"now_by_tz",
"(",
"tz",
"=",
"'US/Central'",
",",
"ignoretz",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"tz",
",",
"string_types",
")",
":",
"tz",
"=",
"pytz",
".",
"timezone",
"(",
"tz",
")",
"if",
"ignoretz",
":",
"return",
"datetime",
... | Gets the current datetime object by timezone.
:param tz: is the timezone to get the date for. tz can be passed as a
string or as a timezone object. (i.e. 'US/Central' or
pytz.timezone('US/Central'), etc)
:param ignoretz: will ignore the timezone portion of the datetime object and
tzinf... | [
"Gets",
"the",
"current",
"datetime",
"object",
"by",
"timezone",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/date_parsers.py#L26-L53 |
InfoAgeTech/django-core | django_core/utils/date_parsers.py | tz_to_utc | def tz_to_utc(dt, tz, ignoretz=True):
"""Converts a datetime object from the specified timezone to a UTC datetime.
:param tz: the timezone the datetime is currently in. tz can be passed
as a string or as a timezone object. (i.e. 'US/Central' or
pytz.timezone('US/Central'), etc)
:param igno... | python | def tz_to_utc(dt, tz, ignoretz=True):
"""Converts a datetime object from the specified timezone to a UTC datetime.
:param tz: the timezone the datetime is currently in. tz can be passed
as a string or as a timezone object. (i.e. 'US/Central' or
pytz.timezone('US/Central'), etc)
:param igno... | [
"def",
"tz_to_utc",
"(",
"dt",
",",
"tz",
",",
"ignoretz",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"tz",
",",
"string_types",
")",
":",
"tz",
"=",
"pytz",
".",
"timezone",
"(",
"tz",
")",
"dt",
"=",
"tz",
".",
"localize",
"(",
"dt",
")",
... | Converts a datetime object from the specified timezone to a UTC datetime.
:param tz: the timezone the datetime is currently in. tz can be passed
as a string or as a timezone object. (i.e. 'US/Central' or
pytz.timezone('US/Central'), etc)
:param ignoretz: will ignore the timezone portion of the... | [
"Converts",
"a",
"datetime",
"object",
"from",
"the",
"specified",
"timezone",
"to",
"a",
"UTC",
"datetime",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/date_parsers.py#L56-L84 |
InfoAgeTech/django-core | django_core/utils/date_parsers.py | utc_to_tz | def utc_to_tz(dt, tz, ignoretz=True):
""" Converts UTC datetime object to the specific timezone.
:param dt: the UTC datetime object to convert.
:param tz: the timezone to convert the UTC datetime object info. tz can be
passed as a string or as a timezone object. (i.e. 'US/Central' or
... | python | def utc_to_tz(dt, tz, ignoretz=True):
""" Converts UTC datetime object to the specific timezone.
:param dt: the UTC datetime object to convert.
:param tz: the timezone to convert the UTC datetime object info. tz can be
passed as a string or as a timezone object. (i.e. 'US/Central' or
... | [
"def",
"utc_to_tz",
"(",
"dt",
",",
"tz",
",",
"ignoretz",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"tz",
",",
"string_types",
")",
":",
"tz",
"=",
"pytz",
".",
"timezone",
"(",
"tz",
")",
"dt",
"=",
"pytz",
".",
"utc",
".",
"localize",
"(... | Converts UTC datetime object to the specific timezone.
:param dt: the UTC datetime object to convert.
:param tz: the timezone to convert the UTC datetime object info. tz can be
passed as a string or as a timezone object. (i.e. 'US/Central' or
pytz.timezone('US/Central'), etc)
... | [
"Converts",
"UTC",
"datetime",
"object",
"to",
"the",
"specific",
"timezone",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/date_parsers.py#L87-L114 |
InfoAgeTech/django-core | django_core/utils/date_parsers.py | parse_date | def parse_date(dt, ignoretz=True, as_tz=None):
"""
:param dt: string datetime to convert into datetime object.
:return: date object if the string can be parsed into a date. Otherwise,
return None.
:see: http://labix.org/python-dateutil
Examples:
>>> parse_date('2011-12-30')
dateti... | python | def parse_date(dt, ignoretz=True, as_tz=None):
"""
:param dt: string datetime to convert into datetime object.
:return: date object if the string can be parsed into a date. Otherwise,
return None.
:see: http://labix.org/python-dateutil
Examples:
>>> parse_date('2011-12-30')
dateti... | [
"def",
"parse_date",
"(",
"dt",
",",
"ignoretz",
"=",
"True",
",",
"as_tz",
"=",
"None",
")",
":",
"dttm",
"=",
"parse_datetime",
"(",
"dt",
",",
"ignoretz",
"=",
"ignoretz",
")",
"return",
"None",
"if",
"dttm",
"is",
"None",
"else",
"dttm",
".",
"da... | :param dt: string datetime to convert into datetime object.
:return: date object if the string can be parsed into a date. Otherwise,
return None.
:see: http://labix.org/python-dateutil
Examples:
>>> parse_date('2011-12-30')
datetime.date(2011, 12, 30)
>>> parse_date('12/30/2011')
... | [
":",
"param",
"dt",
":",
"string",
"datetime",
"to",
"convert",
"into",
"datetime",
"object",
".",
":",
"return",
":",
"date",
"object",
"if",
"the",
"string",
"can",
"be",
"parsed",
"into",
"a",
"date",
".",
"Otherwise",
"return",
"None",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/date_parsers.py#L117-L133 |
InfoAgeTech/django-core | django_core/utils/date_parsers.py | parse_datetime | def parse_datetime(dt, ignoretz=True, **kwargs):
"""
:param dt: string datetime to convert into datetime object.
:return: datetime object if the string can be parsed into a datetime.
Otherwise, return None.
:see: http://labix.org/python-dateutil
Examples:
>>> parse_datetime('2011-12-3... | python | def parse_datetime(dt, ignoretz=True, **kwargs):
"""
:param dt: string datetime to convert into datetime object.
:return: datetime object if the string can be parsed into a datetime.
Otherwise, return None.
:see: http://labix.org/python-dateutil
Examples:
>>> parse_datetime('2011-12-3... | [
"def",
"parse_datetime",
"(",
"dt",
",",
"ignoretz",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"parse",
"(",
"dt",
",",
"ignoretz",
"=",
"ignoretz",
",",
"*",
"*",
"kwargs",
")",
"except",
":",
"return",
"None"
] | :param dt: string datetime to convert into datetime object.
:return: datetime object if the string can be parsed into a datetime.
Otherwise, return None.
:see: http://labix.org/python-dateutil
Examples:
>>> parse_datetime('2011-12-30 13:45:12 CDT')
2011-12-30 13:45:12
>>> parse_dateti... | [
":",
"param",
"dt",
":",
"string",
"datetime",
"to",
"convert",
"into",
"datetime",
"object",
".",
":",
"return",
":",
"datetime",
"object",
"if",
"the",
"string",
"can",
"be",
"parsed",
"into",
"a",
"datetime",
".",
"Otherwise",
"return",
"None",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/date_parsers.py#L136-L159 |
InfoAgeTech/django-core | django_core/decorators.py | turn_emails_off | def turn_emails_off(view_func):
"""Turns emails off so no emails will be sent."""
# Dummy email backend so no emails are sent.
EMAIL_BACKEND_DUMMY = 'django.core.mail.backends.dummy.EmailBackend'
def decorated(request, *args, **kwargs):
orig_email_backend = settings.EMAIL_BACKEND
setti... | python | def turn_emails_off(view_func):
"""Turns emails off so no emails will be sent."""
# Dummy email backend so no emails are sent.
EMAIL_BACKEND_DUMMY = 'django.core.mail.backends.dummy.EmailBackend'
def decorated(request, *args, **kwargs):
orig_email_backend = settings.EMAIL_BACKEND
setti... | [
"def",
"turn_emails_off",
"(",
"view_func",
")",
":",
"# Dummy email backend so no emails are sent.",
"EMAIL_BACKEND_DUMMY",
"=",
"'django.core.mail.backends.dummy.EmailBackend'",
"def",
"decorated",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"... | Turns emails off so no emails will be sent. | [
"Turns",
"emails",
"off",
"so",
"no",
"emails",
"will",
"be",
"sent",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/decorators.py#L6-L20 |
InfoAgeTech/django-core | django_core/utils/file_utils.py | get_md5_for_file | def get_md5_for_file(file):
"""Get the md5 hash for a file.
:param file: the file to get the md5 hash for
"""
md5 = hashlib.md5()
while True:
data = file.read(md5.block_size)
if not data:
break
md5.update(data)
return md5.hexdigest() | python | def get_md5_for_file(file):
"""Get the md5 hash for a file.
:param file: the file to get the md5 hash for
"""
md5 = hashlib.md5()
while True:
data = file.read(md5.block_size)
if not data:
break
md5.update(data)
return md5.hexdigest() | [
"def",
"get_md5_for_file",
"(",
"file",
")",
":",
"md5",
"=",
"hashlib",
".",
"md5",
"(",
")",
"while",
"True",
":",
"data",
"=",
"file",
".",
"read",
"(",
"md5",
".",
"block_size",
")",
"if",
"not",
"data",
":",
"break",
"md5",
".",
"update",
"(",... | Get the md5 hash for a file.
:param file: the file to get the md5 hash for | [
"Get",
"the",
"md5",
"hash",
"for",
"a",
"file",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/file_utils.py#L72-L87 |
InfoAgeTech/django-core | django_core/utils/file_utils.py | get_dict_from_json_file | def get_dict_from_json_file(path, encoding='utf-8'):
"""Gets a dict of data form a json file.
:param path: the absolute path to the file
:param encoding: the encoding the file is in
"""
with open(path, encoding=encoding) as data_file:
return json.loads(data_file.read()) | python | def get_dict_from_json_file(path, encoding='utf-8'):
"""Gets a dict of data form a json file.
:param path: the absolute path to the file
:param encoding: the encoding the file is in
"""
with open(path, encoding=encoding) as data_file:
return json.loads(data_file.read()) | [
"def",
"get_dict_from_json_file",
"(",
"path",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"with",
"open",
"(",
"path",
",",
"encoding",
"=",
"encoding",
")",
"as",
"data_file",
":",
"return",
"json",
".",
"loads",
"(",
"data_file",
".",
"read",
"(",
")",... | Gets a dict of data form a json file.
:param path: the absolute path to the file
:param encoding: the encoding the file is in | [
"Gets",
"a",
"dict",
"of",
"data",
"form",
"a",
"json",
"file",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/utils/file_utils.py#L90-L97 |
InfoAgeTech/django-core | django_core/templatetags/html_tags.py | linebreaks_safe | def linebreaks_safe(value, autoescape=True):
"""
Adds linebreaks only for text that has a newline character.
"""
if isinstance(value, string_types) and '\n' in value:
return linebreaks_filter(value, autoescape=autoescape)
return value | python | def linebreaks_safe(value, autoescape=True):
"""
Adds linebreaks only for text that has a newline character.
"""
if isinstance(value, string_types) and '\n' in value:
return linebreaks_filter(value, autoescape=autoescape)
return value | [
"def",
"linebreaks_safe",
"(",
"value",
",",
"autoescape",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"string_types",
")",
"and",
"'\\n'",
"in",
"value",
":",
"return",
"linebreaks_filter",
"(",
"value",
",",
"autoescape",
"=",
"autoescape... | Adds linebreaks only for text that has a newline character. | [
"Adds",
"linebreaks",
"only",
"for",
"text",
"that",
"has",
"a",
"newline",
"character",
"."
] | train | https://github.com/InfoAgeTech/django-core/blob/9664a145473b75120bf71e1644e9c8086e7e8955/django_core/templatetags/html_tags.py#L11-L18 |
kmedian/korr | korr/kendall.py | kendall | def kendall(x, axis=0):
"""Kendall' tau (Rank) Correlation Matrix (for ordinal data)
Parameters
----------
x : ndarray
data set
axis : int, optional
Variables as columns is the default (axis=0). If variables are
in the rows use axis=1
Returns
-------
r : ndarra... | python | def kendall(x, axis=0):
"""Kendall' tau (Rank) Correlation Matrix (for ordinal data)
Parameters
----------
x : ndarray
data set
axis : int, optional
Variables as columns is the default (axis=0). If variables are
in the rows use axis=1
Returns
-------
r : ndarra... | [
"def",
"kendall",
"(",
"x",
",",
"axis",
"=",
"0",
")",
":",
"# transpose if axis<>0",
"if",
"axis",
"is",
"not",
"0",
":",
"x",
"=",
"x",
".",
"T",
"# read dimensions and",
"n",
",",
"c",
"=",
"x",
".",
"shape",
"# check if enough variables provided",
"... | Kendall' tau (Rank) Correlation Matrix (for ordinal data)
Parameters
----------
x : ndarray
data set
axis : int, optional
Variables as columns is the default (axis=0). If variables are
in the rows use axis=1
Returns
-------
r : ndarray
Correlation Matrix (K... | [
"Kendall",
"tau",
"(",
"Rank",
")",
"Correlation",
"Matrix",
"(",
"for",
"ordinal",
"data",
")"
] | train | https://github.com/kmedian/korr/blob/4eb86fc14b1fc1b69204069b7753d115b327c937/korr/kendall.py#L5-L49 |
QualiSystems/cloudshell-networking-devices | cloudshell/devices/standards/base.py | AbstractResource.add_sub_resource | def add_sub_resource(self, relative_id, sub_resource):
"""Add sub resource"""
existing_sub_resources = self.resources.get(sub_resource.RELATIVE_PATH_TEMPLATE, defaultdict(list))
existing_sub_resources[relative_id].append(sub_resource)
self.resources.update({sub_resource.RELATIVE_PATH_TEM... | python | def add_sub_resource(self, relative_id, sub_resource):
"""Add sub resource"""
existing_sub_resources = self.resources.get(sub_resource.RELATIVE_PATH_TEMPLATE, defaultdict(list))
existing_sub_resources[relative_id].append(sub_resource)
self.resources.update({sub_resource.RELATIVE_PATH_TEM... | [
"def",
"add_sub_resource",
"(",
"self",
",",
"relative_id",
",",
"sub_resource",
")",
":",
"existing_sub_resources",
"=",
"self",
".",
"resources",
".",
"get",
"(",
"sub_resource",
".",
"RELATIVE_PATH_TEMPLATE",
",",
"defaultdict",
"(",
"list",
")",
")",
"existi... | Add sub resource | [
"Add",
"sub",
"resource"
] | train | https://github.com/QualiSystems/cloudshell-networking-devices/blob/009aab33edb30035b52fe10dbb91db61c95ba4d9/cloudshell/devices/standards/base.py#L30-L34 |
QualiSystems/cloudshell-networking-devices | cloudshell/devices/standards/base.py | AbstractResource.cloudshell_model_name | def cloudshell_model_name(self):
"""Return the name of the CloudShell model"""
if self.shell_name:
return "{shell_name}.{resource_model}".format(shell_name=self.shell_name,
resource_model=self.RESOURCE_MODEL.replace(" ", ""))
... | python | def cloudshell_model_name(self):
"""Return the name of the CloudShell model"""
if self.shell_name:
return "{shell_name}.{resource_model}".format(shell_name=self.shell_name,
resource_model=self.RESOURCE_MODEL.replace(" ", ""))
... | [
"def",
"cloudshell_model_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"shell_name",
":",
"return",
"\"{shell_name}.{resource_model}\"",
".",
"format",
"(",
"shell_name",
"=",
"self",
".",
"shell_name",
",",
"resource_model",
"=",
"self",
".",
"RESOURCE_MODEL",... | Return the name of the CloudShell model | [
"Return",
"the",
"name",
"of",
"the",
"CloudShell",
"model"
] | train | https://github.com/QualiSystems/cloudshell-networking-devices/blob/009aab33edb30035b52fe10dbb91db61c95ba4d9/cloudshell/devices/standards/base.py#L37-L43 |
kmedian/korr | korr/slice_yx.py | slice_yx | def slice_yx(r, pval, ydim=1):
"""slice a correlation and p-value matrix of a (y,X) dataset
into a (y,x_i) vector and (x_j, x_k) matrices
Parameters
----------
r : ndarray
Correlation Matrix of a (y,X) dataset
pval : ndarray
p-values
ydim : int
Number of target var... | python | def slice_yx(r, pval, ydim=1):
"""slice a correlation and p-value matrix of a (y,X) dataset
into a (y,x_i) vector and (x_j, x_k) matrices
Parameters
----------
r : ndarray
Correlation Matrix of a (y,X) dataset
pval : ndarray
p-values
ydim : int
Number of target var... | [
"def",
"slice_yx",
"(",
"r",
",",
"pval",
",",
"ydim",
"=",
"1",
")",
":",
"if",
"ydim",
"is",
"1",
":",
"return",
"(",
"r",
"[",
"1",
":",
",",
":",
"1",
"]",
".",
"reshape",
"(",
"-",
"1",
",",
")",
",",
"pval",
"[",
"1",
":",
",",
":... | slice a correlation and p-value matrix of a (y,X) dataset
into a (y,x_i) vector and (x_j, x_k) matrices
Parameters
----------
r : ndarray
Correlation Matrix of a (y,X) dataset
pval : ndarray
p-values
ydim : int
Number of target variables y, i.e. the first ydim-th colum... | [
"slice",
"a",
"correlation",
"and",
"p",
"-",
"value",
"matrix",
"of",
"a",
"(",
"y",
"X",
")",
"dataset",
"into",
"a",
"(",
"y",
"x_i",
")",
"vector",
"and",
"(",
"x_j",
"x_k",
")",
"matrices"
] | train | https://github.com/kmedian/korr/blob/4eb86fc14b1fc1b69204069b7753d115b327c937/korr/slice_yx.py#L2-L47 |
eumis/pyviews | pyviews/compilation/parsing.py | parse_expression | def parse_expression(source: str) -> ExpressionSource:
'''Returns tuple with expression type and expression body'''
if not is_expression(source):
msg = 'Expression is not valid. Expression should be matched with regular expression: {0}'\
.format(EXPRESSION_REGEX)
raise ExpressionEr... | python | def parse_expression(source: str) -> ExpressionSource:
'''Returns tuple with expression type and expression body'''
if not is_expression(source):
msg = 'Expression is not valid. Expression should be matched with regular expression: {0}'\
.format(EXPRESSION_REGEX)
raise ExpressionEr... | [
"def",
"parse_expression",
"(",
"source",
":",
"str",
")",
"->",
"ExpressionSource",
":",
"if",
"not",
"is_expression",
"(",
"source",
")",
":",
"msg",
"=",
"'Expression is not valid. Expression should be matched with regular expression: {0}'",
".",
"format",
"(",
"EXPR... | Returns tuple with expression type and expression body | [
"Returns",
"tuple",
"with",
"expression",
"type",
"and",
"expression",
"body"
] | train | https://github.com/eumis/pyviews/blob/80a868242ee9cdc6f4ded594b3e0544cc238ed55/pyviews/compilation/parsing.py#L20-L32 |
internetarchive/doublethink | doublethink/rethinker.py | Rethinker._server_whitelist | def _server_whitelist(self):
'''
Returns list of servers that have not errored in the last five minutes.
If all servers have errored in the last five minutes, returns list with
one item, the server that errored least recently.
'''
whitelist = []
for server in self... | python | def _server_whitelist(self):
'''
Returns list of servers that have not errored in the last five minutes.
If all servers have errored in the last five minutes, returns list with
one item, the server that errored least recently.
'''
whitelist = []
for server in self... | [
"def",
"_server_whitelist",
"(",
"self",
")",
":",
"whitelist",
"=",
"[",
"]",
"for",
"server",
"in",
"self",
".",
"servers",
":",
"if",
"(",
"server",
"not",
"in",
"self",
".",
"last_error",
"or",
"self",
".",
"last_error",
"[",
"server",
"]",
"<",
... | Returns list of servers that have not errored in the last five minutes.
If all servers have errored in the last five minutes, returns list with
one item, the server that errored least recently. | [
"Returns",
"list",
"of",
"servers",
"that",
"have",
"not",
"errored",
"in",
"the",
"last",
"five",
"minutes",
".",
"If",
"all",
"servers",
"have",
"errored",
"in",
"the",
"last",
"five",
"minutes",
"returns",
"list",
"with",
"one",
"item",
"the",
"server",... | train | https://github.com/internetarchive/doublethink/blob/f7fc7da725c9b572d473c717b3dad9af98a7a2b4/doublethink/rethinker.py#L141-L155 |
QualiSystems/cloudshell-networking-devices | cloudshell/devices/standards/networking/configuration_attributes_structure.py | create_networking_resource_from_context | def create_networking_resource_from_context(shell_name, supported_os, context):
"""
Creates an instance of Networking Resource by given context
:param shell_name: Shell Name
:type shell_name: str
:param supported_os: list of supported OS
:type supported_os: list
:param context: cloudshell.sh... | python | def create_networking_resource_from_context(shell_name, supported_os, context):
"""
Creates an instance of Networking Resource by given context
:param shell_name: Shell Name
:type shell_name: str
:param supported_os: list of supported OS
:type supported_os: list
:param context: cloudshell.sh... | [
"def",
"create_networking_resource_from_context",
"(",
"shell_name",
",",
"supported_os",
",",
"context",
")",
":",
"result",
"=",
"GenericNetworkingResource",
"(",
"shell_name",
"=",
"shell_name",
",",
"name",
"=",
"context",
".",
"resource",
".",
"name",
",",
"s... | Creates an instance of Networking Resource by given context
:param shell_name: Shell Name
:type shell_name: str
:param supported_os: list of supported OS
:type supported_os: list
:param context: cloudshell.shell.core.driver_context.ResourceCommandContext
:type context: cloudshell.shell.core.driv... | [
"Creates",
"an",
"instance",
"of",
"Networking",
"Resource",
"by",
"given",
"context",
":",
"param",
"shell_name",
":",
"Shell",
"Name",
":",
"type",
"shell_name",
":",
"str",
":",
"param",
"supported_os",
":",
"list",
"of",
"supported",
"OS",
":",
"type",
... | train | https://github.com/QualiSystems/cloudshell-networking-devices/blob/009aab33edb30035b52fe10dbb91db61c95ba4d9/cloudshell/devices/standards/networking/configuration_attributes_structure.py#L213-L233 |
kmedian/korr | korr/find_worst.py | find_worst | def find_worst(rho, pval, m=1, rlim=.10, plim=.35):
"""Find the N "worst", i.e. insignificant/random and low, correlations
Parameters
----------
rho : ndarray, list
1D array with correlation coefficients
pval : ndarray, list
1D array with p-values
m : int
The desired n... | python | def find_worst(rho, pval, m=1, rlim=.10, plim=.35):
"""Find the N "worst", i.e. insignificant/random and low, correlations
Parameters
----------
rho : ndarray, list
1D array with correlation coefficients
pval : ndarray, list
1D array with p-values
m : int
The desired n... | [
"def",
"find_worst",
"(",
"rho",
",",
"pval",
",",
"m",
"=",
"1",
",",
"rlim",
"=",
".10",
",",
"plim",
"=",
".35",
")",
":",
"# convert to lists",
"n",
"=",
"len",
"(",
"rho",
")",
"r",
"=",
"list",
"(",
"np",
".",
"abs",
"(",
"rho",
")",
")... | Find the N "worst", i.e. insignificant/random and low, correlations
Parameters
----------
rho : ndarray, list
1D array with correlation coefficients
pval : ndarray, list
1D array with p-values
m : int
The desired number of indicies to return
(How many "worst" corre... | [
"Find",
"the",
"N",
"worst",
"i",
".",
"e",
".",
"insignificant",
"/",
"random",
"and",
"low",
"correlations"
] | train | https://github.com/kmedian/korr/blob/4eb86fc14b1fc1b69204069b7753d115b327c937/korr/find_worst.py#L5-L101 |
upsight/doctor | doctor/parsers.py | _parse_array | def _parse_array(value):
"""Coerce value into an list.
:param str value: Value to parse.
:returns: list or None if the value is not a JSON array
:raises: TypeError or ValueError if value appears to be an array but can't
be parsed as JSON.
"""
value = value.lstrip()
if not value or v... | python | def _parse_array(value):
"""Coerce value into an list.
:param str value: Value to parse.
:returns: list or None if the value is not a JSON array
:raises: TypeError or ValueError if value appears to be an array but can't
be parsed as JSON.
"""
value = value.lstrip()
if not value or v... | [
"def",
"_parse_array",
"(",
"value",
")",
":",
"value",
"=",
"value",
".",
"lstrip",
"(",
")",
"if",
"not",
"value",
"or",
"value",
"[",
"0",
"]",
"not",
"in",
"_bracket_strings",
":",
"return",
"None",
"return",
"json",
".",
"loads",
"(",
"value",
"... | Coerce value into an list.
:param str value: Value to parse.
:returns: list or None if the value is not a JSON array
:raises: TypeError or ValueError if value appears to be an array but can't
be parsed as JSON. | [
"Coerce",
"value",
"into",
"an",
"list",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/parsers.py#L22-L33 |
upsight/doctor | doctor/parsers.py | _parse_boolean | def _parse_boolean(value):
"""Coerce value into an bool.
:param str value: Value to parse.
:returns: bool or None if the value is not a boolean string.
"""
value = value.lower()
if value in _true_strings:
return True
elif value in _false_strings:
return False
else:
... | python | def _parse_boolean(value):
"""Coerce value into an bool.
:param str value: Value to parse.
:returns: bool or None if the value is not a boolean string.
"""
value = value.lower()
if value in _true_strings:
return True
elif value in _false_strings:
return False
else:
... | [
"def",
"_parse_boolean",
"(",
"value",
")",
":",
"value",
"=",
"value",
".",
"lower",
"(",
")",
"if",
"value",
"in",
"_true_strings",
":",
"return",
"True",
"elif",
"value",
"in",
"_false_strings",
":",
"return",
"False",
"else",
":",
"return",
"None"
] | Coerce value into an bool.
:param str value: Value to parse.
:returns: bool or None if the value is not a boolean string. | [
"Coerce",
"value",
"into",
"an",
"bool",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/parsers.py#L36-L48 |
upsight/doctor | doctor/parsers.py | _parse_object | def _parse_object(value):
"""Coerce value into a dict.
:param str value: Value to parse.
:returns: dict or None if the value is not a JSON object
:raises: TypeError or ValueError if value appears to be an object but can't
be parsed as JSON.
"""
value = value.lstrip()
if not value or... | python | def _parse_object(value):
"""Coerce value into a dict.
:param str value: Value to parse.
:returns: dict or None if the value is not a JSON object
:raises: TypeError or ValueError if value appears to be an object but can't
be parsed as JSON.
"""
value = value.lstrip()
if not value or... | [
"def",
"_parse_object",
"(",
"value",
")",
":",
"value",
"=",
"value",
".",
"lstrip",
"(",
")",
"if",
"not",
"value",
"or",
"value",
"[",
"0",
"]",
"not",
"in",
"_brace_strings",
":",
"return",
"None",
"return",
"json",
".",
"loads",
"(",
"value",
")... | Coerce value into a dict.
:param str value: Value to parse.
:returns: dict or None if the value is not a JSON object
:raises: TypeError or ValueError if value appears to be an object but can't
be parsed as JSON. | [
"Coerce",
"value",
"into",
"a",
"dict",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/parsers.py#L51-L62 |
upsight/doctor | doctor/parsers.py | parse_value | def parse_value(value, allowed_types, name='value'):
"""Parse a value into one of a number of types.
This function is used to coerce untyped HTTP parameter strings into an
appropriate type. It tries to coerce the value into each of the allowed
types, and uses the first that evaluates properly.
Bec... | python | def parse_value(value, allowed_types, name='value'):
"""Parse a value into one of a number of types.
This function is used to coerce untyped HTTP parameter strings into an
appropriate type. It tries to coerce the value into each of the allowed
types, and uses the first that evaluates properly.
Bec... | [
"def",
"parse_value",
"(",
"value",
",",
"allowed_types",
",",
"name",
"=",
"'value'",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"raise",
"ValueError",
"(",
"'value for %r must be a string'",
"%",
"name",
")",
"if",
"isinstance... | Parse a value into one of a number of types.
This function is used to coerce untyped HTTP parameter strings into an
appropriate type. It tries to coerce the value into each of the allowed
types, and uses the first that evaluates properly.
Because this is coercing a string into multiple, potentially am... | [
"Parse",
"a",
"value",
"into",
"one",
"of",
"a",
"number",
"of",
"types",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/parsers.py#L87-L145 |
upsight/doctor | doctor/parsers.py | parse_json | def parse_json(value: str, sig_params: List[inspect.Parameter] = None) -> dict:
"""Parse a value as JSON.
This is just a wrapper around json.loads which re-raises any errors as a
ParseError instead.
:param str value: JSON string.
:param dict sig_params: The logic function's signature parameters.
... | python | def parse_json(value: str, sig_params: List[inspect.Parameter] = None) -> dict:
"""Parse a value as JSON.
This is just a wrapper around json.loads which re-raises any errors as a
ParseError instead.
:param str value: JSON string.
:param dict sig_params: The logic function's signature parameters.
... | [
"def",
"parse_json",
"(",
"value",
":",
"str",
",",
"sig_params",
":",
"List",
"[",
"inspect",
".",
"Parameter",
"]",
"=",
"None",
")",
"->",
"dict",
":",
"try",
":",
"loaded",
"=",
"json",
".",
"loads",
"(",
"value",
")",
"except",
"Exception",
"as"... | Parse a value as JSON.
This is just a wrapper around json.loads which re-raises any errors as a
ParseError instead.
:param str value: JSON string.
:param dict sig_params: The logic function's signature parameters.
:returns: the parsed JSON value | [
"Parse",
"a",
"value",
"as",
"JSON",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/parsers.py#L148-L167 |
upsight/doctor | doctor/parsers.py | map_param_names | def map_param_names(
req_params: dict, sig_params: List[inspect.Parameter]) -> dict:
"""Maps request param names to match logic function param names.
If a doctor type defined a `param_name` attribute for the name of the
parameter in the request, we should use that as the key when looking up
the... | python | def map_param_names(
req_params: dict, sig_params: List[inspect.Parameter]) -> dict:
"""Maps request param names to match logic function param names.
If a doctor type defined a `param_name` attribute for the name of the
parameter in the request, we should use that as the key when looking up
the... | [
"def",
"map_param_names",
"(",
"req_params",
":",
"dict",
",",
"sig_params",
":",
"List",
"[",
"inspect",
".",
"Parameter",
"]",
")",
"->",
"dict",
":",
"new_request_params",
"=",
"{",
"}",
"for",
"k",
",",
"param",
"in",
"sig_params",
".",
"items",
"(",... | Maps request param names to match logic function param names.
If a doctor type defined a `param_name` attribute for the name of the
parameter in the request, we should use that as the key when looking up
the value for the request parameter.
When we declare a type we can specify what the parameter name... | [
"Maps",
"request",
"param",
"names",
"to",
"match",
"logic",
"function",
"param",
"names",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/parsers.py#L180-L210 |
upsight/doctor | doctor/parsers.py | parse_form_and_query_params | def parse_form_and_query_params(req_params: dict, sig_params: dict) -> dict:
"""Uses the parameter annotations to coerce string params.
This is used for HTTP requests, in which the form parameters are all
strings, but need to be converted to the appropriate types before
validating them.
:param dic... | python | def parse_form_and_query_params(req_params: dict, sig_params: dict) -> dict:
"""Uses the parameter annotations to coerce string params.
This is used for HTTP requests, in which the form parameters are all
strings, but need to be converted to the appropriate types before
validating them.
:param dic... | [
"def",
"parse_form_and_query_params",
"(",
"req_params",
":",
"dict",
",",
"sig_params",
":",
"dict",
")",
"->",
"dict",
":",
"# Importing here to prevent circular dependencies.",
"from",
"doctor",
".",
"types",
"import",
"SuperType",
",",
"UnionType",
"errors",
"=",
... | Uses the parameter annotations to coerce string params.
This is used for HTTP requests, in which the form parameters are all
strings, but need to be converted to the appropriate types before
validating them.
:param dict req_params: The parameters specified in the request.
:param dict sig_params: T... | [
"Uses",
"the",
"parameter",
"annotations",
"to",
"coerce",
"string",
"params",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/parsers.py#L213-L268 |
Workiva/furious | furious/handlers/webapp.py | AsyncJobHandler._handle_task | def _handle_task(self):
"""Pass request info to the async framework."""
headers = self.request.headers
message = None
try:
status_code, output = process_async_task(
headers, self.request.body)
except AbortAndRestart as restart:
# Async ret... | python | def _handle_task(self):
"""Pass request info to the async framework."""
headers = self.request.headers
message = None
try:
status_code, output = process_async_task(
headers, self.request.body)
except AbortAndRestart as restart:
# Async ret... | [
"def",
"_handle_task",
"(",
"self",
")",
":",
"headers",
"=",
"self",
".",
"request",
".",
"headers",
"message",
"=",
"None",
"try",
":",
"status_code",
",",
"output",
"=",
"process_async_task",
"(",
"headers",
",",
"self",
".",
"request",
".",
"body",
"... | Pass request info to the async framework. | [
"Pass",
"request",
"info",
"to",
"the",
"async",
"framework",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/furious/handlers/webapp.py#L30-L45 |
QualiSystems/cloudshell-networking-devices | cloudshell/devices/autoload/autoload_migration_helper.py | migrate_autoload_details | def migrate_autoload_details(autoload_details, shell_name, shell_type):
""" Migrate autoload details. Add namespace for attributes
:param autoload_details:
:param shell_name:
:param shell_type:
:return:
"""
mapping = {}
for resource in autoload_details.resources:
resource.model... | python | def migrate_autoload_details(autoload_details, shell_name, shell_type):
""" Migrate autoload details. Add namespace for attributes
:param autoload_details:
:param shell_name:
:param shell_type:
:return:
"""
mapping = {}
for resource in autoload_details.resources:
resource.model... | [
"def",
"migrate_autoload_details",
"(",
"autoload_details",
",",
"shell_name",
",",
"shell_type",
")",
":",
"mapping",
"=",
"{",
"}",
"for",
"resource",
"in",
"autoload_details",
".",
"resources",
":",
"resource",
".",
"model",
"=",
"\"{shell_name}.{model}\"",
"."... | Migrate autoload details. Add namespace for attributes
:param autoload_details:
:param shell_name:
:param shell_type:
:return: | [
"Migrate",
"autoload",
"details",
".",
"Add",
"namespace",
"for",
"attributes"
] | train | https://github.com/QualiSystems/cloudshell-networking-devices/blob/009aab33edb30035b52fe10dbb91db61c95ba4d9/cloudshell/devices/autoload/autoload_migration_helper.py#L76-L99 |
QualiSystems/cloudshell-networking-devices | cloudshell/devices/standards/firewall/configuration_attributes_structure.py | create_firewall_resource_from_context | def create_firewall_resource_from_context(shell_name, supported_os, context):
"""
Creates an instance of Firewall Resource by given context
:param shell_name: Shell Name
:type shell_name: str
:param supported_os: list of supported OS
:type supported_os: list
:param context: cloudshell.shell.... | python | def create_firewall_resource_from_context(shell_name, supported_os, context):
"""
Creates an instance of Firewall Resource by given context
:param shell_name: Shell Name
:type shell_name: str
:param supported_os: list of supported OS
:type supported_os: list
:param context: cloudshell.shell.... | [
"def",
"create_firewall_resource_from_context",
"(",
"shell_name",
",",
"supported_os",
",",
"context",
")",
":",
"result",
"=",
"GenericFirewallResource",
"(",
"shell_name",
"=",
"shell_name",
",",
"name",
"=",
"context",
".",
"resource",
".",
"name",
",",
"suppo... | Creates an instance of Firewall Resource by given context
:param shell_name: Shell Name
:type shell_name: str
:param supported_os: list of supported OS
:type supported_os: list
:param context: cloudshell.shell.core.driver_context.ResourceCommandContext
:type context: cloudshell.shell.core.driver... | [
"Creates",
"an",
"instance",
"of",
"Firewall",
"Resource",
"by",
"given",
"context",
":",
"param",
"shell_name",
":",
"Shell",
"Name",
":",
"type",
"shell_name",
":",
"str",
":",
"param",
"supported_os",
":",
"list",
"of",
"supported",
"OS",
":",
"type",
"... | train | https://github.com/QualiSystems/cloudshell-networking-devices/blob/009aab33edb30035b52fe10dbb91db61c95ba4d9/cloudshell/devices/standards/firewall/configuration_attributes_structure.py#L213-L233 |
horejsek/python-sqlpuzzle | sqlpuzzle/_common/sqlvalue.py | SqlValue._get_convert_method | def _get_convert_method(self):
"""
Get right method to convert of the value.
"""
for type_, method in self._map.items():
if type(self.value) is bool and type_ is not bool:
continue
if isinstance(self.value, type_):
return method
... | python | def _get_convert_method(self):
"""
Get right method to convert of the value.
"""
for type_, method in self._map.items():
if type(self.value) is bool and type_ is not bool:
continue
if isinstance(self.value, type_):
return method
... | [
"def",
"_get_convert_method",
"(",
"self",
")",
":",
"for",
"type_",
",",
"method",
"in",
"self",
".",
"_map",
".",
"items",
"(",
")",
":",
"if",
"type",
"(",
"self",
".",
"value",
")",
"is",
"bool",
"and",
"type_",
"is",
"not",
"bool",
":",
"conti... | Get right method to convert of the value. | [
"Get",
"right",
"method",
"to",
"convert",
"of",
"the",
"value",
"."
] | train | https://github.com/horejsek/python-sqlpuzzle/blob/d3a42ed1b339b8eafddb8d2c28a3a5832b3998dd/sqlpuzzle/_common/sqlvalue.py#L68-L79 |
kmedian/korr | korr/flatten.py | flatten | def flatten(rho, pval, sortby="cor"):
"""Flatten correlation and p-value matrix
Parameters:
-----------
rho : ndarray
Correlation Matrix
pval : ndarray
Matrix with p-values
sortby : str
sort the output table by
- "cor" the highest absolute correlation coeffici... | python | def flatten(rho, pval, sortby="cor"):
"""Flatten correlation and p-value matrix
Parameters:
-----------
rho : ndarray
Correlation Matrix
pval : ndarray
Matrix with p-values
sortby : str
sort the output table by
- "cor" the highest absolute correlation coeffici... | [
"def",
"flatten",
"(",
"rho",
",",
"pval",
",",
"sortby",
"=",
"\"cor\"",
")",
":",
"n",
"=",
"rho",
".",
"shape",
"[",
"0",
"]",
"idx",
"=",
"np",
".",
"triu_indices",
"(",
"n",
",",
"k",
"=",
"1",
")",
"tab",
"=",
"pd",
".",
"DataFrame",
"(... | Flatten correlation and p-value matrix
Parameters:
-----------
rho : ndarray
Correlation Matrix
pval : ndarray
Matrix with p-values
sortby : str
sort the output table by
- "cor" the highest absolute correlation coefficient
- "pval" the lowest p-value
... | [
"Flatten",
"correlation",
"and",
"p",
"-",
"value",
"matrix"
] | train | https://github.com/kmedian/korr/blob/4eb86fc14b1fc1b69204069b7753d115b327c937/korr/flatten.py#L5-L48 |
wallento/riscv-python-model | riscvmodel/types.py | Immediate.max | def max(self) -> int:
"""
Get the maximum value this immediate can have
:return: Maximum value of this immediate
"""
if self.signed:
v = (1 << (self.bits - 1)) - 1
else:
v = (1 << self.bits) - 1
if self.lsb0:
v = v - (v % 2)
... | python | def max(self) -> int:
"""
Get the maximum value this immediate can have
:return: Maximum value of this immediate
"""
if self.signed:
v = (1 << (self.bits - 1)) - 1
else:
v = (1 << self.bits) - 1
if self.lsb0:
v = v - (v % 2)
... | [
"def",
"max",
"(",
"self",
")",
"->",
"int",
":",
"if",
"self",
".",
"signed",
":",
"v",
"=",
"(",
"1",
"<<",
"(",
"self",
".",
"bits",
"-",
"1",
")",
")",
"-",
"1",
"else",
":",
"v",
"=",
"(",
"1",
"<<",
"self",
".",
"bits",
")",
"-",
... | Get the maximum value this immediate can have
:return: Maximum value of this immediate | [
"Get",
"the",
"maximum",
"value",
"this",
"immediate",
"can",
"have"
] | train | https://github.com/wallento/riscv-python-model/blob/51df07d16b79b143eb3d3c1e95bf26030c64a39b/riscvmodel/types.py#L34-L46 |
wallento/riscv-python-model | riscvmodel/types.py | Immediate.set | def set(self, value: int):
"""
Set the immediate to a value. This function checks if the value is valid and will raise an
:class:`InvalidImmediateException` if it doesn't.
:param value: Value to set the immediate to
:type value: int
:raises InvalidImmediateException: va... | python | def set(self, value: int):
"""
Set the immediate to a value. This function checks if the value is valid and will raise an
:class:`InvalidImmediateException` if it doesn't.
:param value: Value to set the immediate to
:type value: int
:raises InvalidImmediateException: va... | [
"def",
"set",
"(",
"self",
",",
"value",
":",
"int",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"int",
")",
":",
"raise",
"self",
".",
"exception",
"(",
"\"{} is not an integer\"",
".",
"format",
"(",
"value",
")",
")",
"if",
"self",
"."... | Set the immediate to a value. This function checks if the value is valid and will raise an
:class:`InvalidImmediateException` if it doesn't.
:param value: Value to set the immediate to
:type value: int
:raises InvalidImmediateException: value does not match immediate | [
"Set",
"the",
"immediate",
"to",
"a",
"value",
".",
"This",
"function",
"checks",
"if",
"the",
"value",
"is",
"valid",
"and",
"will",
"raise",
"an",
":",
"class",
":",
"InvalidImmediateException",
"if",
"it",
"doesn",
"t",
"."
] | train | https://github.com/wallento/riscv-python-model/blob/51df07d16b79b143eb3d3c1e95bf26030c64a39b/riscvmodel/types.py#L64-L83 |
wallento/riscv-python-model | riscvmodel/types.py | Immediate.set_from_bits | def set_from_bits(self, value: int):
"""
Set the immediate value from machine code bits. Those are not sign extended, so it will take care of the
proper handling.
:param value: Value to set the immediate to
:type value: int
"""
if self.signed:
value =... | python | def set_from_bits(self, value: int):
"""
Set the immediate value from machine code bits. Those are not sign extended, so it will take care of the
proper handling.
:param value: Value to set the immediate to
:type value: int
"""
if self.signed:
value =... | [
"def",
"set_from_bits",
"(",
"self",
",",
"value",
":",
"int",
")",
":",
"if",
"self",
".",
"signed",
":",
"value",
"=",
"-",
"(",
"value",
"&",
"self",
".",
"tcmask",
")",
"+",
"(",
"value",
"&",
"~",
"self",
".",
"tcmask",
")",
"self",
".",
"... | Set the immediate value from machine code bits. Those are not sign extended, so it will take care of the
proper handling.
:param value: Value to set the immediate to
:type value: int | [
"Set",
"the",
"immediate",
"value",
"from",
"machine",
"code",
"bits",
".",
"Those",
"are",
"not",
"sign",
"extended",
"so",
"it",
"will",
"take",
"care",
"of",
"the",
"proper",
"handling",
"."
] | train | https://github.com/wallento/riscv-python-model/blob/51df07d16b79b143eb3d3c1e95bf26030c64a39b/riscvmodel/types.py#L85-L95 |
wallento/riscv-python-model | riscvmodel/types.py | Immediate.randomize | def randomize(self):
"""
Randomize this immediate to a legal value
"""
self.value = randint(self.min(), self.max())
if self.lsb0:
self.value = self.value - (self.value % 2) | python | def randomize(self):
"""
Randomize this immediate to a legal value
"""
self.value = randint(self.min(), self.max())
if self.lsb0:
self.value = self.value - (self.value % 2) | [
"def",
"randomize",
"(",
"self",
")",
":",
"self",
".",
"value",
"=",
"randint",
"(",
"self",
".",
"min",
"(",
")",
",",
"self",
".",
"max",
"(",
")",
")",
"if",
"self",
".",
"lsb0",
":",
"self",
".",
"value",
"=",
"self",
".",
"value",
"-",
... | Randomize this immediate to a legal value | [
"Randomize",
"this",
"immediate",
"to",
"a",
"legal",
"value"
] | train | https://github.com/wallento/riscv-python-model/blob/51df07d16b79b143eb3d3c1e95bf26030c64a39b/riscvmodel/types.py#L97-L103 |
Workiva/furious | furious/context/_local.py | _init | def _init():
"""Initialize the furious context and registry.
NOTE: Do not directly run this method.
"""
# If there is a context and it is initialized to this request,
# return, otherwise reinitialize the _local_context.
if (hasattr(_local_context, '_initialized') and
_local_context.... | python | def _init():
"""Initialize the furious context and registry.
NOTE: Do not directly run this method.
"""
# If there is a context and it is initialized to this request,
# return, otherwise reinitialize the _local_context.
if (hasattr(_local_context, '_initialized') and
_local_context.... | [
"def",
"_init",
"(",
")",
":",
"# If there is a context and it is initialized to this request,",
"# return, otherwise reinitialize the _local_context.",
"if",
"(",
"hasattr",
"(",
"_local_context",
",",
"'_initialized'",
")",
"and",
"_local_context",
".",
"_initialized",
"==",
... | Initialize the furious context and registry.
NOTE: Do not directly run this method. | [
"Initialize",
"the",
"furious",
"context",
"and",
"registry",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/furious/context/_local.py#L50-L71 |
Workiva/furious | furious/processors.py | run_job | def run_job():
"""Takes an async object and executes its job."""
async = get_current_async()
async_options = async.get_options()
job = async_options.get('job')
if not job:
raise Exception('This async contains no job to execute!')
__, args, kwargs = job
if args is None:
arg... | python | def run_job():
"""Takes an async object and executes its job."""
async = get_current_async()
async_options = async.get_options()
job = async_options.get('job')
if not job:
raise Exception('This async contains no job to execute!')
__, args, kwargs = job
if args is None:
arg... | [
"def",
"run_job",
"(",
")",
":",
"async",
"=",
"get_current_async",
"(",
")",
"async_options",
"=",
"async",
".",
"get_options",
"(",
")",
"job",
"=",
"async_options",
".",
"get",
"(",
"'job'",
")",
"if",
"not",
"job",
":",
"raise",
"Exception",
"(",
"... | Takes an async object and executes its job. | [
"Takes",
"an",
"async",
"object",
"and",
"executes",
"its",
"job",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/furious/processors.py#L36-L75 |
Workiva/furious | furious/processors.py | _handle_results | def _handle_results(options):
"""Process the results of executing the Async's target."""
results_processor = options.get('_process_results')
if not results_processor:
results_processor = _process_results
processor_result = results_processor()
if isinstance(processor_result, (Async, Context)... | python | def _handle_results(options):
"""Process the results of executing the Async's target."""
results_processor = options.get('_process_results')
if not results_processor:
results_processor = _process_results
processor_result = results_processor()
if isinstance(processor_result, (Async, Context)... | [
"def",
"_handle_results",
"(",
"options",
")",
":",
"results_processor",
"=",
"options",
".",
"get",
"(",
"'_process_results'",
")",
"if",
"not",
"results_processor",
":",
"results_processor",
"=",
"_process_results",
"processor_result",
"=",
"results_processor",
"(",... | Process the results of executing the Async's target. | [
"Process",
"the",
"results",
"of",
"executing",
"the",
"Async",
"s",
"target",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/furious/processors.py#L78-L86 |
Workiva/furious | furious/processors.py | encode_exception | def encode_exception(exception):
"""Encode exception to a form that can be passed around and serialized.
This will grab the stack, then strip off the last two calls which are
encode_exception and the function that called it.
"""
import sys
return AsyncException(unicode(exception),
... | python | def encode_exception(exception):
"""Encode exception to a form that can be passed around and serialized.
This will grab the stack, then strip off the last two calls which are
encode_exception and the function that called it.
"""
import sys
return AsyncException(unicode(exception),
... | [
"def",
"encode_exception",
"(",
"exception",
")",
":",
"import",
"sys",
"return",
"AsyncException",
"(",
"unicode",
"(",
"exception",
")",
",",
"exception",
".",
"args",
",",
"sys",
".",
"exc_info",
"(",
")",
",",
"exception",
")"
] | Encode exception to a form that can be passed around and serialized.
This will grab the stack, then strip off the last two calls which are
encode_exception and the function that called it. | [
"Encode",
"exception",
"to",
"a",
"form",
"that",
"can",
"be",
"passed",
"around",
"and",
"serialized",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/furious/processors.py#L100-L110 |
Workiva/furious | furious/processors.py | _process_results | def _process_results():
"""Process the results from an Async job."""
async = get_current_async()
callbacks = async.get_callbacks()
if not isinstance(async.result.payload, AsyncException):
callback = callbacks.get('success')
else:
callback = callbacks.get('error')
if not cal... | python | def _process_results():
"""Process the results from an Async job."""
async = get_current_async()
callbacks = async.get_callbacks()
if not isinstance(async.result.payload, AsyncException):
callback = callbacks.get('success')
else:
callback = callbacks.get('error')
if not cal... | [
"def",
"_process_results",
"(",
")",
":",
"async",
"=",
"get_current_async",
"(",
")",
"callbacks",
"=",
"async",
".",
"get_callbacks",
"(",
")",
"if",
"not",
"isinstance",
"(",
"async",
".",
"result",
".",
"payload",
",",
"AsyncException",
")",
":",
"call... | Process the results from an Async job. | [
"Process",
"the",
"results",
"from",
"an",
"Async",
"job",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/furious/processors.py#L113-L127 |
Workiva/furious | furious/processors.py | _execute_callback | def _execute_callback(async, callback):
"""Execute the given callback or insert the Async callback, or if no
callback is given return the async.result.
"""
from furious.async import Async
if not callback:
return async.result.payload
if isinstance(callback, Async):
return callba... | python | def _execute_callback(async, callback):
"""Execute the given callback or insert the Async callback, or if no
callback is given return the async.result.
"""
from furious.async import Async
if not callback:
return async.result.payload
if isinstance(callback, Async):
return callba... | [
"def",
"_execute_callback",
"(",
"async",
",",
"callback",
")",
":",
"from",
"furious",
".",
"async",
"import",
"Async",
"if",
"not",
"callback",
":",
"return",
"async",
".",
"result",
".",
"payload",
"if",
"isinstance",
"(",
"callback",
",",
"Async",
")",... | Execute the given callback or insert the Async callback, or if no
callback is given return the async.result. | [
"Execute",
"the",
"given",
"callback",
"or",
"insert",
"the",
"Async",
"callback",
"or",
"if",
"no",
"callback",
"is",
"given",
"return",
"the",
"async",
".",
"result",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/furious/processors.py#L130-L142 |
Workiva/furious | example/complex_workflow.py | complex_state_generator_bravo | def complex_state_generator_bravo(last_state=''):
"""Pick a state."""
from random import choice
states = ['ALPHA', 'BRAVO', 'BRAVO', 'DONE']
if last_state:
states.remove(last_state) # Slightly lower chances of previous state.
state = choice(states)
logging.info('Generating a state...... | python | def complex_state_generator_bravo(last_state=''):
"""Pick a state."""
from random import choice
states = ['ALPHA', 'BRAVO', 'BRAVO', 'DONE']
if last_state:
states.remove(last_state) # Slightly lower chances of previous state.
state = choice(states)
logging.info('Generating a state...... | [
"def",
"complex_state_generator_bravo",
"(",
"last_state",
"=",
"''",
")",
":",
"from",
"random",
"import",
"choice",
"states",
"=",
"[",
"'ALPHA'",
",",
"'BRAVO'",
",",
"'BRAVO'",
",",
"'DONE'",
"]",
"if",
"last_state",
":",
"states",
".",
"remove",
"(",
... | Pick a state. | [
"Pick",
"a",
"state",
"."
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/example/complex_workflow.py#L61-L73 |
Workiva/furious | example/complex_workflow.py | state_machine_success | def state_machine_success():
"""A positive result! Iterate!"""
from furious.async import Async
from furious.context import get_current_async
result = get_current_async().result
if result == 'ALPHA':
logging.info('Inserting continuation for state %s.', result)
return Async(target=c... | python | def state_machine_success():
"""A positive result! Iterate!"""
from furious.async import Async
from furious.context import get_current_async
result = get_current_async().result
if result == 'ALPHA':
logging.info('Inserting continuation for state %s.', result)
return Async(target=c... | [
"def",
"state_machine_success",
"(",
")",
":",
"from",
"furious",
".",
"async",
"import",
"Async",
"from",
"furious",
".",
"context",
"import",
"get_current_async",
"result",
"=",
"get_current_async",
"(",
")",
".",
"result",
"if",
"result",
"==",
"'ALPHA'",
"... | A positive result! Iterate! | [
"A",
"positive",
"result!",
"Iterate!"
] | train | https://github.com/Workiva/furious/blob/c29823ec8b98549e7439d7273aa064d1e5830632/example/complex_workflow.py#L76-L91 |
upsight/doctor | doctor/docs/base.py | get_example_curl_lines | def get_example_curl_lines(method: str, url: str, params: dict,
headers: dict) -> List[str]:
"""Render a cURL command for the given request.
:param str method: HTTP request method (e.g. "GET").
:param str url: HTTP request URL.
:param dict params: JSON body, for POST and PUT ... | python | def get_example_curl_lines(method: str, url: str, params: dict,
headers: dict) -> List[str]:
"""Render a cURL command for the given request.
:param str method: HTTP request method (e.g. "GET").
:param str url: HTTP request URL.
:param dict params: JSON body, for POST and PUT ... | [
"def",
"get_example_curl_lines",
"(",
"method",
":",
"str",
",",
"url",
":",
"str",
",",
"params",
":",
"dict",
",",
"headers",
":",
"dict",
")",
"->",
"List",
"[",
"str",
"]",
":",
"parts",
"=",
"[",
"'curl {}'",
".",
"format",
"(",
"pipes",
".",
... | Render a cURL command for the given request.
:param str method: HTTP request method (e.g. "GET").
:param str url: HTTP request URL.
:param dict params: JSON body, for POST and PUT requests.
:param dict headers: A dict of HTTP headers.
:returns: list | [
"Render",
"a",
"cURL",
"command",
"for",
"the",
"given",
"request",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/docs/base.py#L62-L94 |
upsight/doctor | doctor/docs/base.py | get_example_lines | def get_example_lines(headers: Dict[str, str], method: str, url: str,
params: Dict[str, Any], response: str) -> List[str]:
"""Render a reStructuredText example for the given request and response.
:param dict headers: A dict of HTTP headers.
:param str method: HTTP request method (e.g.... | python | def get_example_lines(headers: Dict[str, str], method: str, url: str,
params: Dict[str, Any], response: str) -> List[str]:
"""Render a reStructuredText example for the given request and response.
:param dict headers: A dict of HTTP headers.
:param str method: HTTP request method (e.g.... | [
"def",
"get_example_lines",
"(",
"headers",
":",
"Dict",
"[",
"str",
",",
"str",
"]",
",",
"method",
":",
"str",
",",
"url",
":",
"str",
",",
"params",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
",",
"response",
":",
"str",
")",
"->",
"List",
"[",... | Render a reStructuredText example for the given request and response.
:param dict headers: A dict of HTTP headers.
:param str method: HTTP request method (e.g. "GET").
:param str url: HTTP request URL.
:param dict params: Form parameters, for POST and PUT requests.
:param str response: Text respons... | [
"Render",
"a",
"reStructuredText",
"example",
"for",
"the",
"given",
"request",
"and",
"response",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/docs/base.py#L97-L121 |
upsight/doctor | doctor/docs/base.py | get_object_reference | def get_object_reference(obj: Object) -> str:
"""Gets an object reference string from the obj instance.
This adds the object type to ALL_RESOURCES so that it gets documented and
returns a str which contains a sphinx reference to the documented object.
:param obj: The Object instance.
:returns: A s... | python | def get_object_reference(obj: Object) -> str:
"""Gets an object reference string from the obj instance.
This adds the object type to ALL_RESOURCES so that it gets documented and
returns a str which contains a sphinx reference to the documented object.
:param obj: The Object instance.
:returns: A s... | [
"def",
"get_object_reference",
"(",
"obj",
":",
"Object",
")",
"->",
"str",
":",
"resource_name",
"=",
"obj",
".",
"title",
"if",
"resource_name",
"is",
"None",
":",
"class_name",
"=",
"obj",
".",
"__name__",
"resource_name",
"=",
"class_name_to_resource_name",
... | Gets an object reference string from the obj instance.
This adds the object type to ALL_RESOURCES so that it gets documented and
returns a str which contains a sphinx reference to the documented object.
:param obj: The Object instance.
:returns: A sphinx docs reference str. | [
"Gets",
"an",
"object",
"reference",
"string",
"from",
"the",
"obj",
"instance",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/docs/base.py#L124-L139 |
upsight/doctor | doctor/docs/base.py | get_array_items_description | def get_array_items_description(item: Array) -> str:
"""Returns a description for an array's items.
:param item: The Array type whose items should be documented.
:returns: A string documenting what type the array's items should be.
"""
desc = ''
if isinstance(item.items, list):
# This m... | python | def get_array_items_description(item: Array) -> str:
"""Returns a description for an array's items.
:param item: The Array type whose items should be documented.
:returns: A string documenting what type the array's items should be.
"""
desc = ''
if isinstance(item.items, list):
# This m... | [
"def",
"get_array_items_description",
"(",
"item",
":",
"Array",
")",
"->",
"str",
":",
"desc",
"=",
"''",
"if",
"isinstance",
"(",
"item",
".",
"items",
",",
"list",
")",
":",
"# This means the type has a list of types where each position is",
"# mapped to a differen... | Returns a description for an array's items.
:param item: The Array type whose items should be documented.
:returns: A string documenting what type the array's items should be. | [
"Returns",
"a",
"description",
"for",
"an",
"array",
"s",
"items",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/docs/base.py#L142-L185 |
upsight/doctor | doctor/docs/base.py | get_json_types | def get_json_types(annotated_type: SuperType) -> List[str]:
"""Returns the json types for the provided annotated type.
This handles special cases for when we encounter UnionType and an Array.
UnionType's will have all valid types returned. An Array will document
what the items type is by placing that ... | python | def get_json_types(annotated_type: SuperType) -> List[str]:
"""Returns the json types for the provided annotated type.
This handles special cases for when we encounter UnionType and an Array.
UnionType's will have all valid types returned. An Array will document
what the items type is by placing that ... | [
"def",
"get_json_types",
"(",
"annotated_type",
":",
"SuperType",
")",
"->",
"List",
"[",
"str",
"]",
":",
"types",
"=",
"[",
"]",
"if",
"issubclass",
"(",
"annotated_type",
",",
"UnionType",
")",
":",
"types",
"=",
"[",
"str",
"(",
"t",
".",
"native_t... | Returns the json types for the provided annotated type.
This handles special cases for when we encounter UnionType and an Array.
UnionType's will have all valid types returned. An Array will document
what the items type is by placing that value in brackets, e.g. `list[str]`.
:param annotated_type: A ... | [
"Returns",
"the",
"json",
"types",
"for",
"the",
"provided",
"annotated",
"type",
"."
] | train | https://github.com/upsight/doctor/blob/2cf1d433f6f1aa1355644b449a757c0660793cdd/doctor/docs/base.py#L188-L218 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.