repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
swimlane/swimlane-python | swimlane/core/client.py | Swimlane.product_version | def product_version(self):
"""Swimlane product version"""
version_separator = '+'
if version_separator in self.version:
# Post product/build version separation
return self.version.split(version_separator)[0]
# Pre product/build version separation
return se... | python | def product_version(self):
"""Swimlane product version"""
version_separator = '+'
if version_separator in self.version:
# Post product/build version separation
return self.version.split(version_separator)[0]
# Pre product/build version separation
return se... | [
"def",
"product_version",
"(",
"self",
")",
":",
"version_separator",
"=",
"'+'",
"if",
"version_separator",
"in",
"self",
".",
"version",
":",
"return",
"self",
".",
"version",
".",
"split",
"(",
"version_separator",
")",
"[",
"0",
"]",
"return",
"self",
... | Swimlane product version | [
"Swimlane",
"product",
"version"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/client.py#L241-L248 | train |
swimlane/swimlane-python | swimlane/core/client.py | Swimlane.build_number | def build_number(self):
"""Swimlane build number"""
version_separator = '+'
if version_separator in self.version:
# Post product/build version separation
return self.version.split(version_separator)[2]
# Pre product/build version separation
return self.ver... | python | def build_number(self):
"""Swimlane build number"""
version_separator = '+'
if version_separator in self.version:
# Post product/build version separation
return self.version.split(version_separator)[2]
# Pre product/build version separation
return self.ver... | [
"def",
"build_number",
"(",
"self",
")",
":",
"version_separator",
"=",
"'+'",
"if",
"version_separator",
"in",
"self",
".",
"version",
":",
"return",
"self",
".",
"version",
".",
"split",
"(",
"version_separator",
")",
"[",
"2",
"]",
"return",
"self",
"."... | Swimlane build number | [
"Swimlane",
"build",
"number"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/client.py#L264-L271 | train |
swimlane/swimlane-python | swimlane/core/client.py | SwimlaneJwtAuth.authenticate | def authenticate(self):
"""Send login request and update User instance, login headers, and token expiration"""
# Temporarily remove auth from Swimlane session for auth request to avoid recursive loop during login request
self._swimlane._session.auth = None
resp = self._swimlane.request(... | python | def authenticate(self):
"""Send login request and update User instance, login headers, and token expiration"""
# Temporarily remove auth from Swimlane session for auth request to avoid recursive loop during login request
self._swimlane._session.auth = None
resp = self._swimlane.request(... | [
"def",
"authenticate",
"(",
"self",
")",
":",
"self",
".",
"_swimlane",
".",
"_session",
".",
"auth",
"=",
"None",
"resp",
"=",
"self",
".",
"_swimlane",
".",
"request",
"(",
"'post'",
",",
"'user/login'",
",",
"json",
"=",
"{",
"'userName'",
":",
"sel... | Send login request and update User instance, login headers, and token expiration | [
"Send",
"login",
"request",
"and",
"update",
"User",
"instance",
"login",
"headers",
"and",
"token",
"expiration"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/client.py#L349-L381 | train |
swimlane/swimlane-python | swimlane/core/cursor.py | PaginatedCursor._evaluate | def _evaluate(self):
"""Lazily retrieve and paginate report results and build Record instances from returned data"""
if self._elements:
for element in self._elements:
yield element
else:
for page in itertools.count():
raw_elements = self._r... | python | def _evaluate(self):
"""Lazily retrieve and paginate report results and build Record instances from returned data"""
if self._elements:
for element in self._elements:
yield element
else:
for page in itertools.count():
raw_elements = self._r... | [
"def",
"_evaluate",
"(",
"self",
")",
":",
"if",
"self",
".",
"_elements",
":",
"for",
"element",
"in",
"self",
".",
"_elements",
":",
"yield",
"element",
"else",
":",
"for",
"page",
"in",
"itertools",
".",
"count",
"(",
")",
":",
"raw_elements",
"=",
... | Lazily retrieve and paginate report results and build Record instances from returned data | [
"Lazily",
"retrieve",
"and",
"paginate",
"report",
"results",
"and",
"build",
"Record",
"instances",
"from",
"returned",
"data"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/cursor.py#L44-L64 | train |
swimlane/swimlane-python | swimlane/core/fields/usergroup.py | UserGroupField._validate_user | def _validate_user(self, user):
"""Validate a User instance against allowed user IDs or membership in a group"""
# All users allowed
if self._show_all_users:
return
# User specifically allowed
if user.id in self._allowed_user_ids:
return
# User a... | python | def _validate_user(self, user):
"""Validate a User instance against allowed user IDs or membership in a group"""
# All users allowed
if self._show_all_users:
return
# User specifically allowed
if user.id in self._allowed_user_ids:
return
# User a... | [
"def",
"_validate_user",
"(",
"self",
",",
"user",
")",
":",
"if",
"self",
".",
"_show_all_users",
":",
"return",
"if",
"user",
".",
"id",
"in",
"self",
".",
"_allowed_user_ids",
":",
"return",
"user_member_group_ids",
"=",
"set",
"(",
"[",
"g",
"[",
"'i... | Validate a User instance against allowed user IDs or membership in a group | [
"Validate",
"a",
"User",
"instance",
"against",
"allowed",
"user",
"IDs",
"or",
"membership",
"in",
"a",
"group"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/usergroup.py#L56-L77 | train |
swimlane/swimlane-python | swimlane/core/fields/usergroup.py | UserGroupField._validate_group | def _validate_group(self, group):
"""Validate a Group instance against allowed group IDs or subgroup of a parent group"""
# All groups allowed
if self._show_all_groups:
return
# Group specifically allowed
if group.id in self._allowed_group_ids:
return
... | python | def _validate_group(self, group):
"""Validate a Group instance against allowed group IDs or subgroup of a parent group"""
# All groups allowed
if self._show_all_groups:
return
# Group specifically allowed
if group.id in self._allowed_group_ids:
return
... | [
"def",
"_validate_group",
"(",
"self",
",",
"group",
")",
":",
"if",
"self",
".",
"_show_all_groups",
":",
"return",
"if",
"group",
".",
"id",
"in",
"self",
".",
"_allowed_group_ids",
":",
"return",
"for",
"parent_group_id",
"in",
"self",
".",
"_allowed_subg... | Validate a Group instance against allowed group IDs or subgroup of a parent group | [
"Validate",
"a",
"Group",
"instance",
"against",
"allowed",
"group",
"IDs",
"or",
"subgroup",
"of",
"a",
"parent",
"group"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/usergroup.py#L79-L103 | train |
swimlane/swimlane-python | swimlane/core/fields/usergroup.py | UserGroupField.cast_to_python | def cast_to_python(self, value):
"""Convert JSON definition to UserGroup object"""
# v2.x does not provide a distinction between users and groups at the field selection level, can only return
# UserGroup instances instead of specific User or Group instances
if value is not None:
... | python | def cast_to_python(self, value):
"""Convert JSON definition to UserGroup object"""
# v2.x does not provide a distinction between users and groups at the field selection level, can only return
# UserGroup instances instead of specific User or Group instances
if value is not None:
... | [
"def",
"cast_to_python",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"value",
"=",
"UserGroup",
"(",
"self",
".",
"_swimlane",
",",
"value",
")",
"return",
"value"
] | Convert JSON definition to UserGroup object | [
"Convert",
"JSON",
"definition",
"to",
"UserGroup",
"object"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/usergroup.py#L112-L119 | train |
swimlane/swimlane-python | swimlane/core/fields/base/cursor.py | CursorField.cursor | def cursor(self):
"""Cache and return cursor_class instance"""
if self._cursor is None:
# pylint: disable=not-callable
self._cursor = self.cursor_class(self, self.get_initial_elements())
return self._cursor | python | def cursor(self):
"""Cache and return cursor_class instance"""
if self._cursor is None:
# pylint: disable=not-callable
self._cursor = self.cursor_class(self, self.get_initial_elements())
return self._cursor | [
"def",
"cursor",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cursor",
"is",
"None",
":",
"self",
".",
"_cursor",
"=",
"self",
".",
"cursor_class",
"(",
"self",
",",
"self",
".",
"get_initial_elements",
"(",
")",
")",
"return",
"self",
".",
"_cursor"
] | Cache and return cursor_class instance | [
"Cache",
"and",
"return",
"cursor_class",
"instance"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/cursor.py#L72-L78 | train |
swimlane/swimlane-python | swimlane/core/fields/comment.py | CommentCursor.comment | def comment(self, message):
"""Add new comment to record comment field"""
message = str(message)
sw_repr = {
'$type': 'Core.Models.Record.Comments, Core',
'createdByUser': self._record._swimlane.user.as_usergroup_selection(),
'createdDate': pendulum.now().to_... | python | def comment(self, message):
"""Add new comment to record comment field"""
message = str(message)
sw_repr = {
'$type': 'Core.Models.Record.Comments, Core',
'createdByUser': self._record._swimlane.user.as_usergroup_selection(),
'createdDate': pendulum.now().to_... | [
"def",
"comment",
"(",
"self",
",",
"message",
")",
":",
"message",
"=",
"str",
"(",
"message",
")",
"sw_repr",
"=",
"{",
"'$type'",
":",
"'Core.Models.Record.Comments, Core'",
",",
"'createdByUser'",
":",
"self",
".",
"_record",
".",
"_swimlane",
".",
"user... | Add new comment to record comment field | [
"Add",
"new",
"comment",
"to",
"record",
"comment",
"field"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/comment.py#L10-L27 | train |
swimlane/swimlane-python | swimlane/utils/__init__.py | get_recursive_subclasses | def get_recursive_subclasses(cls):
"""Return list of all subclasses for a class, including subclasses of direct subclasses"""
return cls.__subclasses__() + [g for s in cls.__subclasses__() for g in get_recursive_subclasses(s)] | python | def get_recursive_subclasses(cls):
"""Return list of all subclasses for a class, including subclasses of direct subclasses"""
return cls.__subclasses__() + [g for s in cls.__subclasses__() for g in get_recursive_subclasses(s)] | [
"def",
"get_recursive_subclasses",
"(",
"cls",
")",
":",
"return",
"cls",
".",
"__subclasses__",
"(",
")",
"+",
"[",
"g",
"for",
"s",
"in",
"cls",
".",
"__subclasses__",
"(",
")",
"for",
"g",
"in",
"get_recursive_subclasses",
"(",
"s",
")",
"]"
] | Return list of all subclasses for a class, including subclasses of direct subclasses | [
"Return",
"list",
"of",
"all",
"subclasses",
"for",
"a",
"class",
"including",
"subclasses",
"of",
"direct",
"subclasses"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/utils/__init__.py#L24-L26 | train |
swimlane/swimlane-python | swimlane/utils/__init__.py | import_submodules | def import_submodules(package):
"""Return list of imported module instances from beneath root_package"""
if isinstance(package, str):
package = importlib.import_module(package)
results = {}
for _, full_name, is_pkg in pkgutil.walk_packages(package.__path__, package.__name__ + '.'):
re... | python | def import_submodules(package):
"""Return list of imported module instances from beneath root_package"""
if isinstance(package, str):
package = importlib.import_module(package)
results = {}
for _, full_name, is_pkg in pkgutil.walk_packages(package.__path__, package.__name__ + '.'):
re... | [
"def",
"import_submodules",
"(",
"package",
")",
":",
"if",
"isinstance",
"(",
"package",
",",
"str",
")",
":",
"package",
"=",
"importlib",
".",
"import_module",
"(",
"package",
")",
"results",
"=",
"{",
"}",
"for",
"_",
",",
"full_name",
",",
"is_pkg",... | Return list of imported module instances from beneath root_package | [
"Return",
"list",
"of",
"imported",
"module",
"instances",
"from",
"beneath",
"root_package"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/utils/__init__.py#L29-L43 | train |
swimlane/swimlane-python | swimlane/utils/__init__.py | one_of_keyword_only | def one_of_keyword_only(*valid_keywords):
"""Decorator to help make one-and-only-one keyword-only argument functions more reusable
Notes:
Decorated function should take 2 arguments, the first for the key, the second the value
Examples:
::
@one_of_keyword_only('a', 'b', 'c')
... | python | def one_of_keyword_only(*valid_keywords):
"""Decorator to help make one-and-only-one keyword-only argument functions more reusable
Notes:
Decorated function should take 2 arguments, the first for the key, the second the value
Examples:
::
@one_of_keyword_only('a', 'b', 'c')
... | [
"def",
"one_of_keyword_only",
"(",
"*",
"valid_keywords",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"sentinel",
"=",
"object... | Decorator to help make one-and-only-one keyword-only argument functions more reusable
Notes:
Decorated function should take 2 arguments, the first for the key, the second the value
Examples:
::
@one_of_keyword_only('a', 'b', 'c')
def func(key, value):
... | [
"Decorator",
"to",
"help",
"make",
"one",
"-",
"and",
"-",
"only",
"-",
"one",
"keyword",
"-",
"only",
"argument",
"functions",
"more",
"reusable"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/utils/__init__.py#L46-L117 | train |
swimlane/swimlane-python | swimlane/core/fields/datetime.py | DatetimeField.get_python | def get_python(self):
"""Coerce to best date type representation for the field subtype"""
value = super(DatetimeField, self).get_python()
if value is not None:
# Handle subtypes with matching Pendulum types
if self.input_type == self._type_time:
value = v... | python | def get_python(self):
"""Coerce to best date type representation for the field subtype"""
value = super(DatetimeField, self).get_python()
if value is not None:
# Handle subtypes with matching Pendulum types
if self.input_type == self._type_time:
value = v... | [
"def",
"get_python",
"(",
"self",
")",
":",
"value",
"=",
"super",
"(",
"DatetimeField",
",",
"self",
")",
".",
"get_python",
"(",
")",
"if",
"value",
"is",
"not",
"None",
":",
"if",
"self",
".",
"input_type",
"==",
"self",
".",
"_type_time",
":",
"v... | Coerce to best date type representation for the field subtype | [
"Coerce",
"to",
"best",
"date",
"type",
"representation",
"for",
"the",
"field",
"subtype"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/datetime.py#L68-L79 | train |
swimlane/swimlane-python | swimlane/core/fields/datetime.py | DatetimeField.cast_to_swimlane | def cast_to_swimlane(self, value):
"""Return datetimes formatted as expected by API and timespans as millisecond epochs"""
if value is None:
return value
if self.input_type == self._type_interval:
return value.in_seconds() * 1000
return self.format_datetime(valu... | python | def cast_to_swimlane(self, value):
"""Return datetimes formatted as expected by API and timespans as millisecond epochs"""
if value is None:
return value
if self.input_type == self._type_interval:
return value.in_seconds() * 1000
return self.format_datetime(valu... | [
"def",
"cast_to_swimlane",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"value",
"if",
"self",
".",
"input_type",
"==",
"self",
".",
"_type_interval",
":",
"return",
"value",
".",
"in_seconds",
"(",
")",
"*",
"1000",
... | Return datetimes formatted as expected by API and timespans as millisecond epochs | [
"Return",
"datetimes",
"formatted",
"as",
"expected",
"by",
"API",
"and",
"timespans",
"as",
"millisecond",
"epochs"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/datetime.py#L86-L94 | train |
swimlane/swimlane-python | swimlane/core/fields/datetime.py | DatetimeField.for_json | def for_json(self):
"""Return date ISO8601 string formats for datetime, date, and time values, milliseconds for intervals"""
value = super(DatetimeField, self).for_json()
# Order of instance checks matters for proper inheritance checks
if isinstance(value, pendulum.Interval):
... | python | def for_json(self):
"""Return date ISO8601 string formats for datetime, date, and time values, milliseconds for intervals"""
value = super(DatetimeField, self).for_json()
# Order of instance checks matters for proper inheritance checks
if isinstance(value, pendulum.Interval):
... | [
"def",
"for_json",
"(",
"self",
")",
":",
"value",
"=",
"super",
"(",
"DatetimeField",
",",
"self",
")",
".",
"for_json",
"(",
")",
"if",
"isinstance",
"(",
"value",
",",
"pendulum",
".",
"Interval",
")",
":",
"return",
"value",
".",
"in_seconds",
"(",... | Return date ISO8601 string formats for datetime, date, and time values, milliseconds for intervals | [
"Return",
"date",
"ISO8601",
"string",
"formats",
"for",
"datetime",
"date",
"and",
"time",
"values",
"milliseconds",
"for",
"intervals"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/datetime.py#L96-L108 | train |
swimlane/swimlane-python | swimlane/core/resources/report.py | report_factory | def report_factory(app, report_name, **kwargs):
"""Report instance factory populating boilerplate raw data
Args:
app (App): Swimlane App instance
report_name (str): Generated Report name
Keyword Args
**kwargs: Kwargs to pass to the Report class
"""
# pylint: disable=protect... | python | def report_factory(app, report_name, **kwargs):
"""Report instance factory populating boilerplate raw data
Args:
app (App): Swimlane App instance
report_name (str): Generated Report name
Keyword Args
**kwargs: Kwargs to pass to the Report class
"""
# pylint: disable=protect... | [
"def",
"report_factory",
"(",
"app",
",",
"report_name",
",",
"**",
"kwargs",
")",
":",
"created",
"=",
"pendulum",
".",
"now",
"(",
")",
".",
"to_rfc3339_string",
"(",
")",
"user_model",
"=",
"app",
".",
"_swimlane",
".",
"user",
".",
"as_usergroup_select... | Report instance factory populating boilerplate raw data
Args:
app (App): Swimlane App instance
report_name (str): Generated Report name
Keyword Args
**kwargs: Kwargs to pass to the Report class | [
"Report",
"instance",
"factory",
"populating",
"boilerplate",
"raw",
"data"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/resources/report.py#L113-L156 | train |
swimlane/swimlane-python | swimlane/core/resources/report.py | Report.filter | def filter(self, field_name, operand, value):
"""Adds a filter to report
Notes:
All filters are currently AND'ed together
Args:
field_name (str): Target field name to filter on
operand (str): Operand used in comparison. See `swimlane.core.search` for options... | python | def filter(self, field_name, operand, value):
"""Adds a filter to report
Notes:
All filters are currently AND'ed together
Args:
field_name (str): Target field name to filter on
operand (str): Operand used in comparison. See `swimlane.core.search` for options... | [
"def",
"filter",
"(",
"self",
",",
"field_name",
",",
"operand",
",",
"value",
")",
":",
"if",
"operand",
"not",
"in",
"self",
".",
"_FILTER_OPERANDS",
":",
"raise",
"ValueError",
"(",
"'Operand must be one of {}'",
".",
"format",
"(",
"', '",
".",
"join",
... | Adds a filter to report
Notes:
All filters are currently AND'ed together
Args:
field_name (str): Target field name to filter on
operand (str): Operand used in comparison. See `swimlane.core.search` for options
value: Target value used in comparision | [
"Adds",
"a",
"filter",
"to",
"report"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/resources/report.py#L88-L110 | train |
swimlane/swimlane-python | swimlane/core/adapters/report.py | ReportAdapter.list | def list(self):
"""Retrieve all reports for parent app
Returns:
:class:`list` of :class:`~swimlane.core.resources.report.Report`: List of all returned reports
"""
raw_reports = self._swimlane.request('get', "reports?appId={}".format(self._app.id)).json()
# Ignore Sta... | python | def list(self):
"""Retrieve all reports for parent app
Returns:
:class:`list` of :class:`~swimlane.core.resources.report.Report`: List of all returned reports
"""
raw_reports = self._swimlane.request('get', "reports?appId={}".format(self._app.id)).json()
# Ignore Sta... | [
"def",
"list",
"(",
"self",
")",
":",
"raw_reports",
"=",
"self",
".",
"_swimlane",
".",
"request",
"(",
"'get'",
",",
"\"reports?appId={}\"",
".",
"format",
"(",
"self",
".",
"_app",
".",
"id",
")",
")",
".",
"json",
"(",
")",
"return",
"[",
"Report... | Retrieve all reports for parent app
Returns:
:class:`list` of :class:`~swimlane.core.resources.report.Report`: List of all returned reports | [
"Retrieve",
"all",
"reports",
"for",
"parent",
"app"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/report.py#L20-L28 | train |
swimlane/swimlane-python | swimlane/core/adapters/report.py | ReportAdapter.get | def get(self, report_id):
"""Retrieve report by ID
Args:
report_id (str): Full report ID
Returns:
Report: Corresponding Report instance
"""
return Report(
self._app,
self._swimlane.request('get', "reports/{0}".format(report_id)).j... | python | def get(self, report_id):
"""Retrieve report by ID
Args:
report_id (str): Full report ID
Returns:
Report: Corresponding Report instance
"""
return Report(
self._app,
self._swimlane.request('get', "reports/{0}".format(report_id)).j... | [
"def",
"get",
"(",
"self",
",",
"report_id",
")",
":",
"return",
"Report",
"(",
"self",
".",
"_app",
",",
"self",
".",
"_swimlane",
".",
"request",
"(",
"'get'",
",",
"\"reports/{0}\"",
".",
"format",
"(",
"report_id",
")",
")",
".",
"json",
"(",
")"... | Retrieve report by ID
Args:
report_id (str): Full report ID
Returns:
Report: Corresponding Report instance | [
"Retrieve",
"report",
"by",
"ID"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/report.py#L30-L42 | train |
swimlane/swimlane-python | swimlane/core/adapters/usergroup.py | GroupAdapter.get | def get(self, key, value):
"""Retrieve single group record by id or name
Supports resource cache
Keyword Args:
id (str): Full Group ID
name (str): Group name
Raises:
TypeError: Unexpected or more than one keyword argument provided
ValueE... | python | def get(self, key, value):
"""Retrieve single group record by id or name
Supports resource cache
Keyword Args:
id (str): Full Group ID
name (str): Group name
Raises:
TypeError: Unexpected or more than one keyword argument provided
ValueE... | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"if",
"key",
"==",
"'id'",
":",
"response",
"=",
"self",
".",
"_swimlane",
".",
"request",
"(",
"'get'",
",",
"'groups/{}'",
".",
"format",
"(",
"value",
")",
")",
"return",
"Group",
"(... | Retrieve single group record by id or name
Supports resource cache
Keyword Args:
id (str): Full Group ID
name (str): Group name
Raises:
TypeError: Unexpected or more than one keyword argument provided
ValueError: No matching group found based on... | [
"Retrieve",
"single",
"group",
"record",
"by",
"id",
"or",
"name"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/usergroup.py#L45-L73 | train |
swimlane/swimlane-python | swimlane/core/adapters/usergroup.py | UserAdapter.get | def get(self, arg, value):
"""Retrieve single user record by id or username
Warnings:
User display names are not unique. If using `display_name`, method will fail if multiple Users are returned
with the same display name
Keyword Args:
id (str): Full User ID
... | python | def get(self, arg, value):
"""Retrieve single user record by id or username
Warnings:
User display names are not unique. If using `display_name`, method will fail if multiple Users are returned
with the same display name
Keyword Args:
id (str): Full User ID
... | [
"def",
"get",
"(",
"self",
",",
"arg",
",",
"value",
")",
":",
"if",
"arg",
"==",
"'id'",
":",
"response",
"=",
"self",
".",
"_swimlane",
".",
"request",
"(",
"'get'",
",",
"'user/{}'",
".",
"format",
"(",
"value",
")",
")",
"try",
":",
"user_data"... | Retrieve single user record by id or username
Warnings:
User display names are not unique. If using `display_name`, method will fail if multiple Users are returned
with the same display name
Keyword Args:
id (str): Full User ID
display_name (str): User d... | [
"Retrieve",
"single",
"user",
"record",
"by",
"id",
"or",
"username"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/usergroup.py#L111-L162 | train |
swimlane/swimlane-python | swimlane/core/fields/history.py | RevisionCursor._evaluate | def _evaluate(self):
"""Lazily retrieves, caches, and returns the list of record _revisions"""
if not self.__retrieved:
self._elements = self._retrieve_revisions()
self.__retrieved = True
return super(RevisionCursor, self)._evaluate() | python | def _evaluate(self):
"""Lazily retrieves, caches, and returns the list of record _revisions"""
if not self.__retrieved:
self._elements = self._retrieve_revisions()
self.__retrieved = True
return super(RevisionCursor, self)._evaluate() | [
"def",
"_evaluate",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"__retrieved",
":",
"self",
".",
"_elements",
"=",
"self",
".",
"_retrieve_revisions",
"(",
")",
"self",
".",
"__retrieved",
"=",
"True",
"return",
"super",
"(",
"RevisionCursor",
",",
... | Lazily retrieves, caches, and returns the list of record _revisions | [
"Lazily",
"retrieves",
"caches",
"and",
"returns",
"the",
"list",
"of",
"record",
"_revisions"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/history.py#L15-L21 | train |
swimlane/swimlane-python | swimlane/core/fields/history.py | RevisionCursor._retrieve_revisions | def _retrieve_revisions(self):
"""Retrieve and populate Revision instances from history API endpoint"""
response = self._swimlane.request(
'get',
'history',
params={
'type': 'Records',
'id': self._record.id
}
)
... | python | def _retrieve_revisions(self):
"""Retrieve and populate Revision instances from history API endpoint"""
response = self._swimlane.request(
'get',
'history',
params={
'type': 'Records',
'id': self._record.id
}
)
... | [
"def",
"_retrieve_revisions",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"_swimlane",
".",
"request",
"(",
"'get'",
",",
"'history'",
",",
"params",
"=",
"{",
"'type'",
":",
"'Records'",
",",
"'id'",
":",
"self",
".",
"_record",
".",
"id",
"}... | Retrieve and populate Revision instances from history API endpoint | [
"Retrieve",
"and",
"populate",
"Revision",
"instances",
"from",
"history",
"API",
"endpoint"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/history.py#L23-L36 | train |
swimlane/swimlane-python | swimlane/core/fields/valueslist.py | ValuesListField.validate_value | def validate_value(self, value):
"""Validate provided value is one of the valid options"""
super(ValuesListField, self).validate_value(value)
if value is not None:
if value not in self.selection_to_id_map:
raise ValidationError(
self.record,
... | python | def validate_value(self, value):
"""Validate provided value is one of the valid options"""
super(ValuesListField, self).validate_value(value)
if value is not None:
if value not in self.selection_to_id_map:
raise ValidationError(
self.record,
... | [
"def",
"validate_value",
"(",
"self",
",",
"value",
")",
":",
"super",
"(",
"ValuesListField",
",",
"self",
")",
".",
"validate_value",
"(",
"value",
")",
"if",
"value",
"is",
"not",
"None",
":",
"if",
"value",
"not",
"in",
"self",
".",
"selection_to_id_... | Validate provided value is one of the valid options | [
"Validate",
"provided",
"value",
"is",
"one",
"of",
"the",
"valid",
"options"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/valueslist.py#L20-L33 | train |
swimlane/swimlane-python | swimlane/core/fields/valueslist.py | ValuesListField.cast_to_report | def cast_to_report(self, value):
"""Report format uses only the value's id"""
value = super(ValuesListField, self).cast_to_report(value)
if value:
return value['id'] | python | def cast_to_report(self, value):
"""Report format uses only the value's id"""
value = super(ValuesListField, self).cast_to_report(value)
if value:
return value['id'] | [
"def",
"cast_to_report",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"super",
"(",
"ValuesListField",
",",
"self",
")",
".",
"cast_to_report",
"(",
"value",
")",
"if",
"value",
":",
"return",
"value",
"[",
"'id'",
"]"
] | Report format uses only the value's id | [
"Report",
"format",
"uses",
"only",
"the",
"value",
"s",
"id"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/valueslist.py#L53-L58 | train |
swimlane/swimlane-python | swimlane/core/adapters/record.py | validate_filters_or_records | def validate_filters_or_records(filters_or_records):
"""Validation for filters_or_records variable from bulk_modify and bulk_delete"""
# If filters_or_records is empty, fail
if not filters_or_records:
raise ValueError('Must provide at least one filter tuples or Records')
# If filters_or_records ... | python | def validate_filters_or_records(filters_or_records):
"""Validation for filters_or_records variable from bulk_modify and bulk_delete"""
# If filters_or_records is empty, fail
if not filters_or_records:
raise ValueError('Must provide at least one filter tuples or Records')
# If filters_or_records ... | [
"def",
"validate_filters_or_records",
"(",
"filters_or_records",
")",
":",
"if",
"not",
"filters_or_records",
":",
"raise",
"ValueError",
"(",
"'Must provide at least one filter tuples or Records'",
")",
"if",
"not",
"isinstance",
"(",
"filters_or_records",
"[",
"0",
"]",... | Validation for filters_or_records variable from bulk_modify and bulk_delete | [
"Validation",
"for",
"filters_or_records",
"variable",
"from",
"bulk_modify",
"and",
"bulk_delete"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/record.py#L373-L387 | train |
swimlane/swimlane-python | swimlane/core/adapters/record.py | RecordAdapter.get | def get(self, key, value):
"""Get a single record by id
Supports resource cache
.. versionchanged:: 2.17.0
Added option to retrieve record by tracking_id
Keyword Args:
id (str): Full record ID
tracking_id (str): Record Tracking ID
Returns:... | python | def get(self, key, value):
"""Get a single record by id
Supports resource cache
.. versionchanged:: 2.17.0
Added option to retrieve record by tracking_id
Keyword Args:
id (str): Full record ID
tracking_id (str): Record Tracking ID
Returns:... | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"if",
"key",
"==",
"'id'",
":",
"response",
"=",
"self",
".",
"_swimlane",
".",
"request",
"(",
"'get'",
",",
"\"app/{0}/record/{1}\"",
".",
"format",
"(",
"self",
".",
"_app",
".",
"id",... | Get a single record by id
Supports resource cache
.. versionchanged:: 2.17.0
Added option to retrieve record by tracking_id
Keyword Args:
id (str): Full record ID
tracking_id (str): Record Tracking ID
Returns:
Record: Matching Record i... | [
"Get",
"a",
"single",
"record",
"by",
"id"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/record.py#L17-L40 | train |
swimlane/swimlane-python | swimlane/core/adapters/record.py | RecordAdapter.search | def search(self, *filters, **kwargs):
"""Shortcut to generate a new temporary search report using provided filters and return the resulting records
Args:
*filters (tuple): Zero or more filter tuples of (field_name, operator, field_value)
Keyword Args:
keywords (list(str... | python | def search(self, *filters, **kwargs):
"""Shortcut to generate a new temporary search report using provided filters and return the resulting records
Args:
*filters (tuple): Zero or more filter tuples of (field_name, operator, field_value)
Keyword Args:
keywords (list(str... | [
"def",
"search",
"(",
"self",
",",
"*",
"filters",
",",
"**",
"kwargs",
")",
":",
"report",
"=",
"self",
".",
"_app",
".",
"reports",
".",
"build",
"(",
"'search-'",
"+",
"random_string",
"(",
"8",
")",
",",
"keywords",
"=",
"kwargs",
".",
"pop",
"... | Shortcut to generate a new temporary search report using provided filters and return the resulting records
Args:
*filters (tuple): Zero or more filter tuples of (field_name, operator, field_value)
Keyword Args:
keywords (list(str)): List of strings of keywords to use in report ... | [
"Shortcut",
"to",
"generate",
"a",
"new",
"temporary",
"search",
"report",
"using",
"provided",
"filters",
"and",
"return",
"the",
"resulting",
"records"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/record.py#L42-L98 | train |
swimlane/swimlane-python | swimlane/core/adapters/record.py | RecordAdapter.create | def create(self, **fields):
"""Create and return a new record in associated app and return the newly created Record instance
Args:
**fields: Field names and values to be validated and sent to server with create request
Notes:
Keyword arguments should be field names with... | python | def create(self, **fields):
"""Create and return a new record in associated app and return the newly created Record instance
Args:
**fields: Field names and values to be validated and sent to server with create request
Notes:
Keyword arguments should be field names with... | [
"def",
"create",
"(",
"self",
",",
"**",
"fields",
")",
":",
"new_record",
"=",
"record_factory",
"(",
"self",
".",
"_app",
",",
"fields",
")",
"new_record",
".",
"save",
"(",
")",
"return",
"new_record"
] | Create and return a new record in associated app and return the newly created Record instance
Args:
**fields: Field names and values to be validated and sent to server with create request
Notes:
Keyword arguments should be field names with their respective python values
... | [
"Create",
"and",
"return",
"a",
"new",
"record",
"in",
"associated",
"app",
"and",
"return",
"the",
"newly",
"created",
"Record",
"instance"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/record.py#L100-L143 | train |
swimlane/swimlane-python | swimlane/core/adapters/record.py | RecordAdapter.bulk_create | def bulk_create(self, *records):
"""Create and validate multiple records in associated app
Args:
*records (dict): One or more dicts of new record field names and values
Notes:
Requires Swimlane 2.15+
Validates like :meth:`create`, but only sends a single re... | python | def bulk_create(self, *records):
"""Create and validate multiple records in associated app
Args:
*records (dict): One or more dicts of new record field names and values
Notes:
Requires Swimlane 2.15+
Validates like :meth:`create`, but only sends a single re... | [
"def",
"bulk_create",
"(",
"self",
",",
"*",
"records",
")",
":",
"if",
"not",
"records",
":",
"raise",
"TypeError",
"(",
"'Must provide at least one record'",
")",
"if",
"any",
"(",
"not",
"isinstance",
"(",
"r",
",",
"dict",
")",
"for",
"r",
"in",
"rec... | Create and validate multiple records in associated app
Args:
*records (dict): One or more dicts of new record field names and values
Notes:
Requires Swimlane 2.15+
Validates like :meth:`create`, but only sends a single request to create all provided fields, and doe... | [
"Create",
"and",
"validate",
"multiple",
"records",
"in",
"associated",
"app"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/adapters/record.py#L146-L198 | train |
swimlane/swimlane-python | swimlane/core/fields/list.py | _ListFieldCursor._validate_list | def _validate_list(self, target):
"""Validate a list against field validation rules"""
# Check list length restrictions
min_items = self._field.field_definition.get('minItems')
max_items = self._field.field_definition.get('maxItems')
if min_items is not None:
if len(... | python | def _validate_list(self, target):
"""Validate a list against field validation rules"""
# Check list length restrictions
min_items = self._field.field_definition.get('minItems')
max_items = self._field.field_definition.get('maxItems')
if min_items is not None:
if len(... | [
"def",
"_validate_list",
"(",
"self",
",",
"target",
")",
":",
"min_items",
"=",
"self",
".",
"_field",
".",
"field_definition",
".",
"get",
"(",
"'minItems'",
")",
"max_items",
"=",
"self",
".",
"_field",
".",
"field_definition",
".",
"get",
"(",
"'maxIte... | Validate a list against field validation rules | [
"Validate",
"a",
"list",
"against",
"field",
"validation",
"rules"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/list.py#L18-L40 | train |
swimlane/swimlane-python | swimlane/core/fields/list.py | ListField.set_swimlane | def set_swimlane(self, value):
"""Convert from list of dicts with values to list of values
Cache list items with their ID pairs to restore existing IDs to unmodified values to prevent workflow
evaluating on each save for any already existing values
"""
value = value or []
... | python | def set_swimlane(self, value):
"""Convert from list of dicts with values to list of values
Cache list items with their ID pairs to restore existing IDs to unmodified values to prevent workflow
evaluating on each save for any already existing values
"""
value = value or []
... | [
"def",
"set_swimlane",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"value",
"or",
"[",
"]",
"self",
".",
"_initial_value_to_ids_map",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"item",
"in",
"value",
":",
"self",
".",
"_initial_value_to_ids_map",
... | Convert from list of dicts with values to list of values
Cache list items with their ID pairs to restore existing IDs to unmodified values to prevent workflow
evaluating on each save for any already existing values | [
"Convert",
"from",
"list",
"of",
"dicts",
"with",
"values",
"to",
"list",
"of",
"values"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/list.py#L207-L219 | train |
swimlane/swimlane-python | swimlane/core/fields/list.py | ListField.set_python | def set_python(self, value):
"""Validate using cursor for consistency between direct set of values vs modification of cursor values"""
if not isinstance(value, (list, type(None))):
raise ValidationError(
self.record,
"Field '{}' must be set to a list, not '{}'... | python | def set_python(self, value):
"""Validate using cursor for consistency between direct set of values vs modification of cursor values"""
if not isinstance(value, (list, type(None))):
raise ValidationError(
self.record,
"Field '{}' must be set to a list, not '{}'... | [
"def",
"set_python",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"(",
"list",
",",
"type",
"(",
"None",
")",
")",
")",
":",
"raise",
"ValidationError",
"(",
"self",
".",
"record",
",",
"\"Field '{}' must be set to a... | Validate using cursor for consistency between direct set of values vs modification of cursor values | [
"Validate",
"using",
"cursor",
"for",
"consistency",
"between",
"direct",
"set",
"of",
"values",
"vs",
"modification",
"of",
"cursor",
"values"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/list.py#L221-L233 | train |
swimlane/swimlane-python | swimlane/core/fields/list.py | ListField.cast_to_swimlane | def cast_to_swimlane(self, value):
"""Restore swimlane format, attempting to keep initial IDs for any previously existing values"""
value = super(ListField, self).cast_to_swimlane(value)
if not value:
return None
# Copy initial values to pop IDs out as each value is hydrate... | python | def cast_to_swimlane(self, value):
"""Restore swimlane format, attempting to keep initial IDs for any previously existing values"""
value = super(ListField, self).cast_to_swimlane(value)
if not value:
return None
# Copy initial values to pop IDs out as each value is hydrate... | [
"def",
"cast_to_swimlane",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"super",
"(",
"ListField",
",",
"self",
")",
".",
"cast_to_swimlane",
"(",
"value",
")",
"if",
"not",
"value",
":",
"return",
"None",
"value_ids",
"=",
"deepcopy",
"(",
"self",... | Restore swimlane format, attempting to keep initial IDs for any previously existing values | [
"Restore",
"swimlane",
"format",
"attempting",
"to",
"keep",
"initial",
"IDs",
"for",
"any",
"previously",
"existing",
"values"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/list.py#L235-L246 | train |
swimlane/swimlane-python | swimlane/core/fields/base/multiselect.py | MultiSelectCursor.select | def select(self, element):
"""Add an element to the set of selected elements
Proxy to internal set.add and sync field
"""
self._field.validate_value(element)
self._elements.add(element)
self._sync_field() | python | def select(self, element):
"""Add an element to the set of selected elements
Proxy to internal set.add and sync field
"""
self._field.validate_value(element)
self._elements.add(element)
self._sync_field() | [
"def",
"select",
"(",
"self",
",",
"element",
")",
":",
"self",
".",
"_field",
".",
"validate_value",
"(",
"element",
")",
"self",
".",
"_elements",
".",
"add",
"(",
"element",
")",
"self",
".",
"_sync_field",
"(",
")"
] | Add an element to the set of selected elements
Proxy to internal set.add and sync field | [
"Add",
"an",
"element",
"to",
"the",
"set",
"of",
"selected",
"elements",
"Proxy",
"to",
"internal",
"set",
".",
"add",
"and",
"sync",
"field"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/multiselect.py#L17-L24 | train |
swimlane/swimlane-python | swimlane/core/fields/base/multiselect.py | MultiSelectField.get_python | def get_python(self):
"""Only return cursor instance if configured for multiselect"""
if self.multiselect:
return super(MultiSelectField, self).get_python()
return self._get() | python | def get_python(self):
"""Only return cursor instance if configured for multiselect"""
if self.multiselect:
return super(MultiSelectField, self).get_python()
return self._get() | [
"def",
"get_python",
"(",
"self",
")",
":",
"if",
"self",
".",
"multiselect",
":",
"return",
"super",
"(",
"MultiSelectField",
",",
"self",
")",
".",
"get_python",
"(",
")",
"return",
"self",
".",
"_get",
"(",
")"
] | Only return cursor instance if configured for multiselect | [
"Only",
"return",
"cursor",
"instance",
"if",
"configured",
"for",
"multiselect"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/multiselect.py#L40-L45 | train |
swimlane/swimlane-python | swimlane/core/fields/base/multiselect.py | MultiSelectField.get_swimlane | def get_swimlane(self):
"""Handle multi-select and single-select modes"""
if self.multiselect:
value = self._get()
children = []
if value:
for child in value:
children.append(self.cast_to_swimlane(child))
return chi... | python | def get_swimlane(self):
"""Handle multi-select and single-select modes"""
if self.multiselect:
value = self._get()
children = []
if value:
for child in value:
children.append(self.cast_to_swimlane(child))
return chi... | [
"def",
"get_swimlane",
"(",
"self",
")",
":",
"if",
"self",
".",
"multiselect",
":",
"value",
"=",
"self",
".",
"_get",
"(",
")",
"children",
"=",
"[",
"]",
"if",
"value",
":",
"for",
"child",
"in",
"value",
":",
"children",
".",
"append",
"(",
"se... | Handle multi-select and single-select modes | [
"Handle",
"multi",
"-",
"select",
"and",
"single",
"-",
"select",
"modes"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/multiselect.py#L47-L58 | train |
swimlane/swimlane-python | swimlane/core/fields/base/multiselect.py | MultiSelectField.set_python | def set_python(self, value):
"""Override to remove key from raw data when empty to work with server 2.16+ validation"""
if self.multiselect:
value = value or []
elements = []
for element in value:
self.validate_value(element)
elements.... | python | def set_python(self, value):
"""Override to remove key from raw data when empty to work with server 2.16+ validation"""
if self.multiselect:
value = value or []
elements = []
for element in value:
self.validate_value(element)
elements.... | [
"def",
"set_python",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"multiselect",
":",
"value",
"=",
"value",
"or",
"[",
"]",
"elements",
"=",
"[",
"]",
"for",
"element",
"in",
"value",
":",
"self",
".",
"validate_value",
"(",
"element",
")... | Override to remove key from raw data when empty to work with server 2.16+ validation | [
"Override",
"to",
"remove",
"key",
"from",
"raw",
"data",
"when",
"empty",
"to",
"work",
"with",
"server",
"2",
".",
"16",
"+",
"validation"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/multiselect.py#L64-L78 | train |
swimlane/swimlane-python | swimlane/core/fields/base/multiselect.py | MultiSelectField.set_swimlane | def set_swimlane(self, value):
"""Cast all multi-select elements to correct internal type like single-select mode"""
if self.multiselect:
value = value or []
children = []
for child in value:
children.append(self.cast_to_python(child))
re... | python | def set_swimlane(self, value):
"""Cast all multi-select elements to correct internal type like single-select mode"""
if self.multiselect:
value = value or []
children = []
for child in value:
children.append(self.cast_to_python(child))
re... | [
"def",
"set_swimlane",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"multiselect",
":",
"value",
"=",
"value",
"or",
"[",
"]",
"children",
"=",
"[",
"]",
"for",
"child",
"in",
"value",
":",
"children",
".",
"append",
"(",
"self",
".",
"c... | Cast all multi-select elements to correct internal type like single-select mode | [
"Cast",
"all",
"multi",
"-",
"select",
"elements",
"to",
"correct",
"internal",
"type",
"like",
"single",
"-",
"select",
"mode"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/multiselect.py#L80-L91 | train |
swimlane/swimlane-python | swimlane/core/fields/base/multiselect.py | MultiSelectField.for_json | def for_json(self):
"""Handle multi-select vs single-select"""
if self.multiselect:
return super(MultiSelectField, self).for_json()
value = self.get_python()
if hasattr(value, 'for_json'):
return value.for_json()
return value | python | def for_json(self):
"""Handle multi-select vs single-select"""
if self.multiselect:
return super(MultiSelectField, self).for_json()
value = self.get_python()
if hasattr(value, 'for_json'):
return value.for_json()
return value | [
"def",
"for_json",
"(",
"self",
")",
":",
"if",
"self",
".",
"multiselect",
":",
"return",
"super",
"(",
"MultiSelectField",
",",
"self",
")",
".",
"for_json",
"(",
")",
"value",
"=",
"self",
".",
"get_python",
"(",
")",
"if",
"hasattr",
"(",
"value",
... | Handle multi-select vs single-select | [
"Handle",
"multi",
"-",
"select",
"vs",
"single",
"-",
"select"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/multiselect.py#L93-L103 | train |
swimlane/swimlane-python | swimlane/core/resources/record.py | record_factory | def record_factory(app, fields=None):
"""Return a temporary Record instance to be used for field validation and value parsing
Args:
app (App): Target App to create a transient Record instance for
fields (dict): Optional dict of fields and values to set on new Record instance before returning
... | python | def record_factory(app, fields=None):
"""Return a temporary Record instance to be used for field validation and value parsing
Args:
app (App): Target App to create a transient Record instance for
fields (dict): Optional dict of fields and values to set on new Record instance before returning
... | [
"def",
"record_factory",
"(",
"app",
",",
"fields",
"=",
"None",
")",
":",
"record",
"=",
"Record",
"(",
"app",
",",
"{",
"'$type'",
":",
"Record",
".",
"_type",
",",
"'isNew'",
":",
"True",
",",
"'applicationId'",
":",
"app",
".",
"id",
",",
"'comme... | Return a temporary Record instance to be used for field validation and value parsing
Args:
app (App): Target App to create a transient Record instance for
fields (dict): Optional dict of fields and values to set on new Record instance before returning
Returns:
Record: Unsaved Record in... | [
"Return",
"a",
"temporary",
"Record",
"instance",
"to",
"be",
"used",
"for",
"field",
"validation",
"and",
"value",
"parsing"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/resources/record.py#L311-L347 | train |
swimlane/swimlane-python | swimlane/core/fields/text.py | TextField.set_python | def set_python(self, value):
"""Set field internal value from the python representation of field value"""
# hook exists to stringify before validation
# set to string if not string or unicode
if value is not None and not isinstance(value, self.supported_types) or isinstance(val... | python | def set_python(self, value):
"""Set field internal value from the python representation of field value"""
# hook exists to stringify before validation
# set to string if not string or unicode
if value is not None and not isinstance(value, self.supported_types) or isinstance(val... | [
"def",
"set_python",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
"and",
"not",
"isinstance",
"(",
"value",
",",
"self",
".",
"supported_types",
")",
"or",
"isinstance",
"(",
"value",
",",
"int",
")",
":",
"value",
"=",
"s... | Set field internal value from the python representation of field value | [
"Set",
"field",
"internal",
"value",
"from",
"the",
"python",
"representation",
"of",
"field",
"value"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/text.py#L15-L23 | train |
swimlane/swimlane-python | swimlane/utils/version.py | compare_versions | def compare_versions(version_a, version_b, zerofill=False):
"""Return direction of version relative to provided version sections
Args:
version_a (str): First version to compare
version_b (str): Second version to compare
zerofill (bool): If True, treat any missing version sections as 0, ... | python | def compare_versions(version_a, version_b, zerofill=False):
"""Return direction of version relative to provided version sections
Args:
version_a (str): First version to compare
version_b (str): Second version to compare
zerofill (bool): If True, treat any missing version sections as 0, ... | [
"def",
"compare_versions",
"(",
"version_a",
",",
"version_b",
",",
"zerofill",
"=",
"False",
")",
":",
"a_sections",
"=",
"list",
"(",
"(",
"int",
"(",
"match",
")",
"for",
"match",
"in",
"re",
".",
"findall",
"(",
"r'\\d+'",
",",
"version_a",
")",
")... | Return direction of version relative to provided version sections
Args:
version_a (str): First version to compare
version_b (str): Second version to compare
zerofill (bool): If True, treat any missing version sections as 0, otherwise ignore section. Defaults to False
Returns:
i... | [
"Return",
"direction",
"of",
"version",
"relative",
"to",
"provided",
"version",
"sections"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/utils/version.py#L9-L56 | train |
swimlane/swimlane-python | swimlane/utils/version.py | requires_swimlane_version | def requires_swimlane_version(min_version=None, max_version=None):
"""Decorator for SwimlaneResolver methods verifying Swimlane server build version is within a given inclusive range
Raises:
InvalidVersion: Raised before decorated method call if Swimlane server version is out of provided range
... | python | def requires_swimlane_version(min_version=None, max_version=None):
"""Decorator for SwimlaneResolver methods verifying Swimlane server build version is within a given inclusive range
Raises:
InvalidVersion: Raised before decorated method call if Swimlane server version is out of provided range
... | [
"def",
"requires_swimlane_version",
"(",
"min_version",
"=",
"None",
",",
"max_version",
"=",
"None",
")",
":",
"if",
"min_version",
"is",
"None",
"and",
"max_version",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Must provide either min_version, max_version, or b... | Decorator for SwimlaneResolver methods verifying Swimlane server build version is within a given inclusive range
Raises:
InvalidVersion: Raised before decorated method call if Swimlane server version is out of provided range
ValueError: If neither min_version or max_version were provided, or if tho... | [
"Decorator",
"for",
"SwimlaneResolver",
"methods",
"verifying",
"Swimlane",
"server",
"build",
"version",
"is",
"within",
"a",
"given",
"inclusive",
"range"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/utils/version.py#L59-L89 | train |
swimlane/swimlane-python | swimlane/core/fields/base/field.py | Field.get_report | def get_report(self, value):
"""Return provided field Python value formatted for use in report filter"""
if self.multiselect:
value = value or []
children = []
for child in value:
children.append(self.cast_to_report(child))
return childre... | python | def get_report(self, value):
"""Return provided field Python value formatted for use in report filter"""
if self.multiselect:
value = value or []
children = []
for child in value:
children.append(self.cast_to_report(child))
return childre... | [
"def",
"get_report",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"multiselect",
":",
"value",
"=",
"value",
"or",
"[",
"]",
"children",
"=",
"[",
"]",
"for",
"child",
"in",
"value",
":",
"children",
".",
"append",
"(",
"self",
".",
"cas... | Return provided field Python value formatted for use in report filter | [
"Return",
"provided",
"field",
"Python",
"value",
"formatted",
"for",
"use",
"in",
"report",
"filter"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/field.py#L57-L68 | train |
swimlane/swimlane-python | swimlane/core/fields/base/field.py | Field.get_bulk_modify | def get_bulk_modify(self, value):
"""Return value in format for bulk modify"""
if self.multiselect:
value = value or []
return [self.cast_to_bulk_modify(child) for child in value]
return self.cast_to_bulk_modify(value) | python | def get_bulk_modify(self, value):
"""Return value in format for bulk modify"""
if self.multiselect:
value = value or []
return [self.cast_to_bulk_modify(child) for child in value]
return self.cast_to_bulk_modify(value) | [
"def",
"get_bulk_modify",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"multiselect",
":",
"value",
"=",
"value",
"or",
"[",
"]",
"return",
"[",
"self",
".",
"cast_to_bulk_modify",
"(",
"child",
")",
"for",
"child",
"in",
"value",
"]",
"retu... | Return value in format for bulk modify | [
"Return",
"value",
"in",
"format",
"for",
"bulk",
"modify"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/field.py#L70-L76 | train |
swimlane/swimlane-python | swimlane/core/fields/base/field.py | Field.validate_value | def validate_value(self, value):
"""Validate value is an acceptable type during set_python operation"""
if self.readonly:
raise ValidationError(self.record, "Cannot set readonly field '{}'".format(self.name))
if value not in (None, self._unset):
if self.supported_types an... | python | def validate_value(self, value):
"""Validate value is an acceptable type during set_python operation"""
if self.readonly:
raise ValidationError(self.record, "Cannot set readonly field '{}'".format(self.name))
if value not in (None, self._unset):
if self.supported_types an... | [
"def",
"validate_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"readonly",
":",
"raise",
"ValidationError",
"(",
"self",
".",
"record",
",",
"\"Cannot set readonly field '{}'\"",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"if",
"v... | Validate value is an acceptable type during set_python operation | [
"Validate",
"value",
"is",
"an",
"acceptable",
"type",
"during",
"set_python",
"operation"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/field.py#L101-L111 | train |
swimlane/swimlane-python | swimlane/core/fields/base/field.py | Field._set | def _set(self, value):
"""Default setter used for both representations unless overridden"""
self._value = value
self.record._raw['values'][self.id] = self.get_swimlane() | python | def _set(self, value):
"""Default setter used for both representations unless overridden"""
self._value = value
self.record._raw['values'][self.id] = self.get_swimlane() | [
"def",
"_set",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_value",
"=",
"value",
"self",
".",
"record",
".",
"_raw",
"[",
"'values'",
"]",
"[",
"self",
".",
"id",
"]",
"=",
"self",
".",
"get_swimlane",
"(",
")"
] | Default setter used for both representations unless overridden | [
"Default",
"setter",
"used",
"for",
"both",
"representations",
"unless",
"overridden"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/base/field.py#L113-L116 | train |
swimlane/swimlane-python | swimlane/core/fields/__init__.py | resolve_field_class | def resolve_field_class(field_definition):
"""Return field class most fitting of provided Swimlane field definition"""
try:
return _FIELD_TYPE_MAP[field_definition['$type']]
except KeyError as error:
error.message = 'No field available to handle Swimlane $type "{}"'.format(field_definition)
... | python | def resolve_field_class(field_definition):
"""Return field class most fitting of provided Swimlane field definition"""
try:
return _FIELD_TYPE_MAP[field_definition['$type']]
except KeyError as error:
error.message = 'No field available to handle Swimlane $type "{}"'.format(field_definition)
... | [
"def",
"resolve_field_class",
"(",
"field_definition",
")",
":",
"try",
":",
"return",
"_FIELD_TYPE_MAP",
"[",
"field_definition",
"[",
"'$type'",
"]",
"]",
"except",
"KeyError",
"as",
"error",
":",
"error",
".",
"message",
"=",
"'No field available to handle Swimla... | Return field class most fitting of provided Swimlane field definition | [
"Return",
"field",
"class",
"most",
"fitting",
"of",
"provided",
"Swimlane",
"field",
"definition"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/__init__.py#L37-L43 | train |
swimlane/swimlane-python | swimlane/core/cache.py | get_cache_index_key | def get_cache_index_key(resource):
"""Return a usable cache lookup key for an already initialized resource
Args:
resource (APIResource|tuple): APIResource instance or 3-length tuple key returned from this function
Raises:
TypeError: If resource is not an APIResource instance or acceptable ... | python | def get_cache_index_key(resource):
"""Return a usable cache lookup key for an already initialized resource
Args:
resource (APIResource|tuple): APIResource instance or 3-length tuple key returned from this function
Raises:
TypeError: If resource is not an APIResource instance or acceptable ... | [
"def",
"get_cache_index_key",
"(",
"resource",
")",
":",
"if",
"isinstance",
"(",
"resource",
",",
"APIResource",
")",
":",
"attr",
",",
"attr_value",
"=",
"list",
"(",
"resource",
".",
"get_cache_index_keys",
"(",
")",
".",
"items",
"(",
")",
")",
"[",
... | Return a usable cache lookup key for an already initialized resource
Args:
resource (APIResource|tuple): APIResource instance or 3-length tuple key returned from this function
Raises:
TypeError: If resource is not an APIResource instance or acceptable 3-length tuple cache key | [
"Return",
"a",
"usable",
"cache",
"lookup",
"key",
"for",
"an",
"already",
"initialized",
"resource"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/cache.py#L106-L127 | train |
swimlane/swimlane-python | swimlane/core/cache.py | check_cache | def check_cache(resource_type):
"""Decorator for adapter methods to check cache for resource before normally sending requests to retrieve data
Only works with single kwargs, almost always used with @one_of_keyword_only decorator
Args:
resource_type (type(APIResource)): Subclass of APIResource of c... | python | def check_cache(resource_type):
"""Decorator for adapter methods to check cache for resource before normally sending requests to retrieve data
Only works with single kwargs, almost always used with @one_of_keyword_only decorator
Args:
resource_type (type(APIResource)): Subclass of APIResource of c... | [
"def",
"check_cache",
"(",
"resource_type",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"adapter",
"=",
"args",
... | Decorator for adapter methods to check cache for resource before normally sending requests to retrieve data
Only works with single kwargs, almost always used with @one_of_keyword_only decorator
Args:
resource_type (type(APIResource)): Subclass of APIResource of cache to be checked when called | [
"Decorator",
"for",
"adapter",
"methods",
"to",
"check",
"cache",
"for",
"resource",
"before",
"normally",
"sending",
"requests",
"to",
"retrieve",
"data"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/cache.py#L130-L162 | train |
swimlane/swimlane-python | swimlane/core/cache.py | ResourcesCache.cache | def cache(self, resource):
"""Insert a resource instance into appropriate resource cache"""
if not isinstance(resource, APIResource):
raise TypeError('Cannot cache `{!r}`, can only cache APIResource instances'.format(resource))
# Disable inserts to cache when disabled
if sel... | python | def cache(self, resource):
"""Insert a resource instance into appropriate resource cache"""
if not isinstance(resource, APIResource):
raise TypeError('Cannot cache `{!r}`, can only cache APIResource instances'.format(resource))
# Disable inserts to cache when disabled
if sel... | [
"def",
"cache",
"(",
"self",
",",
"resource",
")",
":",
"if",
"not",
"isinstance",
"(",
"resource",
",",
"APIResource",
")",
":",
"raise",
"TypeError",
"(",
"'Cannot cache `{!r}`, can only cache APIResource instances'",
".",
"format",
"(",
"resource",
")",
")",
... | Insert a resource instance into appropriate resource cache | [
"Insert",
"a",
"resource",
"instance",
"into",
"appropriate",
"resource",
"cache"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/cache.py#L70-L94 | train |
swimlane/swimlane-python | swimlane/core/cache.py | ResourcesCache.clear | def clear(self, *resource_types):
"""Clear cache for each provided APIResource class, or all resources if no classes are provided"""
resource_types = resource_types or tuple(self.__caches.keys())
for cls in resource_types:
# Clear and delete cache instances to guarantee no lingering... | python | def clear(self, *resource_types):
"""Clear cache for each provided APIResource class, or all resources if no classes are provided"""
resource_types = resource_types or tuple(self.__caches.keys())
for cls in resource_types:
# Clear and delete cache instances to guarantee no lingering... | [
"def",
"clear",
"(",
"self",
",",
"*",
"resource_types",
")",
":",
"resource_types",
"=",
"resource_types",
"or",
"tuple",
"(",
"self",
".",
"__caches",
".",
"keys",
"(",
")",
")",
"for",
"cls",
"in",
"resource_types",
":",
"self",
".",
"__caches",
"[",
... | Clear cache for each provided APIResource class, or all resources if no classes are provided | [
"Clear",
"cache",
"for",
"each",
"provided",
"APIResource",
"class",
"or",
"all",
"resources",
"if",
"no",
"classes",
"are",
"provided"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/cache.py#L96-L103 | train |
swimlane/swimlane-python | swimlane/core/fields/attachment.py | AttachmentsField._set | def _set(self, value):
"""Override setter, allow clearing cursor"""
super(AttachmentsField, self)._set(value)
self._cursor = None | python | def _set(self, value):
"""Override setter, allow clearing cursor"""
super(AttachmentsField, self)._set(value)
self._cursor = None | [
"def",
"_set",
"(",
"self",
",",
"value",
")",
":",
"super",
"(",
"AttachmentsField",
",",
"self",
")",
".",
"_set",
"(",
"value",
")",
"self",
".",
"_cursor",
"=",
"None"
] | Override setter, allow clearing cursor | [
"Override",
"setter",
"allow",
"clearing",
"cursor"
] | 588fc503a76799bcdb5aecdf2f64a6ee05e3922d | https://github.com/swimlane/swimlane-python/blob/588fc503a76799bcdb5aecdf2f64a6ee05e3922d/swimlane/core/fields/attachment.py#L58-L61 | train |
MicroPyramid/django-mfa | django_mfa/views.py | verify_otp | def verify_otp(request):
"""
Verify a OTP request
"""
ctx = {}
if request.method == "POST":
verification_code = request.POST.get('verification_code')
if verification_code is None:
ctx['error_message'] = "Missing verification code."
else:
otp_ = UserO... | python | def verify_otp(request):
"""
Verify a OTP request
"""
ctx = {}
if request.method == "POST":
verification_code = request.POST.get('verification_code')
if verification_code is None:
ctx['error_message'] = "Missing verification code."
else:
otp_ = UserO... | [
"def",
"verify_otp",
"(",
"request",
")",
":",
"ctx",
"=",
"{",
"}",
"if",
"request",
".",
"method",
"==",
"\"POST\"",
":",
"verification_code",
"=",
"request",
".",
"POST",
".",
"get",
"(",
"'verification_code'",
")",
"if",
"verification_code",
"is",
"Non... | Verify a OTP request | [
"Verify",
"a",
"OTP",
"request"
] | 7baf16297ffa8b5b4aa0b9961a889a964fcbdb39 | https://github.com/MicroPyramid/django-mfa/blob/7baf16297ffa8b5b4aa0b9961a889a964fcbdb39/django_mfa/views.py#L142-L166 | train |
MicroPyramid/django-mfa | django_mfa/totp.py | TOTP.at | def at(self, for_time, counter_offset=0):
"""
Accepts either a Unix timestamp integer or a Time object.
Time objects will be adjusted to UTC automatically
@param [Time/Integer] time the time to generate an OTP for
@param [Integer] counter_offset an amount of ticks to add to the t... | python | def at(self, for_time, counter_offset=0):
"""
Accepts either a Unix timestamp integer or a Time object.
Time objects will be adjusted to UTC automatically
@param [Time/Integer] time the time to generate an OTP for
@param [Integer] counter_offset an amount of ticks to add to the t... | [
"def",
"at",
"(",
"self",
",",
"for_time",
",",
"counter_offset",
"=",
"0",
")",
":",
"if",
"not",
"isinstance",
"(",
"for_time",
",",
"datetime",
".",
"datetime",
")",
":",
"for_time",
"=",
"datetime",
".",
"datetime",
".",
"fromtimestamp",
"(",
"int",
... | Accepts either a Unix timestamp integer or a Time object.
Time objects will be adjusted to UTC automatically
@param [Time/Integer] time the time to generate an OTP for
@param [Integer] counter_offset an amount of ticks to add to the time counter | [
"Accepts",
"either",
"a",
"Unix",
"timestamp",
"integer",
"or",
"a",
"Time",
"object",
".",
"Time",
"objects",
"will",
"be",
"adjusted",
"to",
"UTC",
"automatically"
] | 7baf16297ffa8b5b4aa0b9961a889a964fcbdb39 | https://github.com/MicroPyramid/django-mfa/blob/7baf16297ffa8b5b4aa0b9961a889a964fcbdb39/django_mfa/totp.py#L19-L28 | train |
MicroPyramid/django-mfa | django_mfa/totp.py | TOTP.verify | def verify(self, otp, for_time=None, valid_window=0):
"""
Verifies the OTP passed in against the current time OTP
@param [String/Integer] otp the OTP to check against
@param [Integer] valid_window extends the validity to this many counter ticks before and after the current one
""... | python | def verify(self, otp, for_time=None, valid_window=0):
"""
Verifies the OTP passed in against the current time OTP
@param [String/Integer] otp the OTP to check against
@param [Integer] valid_window extends the validity to this many counter ticks before and after the current one
""... | [
"def",
"verify",
"(",
"self",
",",
"otp",
",",
"for_time",
"=",
"None",
",",
"valid_window",
"=",
"0",
")",
":",
"if",
"for_time",
"is",
"None",
":",
"for_time",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"if",
"valid_window",
":",
"for"... | Verifies the OTP passed in against the current time OTP
@param [String/Integer] otp the OTP to check against
@param [Integer] valid_window extends the validity to this many counter ticks before and after the current one | [
"Verifies",
"the",
"OTP",
"passed",
"in",
"against",
"the",
"current",
"time",
"OTP"
] | 7baf16297ffa8b5b4aa0b9961a889a964fcbdb39 | https://github.com/MicroPyramid/django-mfa/blob/7baf16297ffa8b5b4aa0b9961a889a964fcbdb39/django_mfa/totp.py#L37-L52 | train |
MicroPyramid/django-mfa | django_mfa/totp.py | TOTP.provisioning_uri | def provisioning_uri(self, name, issuer_name=None):
"""
Returns the provisioning URI for the OTP
This can then be encoded in a QR Code and used
to provision the Google Authenticator app
@param [String] name of the account
@return [String] provisioning uri
"""
... | python | def provisioning_uri(self, name, issuer_name=None):
"""
Returns the provisioning URI for the OTP
This can then be encoded in a QR Code and used
to provision the Google Authenticator app
@param [String] name of the account
@return [String] provisioning uri
"""
... | [
"def",
"provisioning_uri",
"(",
"self",
",",
"name",
",",
"issuer_name",
"=",
"None",
")",
":",
"return",
"utils",
".",
"build_uri",
"(",
"self",
".",
"secret",
",",
"name",
",",
"issuer_name",
"=",
"issuer_name",
")"
] | Returns the provisioning URI for the OTP
This can then be encoded in a QR Code and used
to provision the Google Authenticator app
@param [String] name of the account
@return [String] provisioning uri | [
"Returns",
"the",
"provisioning",
"URI",
"for",
"the",
"OTP",
"This",
"can",
"then",
"be",
"encoded",
"in",
"a",
"QR",
"Code",
"and",
"used",
"to",
"provision",
"the",
"Google",
"Authenticator",
"app"
] | 7baf16297ffa8b5b4aa0b9961a889a964fcbdb39 | https://github.com/MicroPyramid/django-mfa/blob/7baf16297ffa8b5b4aa0b9961a889a964fcbdb39/django_mfa/totp.py#L54-L62 | train |
MicroPyramid/django-mfa | django_mfa/utils.py | build_uri | def build_uri(secret, name, initial_count=None, issuer_name=None):
"""
Returns the provisioning URI for the OTP; works for either TOTP or HOTP.
This can then be encoded in a QR Code and used to provision the Google
Authenticator app.
For module-internal use.
See also:
http://code.goog... | python | def build_uri(secret, name, initial_count=None, issuer_name=None):
"""
Returns the provisioning URI for the OTP; works for either TOTP or HOTP.
This can then be encoded in a QR Code and used to provision the Google
Authenticator app.
For module-internal use.
See also:
http://code.goog... | [
"def",
"build_uri",
"(",
"secret",
",",
"name",
",",
"initial_count",
"=",
"None",
",",
"issuer_name",
"=",
"None",
")",
":",
"is_initial_count_present",
"=",
"(",
"initial_count",
"is",
"not",
"None",
")",
"otp_type",
"=",
"'hotp'",
"if",
"is_initial_count_pr... | Returns the provisioning URI for the OTP; works for either TOTP or HOTP.
This can then be encoded in a QR Code and used to provision the Google
Authenticator app.
For module-internal use.
See also:
http://code.google.com/p/google-authenticator/wiki/KeyUriFormat
@param [String] the hotp/t... | [
"Returns",
"the",
"provisioning",
"URI",
"for",
"the",
"OTP",
";",
"works",
"for",
"either",
"TOTP",
"or",
"HOTP",
"."
] | 7baf16297ffa8b5b4aa0b9961a889a964fcbdb39 | https://github.com/MicroPyramid/django-mfa/blob/7baf16297ffa8b5b4aa0b9961a889a964fcbdb39/django_mfa/utils.py#L15-L57 | train |
MicroPyramid/django-mfa | django_mfa/utils.py | strings_equal | def strings_equal(s1, s2):
"""
Timing-attack resistant string comparison.
Normal comparison using == will short-circuit on the first mismatching
character. This avoids that by scanning the whole string, though we
still reveal to a timing attack whether the strings are the same
length.
"""
... | python | def strings_equal(s1, s2):
"""
Timing-attack resistant string comparison.
Normal comparison using == will short-circuit on the first mismatching
character. This avoids that by scanning the whole string, though we
still reveal to a timing attack whether the strings are the same
length.
"""
... | [
"def",
"strings_equal",
"(",
"s1",
",",
"s2",
")",
":",
"try",
":",
"s1",
"=",
"unicodedata",
".",
"normalize",
"(",
"'NFKC'",
",",
"str",
"(",
"s1",
")",
")",
"s2",
"=",
"unicodedata",
".",
"normalize",
"(",
"'NFKC'",
",",
"str",
"(",
"s2",
")",
... | Timing-attack resistant string comparison.
Normal comparison using == will short-circuit on the first mismatching
character. This avoids that by scanning the whole string, though we
still reveal to a timing attack whether the strings are the same
length. | [
"Timing",
"-",
"attack",
"resistant",
"string",
"comparison",
"."
] | 7baf16297ffa8b5b4aa0b9961a889a964fcbdb39 | https://github.com/MicroPyramid/django-mfa/blob/7baf16297ffa8b5b4aa0b9961a889a964fcbdb39/django_mfa/utils.py#L79-L94 | train |
libyal/libbde | setup.py | GetPythonLibraryDirectoryPath | def GetPythonLibraryDirectoryPath():
"""Retrieves the Python library directory path."""
path = sysconfig.get_python_lib(True)
_, _, path = path.rpartition(sysconfig.PREFIX)
if path.startswith(os.sep):
path = path[1:]
return path | python | def GetPythonLibraryDirectoryPath():
"""Retrieves the Python library directory path."""
path = sysconfig.get_python_lib(True)
_, _, path = path.rpartition(sysconfig.PREFIX)
if path.startswith(os.sep):
path = path[1:]
return path | [
"def",
"GetPythonLibraryDirectoryPath",
"(",
")",
":",
"path",
"=",
"sysconfig",
".",
"get_python_lib",
"(",
"True",
")",
"_",
",",
"_",
",",
"path",
"=",
"path",
".",
"rpartition",
"(",
"sysconfig",
".",
"PREFIX",
")",
"if",
"path",
".",
"startswith",
"... | Retrieves the Python library directory path. | [
"Retrieves",
"the",
"Python",
"library",
"directory",
"path",
"."
] | 5f59d11dbb52690b4155f2cc3fcb1ac512d076a8 | https://github.com/libyal/libbde/blob/5f59d11dbb52690b4155f2cc3fcb1ac512d076a8/setup.py#L267-L275 | train |
libyal/libbde | setup.py | custom_build_ext.run | def run(self):
"""Runs the build extension."""
compiler = new_compiler(compiler=self.compiler)
if compiler.compiler_type == "msvc":
self.define = [
("UNICODE", ""),
]
else:
command = "sh configure --disable-shared-libs"
output = self._RunCommand(command)
print_l... | python | def run(self):
"""Runs the build extension."""
compiler = new_compiler(compiler=self.compiler)
if compiler.compiler_type == "msvc":
self.define = [
("UNICODE", ""),
]
else:
command = "sh configure --disable-shared-libs"
output = self._RunCommand(command)
print_l... | [
"def",
"run",
"(",
"self",
")",
":",
"compiler",
"=",
"new_compiler",
"(",
"compiler",
"=",
"self",
".",
"compiler",
")",
"if",
"compiler",
".",
"compiler_type",
"==",
"\"msvc\"",
":",
"self",
".",
"define",
"=",
"[",
"(",
"\"UNICODE\"",
",",
"\"\"",
"... | Runs the build extension. | [
"Runs",
"the",
"build",
"extension",
"."
] | 5f59d11dbb52690b4155f2cc3fcb1ac512d076a8 | https://github.com/libyal/libbde/blob/5f59d11dbb52690b4155f2cc3fcb1ac512d076a8/setup.py#L82-L108 | train |
libyal/libbde | setup.py | ProjectInformation._ReadConfigureAc | def _ReadConfigureAc(self):
"""Reads configure.ac to initialize the project information."""
file_object = open("configure.ac", "rb")
if not file_object:
raise IOError("Unable to open: configure.ac")
found_ac_init = False
found_library_name = False
for line in file_object.readlines():
... | python | def _ReadConfigureAc(self):
"""Reads configure.ac to initialize the project information."""
file_object = open("configure.ac", "rb")
if not file_object:
raise IOError("Unable to open: configure.ac")
found_ac_init = False
found_library_name = False
for line in file_object.readlines():
... | [
"def",
"_ReadConfigureAc",
"(",
"self",
")",
":",
"file_object",
"=",
"open",
"(",
"\"configure.ac\"",
",",
"\"rb\"",
")",
"if",
"not",
"file_object",
":",
"raise",
"IOError",
"(",
"\"Unable to open: configure.ac\"",
")",
"found_ac_init",
"=",
"False",
"found_libr... | Reads configure.ac to initialize the project information. | [
"Reads",
"configure",
".",
"ac",
"to",
"initialize",
"the",
"project",
"information",
"."
] | 5f59d11dbb52690b4155f2cc3fcb1ac512d076a8 | https://github.com/libyal/libbde/blob/5f59d11dbb52690b4155f2cc3fcb1ac512d076a8/setup.py#L198-L229 | train |
libyal/libbde | setup.py | ProjectInformation._ReadMakefileAm | def _ReadMakefileAm(self):
"""Reads Makefile.am to initialize the project information."""
if not self.library_name:
raise RuntimeError("Missing library name")
file_object = open("Makefile.am", "rb")
if not file_object:
raise IOError("Unable to open: Makefile.am")
found_subdirs = False
... | python | def _ReadMakefileAm(self):
"""Reads Makefile.am to initialize the project information."""
if not self.library_name:
raise RuntimeError("Missing library name")
file_object = open("Makefile.am", "rb")
if not file_object:
raise IOError("Unable to open: Makefile.am")
found_subdirs = False
... | [
"def",
"_ReadMakefileAm",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"library_name",
":",
"raise",
"RuntimeError",
"(",
"\"Missing library name\"",
")",
"file_object",
"=",
"open",
"(",
"\"Makefile.am\"",
",",
"\"rb\"",
")",
"if",
"not",
"file_object",
"... | Reads Makefile.am to initialize the project information. | [
"Reads",
"Makefile",
".",
"am",
"to",
"initialize",
"the",
"project",
"information",
"."
] | 5f59d11dbb52690b4155f2cc3fcb1ac512d076a8 | https://github.com/libyal/libbde/blob/5f59d11dbb52690b4155f2cc3fcb1ac512d076a8/setup.py#L231-L264 | train |
amol-/dukpy | dukpy/babel.py | babel_compile | def babel_compile(source, **kwargs):
"""Compiles the given ``source`` from ES6 to ES5 using Babeljs"""
presets = kwargs.get('presets')
if not presets:
kwargs['presets'] = ["es2015"]
with open(BABEL_COMPILER, 'rb') as babel_js:
return evaljs(
(babel_js.read().decode('utf-8'),
... | python | def babel_compile(source, **kwargs):
"""Compiles the given ``source`` from ES6 to ES5 using Babeljs"""
presets = kwargs.get('presets')
if not presets:
kwargs['presets'] = ["es2015"]
with open(BABEL_COMPILER, 'rb') as babel_js:
return evaljs(
(babel_js.read().decode('utf-8'),
... | [
"def",
"babel_compile",
"(",
"source",
",",
"**",
"kwargs",
")",
":",
"presets",
"=",
"kwargs",
".",
"get",
"(",
"'presets'",
")",
"if",
"not",
"presets",
":",
"kwargs",
"[",
"'presets'",
"]",
"=",
"[",
"\"es2015\"",
"]",
"with",
"open",
"(",
"BABEL_CO... | Compiles the given ``source`` from ES6 to ES5 using Babeljs | [
"Compiles",
"the",
"given",
"source",
"from",
"ES6",
"to",
"ES5",
"using",
"Babeljs"
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/babel.py#L7-L20 | train |
amol-/dukpy | dukpy/coffee.py | coffee_compile | def coffee_compile(source):
"""Compiles the given ``source`` from CoffeeScript to JavaScript"""
with open(COFFEE_COMPILER, 'rb') as coffeescript_js:
return evaljs(
(coffeescript_js.read().decode('utf-8'),
'CoffeeScript.compile(dukpy.coffeecode)'),
coffeecode=source
... | python | def coffee_compile(source):
"""Compiles the given ``source`` from CoffeeScript to JavaScript"""
with open(COFFEE_COMPILER, 'rb') as coffeescript_js:
return evaljs(
(coffeescript_js.read().decode('utf-8'),
'CoffeeScript.compile(dukpy.coffeecode)'),
coffeecode=source
... | [
"def",
"coffee_compile",
"(",
"source",
")",
":",
"with",
"open",
"(",
"COFFEE_COMPILER",
",",
"'rb'",
")",
"as",
"coffeescript_js",
":",
"return",
"evaljs",
"(",
"(",
"coffeescript_js",
".",
"read",
"(",
")",
".",
"decode",
"(",
"'utf-8'",
")",
",",
"'C... | Compiles the given ``source`` from CoffeeScript to JavaScript | [
"Compiles",
"the",
"given",
"source",
"from",
"CoffeeScript",
"to",
"JavaScript"
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/coffee.py#L7-L14 | train |
amol-/dukpy | dukpy/module_loader.py | JSModuleLoader.register_path | def register_path(self, path):
"""Registers a directory where to look for modules.
By default only modules relative to current path are found.
"""
self._paths.insert(0, os.path.abspath(path)) | python | def register_path(self, path):
"""Registers a directory where to look for modules.
By default only modules relative to current path are found.
"""
self._paths.insert(0, os.path.abspath(path)) | [
"def",
"register_path",
"(",
"self",
",",
"path",
")",
":",
"self",
".",
"_paths",
".",
"insert",
"(",
"0",
",",
"os",
".",
"path",
".",
"abspath",
"(",
"path",
")",
")"
] | Registers a directory where to look for modules.
By default only modules relative to current path are found. | [
"Registers",
"a",
"directory",
"where",
"to",
"look",
"for",
"modules",
"."
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/module_loader.py#L20-L25 | train |
amol-/dukpy | dukpy/module_loader.py | JSModuleLoader.lookup | def lookup(self, module_name):
"""Searches for a file providing given module.
Returns the normalized module id and path of the file.
"""
for search_path in self._paths:
module_path = os.path.join(search_path, module_name)
new_module_name, module_file = self._look... | python | def lookup(self, module_name):
"""Searches for a file providing given module.
Returns the normalized module id and path of the file.
"""
for search_path in self._paths:
module_path = os.path.join(search_path, module_name)
new_module_name, module_file = self._look... | [
"def",
"lookup",
"(",
"self",
",",
"module_name",
")",
":",
"for",
"search_path",
"in",
"self",
".",
"_paths",
":",
"module_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"search_path",
",",
"module_name",
")",
"new_module_name",
",",
"module_file",
"=",... | Searches for a file providing given module.
Returns the normalized module id and path of the file. | [
"Searches",
"for",
"a",
"file",
"providing",
"given",
"module",
"."
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/module_loader.py#L27-L37 | train |
amol-/dukpy | dukpy/module_loader.py | JSModuleLoader.load | def load(self, module_name):
"""Returns source code and normalized module id of the given module.
Only supports source code files encoded as UTF-8
"""
module_name, path = self.lookup(module_name)
if path:
with open(path, 'rb') as f:
return module_name... | python | def load(self, module_name):
"""Returns source code and normalized module id of the given module.
Only supports source code files encoded as UTF-8
"""
module_name, path = self.lookup(module_name)
if path:
with open(path, 'rb') as f:
return module_name... | [
"def",
"load",
"(",
"self",
",",
"module_name",
")",
":",
"module_name",
",",
"path",
"=",
"self",
".",
"lookup",
"(",
"module_name",
")",
"if",
"path",
":",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"f",
":",
"return",
"module_name",
",",... | Returns source code and normalized module id of the given module.
Only supports source code files encoded as UTF-8 | [
"Returns",
"source",
"code",
"and",
"normalized",
"module",
"id",
"of",
"the",
"given",
"module",
"."
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/module_loader.py#L39-L48 | train |
amol-/dukpy | dukpy/lessc.py | less_compile | def less_compile(source, options=None):
"""Compiles the given ``source`` from LESS to CSS"""
options = options or {}
res = NodeLikeInterpreter().evaljs(
('var result = null;'
'var less = require("less/less-node");',
'less.render(dukpy.lesscode, dukpy.lessoptions, function(error, ou... | python | def less_compile(source, options=None):
"""Compiles the given ``source`` from LESS to CSS"""
options = options or {}
res = NodeLikeInterpreter().evaljs(
('var result = null;'
'var less = require("less/less-node");',
'less.render(dukpy.lesscode, dukpy.lessoptions, function(error, ou... | [
"def",
"less_compile",
"(",
"source",
",",
"options",
"=",
"None",
")",
":",
"options",
"=",
"options",
"or",
"{",
"}",
"res",
"=",
"NodeLikeInterpreter",
"(",
")",
".",
"evaljs",
"(",
"(",
"'var result = null;'",
"'var less = require(\"less/less-node\");'",
","... | Compiles the given ``source`` from LESS to CSS | [
"Compiles",
"the",
"given",
"source",
"from",
"LESS",
"to",
"CSS"
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/lessc.py#L4-L23 | train |
amol-/dukpy | dukpy/install.py | install_jspackage | def install_jspackage(package_name, version, modulesdir):
"""Installs a JavaScript package downloaded from npmjs.org.
For example to install React::
install_jspackage('react', '0.14.8', './node_modules')
To install last version provide `None` as the version.
"""
if not version:
ve... | python | def install_jspackage(package_name, version, modulesdir):
"""Installs a JavaScript package downloaded from npmjs.org.
For example to install React::
install_jspackage('react', '0.14.8', './node_modules')
To install last version provide `None` as the version.
"""
if not version:
ve... | [
"def",
"install_jspackage",
"(",
"package_name",
",",
"version",
",",
"modulesdir",
")",
":",
"if",
"not",
"version",
":",
"version",
"=",
"''",
"requirements",
"=",
"_resolve_dependencies",
"(",
"package_name",
",",
"version",
")",
"print",
"(",
"'Packages goin... | Installs a JavaScript package downloaded from npmjs.org.
For example to install React::
install_jspackage('react', '0.14.8', './node_modules')
To install last version provide `None` as the version. | [
"Installs",
"a",
"JavaScript",
"package",
"downloaded",
"from",
"npmjs",
".",
"org",
"."
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/install.py#L39-L87 | train |
amol-/dukpy | dukpy/evaljs.py | JSInterpreter.evaljs | def evaljs(self, code, **kwargs):
"""Runs JavaScript code in the context of the interpreter.
All arguments will be converted to plain javascript objects
through the JSON encoder and will be available in `dukpy`
global object.
Returns the last object on javascript stack.
... | python | def evaljs(self, code, **kwargs):
"""Runs JavaScript code in the context of the interpreter.
All arguments will be converted to plain javascript objects
through the JSON encoder and will be available in `dukpy`
global object.
Returns the last object on javascript stack.
... | [
"def",
"evaljs",
"(",
"self",
",",
"code",
",",
"**",
"kwargs",
")",
":",
"jsvars",
"=",
"json",
".",
"dumps",
"(",
"kwargs",
")",
"jscode",
"=",
"self",
".",
"_adapt_code",
"(",
"code",
")",
"if",
"not",
"isinstance",
"(",
"jscode",
",",
"bytes",
... | Runs JavaScript code in the context of the interpreter.
All arguments will be converted to plain javascript objects
through the JSON encoder and will be available in `dukpy`
global object.
Returns the last object on javascript stack. | [
"Runs",
"JavaScript",
"code",
"in",
"the",
"context",
"of",
"the",
"interpreter",
"."
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/evaljs.py#L39-L61 | train |
amol-/dukpy | dukpy/tsc.py | typescript_compile | def typescript_compile(source):
"""Compiles the given ``source`` from TypeScript to ES5 using TypescriptServices.js"""
with open(TS_COMPILER, 'r') as tsservices_js:
return evaljs(
(tsservices_js.read(),
'ts.transpile(dukpy.tscode, {options});'.format(options=TSC_OPTIONS)),
... | python | def typescript_compile(source):
"""Compiles the given ``source`` from TypeScript to ES5 using TypescriptServices.js"""
with open(TS_COMPILER, 'r') as tsservices_js:
return evaljs(
(tsservices_js.read(),
'ts.transpile(dukpy.tscode, {options});'.format(options=TSC_OPTIONS)),
... | [
"def",
"typescript_compile",
"(",
"source",
")",
":",
"with",
"open",
"(",
"TS_COMPILER",
",",
"'r'",
")",
"as",
"tsservices_js",
":",
"return",
"evaljs",
"(",
"(",
"tsservices_js",
".",
"read",
"(",
")",
",",
"'ts.transpile(dukpy.tscode, {options});'",
".",
"... | Compiles the given ``source`` from TypeScript to ES5 using TypescriptServices.js | [
"Compiles",
"the",
"given",
"source",
"from",
"TypeScript",
"to",
"ES5",
"using",
"TypescriptServices",
".",
"js"
] | 69f56f375a217c9f907499c28dbc964af76feae6 | https://github.com/amol-/dukpy/blob/69f56f375a217c9f907499c28dbc964af76feae6/dukpy/tsc.py#L8-L15 | train |
edoburu/django-private-storage | private_storage/views.py | PrivateStorageView.get_private_file | def get_private_file(self):
"""
Return all relevant data in a single object, so this is easy to extend
and server implementations can pick what they need.
"""
return PrivateFile(
request=self.request,
storage=self.get_storage(),
relative_name=s... | python | def get_private_file(self):
"""
Return all relevant data in a single object, so this is easy to extend
and server implementations can pick what they need.
"""
return PrivateFile(
request=self.request,
storage=self.get_storage(),
relative_name=s... | [
"def",
"get_private_file",
"(",
"self",
")",
":",
"return",
"PrivateFile",
"(",
"request",
"=",
"self",
".",
"request",
",",
"storage",
"=",
"self",
".",
"get_storage",
"(",
")",
",",
"relative_name",
"=",
"self",
".",
"get_path",
"(",
")",
")"
] | Return all relevant data in a single object, so this is easy to extend
and server implementations can pick what they need. | [
"Return",
"all",
"relevant",
"data",
"in",
"a",
"single",
"object",
"so",
"this",
"is",
"easy",
"to",
"extend",
"and",
"server",
"implementations",
"can",
"pick",
"what",
"they",
"need",
"."
] | 35b718024fee75b0ed3400f601976b20246c7d05 | https://github.com/edoburu/django-private-storage/blob/35b718024fee75b0ed3400f601976b20246c7d05/private_storage/views.py#L55-L64 | train |
edoburu/django-private-storage | private_storage/views.py | PrivateStorageView.get | def get(self, request, *args, **kwargs):
"""
Handle incoming GET requests
"""
private_file = self.get_private_file()
if not self.can_access_file(private_file):
return HttpResponseForbidden('Private storage access denied')
if not private_file.exists():
... | python | def get(self, request, *args, **kwargs):
"""
Handle incoming GET requests
"""
private_file = self.get_private_file()
if not self.can_access_file(private_file):
return HttpResponseForbidden('Private storage access denied')
if not private_file.exists():
... | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"private_file",
"=",
"self",
".",
"get_private_file",
"(",
")",
"if",
"not",
"self",
".",
"can_access_file",
"(",
"private_file",
")",
":",
"return",
"HttpRespons... | Handle incoming GET requests | [
"Handle",
"incoming",
"GET",
"requests"
] | 35b718024fee75b0ed3400f601976b20246c7d05 | https://github.com/edoburu/django-private-storage/blob/35b718024fee75b0ed3400f601976b20246c7d05/private_storage/views.py#L66-L78 | train |
edoburu/django-private-storage | private_storage/views.py | PrivateStorageView.serve_file | def serve_file(self, private_file):
"""
Serve the file that was retrieved from the storage.
The relative path can be found with ``private_file.relative_name``.
:type private_file: :class:`private_storage.models.PrivateFile`
:rtype: django.http.HttpResponse
"""
re... | python | def serve_file(self, private_file):
"""
Serve the file that was retrieved from the storage.
The relative path can be found with ``private_file.relative_name``.
:type private_file: :class:`private_storage.models.PrivateFile`
:rtype: django.http.HttpResponse
"""
re... | [
"def",
"serve_file",
"(",
"self",
",",
"private_file",
")",
":",
"response",
"=",
"self",
".",
"server_class",
"(",
")",
".",
"serve",
"(",
"private_file",
")",
"if",
"self",
".",
"content_disposition",
":",
"filename",
"=",
"self",
".",
"get_content_disposi... | Serve the file that was retrieved from the storage.
The relative path can be found with ``private_file.relative_name``.
:type private_file: :class:`private_storage.models.PrivateFile`
:rtype: django.http.HttpResponse | [
"Serve",
"the",
"file",
"that",
"was",
"retrieved",
"from",
"the",
"storage",
".",
"The",
"relative",
"path",
"can",
"be",
"found",
"with",
"private_file",
".",
"relative_name",
"."
] | 35b718024fee75b0ed3400f601976b20246c7d05 | https://github.com/edoburu/django-private-storage/blob/35b718024fee75b0ed3400f601976b20246c7d05/private_storage/views.py#L94-L112 | train |
edoburu/django-private-storage | private_storage/views.py | PrivateStorageView.get_content_disposition_filename | def get_content_disposition_filename(self, private_file):
"""
Return the filename in the download header.
"""
return self.content_disposition_filename or os.path.basename(private_file.relative_name) | python | def get_content_disposition_filename(self, private_file):
"""
Return the filename in the download header.
"""
return self.content_disposition_filename or os.path.basename(private_file.relative_name) | [
"def",
"get_content_disposition_filename",
"(",
"self",
",",
"private_file",
")",
":",
"return",
"self",
".",
"content_disposition_filename",
"or",
"os",
".",
"path",
".",
"basename",
"(",
"private_file",
".",
"relative_name",
")"
] | Return the filename in the download header. | [
"Return",
"the",
"filename",
"in",
"the",
"download",
"header",
"."
] | 35b718024fee75b0ed3400f601976b20246c7d05 | https://github.com/edoburu/django-private-storage/blob/35b718024fee75b0ed3400f601976b20246c7d05/private_storage/views.py#L114-L118 | train |
edoburu/django-private-storage | private_storage/views.py | PrivateStorageView._encode_filename_header | def _encode_filename_header(self, filename):
"""
The filename, encoded to use in a ``Content-Disposition`` header.
"""
# Based on https://www.djangosnippets.org/snippets/1710/
user_agent = self.request.META.get('HTTP_USER_AGENT', None)
if 'WebKit' in user_agent:
... | python | def _encode_filename_header(self, filename):
"""
The filename, encoded to use in a ``Content-Disposition`` header.
"""
# Based on https://www.djangosnippets.org/snippets/1710/
user_agent = self.request.META.get('HTTP_USER_AGENT', None)
if 'WebKit' in user_agent:
... | [
"def",
"_encode_filename_header",
"(",
"self",
",",
"filename",
")",
":",
"user_agent",
"=",
"self",
".",
"request",
".",
"META",
".",
"get",
"(",
"'HTTP_USER_AGENT'",
",",
"None",
")",
"if",
"'WebKit'",
"in",
"user_agent",
":",
"return",
"u'filename={}'",
"... | The filename, encoded to use in a ``Content-Disposition`` header. | [
"The",
"filename",
"encoded",
"to",
"use",
"in",
"a",
"Content",
"-",
"Disposition",
"header",
"."
] | 35b718024fee75b0ed3400f601976b20246c7d05 | https://github.com/edoburu/django-private-storage/blob/35b718024fee75b0ed3400f601976b20246c7d05/private_storage/views.py#L120-L139 | train |
edoburu/django-private-storage | private_storage/servers.py | add_no_cache_headers | def add_no_cache_headers(func):
"""
Makes sure the retrieved file is not cached on disk, or cached by proxy servers in between.
This would circumvent any checking whether the user may even access the file.
"""
@wraps(func)
def _dec(*args, **kwargs):
response = func(*args, **kwargs)
... | python | def add_no_cache_headers(func):
"""
Makes sure the retrieved file is not cached on disk, or cached by proxy servers in between.
This would circumvent any checking whether the user may even access the file.
"""
@wraps(func)
def _dec(*args, **kwargs):
response = func(*args, **kwargs)
... | [
"def",
"add_no_cache_headers",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"_dec",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"response",
"=",
"func",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"response",
"[",
"'Expires'",
... | Makes sure the retrieved file is not cached on disk, or cached by proxy servers in between.
This would circumvent any checking whether the user may even access the file. | [
"Makes",
"sure",
"the",
"retrieved",
"file",
"is",
"not",
"cached",
"on",
"disk",
"or",
"cached",
"by",
"proxy",
"servers",
"in",
"between",
".",
"This",
"would",
"circumvent",
"any",
"checking",
"whether",
"the",
"user",
"may",
"even",
"access",
"the",
"f... | 35b718024fee75b0ed3400f601976b20246c7d05 | https://github.com/edoburu/django-private-storage/blob/35b718024fee75b0ed3400f601976b20246c7d05/private_storage/servers.py#L43-L56 | train |
datamade/parserator | parserator/training.py | readTrainingData | def readTrainingData(file_locations, GROUP_LABEL):
'''
Used in downstream tests
'''
class Mock(object):
pass
mock_module = Mock()
mock_module.PARENT_LABEL = GROUP_LABEL
for location in file_locations:
with open(location) as f:
tree = etree.parse(f)
xml = ... | python | def readTrainingData(file_locations, GROUP_LABEL):
'''
Used in downstream tests
'''
class Mock(object):
pass
mock_module = Mock()
mock_module.PARENT_LABEL = GROUP_LABEL
for location in file_locations:
with open(location) as f:
tree = etree.parse(f)
xml = ... | [
"def",
"readTrainingData",
"(",
"file_locations",
",",
"GROUP_LABEL",
")",
":",
"class",
"Mock",
"(",
"object",
")",
":",
"pass",
"mock_module",
"=",
"Mock",
"(",
")",
"mock_module",
".",
"PARENT_LABEL",
"=",
"GROUP_LABEL",
"for",
"location",
"in",
"file_locat... | Used in downstream tests | [
"Used",
"in",
"downstream",
"tests"
] | 4dc69b0d115bf33e2d169ff40b05143257a5f481 | https://github.com/datamade/parserator/blob/4dc69b0d115bf33e2d169ff40b05143257a5f481/parserator/training.py#L58-L72 | train |
Bouke/django-user-sessions | user_sessions/templatetags/user_sessions.py | device | def device(value):
"""
Transform a User Agent into human readable text.
Example output:
* Safari on iPhone
* Chrome on Windows 8.1
* Safari on OS X
* Firefox
* Linux
* None
"""
browser = None
for regex, name in BROWSERS:
if regex.search(value):
brow... | python | def device(value):
"""
Transform a User Agent into human readable text.
Example output:
* Safari on iPhone
* Chrome on Windows 8.1
* Safari on OS X
* Firefox
* Linux
* None
"""
browser = None
for regex, name in BROWSERS:
if regex.search(value):
brow... | [
"def",
"device",
"(",
"value",
")",
":",
"browser",
"=",
"None",
"for",
"regex",
",",
"name",
"in",
"BROWSERS",
":",
"if",
"regex",
".",
"search",
"(",
"value",
")",
":",
"browser",
"=",
"name",
"break",
"device",
"=",
"None",
"for",
"regex",
",",
... | Transform a User Agent into human readable text.
Example output:
* Safari on iPhone
* Chrome on Windows 8.1
* Safari on OS X
* Firefox
* Linux
* None | [
"Transform",
"a",
"User",
"Agent",
"into",
"human",
"readable",
"text",
"."
] | 9362ad60d61b68faccac674e9aae030537ff821a | https://github.com/Bouke/django-user-sessions/blob/9362ad60d61b68faccac674e9aae030537ff821a/user_sessions/templatetags/user_sessions.py#L39-L77 | train |
Bouke/django-user-sessions | user_sessions/templatetags/user_sessions.py | location | def location(value):
"""
Transform an IP address into an approximate location.
Example output:
* Zwolle, The Netherlands
* The Netherlands
* None
"""
try:
location = geoip() and geoip().city(value)
except Exception:
try:
location = geoip() and geoip().co... | python | def location(value):
"""
Transform an IP address into an approximate location.
Example output:
* Zwolle, The Netherlands
* The Netherlands
* None
"""
try:
location = geoip() and geoip().city(value)
except Exception:
try:
location = geoip() and geoip().co... | [
"def",
"location",
"(",
"value",
")",
":",
"try",
":",
"location",
"=",
"geoip",
"(",
")",
"and",
"geoip",
"(",
")",
".",
"city",
"(",
"value",
")",
"except",
"Exception",
":",
"try",
":",
"location",
"=",
"geoip",
"(",
")",
"and",
"geoip",
"(",
... | Transform an IP address into an approximate location.
Example output:
* Zwolle, The Netherlands
* The Netherlands
* None | [
"Transform",
"an",
"IP",
"address",
"into",
"an",
"approximate",
"location",
"."
] | 9362ad60d61b68faccac674e9aae030537ff821a | https://github.com/Bouke/django-user-sessions/blob/9362ad60d61b68faccac674e9aae030537ff821a/user_sessions/templatetags/user_sessions.py#L81-L103 | train |
dschep/lambda-decorators | lambda_decorators.py | before | def before(func):
"""
Run a function before the handler is invoked, is passed the event & context
and must return an event & context too.
Usage::
>>> # to create a reusable decorator
>>> @before
... def print_request_id(event, context):
... print(context.aws_request... | python | def before(func):
"""
Run a function before the handler is invoked, is passed the event & context
and must return an event & context too.
Usage::
>>> # to create a reusable decorator
>>> @before
... def print_request_id(event, context):
... print(context.aws_request... | [
"def",
"before",
"(",
"func",
")",
":",
"class",
"BeforeDecorator",
"(",
"LambdaDecorator",
")",
":",
"def",
"before",
"(",
"self",
",",
"event",
",",
"context",
")",
":",
"return",
"func",
"(",
"event",
",",
"context",
")",
"return",
"BeforeDecorator"
] | Run a function before the handler is invoked, is passed the event & context
and must return an event & context too.
Usage::
>>> # to create a reusable decorator
>>> @before
... def print_request_id(event, context):
... print(context.aws_request_id)
... return ev... | [
"Run",
"a",
"function",
"before",
"the",
"handler",
"is",
"invoked",
"is",
"passed",
"the",
"event",
"&",
"context",
"and",
"must",
"return",
"an",
"event",
"&",
"context",
"too",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L234-L264 | train |
dschep/lambda-decorators | lambda_decorators.py | after | def after(func):
"""
Run a function after the handler is invoked, is passed the response
and must return an response too.
Usage::
>>> # to create a reusable decorator
>>> @after
... def gnu_terry_pratchett(retval):
... retval.setdefault('Headers', {})['X-Clacks-Over... | python | def after(func):
"""
Run a function after the handler is invoked, is passed the response
and must return an response too.
Usage::
>>> # to create a reusable decorator
>>> @after
... def gnu_terry_pratchett(retval):
... retval.setdefault('Headers', {})['X-Clacks-Over... | [
"def",
"after",
"(",
"func",
")",
":",
"class",
"AfterDecorator",
"(",
"LambdaDecorator",
")",
":",
"def",
"after",
"(",
"self",
",",
"retval",
")",
":",
"return",
"func",
"(",
"retval",
")",
"return",
"AfterDecorator"
] | Run a function after the handler is invoked, is passed the response
and must return an response too.
Usage::
>>> # to create a reusable decorator
>>> @after
... def gnu_terry_pratchett(retval):
... retval.setdefault('Headers', {})['X-Clacks-Overhead'] = 'GNU Terry Pratchett... | [
"Run",
"a",
"function",
"after",
"the",
"handler",
"is",
"invoked",
"is",
"passed",
"the",
"response",
"and",
"must",
"return",
"an",
"response",
"too",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L267-L289 | train |
dschep/lambda-decorators | lambda_decorators.py | on_exception | def on_exception(func):
"""
Run a function when a handler thows an exception. It's return value is
returned to AWS.
Usage::
>>> # to create a reusable decorator
>>> @on_exception
... def handle_errors(exception):
... print(exception)
... return {'statusC... | python | def on_exception(func):
"""
Run a function when a handler thows an exception. It's return value is
returned to AWS.
Usage::
>>> # to create a reusable decorator
>>> @on_exception
... def handle_errors(exception):
... print(exception)
... return {'statusC... | [
"def",
"on_exception",
"(",
"func",
")",
":",
"class",
"OnExceptionDecorator",
"(",
"LambdaDecorator",
")",
":",
"def",
"on_exception",
"(",
"self",
",",
"exception",
")",
":",
"return",
"func",
"(",
"exception",
")",
"return",
"OnExceptionDecorator"
] | Run a function when a handler thows an exception. It's return value is
returned to AWS.
Usage::
>>> # to create a reusable decorator
>>> @on_exception
... def handle_errors(exception):
... print(exception)
... return {'statusCode': 500, 'body': 'uh oh'}
... | [
"Run",
"a",
"function",
"when",
"a",
"handler",
"thows",
"an",
"exception",
".",
"It",
"s",
"return",
"value",
"is",
"returned",
"to",
"AWS",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L292-L321 | train |
dschep/lambda-decorators | lambda_decorators.py | async_handler | def async_handler(handler):
"""
This decorator allows for use of async handlers by automatically running
them in an event loop. The loop is added to the context object for if the
handler needs it.
Usage::
>>> from lambda_decorators import async_handler
>>> async def foobar():
... | python | def async_handler(handler):
"""
This decorator allows for use of async handlers by automatically running
them in an event loop. The loop is added to the context object for if the
handler needs it.
Usage::
>>> from lambda_decorators import async_handler
>>> async def foobar():
... | [
"def",
"async_handler",
"(",
"handler",
")",
":",
"@",
"wraps",
"(",
"handler",
")",
"def",
"wrapper",
"(",
"event",
",",
"context",
")",
":",
"context",
".",
"loop",
"=",
"asyncio",
".",
"get_event_loop",
"(",
")",
"return",
"context",
".",
"loop",
".... | This decorator allows for use of async handlers by automatically running
them in an event loop. The loop is added to the context object for if the
handler needs it.
Usage::
>>> from lambda_decorators import async_handler
>>> async def foobar():
... return 'foobar'
>>> @... | [
"This",
"decorator",
"allows",
"for",
"use",
"of",
"async",
"handlers",
"by",
"automatically",
"running",
"them",
"in",
"an",
"event",
"loop",
".",
"The",
"loop",
"is",
"added",
"to",
"the",
"context",
"object",
"for",
"if",
"the",
"handler",
"needs",
"it"... | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L324-L351 | train |
dschep/lambda-decorators | lambda_decorators.py | dump_json_body | def dump_json_body(handler):
"""
Automatically serialize response bodies with json.dumps.
Returns a 500 error if the response cannot be serialized
Usage::
>>> from lambda_decorators import dump_json_body
>>> @dump_json_body
... def handler(event, context):
... return {'statusCode': 200, 'body': {'hel... | python | def dump_json_body(handler):
"""
Automatically serialize response bodies with json.dumps.
Returns a 500 error if the response cannot be serialized
Usage::
>>> from lambda_decorators import dump_json_body
>>> @dump_json_body
... def handler(event, context):
... return {'statusCode': 200, 'body': {'hel... | [
"def",
"dump_json_body",
"(",
"handler",
")",
":",
"@",
"wraps",
"(",
"handler",
")",
"def",
"wrapper",
"(",
"event",
",",
"context",
")",
":",
"response",
"=",
"handler",
"(",
"event",
",",
"context",
")",
"if",
"'body'",
"in",
"response",
":",
"try",... | Automatically serialize response bodies with json.dumps.
Returns a 500 error if the response cannot be serialized
Usage::
>>> from lambda_decorators import dump_json_body
>>> @dump_json_body
... def handler(event, context):
... return {'statusCode': 200, 'body': {'hello': 'world'}}
>>> handler({}, obje... | [
"Automatically",
"serialize",
"response",
"bodies",
"with",
"json",
".",
"dumps",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L401-L425 | train |
dschep/lambda-decorators | lambda_decorators.py | json_http_resp | def json_http_resp(handler):
"""
Automatically serialize return value to the body of a successfull HTTP
response.
Returns a 500 error if the response cannot be serialized
Usage::
>>> from lambda_decorators import json_http_resp
>>> @json_http_resp
... def handler(event, context):
... return {... | python | def json_http_resp(handler):
"""
Automatically serialize return value to the body of a successfull HTTP
response.
Returns a 500 error if the response cannot be serialized
Usage::
>>> from lambda_decorators import json_http_resp
>>> @json_http_resp
... def handler(event, context):
... return {... | [
"def",
"json_http_resp",
"(",
"handler",
")",
":",
"@",
"wraps",
"(",
"handler",
")",
"def",
"wrapper",
"(",
"event",
",",
"context",
")",
":",
"response",
"=",
"handler",
"(",
"event",
",",
"context",
")",
"try",
":",
"body",
"=",
"json",
".",
"dump... | Automatically serialize return value to the body of a successfull HTTP
response.
Returns a 500 error if the response cannot be serialized
Usage::
>>> from lambda_decorators import json_http_resp
>>> @json_http_resp
... def handler(event, context):
... return {'hello': 'world'}
>>> handler({},... | [
"Automatically",
"serialize",
"return",
"value",
"to",
"the",
"body",
"of",
"a",
"successfull",
"HTTP",
"response",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L428-L459 | train |
dschep/lambda-decorators | lambda_decorators.py | load_json_body | def load_json_body(handler):
"""
Automatically deserialize event bodies with json.loads.
Automatically returns a 400 BAD REQUEST if there is an error while parsing.
Usage::
>>> from lambda_decorators import load_json_body
>>> @load_json_body
... def handler(event, context):
..... | python | def load_json_body(handler):
"""
Automatically deserialize event bodies with json.loads.
Automatically returns a 400 BAD REQUEST if there is an error while parsing.
Usage::
>>> from lambda_decorators import load_json_body
>>> @load_json_body
... def handler(event, context):
..... | [
"def",
"load_json_body",
"(",
"handler",
")",
":",
"@",
"wraps",
"(",
"handler",
")",
"def",
"wrapper",
"(",
"event",
",",
"context",
")",
":",
"if",
"isinstance",
"(",
"event",
".",
"get",
"(",
"'body'",
")",
",",
"str",
")",
":",
"try",
":",
"eve... | Automatically deserialize event bodies with json.loads.
Automatically returns a 400 BAD REQUEST if there is an error while parsing.
Usage::
>>> from lambda_decorators import load_json_body
>>> @load_json_body
... def handler(event, context):
... return event['body']['foo']
>... | [
"Automatically",
"deserialize",
"event",
"bodies",
"with",
"json",
".",
"loads",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L462-L489 | train |
dschep/lambda-decorators | lambda_decorators.py | json_schema_validator | def json_schema_validator(request_schema=None, response_schema=None):
"""
Validate your request & response payloads against a JSONSchema.
*NOTE: depends on the* `jsonschema <https://github.com/Julian/jsonschema>`_
*package. If you're using* `serverless-python-requirements <https://github.com/UnitedInco... | python | def json_schema_validator(request_schema=None, response_schema=None):
"""
Validate your request & response payloads against a JSONSchema.
*NOTE: depends on the* `jsonschema <https://github.com/Julian/jsonschema>`_
*package. If you're using* `serverless-python-requirements <https://github.com/UnitedInco... | [
"def",
"json_schema_validator",
"(",
"request_schema",
"=",
"None",
",",
"response_schema",
"=",
"None",
")",
":",
"def",
"wrapper_wrapper",
"(",
"handler",
")",
":",
"@",
"wraps",
"(",
"handler",
")",
"def",
"wrapper",
"(",
"event",
",",
"context",
")",
"... | Validate your request & response payloads against a JSONSchema.
*NOTE: depends on the* `jsonschema <https://github.com/Julian/jsonschema>`_
*package. If you're using* `serverless-python-requirements <https://github.com/UnitedIncome/serverless-python-requirements>`_
*you're all set. If you cURLed* ``lambda_... | [
"Validate",
"your",
"request",
"&",
"response",
"payloads",
"against",
"a",
"JSONSchema",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L492-L546 | train |
dschep/lambda-decorators | lambda_decorators.py | no_retry_on_failure | def no_retry_on_failure(handler):
"""
AWS Lambda retries scheduled lambdas that don't execute succesfully.
This detects this by storing requests IDs in memory and exiting early on
duplicates. Since this is in memory, don't use it on very frequently
scheduled lambdas. It logs a critical message then... | python | def no_retry_on_failure(handler):
"""
AWS Lambda retries scheduled lambdas that don't execute succesfully.
This detects this by storing requests IDs in memory and exiting early on
duplicates. Since this is in memory, don't use it on very frequently
scheduled lambdas. It logs a critical message then... | [
"def",
"no_retry_on_failure",
"(",
"handler",
")",
":",
"seen_request_ids",
"=",
"set",
"(",
")",
"@",
"wraps",
"(",
"handler",
")",
"def",
"wrapper",
"(",
"event",
",",
"context",
")",
":",
"if",
"context",
".",
"aws_request_id",
"in",
"seen_request_ids",
... | AWS Lambda retries scheduled lambdas that don't execute succesfully.
This detects this by storing requests IDs in memory and exiting early on
duplicates. Since this is in memory, don't use it on very frequently
scheduled lambdas. It logs a critical message then exits with a statusCode
of 200 to avoid f... | [
"AWS",
"Lambda",
"retries",
"scheduled",
"lambdas",
"that",
"don",
"t",
"execute",
"succesfully",
"."
] | 9195914c8afe26843de9968d96dae6a89f061e8a | https://github.com/dschep/lambda-decorators/blob/9195914c8afe26843de9968d96dae6a89f061e8a/lambda_decorators.py#L579-L617 | train |
dmarx/psaw | psaw/PushshiftAPI.py | PushshiftAPIMinimal._wrap_thing | def _wrap_thing(self, thing, kind):
"""Mimic praw.Submission and praw.Comment API"""
thing['created'] = self._epoch_utc_to_local(thing['created_utc'])
thing['d_'] = copy.deepcopy(thing)
ThingType = namedtuple(kind, thing.keys())
thing = ThingType(**thing)
return thing | python | def _wrap_thing(self, thing, kind):
"""Mimic praw.Submission and praw.Comment API"""
thing['created'] = self._epoch_utc_to_local(thing['created_utc'])
thing['d_'] = copy.deepcopy(thing)
ThingType = namedtuple(kind, thing.keys())
thing = ThingType(**thing)
return thing | [
"def",
"_wrap_thing",
"(",
"self",
",",
"thing",
",",
"kind",
")",
":",
"thing",
"[",
"'created'",
"]",
"=",
"self",
".",
"_epoch_utc_to_local",
"(",
"thing",
"[",
"'created_utc'",
"]",
")",
"thing",
"[",
"'d_'",
"]",
"=",
"copy",
".",
"deepcopy",
"(",... | Mimic praw.Submission and praw.Comment API | [
"Mimic",
"praw",
".",
"Submission",
"and",
"praw",
".",
"Comment",
"API"
] | 5702abdd1a0ccd60b115fc4b545eb2c087c56194 | https://github.com/dmarx/psaw/blob/5702abdd1a0ccd60b115fc4b545eb2c087c56194/psaw/PushshiftAPI.py#L112-L118 | train |
dmarx/psaw | psaw/PushshiftAPI.py | PushshiftAPIMinimal._add_nec_args | def _add_nec_args(self, payload):
"""Adds 'limit' and 'created_utc' arguments to the payload as necessary."""
if self._limited(payload):
# Do nothing I guess? Not sure how paging works on this endpoint...
return
if 'limit' not in payload:
payload['limit'] = se... | python | def _add_nec_args(self, payload):
"""Adds 'limit' and 'created_utc' arguments to the payload as necessary."""
if self._limited(payload):
# Do nothing I guess? Not sure how paging works on this endpoint...
return
if 'limit' not in payload:
payload['limit'] = se... | [
"def",
"_add_nec_args",
"(",
"self",
",",
"payload",
")",
":",
"if",
"self",
".",
"_limited",
"(",
"payload",
")",
":",
"return",
"if",
"'limit'",
"not",
"in",
"payload",
":",
"payload",
"[",
"'limit'",
"]",
"=",
"self",
".",
"max_results_per_request",
"... | Adds 'limit' and 'created_utc' arguments to the payload as necessary. | [
"Adds",
"limit",
"and",
"created_utc",
"arguments",
"to",
"the",
"payload",
"as",
"necessary",
"."
] | 5702abdd1a0ccd60b115fc4b545eb2c087c56194 | https://github.com/dmarx/psaw/blob/5702abdd1a0ccd60b115fc4b545eb2c087c56194/psaw/PushshiftAPI.py#L130-L147 | train |
pyroscope/pyrocore | src/pyrocore/scripts/rtmv.py | pretty_path | def pretty_path(path):
""" Prettify path for logging.
"""
path = fmt.to_utf8(path)
home_dir = os.path.expanduser("~")
if path.startswith(home_dir):
path = "~" + path[len(home_dir):]
return '"%s"' % (path,) | python | def pretty_path(path):
""" Prettify path for logging.
"""
path = fmt.to_utf8(path)
home_dir = os.path.expanduser("~")
if path.startswith(home_dir):
path = "~" + path[len(home_dir):]
return '"%s"' % (path,) | [
"def",
"pretty_path",
"(",
"path",
")",
":",
"path",
"=",
"fmt",
".",
"to_utf8",
"(",
"path",
")",
"home_dir",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~\"",
")",
"if",
"path",
".",
"startswith",
"(",
"home_dir",
")",
":",
"path",
"=",
"\... | Prettify path for logging. | [
"Prettify",
"path",
"for",
"logging",
"."
] | 89ad01346a570943d20311a0b488440975876612 | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/scripts/rtmv.py#L31-L38 | train |
pyroscope/pyrocore | src/pyrocore/scripts/rtmv.py | RtorrentMove.guarded | def guarded(self, call, *args):
""" Catch exceptions thrown by filesystem calls, and don't really
execute them in dry-run mode.
"""
self.LOG.debug('%s(%s)' % (
call.__name__, ', '.join([pretty_path(i) for i in args]),
))
if not self.options.dry_run:
... | python | def guarded(self, call, *args):
""" Catch exceptions thrown by filesystem calls, and don't really
execute them in dry-run mode.
"""
self.LOG.debug('%s(%s)' % (
call.__name__, ', '.join([pretty_path(i) for i in args]),
))
if not self.options.dry_run:
... | [
"def",
"guarded",
"(",
"self",
",",
"call",
",",
"*",
"args",
")",
":",
"self",
".",
"LOG",
".",
"debug",
"(",
"'%s(%s)'",
"%",
"(",
"call",
".",
"__name__",
",",
"', '",
".",
"join",
"(",
"[",
"pretty_path",
"(",
"i",
")",
"for",
"i",
"in",
"a... | Catch exceptions thrown by filesystem calls, and don't really
execute them in dry-run mode. | [
"Catch",
"exceptions",
"thrown",
"by",
"filesystem",
"calls",
"and",
"don",
"t",
"really",
"execute",
"them",
"in",
"dry",
"-",
"run",
"mode",
"."
] | 89ad01346a570943d20311a0b488440975876612 | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/scripts/rtmv.py#L82-L95 | train |
pyroscope/pyrocore | src/pyrocore/torrent/rtorrent.py | run | def run():
""" Module level test.
"""
logging.basicConfig(level=logging.DEBUG)
load_config.ConfigLoader().load()
config.debug = True
print(repr(config.engine.item(sys.argv[1]))) | python | def run():
""" Module level test.
"""
logging.basicConfig(level=logging.DEBUG)
load_config.ConfigLoader().load()
config.debug = True
print(repr(config.engine.item(sys.argv[1]))) | [
"def",
"run",
"(",
")",
":",
"logging",
".",
"basicConfig",
"(",
"level",
"=",
"logging",
".",
"DEBUG",
")",
"load_config",
".",
"ConfigLoader",
"(",
")",
".",
"load",
"(",
")",
"config",
".",
"debug",
"=",
"True",
"print",
"(",
"repr",
"(",
"config"... | Module level test. | [
"Module",
"level",
"test",
"."
] | 89ad01346a570943d20311a0b488440975876612 | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/torrent/rtorrent.py#L848-L854 | train |
pyroscope/pyrocore | src/pyrocore/torrent/rtorrent.py | RtorrentItem._make_it_so | def _make_it_so(self, command, calls, *args, **kwargs):
""" Perform some error-checked XMLRPC calls.
"""
observer = kwargs.pop('observer', False)
args = (self._fields["hash"],) + args
try:
for call in calls:
self._engine.LOG.debug("%s%s torrent #%s (%s... | python | def _make_it_so(self, command, calls, *args, **kwargs):
""" Perform some error-checked XMLRPC calls.
"""
observer = kwargs.pop('observer', False)
args = (self._fields["hash"],) + args
try:
for call in calls:
self._engine.LOG.debug("%s%s torrent #%s (%s... | [
"def",
"_make_it_so",
"(",
"self",
",",
"command",
",",
"calls",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"observer",
"=",
"kwargs",
".",
"pop",
"(",
"'observer'",
",",
"False",
")",
"args",
"=",
"(",
"self",
".",
"_fields",
"[",
"\"hash\"",
... | Perform some error-checked XMLRPC calls. | [
"Perform",
"some",
"error",
"-",
"checked",
"XMLRPC",
"calls",
"."
] | 89ad01346a570943d20311a0b488440975876612 | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/torrent/rtorrent.py#L60-L77 | train |
pyroscope/pyrocore | src/pyrocore/torrent/rtorrent.py | RtorrentItem.fetch | def fetch(self, name, engine_name=None):
""" Get a field on demand.
"""
# TODO: Get each on-demand field in a multicall for all other items, since
# we likely need it anyway; another (more easy) way would be to pre-fetch dynamically
# with the list of fields from filters and outp... | python | def fetch(self, name, engine_name=None):
""" Get a field on demand.
"""
# TODO: Get each on-demand field in a multicall for all other items, since
# we likely need it anyway; another (more easy) way would be to pre-fetch dynamically
# with the list of fields from filters and outp... | [
"def",
"fetch",
"(",
"self",
",",
"name",
",",
"engine_name",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"_fields",
"[",
"name",
"]",
"except",
"KeyError",
":",
"if",
"isinstance",
"(",
"name",
",",
"(",
"int",
",",
"long",
")",
")",... | Get a field on demand. | [
"Get",
"a",
"field",
"on",
"demand",
"."
] | 89ad01346a570943d20311a0b488440975876612 | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/torrent/rtorrent.py#L167-L211 | train |
pyroscope/pyrocore | src/pyrocore/torrent/rtorrent.py | RtorrentItem.datapath | def datapath(self):
""" Get an item's data path.
"""
path = self._fields['path']
if not path: # stopped item with no base_dir?
path = self.fetch('directory')
if path and not self._fields['is_multi_file']:
path = os.path.join(path, self._fields['na... | python | def datapath(self):
""" Get an item's data path.
"""
path = self._fields['path']
if not path: # stopped item with no base_dir?
path = self.fetch('directory')
if path and not self._fields['is_multi_file']:
path = os.path.join(path, self._fields['na... | [
"def",
"datapath",
"(",
"self",
")",
":",
"path",
"=",
"self",
".",
"_fields",
"[",
"'path'",
"]",
"if",
"not",
"path",
":",
"path",
"=",
"self",
".",
"fetch",
"(",
"'directory'",
")",
"if",
"path",
"and",
"not",
"self",
".",
"_fields",
"[",
"'is_m... | Get an item's data path. | [
"Get",
"an",
"item",
"s",
"data",
"path",
"."
] | 89ad01346a570943d20311a0b488440975876612 | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/torrent/rtorrent.py#L214-L222 | train |
pyroscope/pyrocore | src/pyrocore/torrent/rtorrent.py | RtorrentItem.announce_urls | def announce_urls(self, default=[]): # pylint: disable=dangerous-default-value
""" Get a list of all announce URLs.
Returns `default` if no trackers are found at all.
"""
try:
response = self._engine._rpc.t.multicall(self._fields["hash"], 0, "t.url=", "t.is_enabled=")
... | python | def announce_urls(self, default=[]): # pylint: disable=dangerous-default-value
""" Get a list of all announce URLs.
Returns `default` if no trackers are found at all.
"""
try:
response = self._engine._rpc.t.multicall(self._fields["hash"], 0, "t.url=", "t.is_enabled=")
... | [
"def",
"announce_urls",
"(",
"self",
",",
"default",
"=",
"[",
"]",
")",
":",
"try",
":",
"response",
"=",
"self",
".",
"_engine",
".",
"_rpc",
".",
"t",
".",
"multicall",
"(",
"self",
".",
"_fields",
"[",
"\"hash\"",
"]",
",",
"0",
",",
"\"t.url=\... | Get a list of all announce URLs.
Returns `default` if no trackers are found at all. | [
"Get",
"a",
"list",
"of",
"all",
"announce",
"URLs",
".",
"Returns",
"default",
"if",
"no",
"trackers",
"are",
"found",
"at",
"all",
"."
] | 89ad01346a570943d20311a0b488440975876612 | https://github.com/pyroscope/pyrocore/blob/89ad01346a570943d20311a0b488440975876612/src/pyrocore/torrent/rtorrent.py#L225-L237 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.