repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
codeinthehole/django-cacheback | cacheback/base.py | Job.async_refresh | def async_refresh(self, *args, **kwargs):
"""
Trigger an asynchronous job to refresh the cache
"""
# We trigger the task with the class path to import as well as the
# (a) args and kwargs for instantiating the class
# (b) args and kwargs for calling the 'refresh' method
... | python | def async_refresh(self, *args, **kwargs):
"""
Trigger an asynchronous job to refresh the cache
"""
# We trigger the task with the class path to import as well as the
# (a) args and kwargs for instantiating the class
# (b) args and kwargs for calling the 'refresh' method
... | [
"def",
"async_refresh",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# We trigger the task with the class path to import as well as the",
"# (a) args and kwargs for instantiating the class",
"# (b) args and kwargs for calling the 'refresh' method",
"try",
":",... | Trigger an asynchronous job to refresh the cache | [
"Trigger",
"an",
"asynchronous",
"job",
"to",
"refresh",
"the",
"cache"
] | train | https://github.com/codeinthehole/django-cacheback/blob/0c79a524a28ca2fada98ed58c26c544f07a58e14/cacheback/base.py#L312-L344 |
codeinthehole/django-cacheback | cacheback/base.py | Job.should_stale_item_be_fetched_synchronously | def should_stale_item_be_fetched_synchronously(self, delta, *args, **kwargs):
"""
Return whether to refresh an item synchronously when it is found in the
cache but stale
"""
if self.fetch_on_stale_threshold is None:
return False
return delta > (self.fetch_on_s... | python | def should_stale_item_be_fetched_synchronously(self, delta, *args, **kwargs):
"""
Return whether to refresh an item synchronously when it is found in the
cache but stale
"""
if self.fetch_on_stale_threshold is None:
return False
return delta > (self.fetch_on_s... | [
"def",
"should_stale_item_be_fetched_synchronously",
"(",
"self",
",",
"delta",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"fetch_on_stale_threshold",
"is",
"None",
":",
"return",
"False",
"return",
"delta",
">",
"(",
"self",
"."... | Return whether to refresh an item synchronously when it is found in the
cache but stale | [
"Return",
"whether",
"to",
"refresh",
"an",
"item",
"synchronously",
"when",
"it",
"is",
"found",
"in",
"the",
"cache",
"but",
"stale"
] | train | https://github.com/codeinthehole/django-cacheback/blob/0c79a524a28ca2fada98ed58c26c544f07a58e14/cacheback/base.py#L384-L391 |
codeinthehole/django-cacheback | cacheback/base.py | Job.key | def key(self, *args, **kwargs):
"""
Return the cache key to use.
If you're passing anything but primitive types to the ``get`` method,
it's likely that you'll need to override this method.
"""
if not args and not kwargs:
return self.class_path
try:
... | python | def key(self, *args, **kwargs):
"""
Return the cache key to use.
If you're passing anything but primitive types to the ``get`` method,
it's likely that you'll need to override this method.
"""
if not args and not kwargs:
return self.class_path
try:
... | [
"def",
"key",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"args",
"and",
"not",
"kwargs",
":",
"return",
"self",
".",
"class_path",
"try",
":",
"if",
"args",
"and",
"not",
"kwargs",
":",
"return",
"\"%s:%s\"",
"%"... | Return the cache key to use.
If you're passing anything but primitive types to the ``get`` method,
it's likely that you'll need to override this method. | [
"Return",
"the",
"cache",
"key",
"to",
"use",
"."
] | train | https://github.com/codeinthehole/django-cacheback/blob/0c79a524a28ca2fada98ed58c26c544f07a58e14/cacheback/base.py#L393-L416 |
codeinthehole/django-cacheback | cacheback/base.py | Job.hash | def hash(self, value):
"""
Generate a hash of the given iterable.
This is for use in a cache key.
"""
if is_iterable(value):
value = tuple(to_bytestring(v) for v in value)
return hashlib.md5(six.b(':').join(value)).hexdigest() | python | def hash(self, value):
"""
Generate a hash of the given iterable.
This is for use in a cache key.
"""
if is_iterable(value):
value = tuple(to_bytestring(v) for v in value)
return hashlib.md5(six.b(':').join(value)).hexdigest() | [
"def",
"hash",
"(",
"self",
",",
"value",
")",
":",
"if",
"is_iterable",
"(",
"value",
")",
":",
"value",
"=",
"tuple",
"(",
"to_bytestring",
"(",
"v",
")",
"for",
"v",
"in",
"value",
")",
"return",
"hashlib",
".",
"md5",
"(",
"six",
".",
"b",
"(... | Generate a hash of the given iterable.
This is for use in a cache key. | [
"Generate",
"a",
"hash",
"of",
"the",
"given",
"iterable",
"."
] | train | https://github.com/codeinthehole/django-cacheback/blob/0c79a524a28ca2fada98ed58c26c544f07a58e14/cacheback/base.py#L418-L426 |
codeinthehole/django-cacheback | cacheback/base.py | Job.perform_async_refresh | def perform_async_refresh(cls, klass_str, obj_args, obj_kwargs, call_args, call_kwargs):
"""
Re-populate cache using the given job class.
The job class is instantiated with the passed constructor args and the
refresh method is called with the passed call args. That is::
da... | python | def perform_async_refresh(cls, klass_str, obj_args, obj_kwargs, call_args, call_kwargs):
"""
Re-populate cache using the given job class.
The job class is instantiated with the passed constructor args and the
refresh method is called with the passed call args. That is::
da... | [
"def",
"perform_async_refresh",
"(",
"cls",
",",
"klass_str",
",",
"obj_args",
",",
"obj_kwargs",
",",
"call_args",
",",
"call_kwargs",
")",
":",
"klass",
"=",
"get_job_class",
"(",
"klass_str",
")",
"if",
"klass",
"is",
"None",
":",
"logger",
".",
"error",
... | Re-populate cache using the given job class.
The job class is instantiated with the passed constructor args and the
refresh method is called with the passed call args. That is::
data = klass(*obj_args, **obj_kwargs).refresh(
*call_args, **call_kwargs)
:klass_str: ... | [
"Re",
"-",
"populate",
"cache",
"using",
"the",
"given",
"job",
"class",
"."
] | train | https://github.com/codeinthehole/django-cacheback/blob/0c79a524a28ca2fada98ed58c26c544f07a58e14/cacheback/base.py#L463-L497 |
codeinthehole/django-cacheback | cacheback/decorators.py | cacheback | def cacheback(lifetime=None, fetch_on_miss=None, cache_alias=None,
job_class=None, task_options=None, **job_class_kwargs):
"""
Decorate function to cache its return value.
:lifetime: How long to cache items for
:fetch_on_miss: Whether to perform a synchronous fetch when no cached
... | python | def cacheback(lifetime=None, fetch_on_miss=None, cache_alias=None,
job_class=None, task_options=None, **job_class_kwargs):
"""
Decorate function to cache its return value.
:lifetime: How long to cache items for
:fetch_on_miss: Whether to perform a synchronous fetch when no cached
... | [
"def",
"cacheback",
"(",
"lifetime",
"=",
"None",
",",
"fetch_on_miss",
"=",
"None",
",",
"cache_alias",
"=",
"None",
",",
"job_class",
"=",
"None",
",",
"task_options",
"=",
"None",
",",
"*",
"*",
"job_class_kwargs",
")",
":",
"if",
"job_class",
"is",
"... | Decorate function to cache its return value.
:lifetime: How long to cache items for
:fetch_on_miss: Whether to perform a synchronous fetch when no cached
result is found
:cache_alias: The Django cache alias to store the result into.
:job_class: The class to use for running the cache... | [
"Decorate",
"function",
"to",
"cache",
"its",
"return",
"value",
"."
] | train | https://github.com/codeinthehole/django-cacheback/blob/0c79a524a28ca2fada98ed58c26c544f07a58e14/cacheback/decorators.py#L8-L40 |
bartromgens/geojsoncontour | geojsoncontour/utilities/multipoly.py | angle | def angle(v1, v2):
"""Return the angle in radians between vectors 'v1' and 'v2'."""
v1_u = unit_vector(v1)
v2_u = unit_vector(v2)
return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0)) | python | def angle(v1, v2):
"""Return the angle in radians between vectors 'v1' and 'v2'."""
v1_u = unit_vector(v1)
v2_u = unit_vector(v2)
return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0)) | [
"def",
"angle",
"(",
"v1",
",",
"v2",
")",
":",
"v1_u",
"=",
"unit_vector",
"(",
"v1",
")",
"v2_u",
"=",
"unit_vector",
"(",
"v2",
")",
"return",
"np",
".",
"arccos",
"(",
"np",
".",
"clip",
"(",
"np",
".",
"dot",
"(",
"v1_u",
",",
"v2_u",
")",... | Return the angle in radians between vectors 'v1' and 'v2'. | [
"Return",
"the",
"angle",
"in",
"radians",
"between",
"vectors",
"v1",
"and",
"v2",
"."
] | train | https://github.com/bartromgens/geojsoncontour/blob/79e30718fa0c1d96a2459eb1f45d06d699d240ed/geojsoncontour/utilities/multipoly.py#L39-L43 |
bartromgens/geojsoncontour | geojsoncontour/utilities/multipoly.py | keep_high_angle | def keep_high_angle(vertices, min_angle_deg):
"""Keep vertices with angles higher then given minimum."""
accepted = []
v = vertices
v1 = v[1] - v[0]
accepted.append((v[0][0], v[0][1]))
for i in range(1, len(v) - 2):
v2 = v[i + 1] - v[i - 1]
diff_angle = np.fabs(angle(v1, v2) * 18... | python | def keep_high_angle(vertices, min_angle_deg):
"""Keep vertices with angles higher then given minimum."""
accepted = []
v = vertices
v1 = v[1] - v[0]
accepted.append((v[0][0], v[0][1]))
for i in range(1, len(v) - 2):
v2 = v[i + 1] - v[i - 1]
diff_angle = np.fabs(angle(v1, v2) * 18... | [
"def",
"keep_high_angle",
"(",
"vertices",
",",
"min_angle_deg",
")",
":",
"accepted",
"=",
"[",
"]",
"v",
"=",
"vertices",
"v1",
"=",
"v",
"[",
"1",
"]",
"-",
"v",
"[",
"0",
"]",
"accepted",
".",
"append",
"(",
"(",
"v",
"[",
"0",
"]",
"[",
"0... | Keep vertices with angles higher then given minimum. | [
"Keep",
"vertices",
"with",
"angles",
"higher",
"then",
"given",
"minimum",
"."
] | train | https://github.com/bartromgens/geojsoncontour/blob/79e30718fa0c1d96a2459eb1f45d06d699d240ed/geojsoncontour/utilities/multipoly.py#L46-L59 |
bartromgens/geojsoncontour | geojsoncontour/utilities/multipoly.py | set_contourf_properties | def set_contourf_properties(stroke_width, fcolor, fill_opacity, contour_levels, contourf_idx, unit):
"""Set property values for Polygon."""
return {
"stroke": fcolor,
"stroke-width": stroke_width,
"stroke-opacity": 1,
"fill": fcolor,
"fill-opacity": fill_opacity,
... | python | def set_contourf_properties(stroke_width, fcolor, fill_opacity, contour_levels, contourf_idx, unit):
"""Set property values for Polygon."""
return {
"stroke": fcolor,
"stroke-width": stroke_width,
"stroke-opacity": 1,
"fill": fcolor,
"fill-opacity": fill_opacity,
... | [
"def",
"set_contourf_properties",
"(",
"stroke_width",
",",
"fcolor",
",",
"fill_opacity",
",",
"contour_levels",
",",
"contourf_idx",
",",
"unit",
")",
":",
"return",
"{",
"\"stroke\"",
":",
"fcolor",
",",
"\"stroke-width\"",
":",
"stroke_width",
",",
"\"stroke-o... | Set property values for Polygon. | [
"Set",
"property",
"values",
"for",
"Polygon",
"."
] | train | https://github.com/bartromgens/geojsoncontour/blob/79e30718fa0c1d96a2459eb1f45d06d699d240ed/geojsoncontour/utilities/multipoly.py#L62-L71 |
bartromgens/geojsoncontour | geojsoncontour/contour.py | contour_to_geojson | def contour_to_geojson(contour, geojson_filepath=None, min_angle_deg=None,
ndigits=5, unit='', stroke_width=1, geojson_properties=None, strdump=False,
serialize=True):
"""Transform matplotlib.contour to geojson."""
collections = contour.collections
contour_index... | python | def contour_to_geojson(contour, geojson_filepath=None, min_angle_deg=None,
ndigits=5, unit='', stroke_width=1, geojson_properties=None, strdump=False,
serialize=True):
"""Transform matplotlib.contour to geojson."""
collections = contour.collections
contour_index... | [
"def",
"contour_to_geojson",
"(",
"contour",
",",
"geojson_filepath",
"=",
"None",
",",
"min_angle_deg",
"=",
"None",
",",
"ndigits",
"=",
"5",
",",
"unit",
"=",
"''",
",",
"stroke_width",
"=",
"1",
",",
"geojson_properties",
"=",
"None",
",",
"strdump",
"... | Transform matplotlib.contour to geojson. | [
"Transform",
"matplotlib",
".",
"contour",
"to",
"geojson",
"."
] | train | https://github.com/bartromgens/geojsoncontour/blob/79e30718fa0c1d96a2459eb1f45d06d699d240ed/geojsoncontour/contour.py#L11-L40 |
bartromgens/geojsoncontour | geojsoncontour/contour.py | contourf_to_geojson_overlap | def contourf_to_geojson_overlap(contourf, geojson_filepath=None, min_angle_deg=None,
ndigits=5, unit='', stroke_width=1, fill_opacity=.9,
geojson_properties=None, strdump=False, serialize=True):
"""Transform matplotlib.contourf to geojson with overlapp... | python | def contourf_to_geojson_overlap(contourf, geojson_filepath=None, min_angle_deg=None,
ndigits=5, unit='', stroke_width=1, fill_opacity=.9,
geojson_properties=None, strdump=False, serialize=True):
"""Transform matplotlib.contourf to geojson with overlapp... | [
"def",
"contourf_to_geojson_overlap",
"(",
"contourf",
",",
"geojson_filepath",
"=",
"None",
",",
"min_angle_deg",
"=",
"None",
",",
"ndigits",
"=",
"5",
",",
"unit",
"=",
"''",
",",
"stroke_width",
"=",
"1",
",",
"fill_opacity",
"=",
".9",
",",
"geojson_pro... | Transform matplotlib.contourf to geojson with overlapping filled contours. | [
"Transform",
"matplotlib",
".",
"contourf",
"to",
"geojson",
"with",
"overlapping",
"filled",
"contours",
"."
] | train | https://github.com/bartromgens/geojsoncontour/blob/79e30718fa0c1d96a2459eb1f45d06d699d240ed/geojsoncontour/contour.py#L43-L65 |
bartromgens/geojsoncontour | geojsoncontour/contour.py | contourf_to_geojson | def contourf_to_geojson(contourf, geojson_filepath=None, min_angle_deg=None,
ndigits=5, unit='', stroke_width=1, fill_opacity=.9,
geojson_properties=None, strdump=False, serialize=True):
"""Transform matplotlib.contourf to geojson with MultiPolygons."""
polygon_fe... | python | def contourf_to_geojson(contourf, geojson_filepath=None, min_angle_deg=None,
ndigits=5, unit='', stroke_width=1, fill_opacity=.9,
geojson_properties=None, strdump=False, serialize=True):
"""Transform matplotlib.contourf to geojson with MultiPolygons."""
polygon_fe... | [
"def",
"contourf_to_geojson",
"(",
"contourf",
",",
"geojson_filepath",
"=",
"None",
",",
"min_angle_deg",
"=",
"None",
",",
"ndigits",
"=",
"5",
",",
"unit",
"=",
"''",
",",
"stroke_width",
"=",
"1",
",",
"fill_opacity",
"=",
".9",
",",
"geojson_properties"... | Transform matplotlib.contourf to geojson with MultiPolygons. | [
"Transform",
"matplotlib",
".",
"contourf",
"to",
"geojson",
"with",
"MultiPolygons",
"."
] | train | https://github.com/bartromgens/geojsoncontour/blob/79e30718fa0c1d96a2459eb1f45d06d699d240ed/geojsoncontour/contour.py#L68-L103 |
mattupstate/flask-social | flask_social/utils.py | get_authorize_callback | def get_authorize_callback(endpoint, provider_id):
"""Get a qualified URL for the provider to return to upon authorization
param: endpoint: Absolute path to append to the application's host
"""
endpoint_prefix = config_value('BLUEPRINT_NAME')
url = url_for(endpoint_prefix + '.' + endpoint, provider... | python | def get_authorize_callback(endpoint, provider_id):
"""Get a qualified URL for the provider to return to upon authorization
param: endpoint: Absolute path to append to the application's host
"""
endpoint_prefix = config_value('BLUEPRINT_NAME')
url = url_for(endpoint_prefix + '.' + endpoint, provider... | [
"def",
"get_authorize_callback",
"(",
"endpoint",
",",
"provider_id",
")",
":",
"endpoint_prefix",
"=",
"config_value",
"(",
"'BLUEPRINT_NAME'",
")",
"url",
"=",
"url_for",
"(",
"endpoint_prefix",
"+",
"'.'",
"+",
"endpoint",
",",
"provider_id",
"=",
"provider_id"... | Get a qualified URL for the provider to return to upon authorization
param: endpoint: Absolute path to append to the application's host | [
"Get",
"a",
"qualified",
"URL",
"for",
"the",
"provider",
"to",
"return",
"to",
"upon",
"authorization"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/utils.py#L30-L37 |
mattupstate/flask-social | flask_social/datastore.py | ConnectionDatastore.delete_connection | def delete_connection(self, **kwargs):
"""Remove a single connection to a provider for the specified user."""
conn = self.find_connection(**kwargs)
if not conn:
return False
self.delete(conn)
return True | python | def delete_connection(self, **kwargs):
"""Remove a single connection to a provider for the specified user."""
conn = self.find_connection(**kwargs)
if not conn:
return False
self.delete(conn)
return True | [
"def",
"delete_connection",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"conn",
"=",
"self",
".",
"find_connection",
"(",
"*",
"*",
"kwargs",
")",
"if",
"not",
"conn",
":",
"return",
"False",
"self",
".",
"delete",
"(",
"conn",
")",
"return",
"Tr... | Remove a single connection to a provider for the specified user. | [
"Remove",
"a",
"single",
"connection",
"to",
"a",
"provider",
"for",
"the",
"specified",
"user",
"."
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/datastore.py#L35-L41 |
mattupstate/flask-social | flask_social/datastore.py | ConnectionDatastore.delete_connections | def delete_connections(self, **kwargs):
"""Remove a single connection to a provider for the specified user."""
rv = False
for c in self.find_connections(**kwargs):
self.delete(c)
rv = True
return rv | python | def delete_connections(self, **kwargs):
"""Remove a single connection to a provider for the specified user."""
rv = False
for c in self.find_connections(**kwargs):
self.delete(c)
rv = True
return rv | [
"def",
"delete_connections",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"rv",
"=",
"False",
"for",
"c",
"in",
"self",
".",
"find_connections",
"(",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"delete",
"(",
"c",
")",
"rv",
"=",
"True",
"return"... | Remove a single connection to a provider for the specified user. | [
"Remove",
"a",
"single",
"connection",
"to",
"a",
"provider",
"for",
"the",
"specified",
"user",
"."
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/datastore.py#L43-L49 |
mattupstate/flask-social | flask_social/views.py | login | def login(provider_id):
"""Starts the provider login OAuth flow"""
provider = get_provider_or_404(provider_id)
callback_url = get_authorize_callback('login', provider_id)
post_login = request.form.get('next', get_post_login_redirect())
session[config_value('POST_OAUTH_LOGIN_SESSION_KEY')] = post_log... | python | def login(provider_id):
"""Starts the provider login OAuth flow"""
provider = get_provider_or_404(provider_id)
callback_url = get_authorize_callback('login', provider_id)
post_login = request.form.get('next', get_post_login_redirect())
session[config_value('POST_OAUTH_LOGIN_SESSION_KEY')] = post_log... | [
"def",
"login",
"(",
"provider_id",
")",
":",
"provider",
"=",
"get_provider_or_404",
"(",
"provider_id",
")",
"callback_url",
"=",
"get_authorize_callback",
"(",
"'login'",
",",
"provider_id",
")",
"post_login",
"=",
"request",
".",
"form",
".",
"get",
"(",
"... | Starts the provider login OAuth flow | [
"Starts",
"the",
"provider",
"login",
"OAuth",
"flow"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/views.py#L44-L50 |
mattupstate/flask-social | flask_social/views.py | connect | def connect(provider_id):
"""Starts the provider connection OAuth flow"""
provider = get_provider_or_404(provider_id)
callback_url = get_authorize_callback('connect', provider_id)
allow_view = get_url(config_value('CONNECT_ALLOW_VIEW'))
pc = request.form.get('next', allow_view)
session[config_va... | python | def connect(provider_id):
"""Starts the provider connection OAuth flow"""
provider = get_provider_or_404(provider_id)
callback_url = get_authorize_callback('connect', provider_id)
allow_view = get_url(config_value('CONNECT_ALLOW_VIEW'))
pc = request.form.get('next', allow_view)
session[config_va... | [
"def",
"connect",
"(",
"provider_id",
")",
":",
"provider",
"=",
"get_provider_or_404",
"(",
"provider_id",
")",
"callback_url",
"=",
"get_authorize_callback",
"(",
"'connect'",
",",
"provider_id",
")",
"allow_view",
"=",
"get_url",
"(",
"config_value",
"(",
"'CON... | Starts the provider connection OAuth flow | [
"Starts",
"the",
"provider",
"connection",
"OAuth",
"flow"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/views.py#L54-L61 |
mattupstate/flask-social | flask_social/views.py | remove_all_connections | def remove_all_connections(provider_id):
"""Remove all connections for the authenticated user to the
specified provider
"""
provider = get_provider_or_404(provider_id)
ctx = dict(provider=provider.name, user=current_user)
deleted = _datastore.delete_connections(user_id=current_user.get_id(),
... | python | def remove_all_connections(provider_id):
"""Remove all connections for the authenticated user to the
specified provider
"""
provider = get_provider_or_404(provider_id)
ctx = dict(provider=provider.name, user=current_user)
deleted = _datastore.delete_connections(user_id=current_user.get_id(),
... | [
"def",
"remove_all_connections",
"(",
"provider_id",
")",
":",
"provider",
"=",
"get_provider_or_404",
"(",
"provider_id",
")",
"ctx",
"=",
"dict",
"(",
"provider",
"=",
"provider",
".",
"name",
",",
"user",
"=",
"current_user",
")",
"deleted",
"=",
"_datastor... | Remove all connections for the authenticated user to the
specified provider | [
"Remove",
"all",
"connections",
"for",
"the",
"authenticated",
"user",
"to",
"the",
"specified",
"provider"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/views.py#L73-L93 |
mattupstate/flask-social | flask_social/views.py | remove_connection | def remove_connection(provider_id, provider_user_id):
"""Remove a specific connection for the authenticated user to the
specified provider
"""
provider = get_provider_or_404(provider_id)
ctx = dict(provider=provider.name, user=current_user,
provider_user_id=provider_user_id)
del... | python | def remove_connection(provider_id, provider_user_id):
"""Remove a specific connection for the authenticated user to the
specified provider
"""
provider = get_provider_or_404(provider_id)
ctx = dict(provider=provider.name, user=current_user,
provider_user_id=provider_user_id)
del... | [
"def",
"remove_connection",
"(",
"provider_id",
",",
"provider_user_id",
")",
":",
"provider",
"=",
"get_provider_or_404",
"(",
"provider_id",
")",
"ctx",
"=",
"dict",
"(",
"provider",
"=",
"provider",
".",
"name",
",",
"user",
"=",
"current_user",
",",
"provi... | Remove a specific connection for the authenticated user to the
specified provider | [
"Remove",
"a",
"specific",
"connection",
"for",
"the",
"authenticated",
"user",
"to",
"the",
"specified",
"provider"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/views.py#L97-L120 |
mattupstate/flask-social | flask_social/views.py | connect_handler | def connect_handler(cv, provider):
"""Shared method to handle the connection process
:param connection_values: A dictionary containing the connection values
:param provider_id: The provider ID the connection shoudl be made to
"""
cv.setdefault('user_id', current_user.get_id())
connection = _dat... | python | def connect_handler(cv, provider):
"""Shared method to handle the connection process
:param connection_values: A dictionary containing the connection values
:param provider_id: The provider ID the connection shoudl be made to
"""
cv.setdefault('user_id', current_user.get_id())
connection = _dat... | [
"def",
"connect_handler",
"(",
"cv",
",",
"provider",
")",
":",
"cv",
".",
"setdefault",
"(",
"'user_id'",
",",
"current_user",
".",
"get_id",
"(",
")",
")",
"connection",
"=",
"_datastore",
".",
"find_connection",
"(",
"provider_id",
"=",
"cv",
"[",
"'pro... | Shared method to handle the connection process
:param connection_values: A dictionary containing the connection values
:param provider_id: The provider ID the connection shoudl be made to | [
"Shared",
"method",
"to",
"handle",
"the",
"connection",
"process"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/views.py#L123-L150 |
mattupstate/flask-social | flask_social/views.py | login_handler | def login_handler(response, provider, query):
"""Shared method to handle the signin process"""
connection = _datastore.find_connection(**query)
if connection:
after_this_request(_commit)
token_pair = get_token_pair_from_oauth_response(provider, response)
if (token_pair['access_toke... | python | def login_handler(response, provider, query):
"""Shared method to handle the signin process"""
connection = _datastore.find_connection(**query)
if connection:
after_this_request(_commit)
token_pair = get_token_pair_from_oauth_response(provider, response)
if (token_pair['access_toke... | [
"def",
"login_handler",
"(",
"response",
",",
"provider",
",",
"query",
")",
":",
"connection",
"=",
"_datastore",
".",
"find_connection",
"(",
"*",
"*",
"query",
")",
"if",
"connection",
":",
"after_this_request",
"(",
"_commit",
")",
"token_pair",
"=",
"ge... | Shared method to handle the signin process | [
"Shared",
"method",
"to",
"handle",
"the",
"signin",
"process"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/views.py#L169-L199 |
mattupstate/flask-social | flask_social/core.py | Social.init_app | def init_app(self, app, datastore=None):
"""Initialize the application with the Social extension
:param app: The Flask application
:param datastore: Connection datastore instance
"""
datastore = datastore or self.datastore
for key, value in default_config.items():
... | python | def init_app(self, app, datastore=None):
"""Initialize the application with the Social extension
:param app: The Flask application
:param datastore: Connection datastore instance
"""
datastore = datastore or self.datastore
for key, value in default_config.items():
... | [
"def",
"init_app",
"(",
"self",
",",
"app",
",",
"datastore",
"=",
"None",
")",
":",
"datastore",
"=",
"datastore",
"or",
"self",
".",
"datastore",
"for",
"key",
",",
"value",
"in",
"default_config",
".",
"items",
"(",
")",
":",
"app",
".",
"config",
... | Initialize the application with the Social extension
:param app: The Flask application
:param datastore: Connection datastore instance | [
"Initialize",
"the",
"application",
"with",
"the",
"Social",
"extension"
] | train | https://github.com/mattupstate/flask-social/blob/36f5790c8fb6d4d9a5120d099419ba30fd73e897/flask_social/core.py#L108-L140 |
eugene-eeo/mailthon | mailthon/helpers.py | guess | def guess(filename, fallback='application/octet-stream'):
"""
Using the mimetypes library, guess the mimetype and
encoding for a given *filename*. If the mimetype
cannot be guessed, *fallback* is assumed instead.
:param filename: Filename- can be absolute path.
:param fallback: A fallback mimet... | python | def guess(filename, fallback='application/octet-stream'):
"""
Using the mimetypes library, guess the mimetype and
encoding for a given *filename*. If the mimetype
cannot be guessed, *fallback* is assumed instead.
:param filename: Filename- can be absolute path.
:param fallback: A fallback mimet... | [
"def",
"guess",
"(",
"filename",
",",
"fallback",
"=",
"'application/octet-stream'",
")",
":",
"guessed",
",",
"encoding",
"=",
"mimetypes",
".",
"guess_type",
"(",
"filename",
",",
"strict",
"=",
"False",
")",
"if",
"guessed",
"is",
"None",
":",
"return",
... | Using the mimetypes library, guess the mimetype and
encoding for a given *filename*. If the mimetype
cannot be guessed, *fallback* is assumed instead.
:param filename: Filename- can be absolute path.
:param fallback: A fallback mimetype. | [
"Using",
"the",
"mimetypes",
"library",
"guess",
"the",
"mimetype",
"and",
"encoding",
"for",
"a",
"given",
"*",
"filename",
"*",
".",
"If",
"the",
"mimetype",
"cannot",
"be",
"guessed",
"*",
"fallback",
"*",
"is",
"assumed",
"instead",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/helpers.py#L23-L35 |
eugene-eeo/mailthon | mailthon/helpers.py | format_addresses | def format_addresses(addrs):
"""
Given an iterable of addresses or name-address
tuples *addrs*, return a header value that joins
all of them together with a space and a comma.
"""
return ', '.join(
formataddr(item) if isinstance(item, tuple) else item
for item in addrs
) | python | def format_addresses(addrs):
"""
Given an iterable of addresses or name-address
tuples *addrs*, return a header value that joins
all of them together with a space and a comma.
"""
return ', '.join(
formataddr(item) if isinstance(item, tuple) else item
for item in addrs
) | [
"def",
"format_addresses",
"(",
"addrs",
")",
":",
"return",
"', '",
".",
"join",
"(",
"formataddr",
"(",
"item",
")",
"if",
"isinstance",
"(",
"item",
",",
"tuple",
")",
"else",
"item",
"for",
"item",
"in",
"addrs",
")"
] | Given an iterable of addresses or name-address
tuples *addrs*, return a header value that joins
all of them together with a space and a comma. | [
"Given",
"an",
"iterable",
"of",
"addresses",
"or",
"name",
"-",
"address",
"tuples",
"*",
"addrs",
"*",
"return",
"a",
"header",
"value",
"that",
"joins",
"all",
"of",
"them",
"together",
"with",
"a",
"space",
"and",
"a",
"comma",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/helpers.py#L38-L47 |
eugene-eeo/mailthon | mailthon/helpers.py | stringify_address | def stringify_address(addr, encoding='utf-8'):
"""
Given an email address *addr*, try to encode
it with ASCII. If it's not possible, encode
the *local-part* with the *encoding* and the
*domain* with IDNA.
The result is a unicode string with the domain
encoded as idna.
"""
if isinsta... | python | def stringify_address(addr, encoding='utf-8'):
"""
Given an email address *addr*, try to encode
it with ASCII. If it's not possible, encode
the *local-part* with the *encoding* and the
*domain* with IDNA.
The result is a unicode string with the domain
encoded as idna.
"""
if isinsta... | [
"def",
"stringify_address",
"(",
"addr",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"if",
"isinstance",
"(",
"addr",
",",
"bytes_type",
")",
":",
"return",
"addr",
"try",
":",
"addr",
"=",
"addr",
".",
"encode",
"(",
"'ascii'",
")",
"except",
"UnicodeEnc... | Given an email address *addr*, try to encode
it with ASCII. If it's not possible, encode
the *local-part* with the *encoding* and the
*domain* with IDNA.
The result is a unicode string with the domain
encoded as idna. | [
"Given",
"an",
"email",
"address",
"*",
"addr",
"*",
"try",
"to",
"encode",
"it",
"with",
"ASCII",
".",
"If",
"it",
"s",
"not",
"possible",
"encode",
"the",
"*",
"local",
"-",
"part",
"*",
"with",
"the",
"*",
"encoding",
"*",
"and",
"the",
"*",
"do... | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/helpers.py#L50-L73 |
eugene-eeo/mailthon | mailthon/api.py | email | def email(sender=None, receivers=(), cc=(), bcc=(),
subject=None, content=None, encoding='utf8',
attachments=()):
"""
Creates a Collection object with a HTML *content*,
and *attachments*.
:param content: HTML content.
:param encoding: Encoding of the email.
:param attachment... | python | def email(sender=None, receivers=(), cc=(), bcc=(),
subject=None, content=None, encoding='utf8',
attachments=()):
"""
Creates a Collection object with a HTML *content*,
and *attachments*.
:param content: HTML content.
:param encoding: Encoding of the email.
:param attachment... | [
"def",
"email",
"(",
"sender",
"=",
"None",
",",
"receivers",
"=",
"(",
")",
",",
"cc",
"=",
"(",
")",
",",
"bcc",
"=",
"(",
")",
",",
"subject",
"=",
"None",
",",
"content",
"=",
"None",
",",
"encoding",
"=",
"'utf8'",
",",
"attachments",
"=",
... | Creates a Collection object with a HTML *content*,
and *attachments*.
:param content: HTML content.
:param encoding: Encoding of the email.
:param attachments: List of filenames to
attach to the email. | [
"Creates",
"a",
"Collection",
"object",
"with",
"a",
"HTML",
"*",
"content",
"*",
"and",
"*",
"attachments",
"*",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/api.py#L18-L43 |
eugene-eeo/mailthon | mailthon/api.py | postman | def postman(host, port=587, auth=(None, None),
force_tls=False, options=None):
"""
Creates a Postman object with TLS and Auth
middleware. TLS is placed before authentication
because usually authentication happens and is
accepted only after TLS is enabled.
:param auth: Tuple of (user... | python | def postman(host, port=587, auth=(None, None),
force_tls=False, options=None):
"""
Creates a Postman object with TLS and Auth
middleware. TLS is placed before authentication
because usually authentication happens and is
accepted only after TLS is enabled.
:param auth: Tuple of (user... | [
"def",
"postman",
"(",
"host",
",",
"port",
"=",
"587",
",",
"auth",
"=",
"(",
"None",
",",
"None",
")",
",",
"force_tls",
"=",
"False",
",",
"options",
"=",
"None",
")",
":",
"return",
"Postman",
"(",
"host",
"=",
"host",
",",
"port",
"=",
"port... | Creates a Postman object with TLS and Auth
middleware. TLS is placed before authentication
because usually authentication happens and is
accepted only after TLS is enabled.
:param auth: Tuple of (username, password) to
be used to ``login`` to the server.
:param force_tls: Whether TLS should... | [
"Creates",
"a",
"Postman",
"object",
"with",
"TLS",
"and",
"Auth",
"middleware",
".",
"TLS",
"is",
"placed",
"before",
"authentication",
"because",
"usually",
"authentication",
"happens",
"and",
"is",
"accepted",
"only",
"after",
"TLS",
"is",
"enabled",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/api.py#L46-L68 |
eugene-eeo/mailthon | mailthon/enclosure.py | Enclosure.mime | def mime(self):
"""
Returns the finalised mime object, after
applying the internal headers. Usually this
is not to be overriden.
"""
mime = self.mime_object()
self.headers.prepare(mime)
return mime | python | def mime(self):
"""
Returns the finalised mime object, after
applying the internal headers. Usually this
is not to be overriden.
"""
mime = self.mime_object()
self.headers.prepare(mime)
return mime | [
"def",
"mime",
"(",
"self",
")",
":",
"mime",
"=",
"self",
".",
"mime_object",
"(",
")",
"self",
".",
"headers",
".",
"prepare",
"(",
"mime",
")",
"return",
"mime"
] | Returns the finalised mime object, after
applying the internal headers. Usually this
is not to be overriden. | [
"Returns",
"the",
"finalised",
"mime",
"object",
"after",
"applying",
"the",
"internal",
"headers",
".",
"Usually",
"this",
"is",
"not",
"to",
"be",
"overriden",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/enclosure.py#L56-L64 |
eugene-eeo/mailthon | mailthon/postman.py | Session.send | def send(self, envelope):
"""
Send an *envelope* which may be an envelope
or an enclosure-like object, see
:class:`~mailthon.enclosure.Enclosure` and
:class:`~mailthon.envelope.Envelope`, and
returns a :class:`~mailthon.response.SendmailResponse`
object.
"... | python | def send(self, envelope):
"""
Send an *envelope* which may be an envelope
or an enclosure-like object, see
:class:`~mailthon.enclosure.Enclosure` and
:class:`~mailthon.envelope.Envelope`, and
returns a :class:`~mailthon.response.SendmailResponse`
object.
"... | [
"def",
"send",
"(",
"self",
",",
"envelope",
")",
":",
"rejected",
"=",
"self",
".",
"conn",
".",
"sendmail",
"(",
"stringify_address",
"(",
"envelope",
".",
"sender",
")",
",",
"[",
"stringify_address",
"(",
"k",
")",
"for",
"k",
"in",
"envelope",
"."... | Send an *envelope* which may be an envelope
or an enclosure-like object, see
:class:`~mailthon.enclosure.Enclosure` and
:class:`~mailthon.envelope.Envelope`, and
returns a :class:`~mailthon.response.SendmailResponse`
object. | [
"Send",
"an",
"*",
"envelope",
"*",
"which",
"may",
"be",
"an",
"envelope",
"or",
"an",
"enclosure",
"-",
"like",
"object",
"see",
":",
"class",
":",
"~mailthon",
".",
"enclosure",
".",
"Enclosure",
"and",
":",
"class",
":",
"~mailthon",
".",
"envelope",... | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/postman.py#L37-L56 |
eugene-eeo/mailthon | mailthon/postman.py | Postman.connection | def connection(self):
"""
A context manager that returns a connection
to the server using some *session*.
"""
conn = self.session(**self.options)
try:
for item in self.middlewares:
item(conn)
yield conn
finally:
... | python | def connection(self):
"""
A context manager that returns a connection
to the server using some *session*.
"""
conn = self.session(**self.options)
try:
for item in self.middlewares:
item(conn)
yield conn
finally:
... | [
"def",
"connection",
"(",
"self",
")",
":",
"conn",
"=",
"self",
".",
"session",
"(",
"*",
"*",
"self",
".",
"options",
")",
"try",
":",
"for",
"item",
"in",
"self",
".",
"middlewares",
":",
"item",
"(",
"conn",
")",
"yield",
"conn",
"finally",
":"... | A context manager that returns a connection
to the server using some *session*. | [
"A",
"context",
"manager",
"that",
"returns",
"a",
"connection",
"to",
"the",
"server",
"using",
"some",
"*",
"session",
"*",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/postman.py#L87-L98 |
eugene-eeo/mailthon | mailthon/headers.py | Headers.sender | def sender(self):
"""
Returns the sender, respecting the Resent-*
headers. In any case, prefer Sender over From,
meaning that if Sender is present then From is
ignored, as per the RFC.
"""
to_fetch = (
['Resent-Sender', 'Resent-From'] if self.resent el... | python | def sender(self):
"""
Returns the sender, respecting the Resent-*
headers. In any case, prefer Sender over From,
meaning that if Sender is present then From is
ignored, as per the RFC.
"""
to_fetch = (
['Resent-Sender', 'Resent-From'] if self.resent el... | [
"def",
"sender",
"(",
"self",
")",
":",
"to_fetch",
"=",
"(",
"[",
"'Resent-Sender'",
",",
"'Resent-From'",
"]",
"if",
"self",
".",
"resent",
"else",
"[",
"'Sender'",
",",
"'From'",
"]",
")",
"for",
"item",
"in",
"to_fetch",
":",
"if",
"item",
"in",
... | Returns the sender, respecting the Resent-*
headers. In any case, prefer Sender over From,
meaning that if Sender is present then From is
ignored, as per the RFC. | [
"Returns",
"the",
"sender",
"respecting",
"the",
"Resent",
"-",
"*",
"headers",
".",
"In",
"any",
"case",
"prefer",
"Sender",
"over",
"From",
"meaning",
"that",
"if",
"Sender",
"is",
"present",
"then",
"From",
"is",
"ignored",
"as",
"per",
"the",
"RFC",
... | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/headers.py#L42-L56 |
eugene-eeo/mailthon | mailthon/headers.py | Headers.receivers | def receivers(self):
"""
Returns a list of receivers, obtained from the
To, Cc, and Bcc headers, respecting the Resent-*
headers if the email was resent.
"""
attrs = (
['Resent-To', 'Resent-Cc', 'Resent-Bcc'] if self.resent else
['To', 'Cc', 'Bcc']... | python | def receivers(self):
"""
Returns a list of receivers, obtained from the
To, Cc, and Bcc headers, respecting the Resent-*
headers if the email was resent.
"""
attrs = (
['Resent-To', 'Resent-Cc', 'Resent-Bcc'] if self.resent else
['To', 'Cc', 'Bcc']... | [
"def",
"receivers",
"(",
"self",
")",
":",
"attrs",
"=",
"(",
"[",
"'Resent-To'",
",",
"'Resent-Cc'",
",",
"'Resent-Bcc'",
"]",
"if",
"self",
".",
"resent",
"else",
"[",
"'To'",
",",
"'Cc'",
",",
"'Bcc'",
"]",
")",
"addrs",
"=",
"(",
"v",
"for",
"v... | Returns a list of receivers, obtained from the
To, Cc, and Bcc headers, respecting the Resent-*
headers if the email was resent. | [
"Returns",
"a",
"list",
"of",
"receivers",
"obtained",
"from",
"the",
"To",
"Cc",
"and",
"Bcc",
"headers",
"respecting",
"the",
"Resent",
"-",
"*",
"headers",
"if",
"the",
"email",
"was",
"resent",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/headers.py#L59-L70 |
eugene-eeo/mailthon | mailthon/headers.py | Headers.prepare | def prepare(self, mime):
"""
Prepares a MIME object by applying the headers
to the *mime* object. Ignores any Bcc or
Resent-Bcc headers.
"""
for key in self:
if key == 'Bcc' or key == 'Resent-Bcc':
continue
del mime[key]
... | python | def prepare(self, mime):
"""
Prepares a MIME object by applying the headers
to the *mime* object. Ignores any Bcc or
Resent-Bcc headers.
"""
for key in self:
if key == 'Bcc' or key == 'Resent-Bcc':
continue
del mime[key]
... | [
"def",
"prepare",
"(",
"self",
",",
"mime",
")",
":",
"for",
"key",
"in",
"self",
":",
"if",
"key",
"==",
"'Bcc'",
"or",
"key",
"==",
"'Resent-Bcc'",
":",
"continue",
"del",
"mime",
"[",
"key",
"]",
"# Python 3.* email's compatibility layer will handle",
"# ... | Prepares a MIME object by applying the headers
to the *mime* object. Ignores any Bcc or
Resent-Bcc headers. | [
"Prepares",
"a",
"MIME",
"object",
"by",
"applying",
"the",
"headers",
"to",
"the",
"*",
"mime",
"*",
"object",
".",
"Ignores",
"any",
"Bcc",
"or",
"Resent",
"-",
"Bcc",
"headers",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/headers.py#L72-L90 |
eugene-eeo/mailthon | mailthon/middleware.py | tls | def tls(force=False):
"""
Middleware implementing TLS for SMTP connections. By
default this is not forced- TLS is only used if
STARTTLS is available. If the *force* parameter is set
to True, it will not query the server for TLS features
before upgrading to TLS.
"""
def middleware(conn):
... | python | def tls(force=False):
"""
Middleware implementing TLS for SMTP connections. By
default this is not forced- TLS is only used if
STARTTLS is available. If the *force* parameter is set
to True, it will not query the server for TLS features
before upgrading to TLS.
"""
def middleware(conn):
... | [
"def",
"tls",
"(",
"force",
"=",
"False",
")",
":",
"def",
"middleware",
"(",
"conn",
")",
":",
"if",
"force",
"or",
"conn",
".",
"has_extn",
"(",
"'STARTTLS'",
")",
":",
"conn",
".",
"starttls",
"(",
")",
"conn",
".",
"ehlo",
"(",
")",
"return",
... | Middleware implementing TLS for SMTP connections. By
default this is not forced- TLS is only used if
STARTTLS is available. If the *force* parameter is set
to True, it will not query the server for TLS features
before upgrading to TLS. | [
"Middleware",
"implementing",
"TLS",
"for",
"SMTP",
"connections",
".",
"By",
"default",
"this",
"is",
"not",
"forced",
"-",
"TLS",
"is",
"only",
"used",
"if",
"STARTTLS",
"is",
"available",
".",
"If",
"the",
"*",
"force",
"*",
"parameter",
"is",
"set",
... | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/middleware.py#L14-L26 |
eugene-eeo/mailthon | mailthon/middleware.py | auth | def auth(username, password):
"""
Middleware implementing authentication via LOGIN.
Most of the time this middleware needs to be placed
*after* TLS.
:param username: Username to login with.
:param password: Password of the user.
"""
def middleware(conn):
conn.login(username, pas... | python | def auth(username, password):
"""
Middleware implementing authentication via LOGIN.
Most of the time this middleware needs to be placed
*after* TLS.
:param username: Username to login with.
:param password: Password of the user.
"""
def middleware(conn):
conn.login(username, pas... | [
"def",
"auth",
"(",
"username",
",",
"password",
")",
":",
"def",
"middleware",
"(",
"conn",
")",
":",
"conn",
".",
"login",
"(",
"username",
",",
"password",
")",
"return",
"middleware"
] | Middleware implementing authentication via LOGIN.
Most of the time this middleware needs to be placed
*after* TLS.
:param username: Username to login with.
:param password: Password of the user. | [
"Middleware",
"implementing",
"authentication",
"via",
"LOGIN",
".",
"Most",
"of",
"the",
"time",
"this",
"middleware",
"needs",
"to",
"be",
"placed",
"*",
"after",
"*",
"TLS",
"."
] | train | https://github.com/eugene-eeo/mailthon/blob/e3d5aef62505acb4edbc33e3378a04951c3199cb/mailthon/middleware.py#L29-L40 |
ramses-tech/ramses | ramses/models.py | get_existing_model | def get_existing_model(model_name):
""" Try to find existing model class named `model_name`.
:param model_name: String name of the model class.
"""
try:
model_cls = engine.get_document_cls(model_name)
log.debug('Model `{}` already exists. Using existing one'.format(
model_na... | python | def get_existing_model(model_name):
""" Try to find existing model class named `model_name`.
:param model_name: String name of the model class.
"""
try:
model_cls = engine.get_document_cls(model_name)
log.debug('Model `{}` already exists. Using existing one'.format(
model_na... | [
"def",
"get_existing_model",
"(",
"model_name",
")",
":",
"try",
":",
"model_cls",
"=",
"engine",
".",
"get_document_cls",
"(",
"model_name",
")",
"log",
".",
"debug",
"(",
"'Model `{}` already exists. Using existing one'",
".",
"format",
"(",
"model_name",
")",
"... | Try to find existing model class named `model_name`.
:param model_name: String name of the model class. | [
"Try",
"to",
"find",
"existing",
"model",
"class",
"named",
"model_name",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/models.py#L45-L56 |
ramses-tech/ramses | ramses/models.py | prepare_relationship | def prepare_relationship(config, model_name, raml_resource):
""" Create referenced model if it doesn't exist.
When preparing a relationship, we check to see if the model that will be
referenced already exists. If not, it is created so that it will be possible
to use it in a relationship. Thus the first... | python | def prepare_relationship(config, model_name, raml_resource):
""" Create referenced model if it doesn't exist.
When preparing a relationship, we check to see if the model that will be
referenced already exists. If not, it is created so that it will be possible
to use it in a relationship. Thus the first... | [
"def",
"prepare_relationship",
"(",
"config",
",",
"model_name",
",",
"raml_resource",
")",
":",
"if",
"get_existing_model",
"(",
"model_name",
")",
"is",
"None",
":",
"plural_route",
"=",
"'/'",
"+",
"pluralize",
"(",
"model_name",
".",
"lower",
"(",
")",
"... | Create referenced model if it doesn't exist.
When preparing a relationship, we check to see if the model that will be
referenced already exists. If not, it is created so that it will be possible
to use it in a relationship. Thus the first usage of this model in RAML file
must provide its schema in POST... | [
"Create",
"referenced",
"model",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/models.py#L59-L82 |
ramses-tech/ramses | ramses/models.py | generate_model_cls | def generate_model_cls(config, schema, model_name, raml_resource,
es_based=True):
""" Generate model class.
Engine DB field types are determined using `type_fields` and only those
types may be used.
:param schema: Model schema dict parsed from RAML.
:param model_name: String... | python | def generate_model_cls(config, schema, model_name, raml_resource,
es_based=True):
""" Generate model class.
Engine DB field types are determined using `type_fields` and only those
types may be used.
:param schema: Model schema dict parsed from RAML.
:param model_name: String... | [
"def",
"generate_model_cls",
"(",
"config",
",",
"schema",
",",
"model_name",
",",
"raml_resource",
",",
"es_based",
"=",
"True",
")",
":",
"from",
"nefertari",
".",
"authentication",
".",
"models",
"import",
"AuthModelMethodsMixin",
"base_cls",
"=",
"engine",
"... | Generate model class.
Engine DB field types are determined using `type_fields` and only those
types may be used.
:param schema: Model schema dict parsed from RAML.
:param model_name: String that is used as new model's name.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
:pa... | [
"Generate",
"model",
"class",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/models.py#L85-L169 |
ramses-tech/ramses | ramses/models.py | setup_data_model | def setup_data_model(config, raml_resource, model_name):
""" Setup storage/data model and return generated model class.
Process follows these steps:
* Resource schema is found and restructured by `resource_schema`.
* Model class is generated from properties dict using util function
`generat... | python | def setup_data_model(config, raml_resource, model_name):
""" Setup storage/data model and return generated model class.
Process follows these steps:
* Resource schema is found and restructured by `resource_schema`.
* Model class is generated from properties dict using util function
`generat... | [
"def",
"setup_data_model",
"(",
"config",
",",
"raml_resource",
",",
"model_name",
")",
":",
"model_cls",
"=",
"get_existing_model",
"(",
"model_name",
")",
"schema",
"=",
"resource_schema",
"(",
"raml_resource",
")",
"if",
"not",
"schema",
":",
"raise",
"Except... | Setup storage/data model and return generated model class.
Process follows these steps:
* Resource schema is found and restructured by `resource_schema`.
* Model class is generated from properties dict using util function
`generate_model_cls`.
:param raml_resource: Instance of ramlfication... | [
"Setup",
"storage",
"/",
"data",
"model",
"and",
"return",
"generated",
"model",
"class",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/models.py#L172-L198 |
ramses-tech/ramses | ramses/models.py | handle_model_generation | def handle_model_generation(config, raml_resource):
""" Generates model name and runs `setup_data_model` to get
or generate actual model class.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
model_name = generate_model_name(raml_resource)
try:
return setup_data_m... | python | def handle_model_generation(config, raml_resource):
""" Generates model name and runs `setup_data_model` to get
or generate actual model class.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
model_name = generate_model_name(raml_resource)
try:
return setup_data_m... | [
"def",
"handle_model_generation",
"(",
"config",
",",
"raml_resource",
")",
":",
"model_name",
"=",
"generate_model_name",
"(",
"raml_resource",
")",
"try",
":",
"return",
"setup_data_model",
"(",
"config",
",",
"raml_resource",
",",
"model_name",
")",
"except",
"... | Generates model name and runs `setup_data_model` to get
or generate actual model class.
:param raml_resource: Instance of ramlfications.raml.ResourceNode. | [
"Generates",
"model",
"name",
"and",
"runs",
"setup_data_model",
"to",
"get",
"or",
"generate",
"actual",
"model",
"class",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/models.py#L201-L211 |
ramses-tech/ramses | ramses/models.py | setup_model_event_subscribers | def setup_model_event_subscribers(config, model_cls, schema):
""" Set up model event subscribers.
:param config: Pyramid Configurator instance.
:param model_cls: Model class for which handlers should be connected.
:param schema: Dict of model JSON schema.
"""
events_map = get_events_map()
m... | python | def setup_model_event_subscribers(config, model_cls, schema):
""" Set up model event subscribers.
:param config: Pyramid Configurator instance.
:param model_cls: Model class for which handlers should be connected.
:param schema: Dict of model JSON schema.
"""
events_map = get_events_map()
m... | [
"def",
"setup_model_event_subscribers",
"(",
"config",
",",
"model_cls",
",",
"schema",
")",
":",
"events_map",
"=",
"get_events_map",
"(",
")",
"model_events",
"=",
"schema",
".",
"get",
"(",
"'_event_handlers'",
",",
"{",
"}",
")",
"event_kwargs",
"=",
"{",
... | Set up model event subscribers.
:param config: Pyramid Configurator instance.
:param model_cls: Model class for which handlers should be connected.
:param schema: Dict of model JSON schema. | [
"Set",
"up",
"model",
"event",
"subscribers",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/models.py#L214-L235 |
ramses-tech/ramses | ramses/models.py | setup_fields_processors | def setup_fields_processors(config, model_cls, schema):
""" Set up model fields' processors.
:param config: Pyramid Configurator instance.
:param model_cls: Model class for field of which processors should be
set up.
:param schema: Dict of model JSON schema.
"""
properties = schema.get(... | python | def setup_fields_processors(config, model_cls, schema):
""" Set up model fields' processors.
:param config: Pyramid Configurator instance.
:param model_cls: Model class for field of which processors should be
set up.
:param schema: Dict of model JSON schema.
"""
properties = schema.get(... | [
"def",
"setup_fields_processors",
"(",
"config",
",",
"model_cls",
",",
"schema",
")",
":",
"properties",
"=",
"schema",
".",
"get",
"(",
"'properties'",
",",
"{",
"}",
")",
"for",
"field_name",
",",
"props",
"in",
"properties",
".",
"items",
"(",
")",
"... | Set up model fields' processors.
:param config: Pyramid Configurator instance.
:param model_cls: Model class for field of which processors should be
set up.
:param schema: Dict of model JSON schema. | [
"Set",
"up",
"model",
"fields",
"processors",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/models.py#L238-L274 |
ramses-tech/ramses | ramses/auth.py | _setup_ticket_policy | def _setup_ticket_policy(config, params):
""" Setup Pyramid AuthTktAuthenticationPolicy.
Notes:
* Initial `secret` params value is considered to be a name of config
param that represents a cookie name.
* `auth_model.get_groups_by_userid` is used as a `callback`.
* Also connects basic ... | python | def _setup_ticket_policy(config, params):
""" Setup Pyramid AuthTktAuthenticationPolicy.
Notes:
* Initial `secret` params value is considered to be a name of config
param that represents a cookie name.
* `auth_model.get_groups_by_userid` is used as a `callback`.
* Also connects basic ... | [
"def",
"_setup_ticket_policy",
"(",
"config",
",",
"params",
")",
":",
"from",
"nefertari",
".",
"authentication",
".",
"views",
"import",
"(",
"TicketAuthRegisterView",
",",
"TicketAuthLoginView",
",",
"TicketAuthLogoutView",
")",
"log",
".",
"info",
"(",
"'Confi... | Setup Pyramid AuthTktAuthenticationPolicy.
Notes:
* Initial `secret` params value is considered to be a name of config
param that represents a cookie name.
* `auth_model.get_groups_by_userid` is used as a `callback`.
* Also connects basic routes to perform authentication actions.
:pa... | [
"Setup",
"Pyramid",
"AuthTktAuthenticationPolicy",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/auth.py#L46-L102 |
ramses-tech/ramses | ramses/auth.py | _setup_apikey_policy | def _setup_apikey_policy(config, params):
""" Setup `nefertari.ApiKeyAuthenticationPolicy`.
Notes:
* User may provide model name in :params['user_model']: do define
the name of the user model.
* `auth_model.get_groups_by_token` is used to perform username and
token check
* `au... | python | def _setup_apikey_policy(config, params):
""" Setup `nefertari.ApiKeyAuthenticationPolicy`.
Notes:
* User may provide model name in :params['user_model']: do define
the name of the user model.
* `auth_model.get_groups_by_token` is used to perform username and
token check
* `au... | [
"def",
"_setup_apikey_policy",
"(",
"config",
",",
"params",
")",
":",
"from",
"nefertari",
".",
"authentication",
".",
"views",
"import",
"(",
"TokenAuthRegisterView",
",",
"TokenAuthClaimView",
",",
"TokenAuthResetView",
")",
"log",
".",
"info",
"(",
"'Configuri... | Setup `nefertari.ApiKeyAuthenticationPolicy`.
Notes:
* User may provide model name in :params['user_model']: do define
the name of the user model.
* `auth_model.get_groups_by_token` is used to perform username and
token check
* `auth_model.get_token_credentials` is used to get use... | [
"Setup",
"nefertari",
".",
"ApiKeyAuthenticationPolicy",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/auth.py#L105-L160 |
ramses-tech/ramses | ramses/auth.py | setup_auth_policies | def setup_auth_policies(config, raml_root):
""" Setup authentication, authorization policies.
Performs basic validation to check all the required values are present
and performs authentication, authorization policies generation using
generator functions from `AUTHENTICATION_POLICIES`.
:param confi... | python | def setup_auth_policies(config, raml_root):
""" Setup authentication, authorization policies.
Performs basic validation to check all the required values are present
and performs authentication, authorization policies generation using
generator functions from `AUTHENTICATION_POLICIES`.
:param confi... | [
"def",
"setup_auth_policies",
"(",
"config",
",",
"raml_root",
")",
":",
"log",
".",
"info",
"(",
"'Configuring auth policies'",
")",
"secured_by_all",
"=",
"raml_root",
".",
"secured_by",
"or",
"[",
"]",
"secured_by",
"=",
"[",
"item",
"for",
"item",
"in",
... | Setup authentication, authorization policies.
Performs basic validation to check all the required values are present
and performs authentication, authorization policies generation using
generator functions from `AUTHENTICATION_POLICIES`.
:param config: Pyramid Configurator instance.
:param raml_ro... | [
"Setup",
"authentication",
"authorization",
"policies",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/auth.py#L178-L217 |
ramses-tech/ramses | ramses/auth.py | get_authuser_model | def get_authuser_model():
""" Define and return AuthUser model using nefertari base classes """
from nefertari.authentication.models import AuthUserMixin
from nefertari import engine
class AuthUser(AuthUserMixin, engine.BaseDocument):
__tablename__ = 'ramses_authuser'
return AuthUser | python | def get_authuser_model():
""" Define and return AuthUser model using nefertari base classes """
from nefertari.authentication.models import AuthUserMixin
from nefertari import engine
class AuthUser(AuthUserMixin, engine.BaseDocument):
__tablename__ = 'ramses_authuser'
return AuthUser | [
"def",
"get_authuser_model",
"(",
")",
":",
"from",
"nefertari",
".",
"authentication",
".",
"models",
"import",
"AuthUserMixin",
"from",
"nefertari",
"import",
"engine",
"class",
"AuthUser",
"(",
"AuthUserMixin",
",",
"engine",
".",
"BaseDocument",
")",
":",
"_... | Define and return AuthUser model using nefertari base classes | [
"Define",
"and",
"return",
"AuthUser",
"model",
"using",
"nefertari",
"base",
"classes"
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/auth.py#L245-L253 |
ramses-tech/ramses | ramses/acl.py | validate_permissions | def validate_permissions(perms):
""" Validate :perms: contains valid permissions.
:param perms: List of permission names or ALL_PERMISSIONS.
"""
if not isinstance(perms, (list, tuple)):
perms = [perms]
valid_perms = set(PERMISSIONS.values())
if ALL_PERMISSIONS in perms:
return p... | python | def validate_permissions(perms):
""" Validate :perms: contains valid permissions.
:param perms: List of permission names or ALL_PERMISSIONS.
"""
if not isinstance(perms, (list, tuple)):
perms = [perms]
valid_perms = set(PERMISSIONS.values())
if ALL_PERMISSIONS in perms:
return p... | [
"def",
"validate_permissions",
"(",
"perms",
")",
":",
"if",
"not",
"isinstance",
"(",
"perms",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"perms",
"=",
"[",
"perms",
"]",
"valid_perms",
"=",
"set",
"(",
"PERMISSIONS",
".",
"values",
"(",
")",
")... | Validate :perms: contains valid permissions.
:param perms: List of permission names or ALL_PERMISSIONS. | [
"Validate",
":",
"perms",
":",
"contains",
"valid",
"permissions",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/acl.py#L29-L43 |
ramses-tech/ramses | ramses/acl.py | parse_permissions | def parse_permissions(perms):
""" Parse permissions ("perms") which are either exact permission
names or the keyword 'all'.
:param perms: List or comma-separated string of nefertari permission
names, or 'all'
"""
if isinstance(perms, six.string_types):
perms = perms.split(',')
p... | python | def parse_permissions(perms):
""" Parse permissions ("perms") which are either exact permission
names or the keyword 'all'.
:param perms: List or comma-separated string of nefertari permission
names, or 'all'
"""
if isinstance(perms, six.string_types):
perms = perms.split(',')
p... | [
"def",
"parse_permissions",
"(",
"perms",
")",
":",
"if",
"isinstance",
"(",
"perms",
",",
"six",
".",
"string_types",
")",
":",
"perms",
"=",
"perms",
".",
"split",
"(",
"','",
")",
"perms",
"=",
"[",
"perm",
".",
"strip",
"(",
")",
".",
"lower",
... | Parse permissions ("perms") which are either exact permission
names or the keyword 'all'.
:param perms: List or comma-separated string of nefertari permission
names, or 'all' | [
"Parse",
"permissions",
"(",
"perms",
")",
"which",
"are",
"either",
"exact",
"permission",
"names",
"or",
"the",
"keyword",
"all",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/acl.py#L46-L58 |
ramses-tech/ramses | ramses/acl.py | parse_acl | def parse_acl(acl_string):
""" Parse raw string :acl_string: of RAML-defined ACLs.
If :acl_string: is blank or None, all permissions are given.
Values of ACL action and principal are parsed using `actions` and
`special_principals` maps and are looked up after `strip()` and
`lower()`.
ACEs in :... | python | def parse_acl(acl_string):
""" Parse raw string :acl_string: of RAML-defined ACLs.
If :acl_string: is blank or None, all permissions are given.
Values of ACL action and principal are parsed using `actions` and
`special_principals` maps and are looked up after `strip()` and
`lower()`.
ACEs in :... | [
"def",
"parse_acl",
"(",
"acl_string",
")",
":",
"if",
"not",
"acl_string",
":",
"return",
"[",
"ALLOW_ALL",
"]",
"aces_list",
"=",
"acl_string",
".",
"replace",
"(",
"'\\n'",
",",
"';'",
")",
".",
"split",
"(",
"';'",
")",
"aces_list",
"=",
"[",
"ace"... | Parse raw string :acl_string: of RAML-defined ACLs.
If :acl_string: is blank or None, all permissions are given.
Values of ACL action and principal are parsed using `actions` and
`special_principals` maps and are looked up after `strip()` and
`lower()`.
ACEs in :acl_string: may be separated by new... | [
"Parse",
"raw",
"string",
":",
"acl_string",
":",
"of",
"RAML",
"-",
"defined",
"ACLs",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/acl.py#L61-L107 |
ramses-tech/ramses | ramses/acl.py | generate_acl | def generate_acl(config, model_cls, raml_resource, es_based=True):
""" Generate an ACL.
Generated ACL class has a `item_model` attribute set to
:model_cls:.
ACLs used for collection and item access control are generated from a
first security scheme with type `x-ACL`.
If :raml_resource: has no ... | python | def generate_acl(config, model_cls, raml_resource, es_based=True):
""" Generate an ACL.
Generated ACL class has a `item_model` attribute set to
:model_cls:.
ACLs used for collection and item access control are generated from a
first security scheme with type `x-ACL`.
If :raml_resource: has no ... | [
"def",
"generate_acl",
"(",
"config",
",",
"model_cls",
",",
"raml_resource",
",",
"es_based",
"=",
"True",
")",
":",
"schemes",
"=",
"raml_resource",
".",
"security_schemes",
"or",
"[",
"]",
"schemes",
"=",
"[",
"sch",
"for",
"sch",
"in",
"schemes",
"if",... | Generate an ACL.
Generated ACL class has a `item_model` attribute set to
:model_cls:.
ACLs used for collection and item access control are generated from a
first security scheme with type `x-ACL`.
If :raml_resource: has no x-ACL security schemes defined then ALLOW_ALL
ACL is used.
If the `... | [
"Generate",
"an",
"ACL",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/acl.py#L217-L264 |
ramses-tech/ramses | ramses/acl.py | BaseACL._apply_callables | def _apply_callables(self, acl, obj=None):
""" Iterate over ACEs from :acl: and apply callable principals
if any.
Principals are passed 3 arguments on call:
:ace: Single ACE object that looks like (action, callable,
permission or [permission])
:request: C... | python | def _apply_callables(self, acl, obj=None):
""" Iterate over ACEs from :acl: and apply callable principals
if any.
Principals are passed 3 arguments on call:
:ace: Single ACE object that looks like (action, callable,
permission or [permission])
:request: C... | [
"def",
"_apply_callables",
"(",
"self",
",",
"acl",
",",
"obj",
"=",
"None",
")",
":",
"new_acl",
"=",
"[",
"]",
"for",
"i",
",",
"ace",
"in",
"enumerate",
"(",
"acl",
")",
":",
"principal",
"=",
"ace",
"[",
"1",
"]",
"if",
"six",
".",
"callable"... | Iterate over ACEs from :acl: and apply callable principals
if any.
Principals are passed 3 arguments on call:
:ace: Single ACE object that looks like (action, callable,
permission or [permission])
:request: Current request object
:obj: Object instance... | [
"Iterate",
"over",
"ACEs",
"from",
":",
"acl",
":",
"and",
"apply",
"callable",
"principals",
"if",
"any",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/acl.py#L117-L144 |
ramses-tech/ramses | ramses/acl.py | DatabaseACLMixin.item_acl | def item_acl(self, item):
""" Objectify ACL if ES is used or call item.get_acl() if
db is used.
"""
if self.es_based:
from nefertari_guards.elasticsearch import get_es_item_acl
return get_es_item_acl(item)
return super(DatabaseACLMixin, self).item_acl(item... | python | def item_acl(self, item):
""" Objectify ACL if ES is used or call item.get_acl() if
db is used.
"""
if self.es_based:
from nefertari_guards.elasticsearch import get_es_item_acl
return get_es_item_acl(item)
return super(DatabaseACLMixin, self).item_acl(item... | [
"def",
"item_acl",
"(",
"self",
",",
"item",
")",
":",
"if",
"self",
".",
"es_based",
":",
"from",
"nefertari_guards",
".",
"elasticsearch",
"import",
"get_es_item_acl",
"return",
"get_es_item_acl",
"(",
"item",
")",
"return",
"super",
"(",
"DatabaseACLMixin",
... | Objectify ACL if ES is used or call item.get_acl() if
db is used. | [
"Objectify",
"ACL",
"if",
"ES",
"is",
"used",
"or",
"call",
"item",
".",
"get_acl",
"()",
"if",
"db",
"is",
"used",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/acl.py#L189-L196 |
ramses-tech/ramses | ramses/acl.py | DatabaseACLMixin.getitem_es | def getitem_es(self, key):
""" Override to support ACL filtering.
To do so: passes `self.request` to `get_item` and uses
`ACLFilterES`.
"""
from nefertari_guards.elasticsearch import ACLFilterES
es = ACLFilterES(self.item_model.__name__)
params = {
'i... | python | def getitem_es(self, key):
""" Override to support ACL filtering.
To do so: passes `self.request` to `get_item` and uses
`ACLFilterES`.
"""
from nefertari_guards.elasticsearch import ACLFilterES
es = ACLFilterES(self.item_model.__name__)
params = {
'i... | [
"def",
"getitem_es",
"(",
"self",
",",
"key",
")",
":",
"from",
"nefertari_guards",
".",
"elasticsearch",
"import",
"ACLFilterES",
"es",
"=",
"ACLFilterES",
"(",
"self",
".",
"item_model",
".",
"__name__",
")",
"params",
"=",
"{",
"'id'",
":",
"key",
",",
... | Override to support ACL filtering.
To do so: passes `self.request` to `get_item` and uses
`ACLFilterES`. | [
"Override",
"to",
"support",
"ACL",
"filtering",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/acl.py#L198-L214 |
ramses-tech/ramses | ramses/utils.py | convert_schema | def convert_schema(raml_schema, mime_type):
""" Restructure `raml_schema` to a dictionary that has 'properties'
as well as other schema keys/values.
The resulting dictionary looks like this::
{
"properties": {
"field1": {
"required": boolean,
"type":... | python | def convert_schema(raml_schema, mime_type):
""" Restructure `raml_schema` to a dictionary that has 'properties'
as well as other schema keys/values.
The resulting dictionary looks like this::
{
"properties": {
"field1": {
"required": boolean,
"type":... | [
"def",
"convert_schema",
"(",
"raml_schema",
",",
"mime_type",
")",
":",
"if",
"mime_type",
"==",
"ContentTypes",
".",
"JSON",
":",
"if",
"not",
"isinstance",
"(",
"raml_schema",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"'Schema is not a valid JSON. Ple... | Restructure `raml_schema` to a dictionary that has 'properties'
as well as other schema keys/values.
The resulting dictionary looks like this::
{
"properties": {
"field1": {
"required": boolean,
"type": ...,
...more field options
... | [
"Restructure",
"raml_schema",
"to",
"a",
"dictionary",
"that",
"has",
"properties",
"as",
"well",
"as",
"other",
"schema",
"keys",
"/",
"values",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L22-L54 |
ramses-tech/ramses | ramses/utils.py | generate_model_name | def generate_model_name(raml_resource):
""" Generate model name.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
resource_uri = get_resource_uri(raml_resource).strip('/')
resource_uri = re.sub('\W', ' ', resource_uri)
model_name = inflection.titleize(resource_uri)
ret... | python | def generate_model_name(raml_resource):
""" Generate model name.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
resource_uri = get_resource_uri(raml_resource).strip('/')
resource_uri = re.sub('\W', ' ', resource_uri)
model_name = inflection.titleize(resource_uri)
ret... | [
"def",
"generate_model_name",
"(",
"raml_resource",
")",
":",
"resource_uri",
"=",
"get_resource_uri",
"(",
"raml_resource",
")",
".",
"strip",
"(",
"'/'",
")",
"resource_uri",
"=",
"re",
".",
"sub",
"(",
"'\\W'",
",",
"' '",
",",
"resource_uri",
")",
"model... | Generate model name.
:param raml_resource: Instance of ramlfications.raml.ResourceNode. | [
"Generate",
"model",
"name",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L76-L84 |
ramses-tech/ramses | ramses/utils.py | dynamic_part_name | def dynamic_part_name(raml_resource, route_name, pk_field):
""" Generate a dynamic part for a resource :raml_resource:.
A dynamic part is generated using 2 parts: :route_name: of the
resource and the dynamic part of first dynamic child resources. If
:raml_resource: has no dynamic child resources, 'id' ... | python | def dynamic_part_name(raml_resource, route_name, pk_field):
""" Generate a dynamic part for a resource :raml_resource:.
A dynamic part is generated using 2 parts: :route_name: of the
resource and the dynamic part of first dynamic child resources. If
:raml_resource: has no dynamic child resources, 'id' ... | [
"def",
"dynamic_part_name",
"(",
"raml_resource",
",",
"route_name",
",",
"pk_field",
")",
":",
"subresources",
"=",
"get_resource_children",
"(",
"raml_resource",
")",
"dynamic_uris",
"=",
"[",
"res",
".",
"path",
"for",
"res",
"in",
"subresources",
"if",
"is_d... | Generate a dynamic part for a resource :raml_resource:.
A dynamic part is generated using 2 parts: :route_name: of the
resource and the dynamic part of first dynamic child resources. If
:raml_resource: has no dynamic child resources, 'id' is used as the
2nd part.
E.g. if your dynamic part on route ... | [
"Generate",
"a",
"dynamic",
"part",
"for",
"a",
"resource",
":",
"raml_resource",
":",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L87-L109 |
ramses-tech/ramses | ramses/utils.py | extract_dynamic_part | def extract_dynamic_part(uri):
""" Extract dynamic url part from :uri: string.
:param uri: URI string that may contain dynamic part.
"""
for part in uri.split('/'):
part = part.strip()
if part.startswith('{') and part.endswith('}'):
return clean_dynamic_uri(part) | python | def extract_dynamic_part(uri):
""" Extract dynamic url part from :uri: string.
:param uri: URI string that may contain dynamic part.
"""
for part in uri.split('/'):
part = part.strip()
if part.startswith('{') and part.endswith('}'):
return clean_dynamic_uri(part) | [
"def",
"extract_dynamic_part",
"(",
"uri",
")",
":",
"for",
"part",
"in",
"uri",
".",
"split",
"(",
"'/'",
")",
":",
"part",
"=",
"part",
".",
"strip",
"(",
")",
"if",
"part",
".",
"startswith",
"(",
"'{'",
")",
"and",
"part",
".",
"endswith",
"(",... | Extract dynamic url part from :uri: string.
:param uri: URI string that may contain dynamic part. | [
"Extract",
"dynamic",
"url",
"part",
"from",
":",
"uri",
":",
"string",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L112-L120 |
ramses-tech/ramses | ramses/utils.py | resource_view_attrs | def resource_view_attrs(raml_resource, singular=False):
""" Generate view method names needed for `raml_resource` view.
Collects HTTP method names from resource siblings and dynamic children
if exist. Collected methods are then translated to
`nefertari.view.BaseView` method names, each of which is use... | python | def resource_view_attrs(raml_resource, singular=False):
""" Generate view method names needed for `raml_resource` view.
Collects HTTP method names from resource siblings and dynamic children
if exist. Collected methods are then translated to
`nefertari.view.BaseView` method names, each of which is use... | [
"def",
"resource_view_attrs",
"(",
"raml_resource",
",",
"singular",
"=",
"False",
")",
":",
"from",
".",
"views",
"import",
"collection_methods",
",",
"item_methods",
"# Singular resource doesn't have collection methods though",
"# it looks like a collection",
"if",
"singula... | Generate view method names needed for `raml_resource` view.
Collects HTTP method names from resource siblings and dynamic children
if exist. Collected methods are then translated to
`nefertari.view.BaseView` method names, each of which is used to
process a particular HTTP method request.
Maps of ... | [
"Generate",
"view",
"method",
"names",
"needed",
"for",
"raml_resource",
"view",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L123-L156 |
ramses-tech/ramses | ramses/utils.py | resource_schema | def resource_schema(raml_resource):
""" Get schema properties of RAML resource :raml_resource:.
Must be called with RAML resource that defines body schema. First
body that defines schema is used. Schema is converted on return using
'convert_schema'.
:param raml_resource: Instance of ramlfications.... | python | def resource_schema(raml_resource):
""" Get schema properties of RAML resource :raml_resource:.
Must be called with RAML resource that defines body schema. First
body that defines schema is used. Schema is converted on return using
'convert_schema'.
:param raml_resource: Instance of ramlfications.... | [
"def",
"resource_schema",
"(",
"raml_resource",
")",
":",
"# NOTE: Must be called with resource that defines body schema",
"log",
".",
"info",
"(",
"'Searching for model schema'",
")",
"if",
"not",
"raml_resource",
".",
"body",
":",
"raise",
"ValueError",
"(",
"'RAML reso... | Get schema properties of RAML resource :raml_resource:.
Must be called with RAML resource that defines body schema. First
body that defines schema is used. Schema is converted on return using
'convert_schema'.
:param raml_resource: Instance of ramlfications.raml.ResourceNode of
POST method. | [
"Get",
"schema",
"properties",
"of",
"RAML",
"resource",
":",
"raml_resource",
":",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L159-L178 |
ramses-tech/ramses | ramses/utils.py | get_static_parent | def get_static_parent(raml_resource, method=None):
""" Get static parent resource of :raml_resource: with HTTP
method :method:.
:param raml_resource:Instance of ramlfications.raml.ResourceNode.
:param method: HTTP method name which matching static resource
must have.
"""
parent = raml_r... | python | def get_static_parent(raml_resource, method=None):
""" Get static parent resource of :raml_resource: with HTTP
method :method:.
:param raml_resource:Instance of ramlfications.raml.ResourceNode.
:param method: HTTP method name which matching static resource
must have.
"""
parent = raml_r... | [
"def",
"get_static_parent",
"(",
"raml_resource",
",",
"method",
"=",
"None",
")",
":",
"parent",
"=",
"raml_resource",
".",
"parent",
"while",
"is_dynamic_resource",
"(",
"parent",
")",
":",
"parent",
"=",
"parent",
".",
"parent",
"if",
"parent",
"is",
"Non... | Get static parent resource of :raml_resource: with HTTP
method :method:.
:param raml_resource:Instance of ramlfications.raml.ResourceNode.
:param method: HTTP method name which matching static resource
must have. | [
"Get",
"static",
"parent",
"resource",
"of",
":",
"raml_resource",
":",
"with",
"HTTP",
"method",
":",
"method",
":",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L189-L214 |
ramses-tech/ramses | ramses/utils.py | attr_subresource | def attr_subresource(raml_resource, route_name):
""" Determine if :raml_resource: is an attribute subresource.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
:param route_name: Name of the :raml_resource:.
"""
static_parent = get_static_parent(raml_resource, method='POST')
i... | python | def attr_subresource(raml_resource, route_name):
""" Determine if :raml_resource: is an attribute subresource.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
:param route_name: Name of the :raml_resource:.
"""
static_parent = get_static_parent(raml_resource, method='POST')
i... | [
"def",
"attr_subresource",
"(",
"raml_resource",
",",
"route_name",
")",
":",
"static_parent",
"=",
"get_static_parent",
"(",
"raml_resource",
",",
"method",
"=",
"'POST'",
")",
"if",
"static_parent",
"is",
"None",
":",
"return",
"False",
"schema",
"=",
"resourc... | Determine if :raml_resource: is an attribute subresource.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
:param route_name: Name of the :raml_resource:. | [
"Determine",
"if",
":",
"raml_resource",
":",
"is",
"an",
"attribute",
"subresource",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L217-L231 |
ramses-tech/ramses | ramses/utils.py | singular_subresource | def singular_subresource(raml_resource, route_name):
""" Determine if :raml_resource: is a singular subresource.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
:param route_name: Name of the :raml_resource:.
"""
static_parent = get_static_parent(raml_resource, method='POST')
... | python | def singular_subresource(raml_resource, route_name):
""" Determine if :raml_resource: is a singular subresource.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
:param route_name: Name of the :raml_resource:.
"""
static_parent = get_static_parent(raml_resource, method='POST')
... | [
"def",
"singular_subresource",
"(",
"raml_resource",
",",
"route_name",
")",
":",
"static_parent",
"=",
"get_static_parent",
"(",
"raml_resource",
",",
"method",
"=",
"'POST'",
")",
"if",
"static_parent",
"is",
"None",
":",
"return",
"False",
"schema",
"=",
"res... | Determine if :raml_resource: is a singular subresource.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
:param route_name: Name of the :raml_resource:. | [
"Determine",
"if",
":",
"raml_resource",
":",
"is",
"a",
"singular",
"subresource",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L234-L251 |
ramses-tech/ramses | ramses/utils.py | is_callable_tag | def is_callable_tag(tag):
""" Determine whether :tag: is a valid callable string tag.
String is assumed to be valid callable if it starts with '{{'
and ends with '}}'.
:param tag: String name of tag.
"""
return (isinstance(tag, six.string_types) and
tag.strip().startswith('{{') and... | python | def is_callable_tag(tag):
""" Determine whether :tag: is a valid callable string tag.
String is assumed to be valid callable if it starts with '{{'
and ends with '}}'.
:param tag: String name of tag.
"""
return (isinstance(tag, six.string_types) and
tag.strip().startswith('{{') and... | [
"def",
"is_callable_tag",
"(",
"tag",
")",
":",
"return",
"(",
"isinstance",
"(",
"tag",
",",
"six",
".",
"string_types",
")",
"and",
"tag",
".",
"strip",
"(",
")",
".",
"startswith",
"(",
"'{{'",
")",
"and",
"tag",
".",
"strip",
"(",
")",
".",
"en... | Determine whether :tag: is a valid callable string tag.
String is assumed to be valid callable if it starts with '{{'
and ends with '}}'.
:param tag: String name of tag. | [
"Determine",
"whether",
":",
"tag",
":",
"is",
"a",
"valid",
"callable",
"string",
"tag",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L254-L264 |
ramses-tech/ramses | ramses/utils.py | resolve_to_callable | def resolve_to_callable(callable_name):
""" Resolve string :callable_name: to a callable.
:param callable_name: String representing callable name as registered
in ramses registry or dotted import path of callable. Can be
wrapped in double curly brackets, e.g. '{{my_callable}}'.
"""
from... | python | def resolve_to_callable(callable_name):
""" Resolve string :callable_name: to a callable.
:param callable_name: String representing callable name as registered
in ramses registry or dotted import path of callable. Can be
wrapped in double curly brackets, e.g. '{{my_callable}}'.
"""
from... | [
"def",
"resolve_to_callable",
"(",
"callable_name",
")",
":",
"from",
".",
"import",
"registry",
"clean_callable_name",
"=",
"callable_name",
".",
"replace",
"(",
"'{{'",
",",
"''",
")",
".",
"replace",
"(",
"'}}'",
",",
"''",
")",
".",
"strip",
"(",
")",
... | Resolve string :callable_name: to a callable.
:param callable_name: String representing callable name as registered
in ramses registry or dotted import path of callable. Can be
wrapped in double curly brackets, e.g. '{{my_callable}}'. | [
"Resolve",
"string",
":",
"callable_name",
":",
"to",
"a",
"callable",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L267-L285 |
ramses-tech/ramses | ramses/utils.py | get_resource_siblings | def get_resource_siblings(raml_resource):
""" Get siblings of :raml_resource:.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
path = raml_resource.path
return [res for res in raml_resource.root.resources
if res.path == path] | python | def get_resource_siblings(raml_resource):
""" Get siblings of :raml_resource:.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
path = raml_resource.path
return [res for res in raml_resource.root.resources
if res.path == path] | [
"def",
"get_resource_siblings",
"(",
"raml_resource",
")",
":",
"path",
"=",
"raml_resource",
".",
"path",
"return",
"[",
"res",
"for",
"res",
"in",
"raml_resource",
".",
"root",
".",
"resources",
"if",
"res",
".",
"path",
"==",
"path",
"]"
] | Get siblings of :raml_resource:.
:param raml_resource: Instance of ramlfications.raml.ResourceNode. | [
"Get",
"siblings",
"of",
":",
"raml_resource",
":",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L288-L295 |
ramses-tech/ramses | ramses/utils.py | get_resource_children | def get_resource_children(raml_resource):
""" Get children of :raml_resource:.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
path = raml_resource.path
return [res for res in raml_resource.root.resources
if res.parent and res.parent.path == path] | python | def get_resource_children(raml_resource):
""" Get children of :raml_resource:.
:param raml_resource: Instance of ramlfications.raml.ResourceNode.
"""
path = raml_resource.path
return [res for res in raml_resource.root.resources
if res.parent and res.parent.path == path] | [
"def",
"get_resource_children",
"(",
"raml_resource",
")",
":",
"path",
"=",
"raml_resource",
".",
"path",
"return",
"[",
"res",
"for",
"res",
"in",
"raml_resource",
".",
"root",
".",
"resources",
"if",
"res",
".",
"parent",
"and",
"res",
".",
"parent",
".... | Get children of :raml_resource:.
:param raml_resource: Instance of ramlfications.raml.ResourceNode. | [
"Get",
"children",
"of",
":",
"raml_resource",
":",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L298-L305 |
ramses-tech/ramses | ramses/utils.py | get_events_map | def get_events_map():
""" Prepare map of event subscribers.
* Extends copies of BEFORE_EVENTS and AFTER_EVENTS maps with
'set' action.
* Returns map of {before/after: {action: event class(es)}}
"""
from nefertari import events
set_keys = ('create', 'update', 'replace', 'update_many', 'r... | python | def get_events_map():
""" Prepare map of event subscribers.
* Extends copies of BEFORE_EVENTS and AFTER_EVENTS maps with
'set' action.
* Returns map of {before/after: {action: event class(es)}}
"""
from nefertari import events
set_keys = ('create', 'update', 'replace', 'update_many', 'r... | [
"def",
"get_events_map",
"(",
")",
":",
"from",
"nefertari",
"import",
"events",
"set_keys",
"=",
"(",
"'create'",
",",
"'update'",
",",
"'replace'",
",",
"'update_many'",
",",
"'register'",
")",
"before_events",
"=",
"events",
".",
"BEFORE_EVENTS",
".",
"copy... | Prepare map of event subscribers.
* Extends copies of BEFORE_EVENTS and AFTER_EVENTS maps with
'set' action.
* Returns map of {before/after: {action: event class(es)}} | [
"Prepare",
"map",
"of",
"event",
"subscribers",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L308-L324 |
ramses-tech/ramses | ramses/utils.py | patch_view_model | def patch_view_model(view_cls, model_cls):
""" Patches view_cls.Model with model_cls.
:param view_cls: View class "Model" param of which should be
patched
:param model_cls: Model class which should be used to patch
view_cls.Model
"""
original_model = view_cls.Model
view_cls.Mode... | python | def patch_view_model(view_cls, model_cls):
""" Patches view_cls.Model with model_cls.
:param view_cls: View class "Model" param of which should be
patched
:param model_cls: Model class which should be used to patch
view_cls.Model
"""
original_model = view_cls.Model
view_cls.Mode... | [
"def",
"patch_view_model",
"(",
"view_cls",
",",
"model_cls",
")",
":",
"original_model",
"=",
"view_cls",
".",
"Model",
"view_cls",
".",
"Model",
"=",
"model_cls",
"try",
":",
"yield",
"finally",
":",
"view_cls",
".",
"Model",
"=",
"original_model"
] | Patches view_cls.Model with model_cls.
:param view_cls: View class "Model" param of which should be
patched
:param model_cls: Model class which should be used to patch
view_cls.Model | [
"Patches",
"view_cls",
".",
"Model",
"with",
"model_cls",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L328-L342 |
ramses-tech/ramses | ramses/utils.py | get_route_name | def get_route_name(resource_uri):
""" Get route name from RAML resource URI.
:param resource_uri: String representing RAML resource URI.
:returns string: String with route name, which is :resource_uri:
stripped of non-word characters.
"""
resource_uri = resource_uri.strip('/')
resource_... | python | def get_route_name(resource_uri):
""" Get route name from RAML resource URI.
:param resource_uri: String representing RAML resource URI.
:returns string: String with route name, which is :resource_uri:
stripped of non-word characters.
"""
resource_uri = resource_uri.strip('/')
resource_... | [
"def",
"get_route_name",
"(",
"resource_uri",
")",
":",
"resource_uri",
"=",
"resource_uri",
".",
"strip",
"(",
"'/'",
")",
"resource_uri",
"=",
"re",
".",
"sub",
"(",
"'\\W'",
",",
"''",
",",
"resource_uri",
")",
"return",
"resource_uri"
] | Get route name from RAML resource URI.
:param resource_uri: String representing RAML resource URI.
:returns string: String with route name, which is :resource_uri:
stripped of non-word characters. | [
"Get",
"route",
"name",
"from",
"RAML",
"resource",
"URI",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/utils.py#L345-L354 |
ramses-tech/ramses | ramses/generators.py | generate_resource | def generate_resource(config, raml_resource, parent_resource):
""" Perform complete one resource configuration process
This function generates: ACL, view, route, resource, database
model for a given `raml_resource`. New nefertari resource is
attached to `parent_resource` class which is an instance of
... | python | def generate_resource(config, raml_resource, parent_resource):
""" Perform complete one resource configuration process
This function generates: ACL, view, route, resource, database
model for a given `raml_resource`. New nefertari resource is
attached to `parent_resource` class which is an instance of
... | [
"def",
"generate_resource",
"(",
"config",
",",
"raml_resource",
",",
"parent_resource",
")",
":",
"from",
".",
"models",
"import",
"get_existing_model",
"# Don't generate resources for dynamic routes as they are already",
"# generated by their parent",
"resource_uri",
"=",
"ge... | Perform complete one resource configuration process
This function generates: ACL, view, route, resource, database
model for a given `raml_resource`. New nefertari resource is
attached to `parent_resource` class which is an instance of
`nefertari.resource.Resource`.
Things to consider:
* Top-... | [
"Perform",
"complete",
"one",
"resource",
"configuration",
"process"
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/generators.py#L32-L122 |
ramses-tech/ramses | ramses/generators.py | generate_server | def generate_server(raml_root, config):
""" Handle server generation process.
:param raml_root: Instance of ramlfications.raml.RootNode.
:param config: Pyramid Configurator instance.
"""
log.info('Server generation started')
if not raml_root.resources:
return
root_resource = confi... | python | def generate_server(raml_root, config):
""" Handle server generation process.
:param raml_root: Instance of ramlfications.raml.RootNode.
:param config: Pyramid Configurator instance.
"""
log.info('Server generation started')
if not raml_root.resources:
return
root_resource = confi... | [
"def",
"generate_server",
"(",
"raml_root",
",",
"config",
")",
":",
"log",
".",
"info",
"(",
"'Server generation started'",
")",
"if",
"not",
"raml_root",
".",
"resources",
":",
"return",
"root_resource",
"=",
"config",
".",
"get_root_resource",
"(",
")",
"ge... | Handle server generation process.
:param raml_root: Instance of ramlfications.raml.RootNode.
:param config: Pyramid Configurator instance. | [
"Handle",
"server",
"generation",
"process",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/generators.py#L125-L151 |
ramses-tech/ramses | ramses/generators.py | generate_models | def generate_models(config, raml_resources):
""" Generate model for each resource in :raml_resources:
The DB model name is generated using singular titled version of current
resource's url. E.g. for resource under url '/stories', model with
name 'Story' will be generated.
:param config: Pyramid Co... | python | def generate_models(config, raml_resources):
""" Generate model for each resource in :raml_resources:
The DB model name is generated using singular titled version of current
resource's url. E.g. for resource under url '/stories', model with
name 'Story' will be generated.
:param config: Pyramid Co... | [
"def",
"generate_models",
"(",
"config",
",",
"raml_resources",
")",
":",
"from",
".",
"models",
"import",
"handle_model_generation",
"if",
"not",
"raml_resources",
":",
"return",
"for",
"raml_resource",
"in",
"raml_resources",
":",
"# No need to generate models for dyn... | Generate model for each resource in :raml_resources:
The DB model name is generated using singular titled version of current
resource's url. E.g. for resource under url '/stories', model with
name 'Story' will be generated.
:param config: Pyramid Configurator instance.
:param raml_resources: List ... | [
"Generate",
"model",
"for",
"each",
"resource",
"in",
":",
"raml_resources",
":"
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/generators.py#L154-L186 |
ramses-tech/ramses | ramses/views.py | generate_rest_view | def generate_rest_view(config, model_cls, attrs=None, es_based=True,
attr_view=False, singular=False):
""" Generate REST view for a model class.
:param model_cls: Generated DB model class.
:param attr: List of strings that represent names of view methods, new
generated view s... | python | def generate_rest_view(config, model_cls, attrs=None, es_based=True,
attr_view=False, singular=False):
""" Generate REST view for a model class.
:param model_cls: Generated DB model class.
:param attr: List of strings that represent names of view methods, new
generated view s... | [
"def",
"generate_rest_view",
"(",
"config",
",",
"model_cls",
",",
"attrs",
"=",
"None",
",",
"es_based",
"=",
"True",
",",
"attr_view",
"=",
"False",
",",
"singular",
"=",
"False",
")",
":",
"valid_attrs",
"=",
"(",
"list",
"(",
"collection_methods",
".",... | Generate REST view for a model class.
:param model_cls: Generated DB model class.
:param attr: List of strings that represent names of view methods, new
generated view should support. Not supported methods are replaced
with property that raises AttributeError to display MethodNotAllowed
... | [
"Generate",
"REST",
"view",
"for",
"a",
"model",
"class",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L447-L491 |
ramses-tech/ramses | ramses/views.py | SetObjectACLMixin.set_object_acl | def set_object_acl(self, obj):
""" Set object ACL on creation if not already present. """
if not obj._acl:
from nefertari_guards import engine as guards_engine
acl = self._factory(self.request).generate_item_acl(obj)
obj._acl = guards_engine.ACLField.stringify_acl(acl... | python | def set_object_acl(self, obj):
""" Set object ACL on creation if not already present. """
if not obj._acl:
from nefertari_guards import engine as guards_engine
acl = self._factory(self.request).generate_item_acl(obj)
obj._acl = guards_engine.ACLField.stringify_acl(acl... | [
"def",
"set_object_acl",
"(",
"self",
",",
"obj",
")",
":",
"if",
"not",
"obj",
".",
"_acl",
":",
"from",
"nefertari_guards",
"import",
"engine",
"as",
"guards_engine",
"acl",
"=",
"self",
".",
"_factory",
"(",
"self",
".",
"request",
")",
".",
"generate... | Set object ACL on creation if not already present. | [
"Set",
"object",
"ACL",
"on",
"creation",
"if",
"not",
"already",
"present",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L37-L42 |
ramses-tech/ramses | ramses/views.py | BaseView.resolve_kw | def resolve_kw(self, kwargs):
""" Resolve :kwargs: like `story_id: 1` to the form of `id: 1`.
"""
resolved = {}
for key, value in kwargs.items():
split = key.split('_', 1)
if len(split) > 1:
key = split[1]
resolved[key] = value
... | python | def resolve_kw(self, kwargs):
""" Resolve :kwargs: like `story_id: 1` to the form of `id: 1`.
"""
resolved = {}
for key, value in kwargs.items():
split = key.split('_', 1)
if len(split) > 1:
key = split[1]
resolved[key] = value
... | [
"def",
"resolve_kw",
"(",
"self",
",",
"kwargs",
")",
":",
"resolved",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"split",
"=",
"key",
".",
"split",
"(",
"'_'",
",",
"1",
")",
"if",
"len",
"(",
"spli... | Resolve :kwargs: like `story_id: 1` to the form of `id: 1`. | [
"Resolve",
":",
"kwargs",
":",
"like",
"story_id",
":",
"1",
"to",
"the",
"form",
"of",
"id",
":",
"1",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L62-L72 |
ramses-tech/ramses | ramses/views.py | BaseView._location | def _location(self, obj):
""" Get location of the `obj`
Arguments:
:obj: self.Model instance.
"""
field_name = self.clean_id_name
return self.request.route_url(
self._resource.uid,
**{self._resource.id_name: getattr(obj, field_name)}) | python | def _location(self, obj):
""" Get location of the `obj`
Arguments:
:obj: self.Model instance.
"""
field_name = self.clean_id_name
return self.request.route_url(
self._resource.uid,
**{self._resource.id_name: getattr(obj, field_name)}) | [
"def",
"_location",
"(",
"self",
",",
"obj",
")",
":",
"field_name",
"=",
"self",
".",
"clean_id_name",
"return",
"self",
".",
"request",
".",
"route_url",
"(",
"self",
".",
"_resource",
".",
"uid",
",",
"*",
"*",
"{",
"self",
".",
"_resource",
".",
... | Get location of the `obj`
Arguments:
:obj: self.Model instance. | [
"Get",
"location",
"of",
"the",
"obj"
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L74-L83 |
ramses-tech/ramses | ramses/views.py | BaseView._parent_queryset | def _parent_queryset(self):
""" Get queryset of parent view.
Generated queryset is used to run queries in the current level view.
"""
parent = self._resource.parent
if hasattr(parent, 'view'):
req = self.request.blank(self.request.path)
req.registry = sel... | python | def _parent_queryset(self):
""" Get queryset of parent view.
Generated queryset is used to run queries in the current level view.
"""
parent = self._resource.parent
if hasattr(parent, 'view'):
req = self.request.blank(self.request.path)
req.registry = sel... | [
"def",
"_parent_queryset",
"(",
"self",
")",
":",
"parent",
"=",
"self",
".",
"_resource",
".",
"parent",
"if",
"hasattr",
"(",
"parent",
",",
"'view'",
")",
":",
"req",
"=",
"self",
".",
"request",
".",
"blank",
"(",
"self",
".",
"request",
".",
"pa... | Get queryset of parent view.
Generated queryset is used to run queries in the current level view. | [
"Get",
"queryset",
"of",
"parent",
"view",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L85-L101 |
ramses-tech/ramses | ramses/views.py | BaseView.get_collection | def get_collection(self, **kwargs):
""" Get objects collection taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus a
queryset returned by this method will be a subset of its parent
view's queryset, thus filtering... | python | def get_collection(self, **kwargs):
""" Get objects collection taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus a
queryset returned by this method will be a subset of its parent
view's queryset, thus filtering... | [
"def",
"get_collection",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_query_params",
".",
"update",
"(",
"kwargs",
")",
"objects",
"=",
"self",
".",
"_parent_queryset",
"(",
")",
"if",
"objects",
"is",
"not",
"None",
":",
"return",
"s... | Get objects collection taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus a
queryset returned by this method will be a subset of its parent
view's queryset, thus filtering out objects that don't belong to
the pa... | [
"Get",
"objects",
"collection",
"taking",
"into",
"account",
"generated",
"queryset",
"of",
"parent",
"view",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L103-L117 |
ramses-tech/ramses | ramses/views.py | BaseView.get_item | def get_item(self, **kwargs):
""" Get collection item taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus an item
returned by this method will belong to its parent view's queryset, thus
filtering out objects that... | python | def get_item(self, **kwargs):
""" Get collection item taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus an item
returned by this method will belong to its parent view's queryset, thus
filtering out objects that... | [
"def",
"get_item",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"six",
".",
"callable",
"(",
"self",
".",
"context",
")",
":",
"self",
".",
"reload_context",
"(",
"es_based",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
"objects",
"=",
"sel... | Get collection item taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus an item
returned by this method will belong to its parent view's queryset, thus
filtering out objects that don't belong to the parent object.
... | [
"Get",
"collection",
"item",
"taking",
"into",
"account",
"generated",
"queryset",
"of",
"parent",
"view",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L119-L139 |
ramses-tech/ramses | ramses/views.py | BaseView.reload_context | def reload_context(self, es_based, **kwargs):
""" Reload `self.context` object into a DB or ES object.
A reload is performed by getting the object ID from :kwargs: and then
getting a context key item from the new instance of `self._factory`
which is an ACL class used by the current view... | python | def reload_context(self, es_based, **kwargs):
""" Reload `self.context` object into a DB or ES object.
A reload is performed by getting the object ID from :kwargs: and then
getting a context key item from the new instance of `self._factory`
which is an ACL class used by the current view... | [
"def",
"reload_context",
"(",
"self",
",",
"es_based",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
"acl",
"import",
"BaseACL",
"key",
"=",
"self",
".",
"_get_context_key",
"(",
"*",
"*",
"kwargs",
")",
"kwargs",
"=",
"{",
"'request'",
":",
"self",
... | Reload `self.context` object into a DB or ES object.
A reload is performed by getting the object ID from :kwargs: and then
getting a context key item from the new instance of `self._factory`
which is an ACL class used by the current view.
Arguments:
:es_based: Boolean. Whet... | [
"Reload",
"self",
".",
"context",
"object",
"into",
"a",
"DB",
"or",
"ES",
"object",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L145-L168 |
ramses-tech/ramses | ramses/views.py | ESBaseView._parent_queryset_es | def _parent_queryset_es(self):
""" Get queryset (list of object IDs) of parent view.
The generated queryset is used to run queries in the current level's
view.
"""
parent = self._resource.parent
if hasattr(parent, 'view'):
req = self.request.blank(self.reques... | python | def _parent_queryset_es(self):
""" Get queryset (list of object IDs) of parent view.
The generated queryset is used to run queries in the current level's
view.
"""
parent = self._resource.parent
if hasattr(parent, 'view'):
req = self.request.blank(self.reques... | [
"def",
"_parent_queryset_es",
"(",
"self",
")",
":",
"parent",
"=",
"self",
".",
"_resource",
".",
"parent",
"if",
"hasattr",
"(",
"parent",
",",
"'view'",
")",
":",
"req",
"=",
"self",
".",
"request",
".",
"blank",
"(",
"self",
".",
"request",
".",
... | Get queryset (list of object IDs) of parent view.
The generated queryset is used to run queries in the current level's
view. | [
"Get",
"queryset",
"(",
"list",
"of",
"object",
"IDs",
")",
"of",
"parent",
"view",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L218-L234 |
ramses-tech/ramses | ramses/views.py | ESBaseView.get_es_object_ids | def get_es_object_ids(self, objects):
""" Return IDs of :objects: if they are not IDs already. """
id_field = self.clean_id_name
ids = [getattr(obj, id_field, obj) for obj in objects]
return list(set(str(id_) for id_ in ids)) | python | def get_es_object_ids(self, objects):
""" Return IDs of :objects: if they are not IDs already. """
id_field = self.clean_id_name
ids = [getattr(obj, id_field, obj) for obj in objects]
return list(set(str(id_) for id_ in ids)) | [
"def",
"get_es_object_ids",
"(",
"self",
",",
"objects",
")",
":",
"id_field",
"=",
"self",
".",
"clean_id_name",
"ids",
"=",
"[",
"getattr",
"(",
"obj",
",",
"id_field",
",",
"obj",
")",
"for",
"obj",
"in",
"objects",
"]",
"return",
"list",
"(",
"set"... | Return IDs of :objects: if they are not IDs already. | [
"Return",
"IDs",
"of",
":",
"objects",
":",
"if",
"they",
"are",
"not",
"IDs",
"already",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L236-L240 |
ramses-tech/ramses | ramses/views.py | ESBaseView.get_collection_es | def get_collection_es(self):
""" Get ES objects collection taking into account the generated
queryset of parent view.
This method allows working with nested resources properly. Thus a
queryset returned by this method will be a subset of its parent view's
queryset, thus filtering... | python | def get_collection_es(self):
""" Get ES objects collection taking into account the generated
queryset of parent view.
This method allows working with nested resources properly. Thus a
queryset returned by this method will be a subset of its parent view's
queryset, thus filtering... | [
"def",
"get_collection_es",
"(",
"self",
")",
":",
"objects_ids",
"=",
"self",
".",
"_parent_queryset_es",
"(",
")",
"if",
"objects_ids",
"is",
"not",
"None",
":",
"objects_ids",
"=",
"self",
".",
"get_es_object_ids",
"(",
"objects_ids",
")",
"if",
"not",
"o... | Get ES objects collection taking into account the generated
queryset of parent view.
This method allows working with nested resources properly. Thus a
queryset returned by this method will be a subset of its parent view's
queryset, thus filtering out objects that don't belong to the par... | [
"Get",
"ES",
"objects",
"collection",
"taking",
"into",
"account",
"the",
"generated",
"queryset",
"of",
"parent",
"view",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L242-L259 |
ramses-tech/ramses | ramses/views.py | ESBaseView.get_item_es | def get_item_es(self, **kwargs):
""" Get ES collection item taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus an item
returned by this method will belong to its parent view's queryset, thus
filtering out object... | python | def get_item_es(self, **kwargs):
""" Get ES collection item taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus an item
returned by this method will belong to its parent view's queryset, thus
filtering out object... | [
"def",
"get_item_es",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"item_id",
"=",
"self",
".",
"_get_context_key",
"(",
"*",
"*",
"kwargs",
")",
"objects_ids",
"=",
"self",
".",
"_parent_queryset_es",
"(",
")",
"if",
"objects_ids",
"is",
"not",
"None... | Get ES collection item taking into account generated queryset
of parent view.
This method allows working with nested resources properly. Thus an item
returned by this method will belong to its parent view's queryset, thus
filtering out objects that don't belong to the parent object.
... | [
"Get",
"ES",
"collection",
"item",
"taking",
"into",
"account",
"generated",
"queryset",
"of",
"parent",
"view",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L261-L284 |
ramses-tech/ramses | ramses/views.py | ESCollectionView.update | def update(self, **kwargs):
""" Explicitly reload context with DB usage to get access
to complete DB object.
"""
self.reload_context(es_based=False, **kwargs)
return super(ESCollectionView, self).update(**kwargs) | python | def update(self, **kwargs):
""" Explicitly reload context with DB usage to get access
to complete DB object.
"""
self.reload_context(es_based=False, **kwargs)
return super(ESCollectionView, self).update(**kwargs) | [
"def",
"update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"reload_context",
"(",
"es_based",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
"return",
"super",
"(",
"ESCollectionView",
",",
"self",
")",
".",
"update",
"(",
"*",
"*",
... | Explicitly reload context with DB usage to get access
to complete DB object. | [
"Explicitly",
"reload",
"context",
"with",
"DB",
"usage",
"to",
"get",
"access",
"to",
"complete",
"DB",
"object",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L298-L303 |
ramses-tech/ramses | ramses/views.py | ESCollectionView.delete | def delete(self, **kwargs):
""" Explicitly reload context with DB usage to get access
to complete DB object.
"""
self.reload_context(es_based=False, **kwargs)
return super(ESCollectionView, self).delete(**kwargs) | python | def delete(self, **kwargs):
""" Explicitly reload context with DB usage to get access
to complete DB object.
"""
self.reload_context(es_based=False, **kwargs)
return super(ESCollectionView, self).delete(**kwargs) | [
"def",
"delete",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"reload_context",
"(",
"es_based",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
"return",
"super",
"(",
"ESCollectionView",
",",
"self",
")",
".",
"delete",
"(",
"*",
"*",
... | Explicitly reload context with DB usage to get access
to complete DB object. | [
"Explicitly",
"reload",
"context",
"with",
"DB",
"usage",
"to",
"get",
"access",
"to",
"complete",
"DB",
"object",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L305-L310 |
ramses-tech/ramses | ramses/views.py | ESCollectionView.get_dbcollection_with_es | def get_dbcollection_with_es(self, **kwargs):
""" Get DB objects collection by first querying ES. """
es_objects = self.get_collection_es()
db_objects = self.Model.filter_objects(es_objects)
return db_objects | python | def get_dbcollection_with_es(self, **kwargs):
""" Get DB objects collection by first querying ES. """
es_objects = self.get_collection_es()
db_objects = self.Model.filter_objects(es_objects)
return db_objects | [
"def",
"get_dbcollection_with_es",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"es_objects",
"=",
"self",
".",
"get_collection_es",
"(",
")",
"db_objects",
"=",
"self",
".",
"Model",
".",
"filter_objects",
"(",
"es_objects",
")",
"return",
"db_objects"
] | Get DB objects collection by first querying ES. | [
"Get",
"DB",
"objects",
"collection",
"by",
"first",
"querying",
"ES",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L312-L316 |
ramses-tech/ramses | ramses/views.py | ESCollectionView.delete_many | def delete_many(self, **kwargs):
""" Delete multiple objects from collection.
First ES is queried, then the results are used to query the DB.
This is done to make sure deleted objects are those filtered
by ES in the 'index' method (so user deletes what he saw).
"""
db_ob... | python | def delete_many(self, **kwargs):
""" Delete multiple objects from collection.
First ES is queried, then the results are used to query the DB.
This is done to make sure deleted objects are those filtered
by ES in the 'index' method (so user deletes what he saw).
"""
db_ob... | [
"def",
"delete_many",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"db_objects",
"=",
"self",
".",
"get_dbcollection_with_es",
"(",
"*",
"*",
"kwargs",
")",
"return",
"self",
".",
"Model",
".",
"_delete_many",
"(",
"db_objects",
",",
"self",
".",
"req... | Delete multiple objects from collection.
First ES is queried, then the results are used to query the DB.
This is done to make sure deleted objects are those filtered
by ES in the 'index' method (so user deletes what he saw). | [
"Delete",
"multiple",
"objects",
"from",
"collection",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L318-L326 |
ramses-tech/ramses | ramses/views.py | ESCollectionView.update_many | def update_many(self, **kwargs):
""" Update multiple objects from collection.
First ES is queried, then the results are used to query DB.
This is done to make sure updated objects are those filtered
by ES in the 'index' method (so user updates what he saw).
"""
db_object... | python | def update_many(self, **kwargs):
""" Update multiple objects from collection.
First ES is queried, then the results are used to query DB.
This is done to make sure updated objects are those filtered
by ES in the 'index' method (so user updates what he saw).
"""
db_object... | [
"def",
"update_many",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"db_objects",
"=",
"self",
".",
"get_dbcollection_with_es",
"(",
"*",
"*",
"kwargs",
")",
"return",
"self",
".",
"Model",
".",
"_update_many",
"(",
"db_objects",
",",
"self",
".",
"_js... | Update multiple objects from collection.
First ES is queried, then the results are used to query DB.
This is done to make sure updated objects are those filtered
by ES in the 'index' method (so user updates what he saw). | [
"Update",
"multiple",
"objects",
"from",
"collection",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L328-L337 |
ramses-tech/ramses | ramses/views.py | ItemSubresourceBaseView._get_context_key | def _get_context_key(self, **kwargs):
""" Get value of `self._resource.parent.id_name` from :kwargs: """
return str(kwargs.get(self._resource.parent.id_name)) | python | def _get_context_key(self, **kwargs):
""" Get value of `self._resource.parent.id_name` from :kwargs: """
return str(kwargs.get(self._resource.parent.id_name)) | [
"def",
"_get_context_key",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"str",
"(",
"kwargs",
".",
"get",
"(",
"self",
".",
"_resource",
".",
"parent",
".",
"id_name",
")",
")"
] | Get value of `self._resource.parent.id_name` from :kwargs: | [
"Get",
"value",
"of",
"self",
".",
"_resource",
".",
"parent",
".",
"id_name",
"from",
":",
"kwargs",
":"
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L359-L361 |
ramses-tech/ramses | ramses/views.py | ItemSubresourceBaseView.get_item | def get_item(self, **kwargs):
""" Reload context on each access. """
self.reload_context(es_based=False, **kwargs)
return super(ItemSubresourceBaseView, self).get_item(**kwargs) | python | def get_item(self, **kwargs):
""" Reload context on each access. """
self.reload_context(es_based=False, **kwargs)
return super(ItemSubresourceBaseView, self).get_item(**kwargs) | [
"def",
"get_item",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"reload_context",
"(",
"es_based",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
"return",
"super",
"(",
"ItemSubresourceBaseView",
",",
"self",
")",
".",
"get_item",
"(",
"*... | Reload context on each access. | [
"Reload",
"context",
"on",
"each",
"access",
"."
] | train | https://github.com/ramses-tech/ramses/blob/ea2e1e896325b7256cdf5902309e05fd98e0c14c/ramses/views.py#L363-L366 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/__init__.py | setup | def setup(app):
"""Allow this module to be used as sphinx extension.
This attaches the Sphinx hooks.
:type app: sphinx.application.Sphinx
"""
import sphinxcontrib_django.docstrings
import sphinxcontrib_django.roles
# Setup both modules at once. They can also be separately imported to
#... | python | def setup(app):
"""Allow this module to be used as sphinx extension.
This attaches the Sphinx hooks.
:type app: sphinx.application.Sphinx
"""
import sphinxcontrib_django.docstrings
import sphinxcontrib_django.roles
# Setup both modules at once. They can also be separately imported to
#... | [
"def",
"setup",
"(",
"app",
")",
":",
"import",
"sphinxcontrib_django",
".",
"docstrings",
"import",
"sphinxcontrib_django",
".",
"roles",
"# Setup both modules at once. They can also be separately imported to",
"# use only fragments of this package.",
"sphinxcontrib_django",
".",
... | Allow this module to be used as sphinx extension.
This attaches the Sphinx hooks.
:type app: sphinx.application.Sphinx | [
"Allow",
"this",
"module",
"to",
"be",
"used",
"as",
"sphinx",
"extension",
".",
"This",
"attaches",
"the",
"Sphinx",
"hooks",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/__init__.py#L8-L20 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/patches.py | patch_django_for_autodoc | def patch_django_for_autodoc():
"""Fix the appearance of some classes in autodoc.
This avoids query evaluation.
"""
# Fix Django's manager appearance
ManagerDescriptor.__get__ = lambda self, *args, **kwargs: self.manager
# Stop Django from executing DB queries
models.QuerySet.__repr__ = la... | python | def patch_django_for_autodoc():
"""Fix the appearance of some classes in autodoc.
This avoids query evaluation.
"""
# Fix Django's manager appearance
ManagerDescriptor.__get__ = lambda self, *args, **kwargs: self.manager
# Stop Django from executing DB queries
models.QuerySet.__repr__ = la... | [
"def",
"patch_django_for_autodoc",
"(",
")",
":",
"# Fix Django's manager appearance",
"ManagerDescriptor",
".",
"__get__",
"=",
"lambda",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
":",
"self",
".",
"manager",
"# Stop Django from executing DB queries",
"model... | Fix the appearance of some classes in autodoc.
This avoids query evaluation. | [
"Fix",
"the",
"appearance",
"of",
"some",
"classes",
"in",
"autodoc",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/patches.py#L5-L14 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/docstrings.py | setup | def setup(app):
"""Allow this package to be used as Sphinx extension.
This is also called from the top-level ``__init__.py``.
:type app: sphinx.application.Sphinx
"""
from .patches import patch_django_for_autodoc
# When running, make sure Django doesn't execute querysets
patch_django_for_a... | python | def setup(app):
"""Allow this package to be used as Sphinx extension.
This is also called from the top-level ``__init__.py``.
:type app: sphinx.application.Sphinx
"""
from .patches import patch_django_for_autodoc
# When running, make sure Django doesn't execute querysets
patch_django_for_a... | [
"def",
"setup",
"(",
"app",
")",
":",
"from",
".",
"patches",
"import",
"patch_django_for_autodoc",
"# When running, make sure Django doesn't execute querysets",
"patch_django_for_autodoc",
"(",
")",
"# Generate docstrings for Django model fields",
"# Register the docstring processor... | Allow this package to be used as Sphinx extension.
This is also called from the top-level ``__init__.py``.
:type app: sphinx.application.Sphinx | [
"Allow",
"this",
"package",
"to",
"be",
"used",
"as",
"Sphinx",
"extension",
".",
"This",
"is",
"also",
"called",
"from",
"the",
"top",
"-",
"level",
"__init__",
".",
"py",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/docstrings.py#L43-L59 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/docstrings.py | autodoc_skip | def autodoc_skip(app, what, name, obj, skip, options):
"""Hook that tells autodoc to include or exclude certain fields.
Sadly, it doesn't give a reference to the parent object,
so only the ``name`` can be used for referencing.
:type app: sphinx.application.Sphinx
:param what: The parent type, ``cl... | python | def autodoc_skip(app, what, name, obj, skip, options):
"""Hook that tells autodoc to include or exclude certain fields.
Sadly, it doesn't give a reference to the parent object,
so only the ``name`` can be used for referencing.
:type app: sphinx.application.Sphinx
:param what: The parent type, ``cl... | [
"def",
"autodoc_skip",
"(",
"app",
",",
"what",
",",
"name",
",",
"obj",
",",
"skip",
",",
"options",
")",
":",
"if",
"name",
"in",
"config",
".",
"EXCLUDE_MEMBERS",
":",
"return",
"True",
"if",
"name",
"in",
"config",
".",
"INCLUDE_MEMBERS",
":",
"ret... | Hook that tells autodoc to include or exclude certain fields.
Sadly, it doesn't give a reference to the parent object,
so only the ``name`` can be used for referencing.
:type app: sphinx.application.Sphinx
:param what: The parent type, ``class`` or ``module``
:type what: str
:param name: The n... | [
"Hook",
"that",
"tells",
"autodoc",
"to",
"include",
"or",
"exclude",
"certain",
"fields",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/docstrings.py#L62-L85 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/docstrings.py | improve_model_docstring | def improve_model_docstring(app, what, name, obj, options, lines):
"""Hook that improves the autodoc docstrings for Django models.
:type app: sphinx.application.Sphinx
:param what: The parent type, ``class`` or ``module``
:type what: str
:param name: The dotted path to the child method/attribute.
... | python | def improve_model_docstring(app, what, name, obj, options, lines):
"""Hook that improves the autodoc docstrings for Django models.
:type app: sphinx.application.Sphinx
:param what: The parent type, ``class`` or ``module``
:type what: str
:param name: The dotted path to the child method/attribute.
... | [
"def",
"improve_model_docstring",
"(",
"app",
",",
"what",
",",
"name",
",",
"obj",
",",
"options",
",",
"lines",
")",
":",
"if",
"what",
"==",
"'class'",
":",
"_improve_class_docs",
"(",
"app",
",",
"obj",
",",
"lines",
")",
"elif",
"what",
"==",
"'at... | Hook that improves the autodoc docstrings for Django models.
:type app: sphinx.application.Sphinx
:param what: The parent type, ``class`` or ``module``
:type what: str
:param name: The dotted path to the child method/attribute.
:type name: str
:param obj: The Python object that i s being docume... | [
"Hook",
"that",
"improves",
"the",
"autodoc",
"docstrings",
"for",
"Django",
"models",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/docstrings.py#L88-L110 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/docstrings.py | _improve_class_docs | def _improve_class_docs(app, cls, lines):
"""Improve the documentation of a class."""
if issubclass(cls, models.Model):
_add_model_fields_as_params(app, cls, lines)
elif issubclass(cls, forms.Form):
_add_form_fields(cls, lines) | python | def _improve_class_docs(app, cls, lines):
"""Improve the documentation of a class."""
if issubclass(cls, models.Model):
_add_model_fields_as_params(app, cls, lines)
elif issubclass(cls, forms.Form):
_add_form_fields(cls, lines) | [
"def",
"_improve_class_docs",
"(",
"app",
",",
"cls",
",",
"lines",
")",
":",
"if",
"issubclass",
"(",
"cls",
",",
"models",
".",
"Model",
")",
":",
"_add_model_fields_as_params",
"(",
"app",
",",
"cls",
",",
"lines",
")",
"elif",
"issubclass",
"(",
"cls... | Improve the documentation of a class. | [
"Improve",
"the",
"documentation",
"of",
"a",
"class",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/docstrings.py#L113-L118 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/docstrings.py | _add_model_fields_as_params | def _add_model_fields_as_params(app, obj, lines):
"""Improve the documentation of a Django model subclass.
This adds all model fields as parameters to the ``__init__()`` method.
:type app: sphinx.application.Sphinx
:type lines: list
"""
for field in obj._meta.get_fields():
try:
... | python | def _add_model_fields_as_params(app, obj, lines):
"""Improve the documentation of a Django model subclass.
This adds all model fields as parameters to the ``__init__()`` method.
:type app: sphinx.application.Sphinx
:type lines: list
"""
for field in obj._meta.get_fields():
try:
... | [
"def",
"_add_model_fields_as_params",
"(",
"app",
",",
"obj",
",",
"lines",
")",
":",
"for",
"field",
"in",
"obj",
".",
"_meta",
".",
"get_fields",
"(",
")",
":",
"try",
":",
"help_text",
"=",
"strip_tags",
"(",
"force_text",
"(",
"field",
".",
"help_tex... | Improve the documentation of a Django model subclass.
This adds all model fields as parameters to the ``__init__()`` method.
:type app: sphinx.application.Sphinx
:type lines: list | [
"Improve",
"the",
"documentation",
"of",
"a",
"Django",
"model",
"subclass",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/docstrings.py#L121-L149 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/docstrings.py | _add_form_fields | def _add_form_fields(obj, lines):
"""Improve the documentation of a Django Form class.
This highlights the available fields in the form.
"""
lines.append("**Form fields:**")
lines.append("")
for name, field in obj.base_fields.items():
field_type = "{}.{}".format(field.__class__.__module... | python | def _add_form_fields(obj, lines):
"""Improve the documentation of a Django Form class.
This highlights the available fields in the form.
"""
lines.append("**Form fields:**")
lines.append("")
for name, field in obj.base_fields.items():
field_type = "{}.{}".format(field.__class__.__module... | [
"def",
"_add_form_fields",
"(",
"obj",
",",
"lines",
")",
":",
"lines",
".",
"append",
"(",
"\"**Form fields:**\"",
")",
"lines",
".",
"append",
"(",
"\"\"",
")",
"for",
"name",
",",
"field",
"in",
"obj",
".",
"base_fields",
".",
"items",
"(",
")",
":"... | Improve the documentation of a Django Form class.
This highlights the available fields in the form. | [
"Improve",
"the",
"documentation",
"of",
"a",
"Django",
"Form",
"class",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/docstrings.py#L152-L167 |
edoburu/sphinxcontrib-django | sphinxcontrib_django/docstrings.py | _improve_attribute_docs | def _improve_attribute_docs(obj, name, lines):
"""Improve the documentation of various attributes.
This improves the navigation between related objects.
:param obj: the instance of the object to document.
:param name: full dotted path to the object.
:param lines: expected documentation lines.
"... | python | def _improve_attribute_docs(obj, name, lines):
"""Improve the documentation of various attributes.
This improves the navigation between related objects.
:param obj: the instance of the object to document.
:param name: full dotted path to the object.
:param lines: expected documentation lines.
"... | [
"def",
"_improve_attribute_docs",
"(",
"obj",
",",
"name",
",",
"lines",
")",
":",
"if",
"obj",
"is",
"None",
":",
"# Happens with form attributes.",
"return",
"if",
"isinstance",
"(",
"obj",
",",
"DeferredAttribute",
")",
":",
"# This only points to a field name, n... | Improve the documentation of various attributes.
This improves the navigation between related objects.
:param obj: the instance of the object to document.
:param name: full dotted path to the object.
:param lines: expected documentation lines. | [
"Improve",
"the",
"documentation",
"of",
"various",
"attributes",
".",
"This",
"improves",
"the",
"navigation",
"between",
"related",
"objects",
"."
] | train | https://github.com/edoburu/sphinxcontrib-django/blob/5116ac7f1510a76b1ff58cf7f8d2fab7d8bbe2a9/sphinxcontrib_django/docstrings.py#L195-L268 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.