repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
rfosterslo/wagtailplus | wagtailplus/utils/edit_handlers.py | add_panel_to_edit_handler | def add_panel_to_edit_handler(model, panel_cls, heading, index=None):
"""
Adds specified panel class to model class.
:param model: the model class.
:param panel_cls: the panel class.
:param heading: the panel heading.
:param index: the index position to insert at.
"""
from wagtail.wagta... | python | def add_panel_to_edit_handler(model, panel_cls, heading, index=None):
"""
Adds specified panel class to model class.
:param model: the model class.
:param panel_cls: the panel class.
:param heading: the panel heading.
:param index: the index position to insert at.
"""
from wagtail.wagta... | [
"def",
"add_panel_to_edit_handler",
"(",
"model",
",",
"panel_cls",
",",
"heading",
",",
"index",
"=",
"None",
")",
":",
"from",
"wagtail",
".",
"wagtailadmin",
".",
"views",
".",
"pages",
"import",
"get_page_edit_handler",
"edit_handler",
"=",
"get_page_edit_hand... | Adds specified panel class to model class.
:param model: the model class.
:param panel_cls: the panel class.
:param heading: the panel heading.
:param index: the index position to insert at. | [
"Adds",
"specified",
"panel",
"class",
"to",
"model",
"class",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/edit_handlers.py#L7-L27 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | IndexView.get_context_data | def get_context_data(self, **kwargs):
"""
Returns context dictionary for view.
:rtype: dict.
"""
#noinspection PyUnresolvedReferences
query_str = self.request.GET.get('q', None)
queryset = kwargs.pop('object_list', self.object_list)
c... | python | def get_context_data(self, **kwargs):
"""
Returns context dictionary for view.
:rtype: dict.
"""
#noinspection PyUnresolvedReferences
query_str = self.request.GET.get('q', None)
queryset = kwargs.pop('object_list', self.object_list)
c... | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"#noinspection PyUnresolvedReferences",
"query_str",
"=",
"self",
".",
"request",
".",
"GET",
".",
"get",
"(",
"'q'",
",",
"None",
")",
"queryset",
"=",
"kwargs",
".",
"pop",
"(",
... | Returns context dictionary for view.
:rtype: dict. | [
"Returns",
"context",
"dictionary",
"for",
"view",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L51-L83 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | IndexView.get_ordering | def get_ordering(self):
"""
Returns ordering value for list.
:rtype: str.
"""
#noinspection PyUnresolvedReferences
ordering = self.request.GET.get('ordering', None)
if ordering not in ['title', '-created_at']:
ordering = '-created_at'
return... | python | def get_ordering(self):
"""
Returns ordering value for list.
:rtype: str.
"""
#noinspection PyUnresolvedReferences
ordering = self.request.GET.get('ordering', None)
if ordering not in ['title', '-created_at']:
ordering = '-created_at'
return... | [
"def",
"get_ordering",
"(",
"self",
")",
":",
"#noinspection PyUnresolvedReferences",
"ordering",
"=",
"self",
".",
"request",
".",
"GET",
".",
"get",
"(",
"'ordering'",
",",
"None",
")",
"if",
"ordering",
"not",
"in",
"[",
"'title'",
",",
"'-created_at'",
"... | Returns ordering value for list.
:rtype: str. | [
"Returns",
"ordering",
"value",
"for",
"list",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L85-L97 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | IndexView.get_queryset | def get_queryset(self):
"""
Returns queryset instance.
:rtype: django.db.models.query.QuerySet.
"""
queryset = super(IndexView, self).get_queryset()
search_form = self.get_search_form()
if search_form.is_valid():
query_str = search_form.cleaned_... | python | def get_queryset(self):
"""
Returns queryset instance.
:rtype: django.db.models.query.QuerySet.
"""
queryset = super(IndexView, self).get_queryset()
search_form = self.get_search_form()
if search_form.is_valid():
query_str = search_form.cleaned_... | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"queryset",
"=",
"super",
"(",
"IndexView",
",",
"self",
")",
".",
"get_queryset",
"(",
")",
"search_form",
"=",
"self",
".",
"get_search_form",
"(",
")",
"if",
"search_form",
".",
"is_valid",
"(",
")",
":",
... | Returns queryset instance.
:rtype: django.db.models.query.QuerySet. | [
"Returns",
"queryset",
"instance",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L99-L112 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | IndexView.get_search_form | def get_search_form(self):
"""
Returns search form instance.
:rtype: django.forms.ModelForm.
"""
#noinspection PyUnresolvedReferences
if 'q' in self.request.GET:
#noinspection PyUnresolvedReferences
return self.search_form_class(self.request.GET)
... | python | def get_search_form(self):
"""
Returns search form instance.
:rtype: django.forms.ModelForm.
"""
#noinspection PyUnresolvedReferences
if 'q' in self.request.GET:
#noinspection PyUnresolvedReferences
return self.search_form_class(self.request.GET)
... | [
"def",
"get_search_form",
"(",
"self",
")",
":",
"#noinspection PyUnresolvedReferences",
"if",
"'q'",
"in",
"self",
".",
"request",
".",
"GET",
":",
"#noinspection PyUnresolvedReferences",
"return",
"self",
".",
"search_form_class",
"(",
"self",
".",
"request",
".",... | Returns search form instance.
:rtype: django.forms.ModelForm. | [
"Returns",
"search",
"form",
"instance",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L114-L125 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | IndexView.get_template_names | def get_template_names(self):
"""
Returns a list of template names for the view.
:rtype: list.
"""
#noinspection PyUnresolvedReferences
if self.request.is_ajax():
template_name = '/results.html'
else:
template_name = '/index.html'
... | python | def get_template_names(self):
"""
Returns a list of template names for the view.
:rtype: list.
"""
#noinspection PyUnresolvedReferences
if self.request.is_ajax():
template_name = '/results.html'
else:
template_name = '/index.html'
... | [
"def",
"get_template_names",
"(",
"self",
")",
":",
"#noinspection PyUnresolvedReferences",
"if",
"self",
".",
"request",
".",
"is_ajax",
"(",
")",
":",
"template_name",
"=",
"'/results.html'",
"else",
":",
"template_name",
"=",
"'/index.html'",
"return",
"[",
"'{... | Returns a list of template names for the view.
:rtype: list. | [
"Returns",
"a",
"list",
"of",
"template",
"names",
"for",
"the",
"view",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L127-L139 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | IndexView.paginate_queryset | def paginate_queryset(self, queryset, page_size):
"""
Returns tuple containing paginator instance, page instance,
object list, and whether there are other pages.
:param queryset: the queryset instance to paginate.
:param page_size: the number of instances per page.
:rtyp... | python | def paginate_queryset(self, queryset, page_size):
"""
Returns tuple containing paginator instance, page instance,
object list, and whether there are other pages.
:param queryset: the queryset instance to paginate.
:param page_size: the number of instances per page.
:rtyp... | [
"def",
"paginate_queryset",
"(",
"self",
",",
"queryset",
",",
"page_size",
")",
":",
"paginator",
"=",
"self",
".",
"get_paginator",
"(",
"queryset",
",",
"page_size",
",",
"orphans",
"=",
"self",
".",
"get_paginate_orphans",
"(",
")",
",",
"allow_empty_first... | Returns tuple containing paginator instance, page instance,
object list, and whether there are other pages.
:param queryset: the queryset instance to paginate.
:param page_size: the number of instances per page.
:rtype: tuple. | [
"Returns",
"tuple",
"containing",
"paginator",
"instance",
"page",
"instance",
"object",
"list",
"and",
"whether",
"there",
"are",
"other",
"pages",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L141-L170 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | BaseEditView.form_invalid | def form_invalid(self, form):
"""
Processes an invalid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
meta = getattr(self.model, '_meta')
#noinspection PyUnresolvedReferences
messages.error(
self.request... | python | def form_invalid(self, form):
"""
Processes an invalid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
meta = getattr(self.model, '_meta')
#noinspection PyUnresolvedReferences
messages.error(
self.request... | [
"def",
"form_invalid",
"(",
"self",
",",
"form",
")",
":",
"meta",
"=",
"getattr",
"(",
"self",
".",
"model",
",",
"'_meta'",
")",
"#noinspection PyUnresolvedReferences",
"messages",
".",
"error",
"(",
"self",
".",
"request",
",",
"_",
"(",
"u'The {0} could ... | Processes an invalid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse. | [
"Processes",
"an",
"invalid",
"form",
"submittal",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L205-L222 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | BaseEditView.form_valid | def form_valid(self, form):
"""
Processes a valid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = form.save()
meta = getattr(self.object, '_meta')
# I... | python | def form_valid(self, form):
"""
Processes a valid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = form.save()
meta = getattr(self.object, '_meta')
# I... | [
"def",
"form_valid",
"(",
"self",
",",
"form",
")",
":",
"#noinspection PyAttributeOutsideInit",
"self",
".",
"object",
"=",
"form",
".",
"save",
"(",
")",
"meta",
"=",
"getattr",
"(",
"self",
".",
"object",
",",
"'_meta'",
")",
"# Index the object.",
"for",... | Processes a valid form submittal.
:param form: the form instance.
:rtype: django.http.HttpResponse. | [
"Processes",
"a",
"valid",
"form",
"submittal",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L224-L255 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | BaseEditView.get_success_url | def get_success_url(self):
"""
Returns redirect URL for valid form submittal.
:rtype: str.
"""
if self.success_url:
url = force_text(self.success_url)
else:
url = reverse('{0}:index'.format(self.url_namespace))
return url | python | def get_success_url(self):
"""
Returns redirect URL for valid form submittal.
:rtype: str.
"""
if self.success_url:
url = force_text(self.success_url)
else:
url = reverse('{0}:index'.format(self.url_namespace))
return url | [
"def",
"get_success_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"success_url",
":",
"url",
"=",
"force_text",
"(",
"self",
".",
"success_url",
")",
"else",
":",
"url",
"=",
"reverse",
"(",
"'{0}:index'",
".",
"format",
"(",
"self",
".",
"url_namespac... | Returns redirect URL for valid form submittal.
:rtype: str. | [
"Returns",
"redirect",
"URL",
"for",
"valid",
"form",
"submittal",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L257-L268 |
rfosterslo/wagtailplus | wagtailplus/utils/views/crud.py | DeleteView.delete | def delete(self, request, *args, **kwargs):
"""
Processes deletion of the specified instance.
:param request: the request instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = self.get_object()
success_url = se... | python | def delete(self, request, *args, **kwargs):
"""
Processes deletion of the specified instance.
:param request: the request instance.
:rtype: django.http.HttpResponse.
"""
#noinspection PyAttributeOutsideInit
self.object = self.get_object()
success_url = se... | [
"def",
"delete",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"#noinspection PyAttributeOutsideInit",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
... | Processes deletion of the specified instance.
:param request: the request instance.
:rtype: django.http.HttpResponse. | [
"Processes",
"deletion",
"of",
"the",
"specified",
"instance",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/utils/views/crud.py#L301-L323 |
mozilla/elasticutils | elasticutils/utils.py | chunked | def chunked(iterable, n):
"""Returns chunks of n length of iterable
If len(iterable) % n != 0, then the last chunk will have length
less than n.
Example:
>>> chunked([1, 2, 3, 4, 5], 2)
[(1, 2), (3, 4), (5,)]
"""
iterable = iter(iterable)
while 1:
t = tuple(islice(iterab... | python | def chunked(iterable, n):
"""Returns chunks of n length of iterable
If len(iterable) % n != 0, then the last chunk will have length
less than n.
Example:
>>> chunked([1, 2, 3, 4, 5], 2)
[(1, 2), (3, 4), (5,)]
"""
iterable = iter(iterable)
while 1:
t = tuple(islice(iterab... | [
"def",
"chunked",
"(",
"iterable",
",",
"n",
")",
":",
"iterable",
"=",
"iter",
"(",
"iterable",
")",
"while",
"1",
":",
"t",
"=",
"tuple",
"(",
"islice",
"(",
"iterable",
",",
"n",
")",
")",
"if",
"t",
":",
"yield",
"t",
"else",
":",
"return"
] | Returns chunks of n length of iterable
If len(iterable) % n != 0, then the last chunk will have length
less than n.
Example:
>>> chunked([1, 2, 3, 4, 5], 2)
[(1, 2), (3, 4), (5,)] | [
"Returns",
"chunks",
"of",
"n",
"length",
"of",
"iterable"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/utils.py#L33-L52 |
mozilla/elasticutils | elasticutils/utils.py | format_explanation | def format_explanation(explanation, indent=' ', indent_level=0):
"""Return explanation in an easier to read format
Easier to read for me, at least.
"""
if not explanation:
return ''
# Note: This is probably a crap implementation, but it's an
# interesting starting point for a better ... | python | def format_explanation(explanation, indent=' ', indent_level=0):
"""Return explanation in an easier to read format
Easier to read for me, at least.
"""
if not explanation:
return ''
# Note: This is probably a crap implementation, but it's an
# interesting starting point for a better ... | [
"def",
"format_explanation",
"(",
"explanation",
",",
"indent",
"=",
"' '",
",",
"indent_level",
"=",
"0",
")",
":",
"if",
"not",
"explanation",
":",
"return",
"''",
"# Note: This is probably a crap implementation, but it's an",
"# interesting starting point for a better f... | Return explanation in an easier to read format
Easier to read for me, at least. | [
"Return",
"explanation",
"in",
"an",
"easier",
"to",
"read",
"format"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/utils.py#L55-L76 |
mozilla/elasticutils | elasticutils/contrib/django/__init__.py | get_es | def get_es(**overrides):
"""Return a elasticsearch Elasticsearch object using settings
from ``settings.py``.
:arg overrides: Allows you to override defaults to create the
ElasticSearch object. You can override any of the arguments
isted in :py:func:`elasticutils.get_es`.
For example, i... | python | def get_es(**overrides):
"""Return a elasticsearch Elasticsearch object using settings
from ``settings.py``.
:arg overrides: Allows you to override defaults to create the
ElasticSearch object. You can override any of the arguments
isted in :py:func:`elasticutils.get_es`.
For example, i... | [
"def",
"get_es",
"(",
"*",
"*",
"overrides",
")",
":",
"defaults",
"=",
"{",
"'urls'",
":",
"settings",
".",
"ES_URLS",
",",
"'timeout'",
":",
"getattr",
"(",
"settings",
",",
"'ES_TIMEOUT'",
",",
"5",
")",
"}",
"defaults",
".",
"update",
"(",
"overrid... | Return a elasticsearch Elasticsearch object using settings
from ``settings.py``.
:arg overrides: Allows you to override defaults to create the
ElasticSearch object. You can override any of the arguments
isted in :py:func:`elasticutils.get_es`.
For example, if you wanted to create an Elasti... | [
"Return",
"a",
"elasticsearch",
"Elasticsearch",
"object",
"using",
"settings",
"from",
"settings",
".",
"py",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L26-L47 |
mozilla/elasticutils | elasticutils/contrib/django/__init__.py | es_required | def es_required(fun):
"""Wrap a callable and return None if ES_DISABLED is False.
This also adds an additional `es` argument to the callable
giving you an ElasticSearch instance to use.
"""
@wraps(fun)
def wrapper(*args, **kw):
if getattr(settings, 'ES_DISABLED', False):
lo... | python | def es_required(fun):
"""Wrap a callable and return None if ES_DISABLED is False.
This also adds an additional `es` argument to the callable
giving you an ElasticSearch instance to use.
"""
@wraps(fun)
def wrapper(*args, **kw):
if getattr(settings, 'ES_DISABLED', False):
lo... | [
"def",
"es_required",
"(",
"fun",
")",
":",
"@",
"wraps",
"(",
"fun",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"if",
"getattr",
"(",
"settings",
",",
"'ES_DISABLED'",
",",
"False",
")",
":",
"log",
".",
"debug",
"("... | Wrap a callable and return None if ES_DISABLED is False.
This also adds an additional `es` argument to the callable
giving you an ElasticSearch instance to use. | [
"Wrap",
"a",
"callable",
"and",
"return",
"None",
"if",
"ES_DISABLED",
"is",
"False",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L50-L64 |
mozilla/elasticutils | elasticutils/contrib/django/__init__.py | S.get_es | def get_es(self, default_builder=get_es):
"""Returns the elasticsearch Elasticsearch object to use.
This uses the django get_es builder by default which takes
into account settings in ``settings.py``.
"""
return super(S, self).get_es(default_builder=default_builder) | python | def get_es(self, default_builder=get_es):
"""Returns the elasticsearch Elasticsearch object to use.
This uses the django get_es builder by default which takes
into account settings in ``settings.py``.
"""
return super(S, self).get_es(default_builder=default_builder) | [
"def",
"get_es",
"(",
"self",
",",
"default_builder",
"=",
"get_es",
")",
":",
"return",
"super",
"(",
"S",
",",
"self",
")",
".",
"get_es",
"(",
"default_builder",
"=",
"default_builder",
")"
] | Returns the elasticsearch Elasticsearch object to use.
This uses the django get_es builder by default which takes
into account settings in ``settings.py``. | [
"Returns",
"the",
"elasticsearch",
"Elasticsearch",
"object",
"to",
"use",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L165-L172 |
mozilla/elasticutils | elasticutils/contrib/django/__init__.py | S.get_indexes | def get_indexes(self, default_indexes=None):
"""Returns the list of indexes to act on based on ES_INDEXES setting
"""
doctype = self.type.get_mapping_type_name()
indexes = (settings.ES_INDEXES.get(doctype) or
settings.ES_INDEXES['default'])
if isinstance(index... | python | def get_indexes(self, default_indexes=None):
"""Returns the list of indexes to act on based on ES_INDEXES setting
"""
doctype = self.type.get_mapping_type_name()
indexes = (settings.ES_INDEXES.get(doctype) or
settings.ES_INDEXES['default'])
if isinstance(index... | [
"def",
"get_indexes",
"(",
"self",
",",
"default_indexes",
"=",
"None",
")",
":",
"doctype",
"=",
"self",
".",
"type",
".",
"get_mapping_type_name",
"(",
")",
"indexes",
"=",
"(",
"settings",
".",
"ES_INDEXES",
".",
"get",
"(",
"doctype",
")",
"or",
"set... | Returns the list of indexes to act on based on ES_INDEXES setting | [
"Returns",
"the",
"list",
"of",
"indexes",
"to",
"act",
"on",
"based",
"on",
"ES_INDEXES",
"setting"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L174-L183 |
mozilla/elasticutils | elasticutils/contrib/django/__init__.py | S.get_doctypes | def get_doctypes(self, default_doctypes=None):
"""Returns the doctypes (or mapping type names) to use."""
doctypes = self.type.get_mapping_type_name()
if isinstance(doctypes, six.string_types):
doctypes = [doctypes]
return super(S, self).get_doctypes(default_doctypes=doctypes... | python | def get_doctypes(self, default_doctypes=None):
"""Returns the doctypes (or mapping type names) to use."""
doctypes = self.type.get_mapping_type_name()
if isinstance(doctypes, six.string_types):
doctypes = [doctypes]
return super(S, self).get_doctypes(default_doctypes=doctypes... | [
"def",
"get_doctypes",
"(",
"self",
",",
"default_doctypes",
"=",
"None",
")",
":",
"doctypes",
"=",
"self",
".",
"type",
".",
"get_mapping_type_name",
"(",
")",
"if",
"isinstance",
"(",
"doctypes",
",",
"six",
".",
"string_types",
")",
":",
"doctypes",
"=... | Returns the doctypes (or mapping type names) to use. | [
"Returns",
"the",
"doctypes",
"(",
"or",
"mapping",
"type",
"names",
")",
"to",
"use",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L185-L190 |
mozilla/elasticutils | elasticutils/contrib/django/__init__.py | MappingType.get_index | def get_index(cls):
"""Gets the index for this model.
The index for this model is specified in `settings.ES_INDEXES`
which is a dict of mapping type -> index name.
By default, this uses `.get_mapping_type()` to determine the
mapping and returns the value in `settings.ES_INDEXES... | python | def get_index(cls):
"""Gets the index for this model.
The index for this model is specified in `settings.ES_INDEXES`
which is a dict of mapping type -> index name.
By default, this uses `.get_mapping_type()` to determine the
mapping and returns the value in `settings.ES_INDEXES... | [
"def",
"get_index",
"(",
"cls",
")",
":",
"indexes",
"=",
"settings",
".",
"ES_INDEXES",
"index",
"=",
"indexes",
".",
"get",
"(",
"cls",
".",
"get_mapping_type_name",
"(",
")",
")",
"or",
"indexes",
"[",
"'default'",
"]",
"if",
"not",
"(",
"isinstance",... | Gets the index for this model.
The index for this model is specified in `settings.ES_INDEXES`
which is a dict of mapping type -> index name.
By default, this uses `.get_mapping_type()` to determine the
mapping and returns the value in `settings.ES_INDEXES` for that
or ``setting... | [
"Gets",
"the",
"index",
"for",
"this",
"model",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L225-L246 |
mozilla/elasticutils | elasticutils/contrib/django/__init__.py | Indexable.get_indexable | def get_indexable(cls):
"""Returns the queryset of ids of all things to be indexed.
Defaults to::
cls.get_model().objects.order_by('id').values_list(
'id', flat=True)
:returns: iterable of ids of objects to be indexed
"""
model = cls.get_model()
... | python | def get_indexable(cls):
"""Returns the queryset of ids of all things to be indexed.
Defaults to::
cls.get_model().objects.order_by('id').values_list(
'id', flat=True)
:returns: iterable of ids of objects to be indexed
"""
model = cls.get_model()
... | [
"def",
"get_indexable",
"(",
"cls",
")",
":",
"model",
"=",
"cls",
".",
"get_model",
"(",
")",
"return",
"model",
".",
"objects",
".",
"order_by",
"(",
"'id'",
")",
".",
"values_list",
"(",
"'id'",
",",
"flat",
"=",
"True",
")"
] | Returns the queryset of ids of all things to be indexed.
Defaults to::
cls.get_model().objects.order_by('id').values_list(
'id', flat=True)
:returns: iterable of ids of objects to be indexed | [
"Returns",
"the",
"queryset",
"of",
"ids",
"of",
"all",
"things",
"to",
"be",
"indexed",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/__init__.py#L298-L310 |
mozilla/elasticutils | elasticutils/__init__.py | get_es | def get_es(urls=None, timeout=DEFAULT_TIMEOUT, force_new=False, **settings):
"""Create an elasticsearch `Elasticsearch` object and return it.
This will aggressively re-use `Elasticsearch` objects with the
following rules:
1. if you pass the same argument values to `get_es()`, then it
will retur... | python | def get_es(urls=None, timeout=DEFAULT_TIMEOUT, force_new=False, **settings):
"""Create an elasticsearch `Elasticsearch` object and return it.
This will aggressively re-use `Elasticsearch` objects with the
following rules:
1. if you pass the same argument values to `get_es()`, then it
will retur... | [
"def",
"get_es",
"(",
"urls",
"=",
"None",
",",
"timeout",
"=",
"DEFAULT_TIMEOUT",
",",
"force_new",
"=",
"False",
",",
"*",
"*",
"settings",
")",
":",
"# Cheap way of de-None-ifying things",
"urls",
"=",
"urls",
"or",
"DEFAULT_URLS",
"# v0.7: Check for 'hosts' in... | Create an elasticsearch `Elasticsearch` object and return it.
This will aggressively re-use `Elasticsearch` objects with the
following rules:
1. if you pass the same argument values to `get_es()`, then it
will return the same `Elasticsearch` object
2. if you pass different argument values to `g... | [
"Create",
"an",
"elasticsearch",
"Elasticsearch",
"object",
"and",
"return",
"it",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L109-L167 |
mozilla/elasticutils | elasticutils/__init__.py | _facet_counts | def _facet_counts(items):
"""Returns facet counts as dict.
Given the `items()` on the raw dictionary from Elasticsearch this processes
it and returns the counts keyed on the facet name provided in the original
query.
"""
facets = {}
for name, data in items:
facets[name] = FacetResu... | python | def _facet_counts(items):
"""Returns facet counts as dict.
Given the `items()` on the raw dictionary from Elasticsearch this processes
it and returns the counts keyed on the facet name provided in the original
query.
"""
facets = {}
for name, data in items:
facets[name] = FacetResu... | [
"def",
"_facet_counts",
"(",
"items",
")",
":",
"facets",
"=",
"{",
"}",
"for",
"name",
",",
"data",
"in",
"items",
":",
"facets",
"[",
"name",
"]",
"=",
"FacetResult",
"(",
"name",
",",
"data",
")",
"return",
"facets"
] | Returns facet counts as dict.
Given the `items()` on the raw dictionary from Elasticsearch this processes
it and returns the counts keyed on the facet name provided in the original
query. | [
"Returns",
"facet",
"counts",
"as",
"dict",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L203-L214 |
mozilla/elasticutils | elasticutils/__init__.py | _boosted_value | def _boosted_value(name, action, key, value, boost):
"""Boost a value if we should in _process_queries"""
if boost is not None:
# Note: Most queries use 'value' for the key name except
# Match queries which use 'query'. So we have to do some
# switcheroo for that.
value_key = 'qu... | python | def _boosted_value(name, action, key, value, boost):
"""Boost a value if we should in _process_queries"""
if boost is not None:
# Note: Most queries use 'value' for the key name except
# Match queries which use 'query'. So we have to do some
# switcheroo for that.
value_key = 'qu... | [
"def",
"_boosted_value",
"(",
"name",
",",
"action",
",",
"key",
",",
"value",
",",
"boost",
")",
":",
"if",
"boost",
"is",
"not",
"None",
":",
"# Note: Most queries use 'value' for the key name except",
"# Match queries which use 'query'. So we have to do some",
"# switc... | Boost a value if we should in _process_queries | [
"Boost",
"a",
"value",
"if",
"we",
"should",
"in",
"_process_queries"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L397-L405 |
mozilla/elasticutils | elasticutils/__init__.py | decorate_with_metadata | def decorate_with_metadata(obj, result):
"""Return obj decorated with es_meta object"""
# Create es_meta object with Elasticsearch metadata about this
# search result
obj.es_meta = Metadata(
# Elasticsearch id
id=result.get('_id', 0),
# Source data
source=result.get('_sou... | python | def decorate_with_metadata(obj, result):
"""Return obj decorated with es_meta object"""
# Create es_meta object with Elasticsearch metadata about this
# search result
obj.es_meta = Metadata(
# Elasticsearch id
id=result.get('_id', 0),
# Source data
source=result.get('_sou... | [
"def",
"decorate_with_metadata",
"(",
"obj",
",",
"result",
")",
":",
"# Create es_meta object with Elasticsearch metadata about this",
"# search result",
"obj",
".",
"es_meta",
"=",
"Metadata",
"(",
"# Elasticsearch id",
"id",
"=",
"result",
".",
"get",
"(",
"'_id'",
... | Return obj decorated with es_meta object | [
"Return",
"obj",
"decorated",
"with",
"es_meta",
"object"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1918-L1938 |
mozilla/elasticutils | elasticutils/__init__.py | F._combine | def _combine(self, other, conn='and'):
"""
OR and AND will create a new F, with the filters from both F
objects combined with the connector `conn`.
"""
f = F()
self_filters = copy.deepcopy(self.filters)
other_filters = copy.deepcopy(other.filters)
if not... | python | def _combine(self, other, conn='and'):
"""
OR and AND will create a new F, with the filters from both F
objects combined with the connector `conn`.
"""
f = F()
self_filters = copy.deepcopy(self.filters)
other_filters = copy.deepcopy(other.filters)
if not... | [
"def",
"_combine",
"(",
"self",
",",
"other",
",",
"conn",
"=",
"'and'",
")",
":",
"f",
"=",
"F",
"(",
")",
"self_filters",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"filters",
")",
"other_filters",
"=",
"copy",
".",
"deepcopy",
"(",
"other",
... | OR and AND will create a new F, with the filters from both F
objects combined with the connector `conn`. | [
"OR",
"and",
"AND",
"will",
"create",
"a",
"new",
"F",
"with",
"the",
"filters",
"from",
"both",
"F",
"objects",
"combined",
"with",
"the",
"connector",
"conn",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L277-L300 |
mozilla/elasticutils | elasticutils/__init__.py | PythonMixin.to_python | def to_python(self, obj):
"""Converts strings in a data structure to Python types
It converts datetime-ish things to Python datetimes.
Override if you want something different.
:arg obj: Python datastructure
:returns: Python datastructure with strings converted to
... | python | def to_python(self, obj):
"""Converts strings in a data structure to Python types
It converts datetime-ish things to Python datetimes.
Override if you want something different.
:arg obj: Python datastructure
:returns: Python datastructure with strings converted to
... | [
"def",
"to_python",
"(",
"self",
",",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"string_types",
")",
":",
"if",
"len",
"(",
"obj",
")",
"==",
"26",
":",
"try",
":",
"return",
"datetime",
".",
"strptime",
"(",
"obj",
",",
"'%Y-%m-%dT%H:%M:... | Converts strings in a data structure to Python types
It converts datetime-ish things to Python datetimes.
Override if you want something different.
:arg obj: Python datastructure
:returns: Python datastructure with strings converted to
Python types
.. Note::
... | [
"Converts",
"strings",
"in",
"a",
"data",
"structure",
"to",
"Python",
"types"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L410-L451 |
mozilla/elasticutils | elasticutils/__init__.py | S.query | def query(self, *queries, **kw):
"""
Return a new S instance with query args combined with existing
set in a must boolean query.
:arg queries: instances of Q
:arg kw: queries in the form of ``field__action=value``
There are three special flags you can use:
* ``... | python | def query(self, *queries, **kw):
"""
Return a new S instance with query args combined with existing
set in a must boolean query.
:arg queries: instances of Q
:arg kw: queries in the form of ``field__action=value``
There are three special flags you can use:
* ``... | [
"def",
"query",
"(",
"self",
",",
"*",
"queries",
",",
"*",
"*",
"kw",
")",
":",
"q",
"=",
"Q",
"(",
")",
"for",
"query",
"in",
"queries",
":",
"q",
"+=",
"query",
"if",
"'or_'",
"in",
"kw",
":",
"# Backwards compatibile with pre-0.7 version.",
"or_que... | Return a new S instance with query args combined with existing
set in a must boolean query.
:arg queries: instances of Q
:arg kw: queries in the form of ``field__action=value``
There are three special flags you can use:
* ``must=True``: Specifies that the queries and kw querie... | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"query",
"args",
"combined",
"with",
"existing",
"set",
"in",
"a",
"must",
"boolean",
"query",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L694-L759 |
mozilla/elasticutils | elasticutils/__init__.py | S.filter | def filter(self, *filters, **kw):
"""
Return a new S instance with filter args combined with
existing set with AND.
:arg filters: this will be instances of F
:arg kw: this will be in the form of ``field__action=value``
Examples:
>>> s = S().filter(foo='bar')
... | python | def filter(self, *filters, **kw):
"""
Return a new S instance with filter args combined with
existing set with AND.
:arg filters: this will be instances of F
:arg kw: this will be in the form of ``field__action=value``
Examples:
>>> s = S().filter(foo='bar')
... | [
"def",
"filter",
"(",
"self",
",",
"*",
"filters",
",",
"*",
"*",
"kw",
")",
":",
"items",
"=",
"kw",
".",
"items",
"(",
")",
"if",
"six",
".",
"PY3",
":",
"items",
"=",
"list",
"(",
"items",
")",
"return",
"self",
".",
"_clone",
"(",
"next_ste... | Return a new S instance with filter args combined with
existing set with AND.
:arg filters: this will be instances of F
:arg kw: this will be in the form of ``field__action=value``
Examples:
>>> s = S().filter(foo='bar')
>>> s = S().filter(F(foo='bar'))
>>> s =... | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"filter",
"args",
"combined",
"with",
"existing",
"set",
"with",
"AND",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L782-L817 |
mozilla/elasticutils | elasticutils/__init__.py | S.boost | def boost(self, **kw):
"""
Return a new S instance with field boosts.
ElasticUtils allows you to specify query-time field boosts
with ``.boost()``. It takes a set of arguments where the keys
are either field names or field name + ``__`` + field action.
Examples::
... | python | def boost(self, **kw):
"""
Return a new S instance with field boosts.
ElasticUtils allows you to specify query-time field boosts
with ``.boost()``. It takes a set of arguments where the keys
are either field names or field name + ``__`` + field action.
Examples::
... | [
"def",
"boost",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"new",
"=",
"self",
".",
"_clone",
"(",
")",
"new",
".",
"field_boosts",
".",
"update",
"(",
"kw",
")",
"return",
"new"
] | Return a new S instance with field boosts.
ElasticUtils allows you to specify query-time field boosts
with ``.boost()``. It takes a set of arguments where the keys
are either field names or field name + ``__`` + field action.
Examples::
q = (S().query(title='taco trucks',
... | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"field",
"boosts",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L839-L897 |
mozilla/elasticutils | elasticutils/__init__.py | S.demote | def demote(self, amount_, *queries, **kw):
"""
Returns a new S instance with boosting query and demotion.
You can demote documents that match query criteria::
q = (S().query(title='trucks')
.demote(0.5, description__match='gross'))
q = (S().query(ti... | python | def demote(self, amount_, *queries, **kw):
"""
Returns a new S instance with boosting query and demotion.
You can demote documents that match query criteria::
q = (S().query(title='trucks')
.demote(0.5, description__match='gross'))
q = (S().query(ti... | [
"def",
"demote",
"(",
"self",
",",
"amount_",
",",
"*",
"queries",
",",
"*",
"*",
"kw",
")",
":",
"q",
"=",
"Q",
"(",
")",
"for",
"query",
"in",
"queries",
":",
"q",
"+=",
"query",
"q",
"+=",
"Q",
"(",
"*",
"*",
"kw",
")",
"return",
"self",
... | Returns a new S instance with boosting query and demotion.
You can demote documents that match query criteria::
q = (S().query(title='trucks')
.demote(0.5, description__match='gross'))
q = (S().query(title='trucks')
.demote(0.5, Q(description__m... | [
"Returns",
"a",
"new",
"S",
"instance",
"with",
"boosting",
"query",
"and",
"demotion",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L899-L928 |
mozilla/elasticutils | elasticutils/__init__.py | S.facet_raw | def facet_raw(self, **kw):
"""
Return a new S instance with raw facet args combined with
existing set.
"""
items = kw.items()
if six.PY3:
items = list(items)
return self._clone(next_step=('facet_raw', items)) | python | def facet_raw(self, **kw):
"""
Return a new S instance with raw facet args combined with
existing set.
"""
items = kw.items()
if six.PY3:
items = list(items)
return self._clone(next_step=('facet_raw', items)) | [
"def",
"facet_raw",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"items",
"=",
"kw",
".",
"items",
"(",
")",
"if",
"six",
".",
"PY3",
":",
"items",
"=",
"list",
"(",
"items",
")",
"return",
"self",
".",
"_clone",
"(",
"next_step",
"=",
"(",
"'fa... | Return a new S instance with raw facet args combined with
existing set. | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"raw",
"facet",
"args",
"combined",
"with",
"existing",
"set",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L944-L952 |
mozilla/elasticutils | elasticutils/__init__.py | S.suggest | def suggest(self, name, term, **kwargs):
"""Set suggestion options.
:arg name: The name to use for the suggestions.
:arg term: The term to suggest similar looking terms for.
Additional keyword options:
* ``field`` -- The field to base suggestions upon, defaults to _all
... | python | def suggest(self, name, term, **kwargs):
"""Set suggestion options.
:arg name: The name to use for the suggestions.
:arg term: The term to suggest similar looking terms for.
Additional keyword options:
* ``field`` -- The field to base suggestions upon, defaults to _all
... | [
"def",
"suggest",
"(",
"self",
",",
"name",
",",
"term",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_clone",
"(",
"next_step",
"=",
"(",
"'suggest'",
",",
"(",
"name",
",",
"term",
",",
"kwargs",
")",
")",
")"
] | Set suggestion options.
:arg name: The name to use for the suggestions.
:arg term: The term to suggest similar looking terms for.
Additional keyword options:
* ``field`` -- The field to base suggestions upon, defaults to _all
Results will have a ``_suggestions`` property cont... | [
"Set",
"suggestion",
"options",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1019-L1039 |
mozilla/elasticutils | elasticutils/__init__.py | S.extra | def extra(self, **kw):
"""
Return a new S instance with extra args combined with existing
set.
"""
new = self._clone()
actions = ['values_list', 'values_dict', 'order_by', 'query',
'filter', 'facet']
for key, vals in kw.items():
asse... | python | def extra(self, **kw):
"""
Return a new S instance with extra args combined with existing
set.
"""
new = self._clone()
actions = ['values_list', 'values_dict', 'order_by', 'query',
'filter', 'facet']
for key, vals in kw.items():
asse... | [
"def",
"extra",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"new",
"=",
"self",
".",
"_clone",
"(",
")",
"actions",
"=",
"[",
"'values_list'",
",",
"'values_dict'",
",",
"'order_by'",
",",
"'query'",
",",
"'filter'",
",",
"'facet'",
"]",
"for",
"key"... | Return a new S instance with extra args combined with existing
set. | [
"Return",
"a",
"new",
"S",
"instance",
"with",
"extra",
"args",
"combined",
"with",
"existing",
"set",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1041-L1055 |
mozilla/elasticutils | elasticutils/__init__.py | S.build_search | def build_search(self):
"""Builds the Elasticsearch search body represented by this S.
Loop over self.steps to build the search body that will be
sent to Elasticsearch. This returns a Python dict.
If you want the JSON that actually gets sent, then pass the return
value through ... | python | def build_search(self):
"""Builds the Elasticsearch search body represented by this S.
Loop over self.steps to build the search body that will be
sent to Elasticsearch. This returns a Python dict.
If you want the JSON that actually gets sent, then pass the return
value through ... | [
"def",
"build_search",
"(",
"self",
")",
":",
"filters",
"=",
"[",
"]",
"filters_raw",
"=",
"None",
"queries",
"=",
"[",
"]",
"query_raw",
"=",
"None",
"sort",
"=",
"[",
"]",
"dict_fields",
"=",
"set",
"(",
")",
"list_fields",
"=",
"set",
"(",
")",
... | Builds the Elasticsearch search body represented by this S.
Loop over self.steps to build the search body that will be
sent to Elasticsearch. This returns a Python dict.
If you want the JSON that actually gets sent, then pass the return
value through :py:func:`elasticutils.utils.to_jso... | [
"Builds",
"the",
"Elasticsearch",
"search",
"body",
"represented",
"by",
"this",
"S",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1067-L1227 |
mozilla/elasticutils | elasticutils/__init__.py | S._build_highlight | def _build_highlight(self, fields, options):
"""Return the portion of the query that controls highlighting."""
ret = {'fields': dict((f, {}) for f in fields),
'order': 'score'}
ret.update(options)
return ret | python | def _build_highlight(self, fields, options):
"""Return the portion of the query that controls highlighting."""
ret = {'fields': dict((f, {}) for f in fields),
'order': 'score'}
ret.update(options)
return ret | [
"def",
"_build_highlight",
"(",
"self",
",",
"fields",
",",
"options",
")",
":",
"ret",
"=",
"{",
"'fields'",
":",
"dict",
"(",
"(",
"f",
",",
"{",
"}",
")",
"for",
"f",
"in",
"fields",
")",
",",
"'order'",
":",
"'score'",
"}",
"ret",
".",
"updat... | Return the portion of the query that controls highlighting. | [
"Return",
"the",
"portion",
"of",
"the",
"query",
"that",
"controls",
"highlighting",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1229-L1234 |
mozilla/elasticutils | elasticutils/__init__.py | S._process_filters | def _process_filters(self, filters):
"""Takes a list of filters and returns ES JSON API
:arg filters: list of F, (key, val) tuples, or dicts
:returns: list of ES JSON API filters
"""
rv = []
for f in filters:
if isinstance(f, F):
if f.filter... | python | def _process_filters(self, filters):
"""Takes a list of filters and returns ES JSON API
:arg filters: list of F, (key, val) tuples, or dicts
:returns: list of ES JSON API filters
"""
rv = []
for f in filters:
if isinstance(f, F):
if f.filter... | [
"def",
"_process_filters",
"(",
"self",
",",
"filters",
")",
":",
"rv",
"=",
"[",
"]",
"for",
"f",
"in",
"filters",
":",
"if",
"isinstance",
"(",
"f",
",",
"F",
")",
":",
"if",
"f",
".",
"filters",
":",
"rv",
".",
"extend",
"(",
"self",
".",
"_... | Takes a list of filters and returns ES JSON API
:arg filters: list of F, (key, val) tuples, or dicts
:returns: list of ES JSON API filters | [
"Takes",
"a",
"list",
"of",
"filters",
"and",
"returns",
"ES",
"JSON",
"API"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1236-L1318 |
mozilla/elasticutils | elasticutils/__init__.py | S._process_query | def _process_query(self, query):
"""Takes a key/val pair and returns the Elasticsearch code for it"""
key, val = query
field_name, field_action = split_field_action(key)
# Boost by name__action overrides boost by name.
boost = self.field_boosts.get(key)
if boost is None:... | python | def _process_query(self, query):
"""Takes a key/val pair and returns the Elasticsearch code for it"""
key, val = query
field_name, field_action = split_field_action(key)
# Boost by name__action overrides boost by name.
boost = self.field_boosts.get(key)
if boost is None:... | [
"def",
"_process_query",
"(",
"self",
",",
"query",
")",
":",
"key",
",",
"val",
"=",
"query",
"field_name",
",",
"field_action",
"=",
"split_field_action",
"(",
"key",
")",
"# Boost by name__action overrides boost by name.",
"boost",
"=",
"self",
".",
"field_boos... | Takes a key/val pair and returns the Elasticsearch code for it | [
"Takes",
"a",
"key",
"/",
"val",
"pair",
"and",
"returns",
"the",
"Elasticsearch",
"code",
"for",
"it"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1320-L1371 |
mozilla/elasticutils | elasticutils/__init__.py | S._process_queries | def _process_queries(self, queries):
"""Takes a list of queries and returns query clause value
:arg queries: list of Q instances
:returns: dict which is the query clause value
"""
# First, let's mush everything into a single Q. Then we can
# parse that into bits.
... | python | def _process_queries(self, queries):
"""Takes a list of queries and returns query clause value
:arg queries: list of Q instances
:returns: dict which is the query clause value
"""
# First, let's mush everything into a single Q. Then we can
# parse that into bits.
... | [
"def",
"_process_queries",
"(",
"self",
",",
"queries",
")",
":",
"# First, let's mush everything into a single Q. Then we can",
"# parse that into bits.",
"new_q",
"=",
"Q",
"(",
")",
"for",
"query",
"in",
"queries",
":",
"new_q",
"+=",
"query",
"# Now we have a single... | Takes a list of queries and returns query clause value
:arg queries: list of Q instances
:returns: dict which is the query clause value | [
"Takes",
"a",
"list",
"of",
"queries",
"and",
"returns",
"query",
"clause",
"value"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1373-L1411 |
mozilla/elasticutils | elasticutils/__init__.py | S._do_search | def _do_search(self):
"""
Perform the search, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
ResultsClass = self.get_results_class()
results = self.to_python(r... | python | def _do_search(self):
"""
Perform the search, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
ResultsClass = self.get_results_class()
results = self.to_python(r... | [
"def",
"_do_search",
"(",
"self",
")",
":",
"if",
"self",
".",
"_results_cache",
"is",
"None",
":",
"response",
"=",
"self",
".",
"raw",
"(",
")",
"ResultsClass",
"=",
"self",
".",
"get_results_class",
"(",
")",
"results",
"=",
"self",
".",
"to_python",
... | Perform the search, then convert that raw format into a
SearchResults instance and return it. | [
"Perform",
"the",
"search",
"then",
"convert",
"that",
"raw",
"format",
"into",
"a",
"SearchResults",
"instance",
"and",
"return",
"it",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1426-L1437 |
mozilla/elasticutils | elasticutils/__init__.py | S.get_es | def get_es(self, default_builder=get_es):
"""Returns the Elasticsearch object to use.
:arg default_builder: The function that takes a bunch of
arguments and generates a elasticsearch Elasticsearch
object.
.. Note::
If you desire special behavior regarding bu... | python | def get_es(self, default_builder=get_es):
"""Returns the Elasticsearch object to use.
:arg default_builder: The function that takes a bunch of
arguments and generates a elasticsearch Elasticsearch
object.
.. Note::
If you desire special behavior regarding bu... | [
"def",
"get_es",
"(",
"self",
",",
"default_builder",
"=",
"get_es",
")",
":",
"# .es() calls are incremental, so we go through them all and",
"# update bits that are specified.",
"args",
"=",
"{",
"}",
"for",
"action",
",",
"value",
"in",
"self",
".",
"steps",
":",
... | Returns the Elasticsearch object to use.
:arg default_builder: The function that takes a bunch of
arguments and generates a elasticsearch Elasticsearch
object.
.. Note::
If you desire special behavior regarding building the
Elasticsearch object for this S... | [
"Returns",
"the",
"Elasticsearch",
"object",
"to",
"use",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1439-L1462 |
mozilla/elasticutils | elasticutils/__init__.py | S.get_indexes | def get_indexes(self, default_indexes=DEFAULT_INDEXES):
"""Returns the list of indexes to act on."""
for action, value in reversed(self.steps):
if action == 'indexes':
return list(value)
if self.type is not None:
indexes = self.type.get_index()
... | python | def get_indexes(self, default_indexes=DEFAULT_INDEXES):
"""Returns the list of indexes to act on."""
for action, value in reversed(self.steps):
if action == 'indexes':
return list(value)
if self.type is not None:
indexes = self.type.get_index()
... | [
"def",
"get_indexes",
"(",
"self",
",",
"default_indexes",
"=",
"DEFAULT_INDEXES",
")",
":",
"for",
"action",
",",
"value",
"in",
"reversed",
"(",
"self",
".",
"steps",
")",
":",
"if",
"action",
"==",
"'indexes'",
":",
"return",
"list",
"(",
"value",
")"... | Returns the list of indexes to act on. | [
"Returns",
"the",
"list",
"of",
"indexes",
"to",
"act",
"on",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1464-L1476 |
mozilla/elasticutils | elasticutils/__init__.py | S.get_doctypes | def get_doctypes(self, default_doctypes=DEFAULT_DOCTYPES):
"""Returns the list of doctypes to use."""
for action, value in reversed(self.steps):
if action == 'doctypes':
return list(value)
if self.type is not None:
return [self.type.get_mapping_type_name(... | python | def get_doctypes(self, default_doctypes=DEFAULT_DOCTYPES):
"""Returns the list of doctypes to use."""
for action, value in reversed(self.steps):
if action == 'doctypes':
return list(value)
if self.type is not None:
return [self.type.get_mapping_type_name(... | [
"def",
"get_doctypes",
"(",
"self",
",",
"default_doctypes",
"=",
"DEFAULT_DOCTYPES",
")",
":",
"for",
"action",
",",
"value",
"in",
"reversed",
"(",
"self",
".",
"steps",
")",
":",
"if",
"action",
"==",
"'doctypes'",
":",
"return",
"list",
"(",
"value",
... | Returns the list of doctypes to use. | [
"Returns",
"the",
"list",
"of",
"doctypes",
"to",
"use",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1478-L1487 |
mozilla/elasticutils | elasticutils/__init__.py | S.raw | def raw(self):
"""
Build query and passes to Elasticsearch, then returns the raw
format returned.
"""
qs = self.build_search()
es = self.get_es()
index = self.get_indexes()
doc_type = self.get_doctypes()
if doc_type and not index:
rai... | python | def raw(self):
"""
Build query and passes to Elasticsearch, then returns the raw
format returned.
"""
qs = self.build_search()
es = self.get_es()
index = self.get_indexes()
doc_type = self.get_doctypes()
if doc_type and not index:
rai... | [
"def",
"raw",
"(",
"self",
")",
":",
"qs",
"=",
"self",
".",
"build_search",
"(",
")",
"es",
"=",
"self",
".",
"get_es",
"(",
")",
"index",
"=",
"self",
".",
"get_indexes",
"(",
")",
"doc_type",
"=",
"self",
".",
"get_doctypes",
"(",
")",
"if",
"... | Build query and passes to Elasticsearch, then returns the raw
format returned. | [
"Build",
"query",
"and",
"passes",
"to",
"Elasticsearch",
"then",
"returns",
"the",
"raw",
"format",
"returned",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1489-L1514 |
mozilla/elasticutils | elasticutils/__init__.py | MLT.get_es | def get_es(self):
"""Returns an `Elasticsearch`.
* If there's an s, then it returns that `Elasticsearch`.
* If the es was provided in the constructor, then it returns
that `Elasticsearch`.
* Otherwise, it creates a new `Elasticsearch` and returns
that.
Overr... | python | def get_es(self):
"""Returns an `Elasticsearch`.
* If there's an s, then it returns that `Elasticsearch`.
* If the es was provided in the constructor, then it returns
that `Elasticsearch`.
* Otherwise, it creates a new `Elasticsearch` and returns
that.
Overr... | [
"def",
"get_es",
"(",
"self",
")",
":",
"if",
"self",
".",
"s",
":",
"return",
"self",
".",
"s",
".",
"get_es",
"(",
")",
"return",
"self",
".",
"es",
"or",
"get_es",
"(",
")"
] | Returns an `Elasticsearch`.
* If there's an s, then it returns that `Elasticsearch`.
* If the es was provided in the constructor, then it returns
that `Elasticsearch`.
* Otherwise, it creates a new `Elasticsearch` and returns
that.
Override this if that behavior isn... | [
"Returns",
"an",
"Elasticsearch",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1721-L1736 |
mozilla/elasticutils | elasticutils/__init__.py | MLT.raw | def raw(self):
"""
Build query and passes to `Elasticsearch`, then returns the raw
format returned.
"""
es = self.get_es()
params = dict(self.query_params)
mlt_fields = self.mlt_fields or params.pop('mlt_fields', [])
body = self.s.build_search() if self.... | python | def raw(self):
"""
Build query and passes to `Elasticsearch`, then returns the raw
format returned.
"""
es = self.get_es()
params = dict(self.query_params)
mlt_fields = self.mlt_fields or params.pop('mlt_fields', [])
body = self.s.build_search() if self.... | [
"def",
"raw",
"(",
"self",
")",
":",
"es",
"=",
"self",
".",
"get_es",
"(",
")",
"params",
"=",
"dict",
"(",
"self",
".",
"query_params",
")",
"mlt_fields",
"=",
"self",
".",
"mlt_fields",
"or",
"params",
".",
"pop",
"(",
"'mlt_fields'",
",",
"[",
... | Build query and passes to `Elasticsearch`, then returns the raw
format returned. | [
"Build",
"query",
"and",
"passes",
"to",
"Elasticsearch",
"then",
"returns",
"the",
"raw",
"format",
"returned",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1738-L1756 |
mozilla/elasticutils | elasticutils/__init__.py | MLT._do_search | def _do_search(self):
"""
Perform the mlt call, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
results = self.to_python(response.get('hits', {}).get('hits', []))
... | python | def _do_search(self):
"""
Perform the mlt call, then convert that raw format into a
SearchResults instance and return it.
"""
if self._results_cache is None:
response = self.raw()
results = self.to_python(response.get('hits', {}).get('hits', []))
... | [
"def",
"_do_search",
"(",
"self",
")",
":",
"if",
"self",
".",
"_results_cache",
"is",
"None",
":",
"response",
"=",
"self",
".",
"raw",
"(",
")",
"results",
"=",
"self",
".",
"to_python",
"(",
"response",
".",
"get",
"(",
"'hits'",
",",
"{",
"}",
... | Perform the mlt call, then convert that raw format into a
SearchResults instance and return it. | [
"Perform",
"the",
"mlt",
"call",
"then",
"convert",
"that",
"raw",
"format",
"into",
"a",
"SearchResults",
"instance",
"and",
"return",
"it",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L1758-L1768 |
mozilla/elasticutils | elasticutils/__init__.py | Indexable.index | def index(cls, document, id_=None, overwrite_existing=True, es=None,
index=None):
"""Adds or updates a document to the index
:arg document: Python dict of key/value pairs representing
the document
.. Note::
This must be serializable into JSON.
... | python | def index(cls, document, id_=None, overwrite_existing=True, es=None,
index=None):
"""Adds or updates a document to the index
:arg document: Python dict of key/value pairs representing
the document
.. Note::
This must be serializable into JSON.
... | [
"def",
"index",
"(",
"cls",
",",
"document",
",",
"id_",
"=",
"None",
",",
"overwrite_existing",
"=",
"True",
",",
"es",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"if",
"es",
"is",
"None",
":",
"es",
"=",
"cls",
".",
"get_es",
"(",
")",
... | Adds or updates a document to the index
:arg document: Python dict of key/value pairs representing
the document
.. Note::
This must be serializable into JSON.
:arg id_: the id of the document
.. Note::
If you don't provide an ``id_`... | [
"Adds",
"or",
"updates",
"a",
"document",
"to",
"the",
"index"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L2182-L2227 |
mozilla/elasticutils | elasticutils/__init__.py | Indexable.bulk_index | def bulk_index(cls, documents, id_field='id', es=None, index=None):
"""Adds or updates a batch of documents.
:arg documents: List of Python dicts representing individual
documents to be added to the index
.. Note::
This must be serializable into JSON.
:... | python | def bulk_index(cls, documents, id_field='id', es=None, index=None):
"""Adds or updates a batch of documents.
:arg documents: List of Python dicts representing individual
documents to be added to the index
.. Note::
This must be serializable into JSON.
:... | [
"def",
"bulk_index",
"(",
"cls",
",",
"documents",
",",
"id_field",
"=",
"'id'",
",",
"es",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"if",
"es",
"is",
"None",
":",
"es",
"=",
"cls",
".",
"get_es",
"(",
")",
"if",
"index",
"is",
"None",
... | Adds or updates a batch of documents.
:arg documents: List of Python dicts representing individual
documents to be added to the index
.. Note::
This must be serializable into JSON.
:arg id_field: The name of the field to use as the document
id. This... | [
"Adds",
"or",
"updates",
"a",
"batch",
"of",
"documents",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L2230-L2270 |
mozilla/elasticutils | elasticutils/__init__.py | Indexable.unindex | def unindex(cls, id_, es=None, index=None):
"""Removes a particular item from the search index.
:arg id_: The Elasticsearch id for the document to remove from
the index.
:arg es: The `Elasticsearch` to use. If you don't specify an
`Elasticsearch`, it'll use `cls.get_es(... | python | def unindex(cls, id_, es=None, index=None):
"""Removes a particular item from the search index.
:arg id_: The Elasticsearch id for the document to remove from
the index.
:arg es: The `Elasticsearch` to use. If you don't specify an
`Elasticsearch`, it'll use `cls.get_es(... | [
"def",
"unindex",
"(",
"cls",
",",
"id_",
",",
"es",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"if",
"es",
"is",
"None",
":",
"es",
"=",
"cls",
".",
"get_es",
"(",
")",
"if",
"index",
"is",
"None",
":",
"index",
"=",
"cls",
".",
"get_... | Removes a particular item from the search index.
:arg id_: The Elasticsearch id for the document to remove from
the index.
:arg es: The `Elasticsearch` to use. If you don't specify an
`Elasticsearch`, it'll use `cls.get_es()`.
:arg index: The name of the index to use. ... | [
"Removes",
"a",
"particular",
"item",
"from",
"the",
"search",
"index",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L2273-L2292 |
mozilla/elasticutils | elasticutils/__init__.py | Indexable.refresh_index | def refresh_index(cls, es=None, index=None):
"""Refreshes the index.
Elasticsearch will update the index periodically
automatically. If you need to see the documents you just
indexed in your search results right now, you should call
`refresh_index` as soon as you're done indexin... | python | def refresh_index(cls, es=None, index=None):
"""Refreshes the index.
Elasticsearch will update the index periodically
automatically. If you need to see the documents you just
indexed in your search results right now, you should call
`refresh_index` as soon as you're done indexin... | [
"def",
"refresh_index",
"(",
"cls",
",",
"es",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"if",
"es",
"is",
"None",
":",
"es",
"=",
"cls",
".",
"get_es",
"(",
")",
"if",
"index",
"is",
"None",
":",
"index",
"=",
"cls",
".",
"get_index",
... | Refreshes the index.
Elasticsearch will update the index periodically
automatically. If you need to see the documents you just
indexed in your search results right now, you should call
`refresh_index` as soon as you're done indexing. This is
particularly helpful for unit tests.
... | [
"Refreshes",
"the",
"index",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/__init__.py#L2295-L2317 |
mozilla/elasticutils | elasticutils/monkeypatch.py | monkeypatch_es | def monkeypatch_es():
"""Monkey patch for elasticsearch-py 1.0+ to make it work with ES 0.90
1. tweaks elasticsearch.client.bulk to normalize return status codes
.. Note::
We can nix this whe we drop support for ES 0.90.
"""
if _monkeypatched_es:
return
def normalize_bulk_ret... | python | def monkeypatch_es():
"""Monkey patch for elasticsearch-py 1.0+ to make it work with ES 0.90
1. tweaks elasticsearch.client.bulk to normalize return status codes
.. Note::
We can nix this whe we drop support for ES 0.90.
"""
if _monkeypatched_es:
return
def normalize_bulk_ret... | [
"def",
"monkeypatch_es",
"(",
")",
":",
"if",
"_monkeypatched_es",
":",
"return",
"def",
"normalize_bulk_return",
"(",
"fun",
")",
":",
"\"\"\"Set's \"ok\" based on \"status\" if \"status\" exists\"\"\"",
"@",
"wraps",
"(",
"fun",
")",
"def",
"_fixed_bulk",
"(",
"self... | Monkey patch for elasticsearch-py 1.0+ to make it work with ES 0.90
1. tweaks elasticsearch.client.bulk to normalize return status codes
.. Note::
We can nix this whe we drop support for ES 0.90. | [
"Monkey",
"patch",
"for",
"elasticsearch",
"-",
"py",
"1",
".",
"0",
"+",
"to",
"make",
"it",
"work",
"with",
"ES",
"0",
".",
"90"
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/monkeypatch.py#L9-L40 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/views.py | EntriesView.get_context_data | def get_context_data(self, **kwargs):
"""
Returns view context dictionary.
:rtype: dict.
"""
kwargs.update({
'entries': Entry.objects.get_for_tag(
self.kwargs.get('slug', 0)
)
})
return super(EntriesView, self).get_context... | python | def get_context_data(self, **kwargs):
"""
Returns view context dictionary.
:rtype: dict.
"""
kwargs.update({
'entries': Entry.objects.get_for_tag(
self.kwargs.get('slug', 0)
)
})
return super(EntriesView, self).get_context... | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"'entries'",
":",
"Entry",
".",
"objects",
".",
"get_for_tag",
"(",
"self",
".",
"kwargs",
".",
"get",
"(",
"'slug'",
",",
"0",
")",
")",
... | Returns view context dictionary.
:rtype: dict. | [
"Returns",
"view",
"context",
"dictionary",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/views.py#L28-L40 |
jaraco/keyrings.alt | keyrings/alt/file_base.py | Keyring.get_password | def get_password(self, service, username):
"""
Read the password from the file.
"""
assoc = self._generate_assoc(service, username)
service = escape_for_ini(service)
username = escape_for_ini(username)
# load the passwords from the file
config = configpar... | python | def get_password(self, service, username):
"""
Read the password from the file.
"""
assoc = self._generate_assoc(service, username)
service = escape_for_ini(service)
username = escape_for_ini(username)
# load the passwords from the file
config = configpar... | [
"def",
"get_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"assoc",
"=",
"self",
".",
"_generate_assoc",
"(",
"service",
",",
"username",
")",
"service",
"=",
"escape_for_ini",
"(",
"service",
")",
"username",
"=",
"escape_for_ini",
"(",
... | Read the password from the file. | [
"Read",
"the",
"password",
"from",
"the",
"file",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file_base.py#L96-L123 |
jaraco/keyrings.alt | keyrings/alt/file_base.py | Keyring.set_password | def set_password(self, service, username, password):
"""Write the password in the file.
"""
if not username:
# https://github.com/jaraco/keyrings.alt/issues/21
raise ValueError("Username cannot be blank.")
if not isinstance(password, string_types):
rai... | python | def set_password(self, service, username, password):
"""Write the password in the file.
"""
if not username:
# https://github.com/jaraco/keyrings.alt/issues/21
raise ValueError("Username cannot be blank.")
if not isinstance(password, string_types):
rai... | [
"def",
"set_password",
"(",
"self",
",",
"service",
",",
"username",
",",
"password",
")",
":",
"if",
"not",
"username",
":",
"# https://github.com/jaraco/keyrings.alt/issues/21",
"raise",
"ValueError",
"(",
"\"Username cannot be blank.\"",
")",
"if",
"not",
"isinstan... | Write the password in the file. | [
"Write",
"the",
"password",
"in",
"the",
"file",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file_base.py#L125-L139 |
jaraco/keyrings.alt | keyrings/alt/file_base.py | Keyring._ensure_file_path | def _ensure_file_path(self):
"""
Ensure the storage path exists.
If it doesn't, create it with "go-rwx" permissions.
"""
storage_root = os.path.dirname(self.file_path)
needs_storage_root = storage_root and not os.path.isdir(storage_root)
if needs_storage_root: # ... | python | def _ensure_file_path(self):
"""
Ensure the storage path exists.
If it doesn't, create it with "go-rwx" permissions.
"""
storage_root = os.path.dirname(self.file_path)
needs_storage_root = storage_root and not os.path.isdir(storage_root)
if needs_storage_root: # ... | [
"def",
"_ensure_file_path",
"(",
"self",
")",
":",
"storage_root",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"self",
".",
"file_path",
")",
"needs_storage_root",
"=",
"storage_root",
"and",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"storage_root",
")... | Ensure the storage path exists.
If it doesn't, create it with "go-rwx" permissions. | [
"Ensure",
"the",
"storage",
"path",
"exists",
".",
"If",
"it",
"doesn",
"t",
"create",
"it",
"with",
"go",
"-",
"rwx",
"permissions",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file_base.py#L167-L181 |
jaraco/keyrings.alt | keyrings/alt/file_base.py | Keyring.delete_password | def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
service = escape_for_ini(service)
username = escape_for_ini(username)
config = configparser.RawConfigParser()
if os.path.exists(self.file_path):
config.re... | python | def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
service = escape_for_ini(service)
username = escape_for_ini(username)
config = configparser.RawConfigParser()
if os.path.exists(self.file_path):
config.re... | [
"def",
"delete_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"service",
"=",
"escape_for_ini",
"(",
"service",
")",
"username",
"=",
"escape_for_ini",
"(",
"username",
")",
"config",
"=",
"configparser",
".",
"RawConfigParser",
"(",
")",
... | Delete the password for the username of the service. | [
"Delete",
"the",
"password",
"for",
"the",
"username",
"of",
"the",
"service",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file_base.py#L183-L198 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/apps.py | WagtailRelationsAppConfig.applicable_models | def applicable_models(self):
"""
Returns a list of model classes that subclass Page
and include a "tags" field.
:rtype: list.
"""
Page = apps.get_model('wagtailcore', 'Page')
applicable = []
for model in apps.get_models():
... | python | def applicable_models(self):
"""
Returns a list of model classes that subclass Page
and include a "tags" field.
:rtype: list.
"""
Page = apps.get_model('wagtailcore', 'Page')
applicable = []
for model in apps.get_models():
... | [
"def",
"applicable_models",
"(",
"self",
")",
":",
"Page",
"=",
"apps",
".",
"get_model",
"(",
"'wagtailcore'",
",",
"'Page'",
")",
"applicable",
"=",
"[",
"]",
"for",
"model",
"in",
"apps",
".",
"get_models",
"(",
")",
":",
"meta",
"=",
"getattr",
"("... | Returns a list of model classes that subclass Page
and include a "tags" field.
:rtype: list. | [
"Returns",
"a",
"list",
"of",
"model",
"classes",
"that",
"subclass",
"Page",
"and",
"include",
"a",
"tags",
"field",
".",
":",
"rtype",
":",
"list",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/apps.py#L17-L34 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/apps.py | WagtailRelationsAppConfig.add_relationship_panels | def add_relationship_panels(self):
"""
Add edit handler that includes "related" panels to applicable
model classes that don't explicitly define their own edit handler.
"""
from wagtailplus.utils.edit_handlers import add_panel_to_edit_handler
from wagtailplus.wagtail... | python | def add_relationship_panels(self):
"""
Add edit handler that includes "related" panels to applicable
model classes that don't explicitly define their own edit handler.
"""
from wagtailplus.utils.edit_handlers import add_panel_to_edit_handler
from wagtailplus.wagtail... | [
"def",
"add_relationship_panels",
"(",
"self",
")",
":",
"from",
"wagtailplus",
".",
"utils",
".",
"edit_handlers",
"import",
"add_panel_to_edit_handler",
"from",
"wagtailplus",
".",
"wagtailrelations",
".",
"edit_handlers",
"import",
"RelatedPanel",
"for",
"model",
"... | Add edit handler that includes "related" panels to applicable
model classes that don't explicitly define their own edit handler. | [
"Add",
"edit",
"handler",
"that",
"includes",
"related",
"panels",
"to",
"applicable",
"model",
"classes",
"that",
"don",
"t",
"explicitly",
"define",
"their",
"own",
"edit",
"handler",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/apps.py#L36-L45 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/apps.py | WagtailRelationsAppConfig.add_relationship_methods | def add_relationship_methods(self):
"""
Adds relationship methods to applicable model classes.
"""
Entry = apps.get_model('wagtailrelations', 'Entry')
@cached_property
def related(instance):
return instance.get_related()
@cached_property
... | python | def add_relationship_methods(self):
"""
Adds relationship methods to applicable model classes.
"""
Entry = apps.get_model('wagtailrelations', 'Entry')
@cached_property
def related(instance):
return instance.get_related()
@cached_property
... | [
"def",
"add_relationship_methods",
"(",
"self",
")",
":",
"Entry",
"=",
"apps",
".",
"get_model",
"(",
"'wagtailrelations'",
",",
"'Entry'",
")",
"@",
"cached_property",
"def",
"related",
"(",
"instance",
")",
":",
"return",
"instance",
".",
"get_related",
"("... | Adds relationship methods to applicable model classes. | [
"Adds",
"relationship",
"methods",
"to",
"applicable",
"model",
"classes",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/apps.py#L47-L104 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/apps.py | WagtailRelationsAppConfig.ready | def ready(self):
"""
Finalizes application configuration.
"""
import wagtailplus.wagtailrelations.signals.handlers
self.add_relationship_panels()
self.add_relationship_methods()
super(WagtailRelationsAppConfig, self).ready() | python | def ready(self):
"""
Finalizes application configuration.
"""
import wagtailplus.wagtailrelations.signals.handlers
self.add_relationship_panels()
self.add_relationship_methods()
super(WagtailRelationsAppConfig, self).ready() | [
"def",
"ready",
"(",
"self",
")",
":",
"import",
"wagtailplus",
".",
"wagtailrelations",
".",
"signals",
".",
"handlers",
"self",
".",
"add_relationship_panels",
"(",
")",
"self",
".",
"add_relationship_methods",
"(",
")",
"super",
"(",
"WagtailRelationsAppConfig"... | Finalizes application configuration. | [
"Finalizes",
"application",
"configuration",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/apps.py#L106-L114 |
rfosterslo/wagtailplus | wagtailplus/wagtailrollbacks/apps.py | WagtailRollbacksAppConfig.applicable_models | def applicable_models(self):
"""
Returns a list of model classes that subclass Page.
:rtype: list.
"""
Page = apps.get_model('wagtailcore', 'Page')
applicable = []
for model in apps.get_models():
if issubclass(model, Page):
... | python | def applicable_models(self):
"""
Returns a list of model classes that subclass Page.
:rtype: list.
"""
Page = apps.get_model('wagtailcore', 'Page')
applicable = []
for model in apps.get_models():
if issubclass(model, Page):
... | [
"def",
"applicable_models",
"(",
"self",
")",
":",
"Page",
"=",
"apps",
".",
"get_model",
"(",
"'wagtailcore'",
",",
"'Page'",
")",
"applicable",
"=",
"[",
"]",
"for",
"model",
"in",
"apps",
".",
"get_models",
"(",
")",
":",
"if",
"issubclass",
"(",
"m... | Returns a list of model classes that subclass Page.
:rtype: list. | [
"Returns",
"a",
"list",
"of",
"model",
"classes",
"that",
"subclass",
"Page",
".",
":",
"rtype",
":",
"list",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrollbacks/apps.py#L20-L33 |
rfosterslo/wagtailplus | wagtailplus/wagtailrollbacks/apps.py | WagtailRollbacksAppConfig.add_rollback_panels | def add_rollback_panels(self):
"""
Adds rollback panel to applicable model class's edit handlers.
"""
from wagtailplus.utils.edit_handlers import add_panel_to_edit_handler
from wagtailplus.wagtailrollbacks.edit_handlers import HistoryPanel
for model in self.applic... | python | def add_rollback_panels(self):
"""
Adds rollback panel to applicable model class's edit handlers.
"""
from wagtailplus.utils.edit_handlers import add_panel_to_edit_handler
from wagtailplus.wagtailrollbacks.edit_handlers import HistoryPanel
for model in self.applic... | [
"def",
"add_rollback_panels",
"(",
"self",
")",
":",
"from",
"wagtailplus",
".",
"utils",
".",
"edit_handlers",
"import",
"add_panel_to_edit_handler",
"from",
"wagtailplus",
".",
"wagtailrollbacks",
".",
"edit_handlers",
"import",
"HistoryPanel",
"for",
"model",
"in",... | Adds rollback panel to applicable model class's edit handlers. | [
"Adds",
"rollback",
"panel",
"to",
"applicable",
"model",
"class",
"s",
"edit",
"handlers",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrollbacks/apps.py#L35-L43 |
rfosterslo/wagtailplus | wagtailplus/wagtailrollbacks/apps.py | WagtailRollbacksAppConfig.add_rollback_methods | def add_rollback_methods():
"""
Adds rollback methods to applicable model classes.
"""
# Modified Page.save_revision method.
def page_rollback(instance, revision_id, user=None, submitted_for_moderation=False, approved_go_live_at=None, changed=True):
old_revision... | python | def add_rollback_methods():
"""
Adds rollback methods to applicable model classes.
"""
# Modified Page.save_revision method.
def page_rollback(instance, revision_id, user=None, submitted_for_moderation=False, approved_go_live_at=None, changed=True):
old_revision... | [
"def",
"add_rollback_methods",
"(",
")",
":",
"# Modified Page.save_revision method.\r",
"def",
"page_rollback",
"(",
"instance",
",",
"revision_id",
",",
"user",
"=",
"None",
",",
"submitted_for_moderation",
"=",
"False",
",",
"approved_go_live_at",
"=",
"None",
",",... | Adds rollback methods to applicable model classes. | [
"Adds",
"rollback",
"methods",
"to",
"applicable",
"model",
"classes",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrollbacks/apps.py#L46-L90 |
rfosterslo/wagtailplus | wagtailplus/wagtailrollbacks/apps.py | WagtailRollbacksAppConfig.ready | def ready(self):
"""
Finalizes application configuration.
"""
self.add_rollback_panels()
self.add_rollback_methods()
super(WagtailRollbacksAppConfig, self).ready() | python | def ready(self):
"""
Finalizes application configuration.
"""
self.add_rollback_panels()
self.add_rollback_methods()
super(WagtailRollbacksAppConfig, self).ready() | [
"def",
"ready",
"(",
"self",
")",
":",
"self",
".",
"add_rollback_panels",
"(",
")",
"self",
".",
"add_rollback_methods",
"(",
")",
"super",
"(",
"WagtailRollbacksAppConfig",
",",
"self",
")",
".",
"ready",
"(",
")"
] | Finalizes application configuration. | [
"Finalizes",
"application",
"configuration",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrollbacks/apps.py#L92-L98 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/templatetags/wagtailrelations_tags.py | get_related | def get_related(page):
"""
Returns list of related Entry instances for specified page.
:param page: the page instance.
:rtype: list.
"""
related = []
entry = Entry.get_for_model(page)
if entry:
related = entry.related
return related | python | def get_related(page):
"""
Returns list of related Entry instances for specified page.
:param page: the page instance.
:rtype: list.
"""
related = []
entry = Entry.get_for_model(page)
if entry:
related = entry.related
return related | [
"def",
"get_related",
"(",
"page",
")",
":",
"related",
"=",
"[",
"]",
"entry",
"=",
"Entry",
".",
"get_for_model",
"(",
"page",
")",
"if",
"entry",
":",
"related",
"=",
"entry",
".",
"related",
"return",
"related"
] | Returns list of related Entry instances for specified page.
:param page: the page instance.
:rtype: list. | [
"Returns",
"list",
"of",
"related",
"Entry",
"instances",
"for",
"specified",
"page",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/templatetags/wagtailrelations_tags.py#L17-L30 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/templatetags/wagtailrelations_tags.py | get_related_entry_admin_url | def get_related_entry_admin_url(entry):
"""
Returns admin URL for specified entry instance.
:param entry: the entry instance.
:return: str.
"""
namespaces = {
Document: 'wagtaildocs:edit',
Link: 'wagtaillinks:edit',
Page: 'wagtailadmin_pages:edit',
}
... | python | def get_related_entry_admin_url(entry):
"""
Returns admin URL for specified entry instance.
:param entry: the entry instance.
:return: str.
"""
namespaces = {
Document: 'wagtaildocs:edit',
Link: 'wagtaillinks:edit',
Page: 'wagtailadmin_pages:edit',
}
... | [
"def",
"get_related_entry_admin_url",
"(",
"entry",
")",
":",
"namespaces",
"=",
"{",
"Document",
":",
"'wagtaildocs:edit'",
",",
"Link",
":",
"'wagtaillinks:edit'",
",",
"Page",
":",
"'wagtailadmin_pages:edit'",
",",
"}",
"for",
"cls",
",",
"url",
"in",
"namesp... | Returns admin URL for specified entry instance.
:param entry: the entry instance.
:return: str. | [
"Returns",
"admin",
"URL",
"for",
"specified",
"entry",
"instance",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/templatetags/wagtailrelations_tags.py#L33-L50 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/templatetags/wagtailrelations_tags.py | get_related_with_scores | def get_related_with_scores(page):
"""
Returns list of related tuples (Entry instance, score) for
specified page.
:param page: the page instance.
:rtype: list.
"""
related = []
entry = Entry.get_for_model(page)
if entry:
related = entry.related_with_scores
return rel... | python | def get_related_with_scores(page):
"""
Returns list of related tuples (Entry instance, score) for
specified page.
:param page: the page instance.
:rtype: list.
"""
related = []
entry = Entry.get_for_model(page)
if entry:
related = entry.related_with_scores
return rel... | [
"def",
"get_related_with_scores",
"(",
"page",
")",
":",
"related",
"=",
"[",
"]",
"entry",
"=",
"Entry",
".",
"get_for_model",
"(",
"page",
")",
"if",
"entry",
":",
"related",
"=",
"entry",
".",
"related_with_scores",
"return",
"related"
] | Returns list of related tuples (Entry instance, score) for
specified page.
:param page: the page instance.
:rtype: list. | [
"Returns",
"list",
"of",
"related",
"tuples",
"(",
"Entry",
"instance",
"score",
")",
"for",
"specified",
"page",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/templatetags/wagtailrelations_tags.py#L53-L67 |
jaraco/keyrings.alt | keyrings/alt/multi.py | MultipartKeyringWrapper.get_password | def get_password(self, service, username):
"""Get password of the username for the service
"""
init_part = self._keyring.get_password(service, username)
if init_part:
parts = [init_part]
i = 1
while True:
next_part = self._keyring.get_p... | python | def get_password(self, service, username):
"""Get password of the username for the service
"""
init_part = self._keyring.get_password(service, username)
if init_part:
parts = [init_part]
i = 1
while True:
next_part = self._keyring.get_p... | [
"def",
"get_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"init_part",
"=",
"self",
".",
"_keyring",
".",
"get_password",
"(",
"service",
",",
"username",
")",
"if",
"init_part",
":",
"parts",
"=",
"[",
"init_part",
"]",
"i",
"=",
... | Get password of the username for the service | [
"Get",
"password",
"of",
"the",
"username",
"for",
"the",
"service"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/multi.py#L24-L41 |
jaraco/keyrings.alt | keyrings/alt/multi.py | MultipartKeyringWrapper.set_password | def set_password(self, service, username, password):
"""Set password for the username of the service
"""
segments = range(0, len(password), self._max_password_size)
password_parts = [
password[i:i + self._max_password_size] for i in segments]
for i, password_part in e... | python | def set_password(self, service, username, password):
"""Set password for the username of the service
"""
segments = range(0, len(password), self._max_password_size)
password_parts = [
password[i:i + self._max_password_size] for i in segments]
for i, password_part in e... | [
"def",
"set_password",
"(",
"self",
",",
"service",
",",
"username",
",",
"password",
")",
":",
"segments",
"=",
"range",
"(",
"0",
",",
"len",
"(",
"password",
")",
",",
"self",
".",
"_max_password_size",
")",
"password_parts",
"=",
"[",
"password",
"["... | Set password for the username of the service | [
"Set",
"password",
"for",
"the",
"username",
"of",
"the",
"service"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/multi.py#L43-L53 |
rfosterslo/wagtailplus | wagtailplus/wagtaillinks/rich_text.py | LinkHandler.expand_db_attributes | def expand_db_attributes(attrs, for_editor):
"""
Given a dictionary of attributes, find the corresponding link instance and
return its HTML representation.
:param attrs: dictionary of link attributes.
:param for_editor: whether or not HTML is for editor.
:rtype: str.
... | python | def expand_db_attributes(attrs, for_editor):
"""
Given a dictionary of attributes, find the corresponding link instance and
return its HTML representation.
:param attrs: dictionary of link attributes.
:param for_editor: whether or not HTML is for editor.
:rtype: str.
... | [
"def",
"expand_db_attributes",
"(",
"attrs",
",",
"for_editor",
")",
":",
"try",
":",
"editor_attrs",
"=",
"''",
"link",
"=",
"Link",
".",
"objects",
".",
"get",
"(",
"id",
"=",
"attrs",
"[",
"'id'",
"]",
")",
"if",
"for_editor",
":",
"editor_attrs",
"... | Given a dictionary of attributes, find the corresponding link instance and
return its HTML representation.
:param attrs: dictionary of link attributes.
:param for_editor: whether or not HTML is for editor.
:rtype: str. | [
"Given",
"a",
"dictionary",
"of",
"attributes",
"find",
"the",
"corresponding",
"link",
"instance",
"and",
"return",
"its",
"HTML",
"representation",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtaillinks/rich_text.py#L28-L52 |
jaraco/keyrings.alt | keyrings/alt/keyczar.py | BaseCrypter.crypter | def crypter(self):
"""The actual keyczar crypter"""
if not hasattr(self, '_crypter'):
# initialise the Keyczar keysets
if not self.keyset_location:
raise ValueError('No encrypted keyset location!')
reader = keyczar.readers.CreateReader(self.keyset_loca... | python | def crypter(self):
"""The actual keyczar crypter"""
if not hasattr(self, '_crypter'):
# initialise the Keyczar keysets
if not self.keyset_location:
raise ValueError('No encrypted keyset location!')
reader = keyczar.readers.CreateReader(self.keyset_loca... | [
"def",
"crypter",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_crypter'",
")",
":",
"# initialise the Keyczar keysets",
"if",
"not",
"self",
".",
"keyset_location",
":",
"raise",
"ValueError",
"(",
"'No encrypted keyset location!'",
")",
"... | The actual keyczar crypter | [
"The",
"actual",
"keyczar",
"crypter"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/keyczar.py#L39-L52 |
mozilla/elasticutils | elasticutils/contrib/django/tasks.py | index_objects | def index_objects(mapping_type, ids, chunk_size=100, es=None, index=None):
"""Index documents of a specified mapping type.
This allows for asynchronous indexing.
If a mapping_type extends Indexable, you can add a ``post_save``
hook for the model that it's based on like this::
@receiver(dbsign... | python | def index_objects(mapping_type, ids, chunk_size=100, es=None, index=None):
"""Index documents of a specified mapping type.
This allows for asynchronous indexing.
If a mapping_type extends Indexable, you can add a ``post_save``
hook for the model that it's based on like this::
@receiver(dbsign... | [
"def",
"index_objects",
"(",
"mapping_type",
",",
"ids",
",",
"chunk_size",
"=",
"100",
",",
"es",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"if",
"settings",
".",
"ES_DISABLED",
":",
"return",
"log",
".",
"debug",
"(",
"'Indexing objects {0}-{1}. ... | Index documents of a specified mapping type.
This allows for asynchronous indexing.
If a mapping_type extends Indexable, you can add a ``post_save``
hook for the model that it's based on like this::
@receiver(dbsignals.post_save, sender=MyModel)
def update_in_index(sender, instance, **kw)... | [
"Index",
"documents",
"of",
"a",
"specified",
"mapping",
"type",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/tasks.py#L13-L65 |
mozilla/elasticutils | elasticutils/contrib/django/tasks.py | unindex_objects | def unindex_objects(mapping_type, ids, es=None, index=None):
"""Remove documents of a specified mapping_type from the index.
This allows for asynchronous deleting.
If a mapping_type extends Indexable, you can add a ``pre_delete``
hook for the model that it's based on like this::
@receiver(dbs... | python | def unindex_objects(mapping_type, ids, es=None, index=None):
"""Remove documents of a specified mapping_type from the index.
This allows for asynchronous deleting.
If a mapping_type extends Indexable, you can add a ``pre_delete``
hook for the model that it's based on like this::
@receiver(dbs... | [
"def",
"unindex_objects",
"(",
"mapping_type",
",",
"ids",
",",
"es",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"if",
"settings",
".",
"ES_DISABLED",
":",
"return",
"for",
"id_",
"in",
"ids",
":",
"mapping_type",
".",
"unindex",
"(",
"id_",
","... | Remove documents of a specified mapping_type from the index.
This allows for asynchronous deleting.
If a mapping_type extends Indexable, you can add a ``pre_delete``
hook for the model that it's based on like this::
@receiver(dbsignals.pre_delete, sender=MyModel)
def remove_from_index(sen... | [
"Remove",
"documents",
"of",
"a",
"specified",
"mapping_type",
"from",
"the",
"index",
"."
] | train | https://github.com/mozilla/elasticutils/blob/b880cc5d51fb1079b0581255ec664c1ec934656e/elasticutils/contrib/django/tasks.py#L69-L93 |
rfosterslo/wagtailplus | wagtailplus/wagtaillinks/views/chooser.py | LinkChooser.get_json | def get_json(self, link):
"""
Returns specified link instance as JSON.
:param link: the link instance.
:rtype: JSON.
"""
return json.dumps({
'id': link.id,
'title': link.title,
'url': link.get_absolute_url(),
... | python | def get_json(self, link):
"""
Returns specified link instance as JSON.
:param link: the link instance.
:rtype: JSON.
"""
return json.dumps({
'id': link.id,
'title': link.title,
'url': link.get_absolute_url(),
... | [
"def",
"get_json",
"(",
"self",
",",
"link",
")",
":",
"return",
"json",
".",
"dumps",
"(",
"{",
"'id'",
":",
"link",
".",
"id",
",",
"'title'",
":",
"link",
".",
"title",
",",
"'url'",
":",
"link",
".",
"get_absolute_url",
"(",
")",
",",
"'edit_li... | Returns specified link instance as JSON.
:param link: the link instance.
:rtype: JSON. | [
"Returns",
"specified",
"link",
"instance",
"as",
"JSON",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtaillinks/views/chooser.py#L14-L29 |
jaraco/keyrings.alt | keyrings/alt/file.py | Encrypted._create_cipher | def _create_cipher(self, password, salt, IV):
"""
Create the cipher object to encrypt or decrypt a payload.
"""
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Cipher import AES
pw = PBKDF2(password, salt, dkLen=self.block_size)
return AES.new(pw[:self.block_si... | python | def _create_cipher(self, password, salt, IV):
"""
Create the cipher object to encrypt or decrypt a payload.
"""
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Cipher import AES
pw = PBKDF2(password, salt, dkLen=self.block_size)
return AES.new(pw[:self.block_si... | [
"def",
"_create_cipher",
"(",
"self",
",",
"password",
",",
"salt",
",",
"IV",
")",
":",
"from",
"Crypto",
".",
"Protocol",
".",
"KDF",
"import",
"PBKDF2",
"from",
"Crypto",
".",
"Cipher",
"import",
"AES",
"pw",
"=",
"PBKDF2",
"(",
"password",
",",
"sa... | Create the cipher object to encrypt or decrypt a payload. | [
"Create",
"the",
"cipher",
"object",
"to",
"encrypt",
"or",
"decrypt",
"a",
"payload",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file.py#L47-L54 |
jaraco/keyrings.alt | keyrings/alt/file.py | EncryptedKeyring._init_file | def _init_file(self):
"""
Initialize a new password file and set the reference password.
"""
self.keyring_key = self._get_new_password()
# set a reference password, used to check that the password provided
# matches for subsequent checks.
self.set_password('keyri... | python | def _init_file(self):
"""
Initialize a new password file and set the reference password.
"""
self.keyring_key = self._get_new_password()
# set a reference password, used to check that the password provided
# matches for subsequent checks.
self.set_password('keyri... | [
"def",
"_init_file",
"(",
"self",
")",
":",
"self",
".",
"keyring_key",
"=",
"self",
".",
"_get_new_password",
"(",
")",
"# set a reference password, used to check that the password provided",
"# matches for subsequent checks.",
"self",
".",
"set_password",
"(",
"'keyring-... | Initialize a new password file and set the reference password. | [
"Initialize",
"a",
"new",
"password",
"file",
"and",
"set",
"the",
"reference",
"password",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file.py#L101-L116 |
jaraco/keyrings.alt | keyrings/alt/file.py | EncryptedKeyring._check_file | def _check_file(self):
"""
Check if the file exists and has the expected password reference.
"""
if not os.path.exists(self.file_path):
return False
self._migrate()
config = configparser.RawConfigParser()
config.read(self.file_path)
try:
... | python | def _check_file(self):
"""
Check if the file exists and has the expected password reference.
"""
if not os.path.exists(self.file_path):
return False
self._migrate()
config = configparser.RawConfigParser()
config.read(self.file_path)
try:
... | [
"def",
"_check_file",
"(",
"self",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"file_path",
")",
":",
"return",
"False",
"self",
".",
"_migrate",
"(",
")",
"config",
"=",
"configparser",
".",
"RawConfigParser",
"(",
")",
... | Check if the file exists and has the expected password reference. | [
"Check",
"if",
"the",
"file",
"exists",
"and",
"has",
"the",
"expected",
"password",
"reference",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file.py#L118-L139 |
jaraco/keyrings.alt | keyrings/alt/file.py | EncryptedKeyring._check_version | def _check_version(self, config):
"""
check for a valid version
an existing scheme implies an existing version as well
return True, if version is valid, and False otherwise
"""
try:
self.file_version = config.get(
escape_for_ini('keyring-setti... | python | def _check_version(self, config):
"""
check for a valid version
an existing scheme implies an existing version as well
return True, if version is valid, and False otherwise
"""
try:
self.file_version = config.get(
escape_for_ini('keyring-setti... | [
"def",
"_check_version",
"(",
"self",
",",
"config",
")",
":",
"try",
":",
"self",
".",
"file_version",
"=",
"config",
".",
"get",
"(",
"escape_for_ini",
"(",
"'keyring-setting'",
")",
",",
"escape_for_ini",
"(",
"'version'",
")",
",",
")",
"except",
"(",
... | check for a valid version
an existing scheme implies an existing version as well
return True, if version is valid, and False otherwise | [
"check",
"for",
"a",
"valid",
"version",
"an",
"existing",
"scheme",
"implies",
"an",
"existing",
"version",
"as",
"well"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file.py#L164-L178 |
jaraco/keyrings.alt | keyrings/alt/file.py | EncryptedKeyring._unlock | def _unlock(self):
"""
Unlock this keyring by getting the password for the keyring from the
user.
"""
self.keyring_key = getpass.getpass(
'Please enter password for encrypted keyring: ')
try:
ref_pw = self.get_password('keyring-setting', 'password ... | python | def _unlock(self):
"""
Unlock this keyring by getting the password for the keyring from the
user.
"""
self.keyring_key = getpass.getpass(
'Please enter password for encrypted keyring: ')
try:
ref_pw = self.get_password('keyring-setting', 'password ... | [
"def",
"_unlock",
"(",
"self",
")",
":",
"self",
".",
"keyring_key",
"=",
"getpass",
".",
"getpass",
"(",
"'Please enter password for encrypted keyring: '",
")",
"try",
":",
"ref_pw",
"=",
"self",
".",
"get_password",
"(",
"'keyring-setting'",
",",
"'password refe... | Unlock this keyring by getting the password for the keyring from the
user. | [
"Unlock",
"this",
"keyring",
"by",
"getting",
"the",
"password",
"for",
"the",
"keyring",
"from",
"the",
"user",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/file.py#L180-L192 |
jaraco/keyrings.alt | keyrings/alt/escape.py | _escape_char | def _escape_char(c):
"Single char escape. Return the char, escaped if not already legal"
if isinstance(c, int):
c = _unichr(c)
return c if c in LEGAL_CHARS else ESCAPE_FMT % ord(c) | python | def _escape_char(c):
"Single char escape. Return the char, escaped if not already legal"
if isinstance(c, int):
c = _unichr(c)
return c if c in LEGAL_CHARS else ESCAPE_FMT % ord(c) | [
"def",
"_escape_char",
"(",
"c",
")",
":",
"if",
"isinstance",
"(",
"c",
",",
"int",
")",
":",
"c",
"=",
"_unichr",
"(",
"c",
")",
"return",
"c",
"if",
"c",
"in",
"LEGAL_CHARS",
"else",
"ESCAPE_FMT",
"%",
"ord",
"(",
"c",
")"
] | Single char escape. Return the char, escaped if not already legal | [
"Single",
"char",
"escape",
".",
"Return",
"the",
"char",
"escaped",
"if",
"not",
"already",
"legal"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/escape.py#L25-L29 |
jaraco/keyrings.alt | keyrings/alt/escape.py | unescape | def unescape(value):
"""
Inverse of escape.
"""
pattern = ESCAPE_FMT.replace('%02X', '(?P<code>[0-9A-Fa-f]{2})')
# the pattern must be bytes to operate on bytes
pattern_bytes = pattern.encode('ascii')
re_esc = re.compile(pattern_bytes)
return re_esc.sub(_unescape_code, value.encode('asci... | python | def unescape(value):
"""
Inverse of escape.
"""
pattern = ESCAPE_FMT.replace('%02X', '(?P<code>[0-9A-Fa-f]{2})')
# the pattern must be bytes to operate on bytes
pattern_bytes = pattern.encode('ascii')
re_esc = re.compile(pattern_bytes)
return re_esc.sub(_unescape_code, value.encode('asci... | [
"def",
"unescape",
"(",
"value",
")",
":",
"pattern",
"=",
"ESCAPE_FMT",
".",
"replace",
"(",
"'%02X'",
",",
"'(?P<code>[0-9A-Fa-f]{2})'",
")",
"# the pattern must be bytes to operate on bytes",
"pattern_bytes",
"=",
"pattern",
".",
"encode",
"(",
"'ascii'",
")",
"r... | Inverse of escape. | [
"Inverse",
"of",
"escape",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/escape.py#L45-L53 |
jaraco/keyrings.alt | keyrings/alt/Gnome.py | Keyring._find_passwords | def _find_passwords(self, service, username, deleting=False):
"""Get password of the username for the service
"""
passwords = []
service = self._safe_string(service)
username = self._safe_string(username)
for attrs_tuple in (('username', 'service'), ('user', 'domain')):
... | python | def _find_passwords(self, service, username, deleting=False):
"""Get password of the username for the service
"""
passwords = []
service = self._safe_string(service)
username = self._safe_string(username)
for attrs_tuple in (('username', 'service'), ('user', 'domain')):
... | [
"def",
"_find_passwords",
"(",
"self",
",",
"service",
",",
"username",
",",
"deleting",
"=",
"False",
")",
":",
"passwords",
"=",
"[",
"]",
"service",
"=",
"self",
".",
"_safe_string",
"(",
"service",
")",
"username",
"=",
"self",
".",
"_safe_string",
"... | Get password of the username for the service | [
"Get",
"password",
"of",
"the",
"username",
"for",
"the",
"service"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Gnome.py#L39-L61 |
jaraco/keyrings.alt | keyrings/alt/Gnome.py | Keyring.get_password | def get_password(self, service, username):
"""Get password of the username for the service
"""
items = self._find_passwords(service, username)
if not items:
return None
secret = items[0].secret
return (
secret
if isinstance(secret, six... | python | def get_password(self, service, username):
"""Get password of the username for the service
"""
items = self._find_passwords(service, username)
if not items:
return None
secret = items[0].secret
return (
secret
if isinstance(secret, six... | [
"def",
"get_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"items",
"=",
"self",
".",
"_find_passwords",
"(",
"service",
",",
"username",
")",
"if",
"not",
"items",
":",
"return",
"None",
"secret",
"=",
"items",
"[",
"0",
"]",
".",
... | Get password of the username for the service | [
"Get",
"password",
"of",
"the",
"username",
"for",
"the",
"service"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Gnome.py#L63-L75 |
jaraco/keyrings.alt | keyrings/alt/Gnome.py | Keyring.set_password | def set_password(self, service, username, password):
"""Set password for the username of the service
"""
service = self._safe_string(service)
username = self._safe_string(username)
password = self._safe_string(password)
attrs = GnomeKeyring.Attribute.list_new()
Gn... | python | def set_password(self, service, username, password):
"""Set password for the username of the service
"""
service = self._safe_string(service)
username = self._safe_string(username)
password = self._safe_string(password)
attrs = GnomeKeyring.Attribute.list_new()
Gn... | [
"def",
"set_password",
"(",
"self",
",",
"service",
",",
"username",
",",
"password",
")",
":",
"service",
"=",
"self",
".",
"_safe_string",
"(",
"service",
")",
"username",
"=",
"self",
".",
"_safe_string",
"(",
"username",
")",
"password",
"=",
"self",
... | Set password for the username of the service | [
"Set",
"password",
"for",
"the",
"username",
"of",
"the",
"service"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Gnome.py#L77-L96 |
jaraco/keyrings.alt | keyrings/alt/Gnome.py | Keyring.delete_password | def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
items = self._find_passwords(service, username, deleting=True)
if not items:
raise PasswordDeleteError("Password not found")
for current in items:
res... | python | def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
items = self._find_passwords(service, username, deleting=True)
if not items:
raise PasswordDeleteError("Password not found")
for current in items:
res... | [
"def",
"delete_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"items",
"=",
"self",
".",
"_find_passwords",
"(",
"service",
",",
"username",
",",
"deleting",
"=",
"True",
")",
"if",
"not",
"items",
":",
"raise",
"PasswordDeleteError",
"... | Delete the password for the username of the service. | [
"Delete",
"the",
"password",
"for",
"the",
"username",
"of",
"the",
"service",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Gnome.py#L98-L110 |
jaraco/keyrings.alt | keyrings/alt/Gnome.py | Keyring._safe_string | def _safe_string(self, source, encoding='utf-8'):
"""Convert unicode to string as gnomekeyring barfs on unicode"""
if not isinstance(source, str):
return source.encode(encoding)
return str(source) | python | def _safe_string(self, source, encoding='utf-8'):
"""Convert unicode to string as gnomekeyring barfs on unicode"""
if not isinstance(source, str):
return source.encode(encoding)
return str(source) | [
"def",
"_safe_string",
"(",
"self",
",",
"source",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"if",
"not",
"isinstance",
"(",
"source",
",",
"str",
")",
":",
"return",
"source",
".",
"encode",
"(",
"encoding",
")",
"return",
"str",
"(",
"source",
")"
] | Convert unicode to string as gnomekeyring barfs on unicode | [
"Convert",
"unicode",
"to",
"string",
"as",
"gnomekeyring",
"barfs",
"on",
"unicode"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Gnome.py#L112-L116 |
rfosterslo/wagtailplus | wagtailplus/wagtaillinks/views/links.py | CreateView.get_context_data | def get_context_data(self, **kwargs):
"""
Returns context dictionary for view.
:rtype: dict.
"""
kwargs.update({
'view': self,
'email_form': EmailLinkForm(),
'external_form': ExternalLinkForm(),
'type_email': ... | python | def get_context_data(self, **kwargs):
"""
Returns context dictionary for view.
:rtype: dict.
"""
kwargs.update({
'view': self,
'email_form': EmailLinkForm(),
'external_form': ExternalLinkForm(),
'type_email': ... | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"'view'",
":",
"self",
",",
"'email_form'",
":",
"EmailLinkForm",
"(",
")",
",",
"'external_form'",
":",
"ExternalLinkForm",
"(",
")",
",",
"'ty... | Returns context dictionary for view.
:rtype: dict. | [
"Returns",
"context",
"dictionary",
"for",
"view",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtaillinks/views/links.py#L26-L49 |
rfosterslo/wagtailplus | wagtailplus/wagtaillinks/views/links.py | CreateView.post | def post(self, request, *args, **kwargs):
"""
Returns POST response.
:param request: the request instance.
:rtype: django.http.HttpResponse.
"""
form = None
link_type = int(request.POST.get('link_type', 0))
if link_type == Link.LINK_TYPE_EMAIL:
... | python | def post(self, request, *args, **kwargs):
"""
Returns POST response.
:param request: the request instance.
:rtype: django.http.HttpResponse.
"""
form = None
link_type = int(request.POST.get('link_type', 0))
if link_type == Link.LINK_TYPE_EMAIL:
... | [
"def",
"post",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"form",
"=",
"None",
"link_type",
"=",
"int",
"(",
"request",
".",
"POST",
".",
"get",
"(",
"'link_type'",
",",
"0",
")",
")",
"if",
"link_type",
"==... | Returns POST response.
:param request: the request instance.
:rtype: django.http.HttpResponse. | [
"Returns",
"POST",
"response",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtaillinks/views/links.py#L57-L78 |
rfosterslo/wagtailplus | wagtailplus/wagtaillinks/views/links.py | UpdateView.get_form_class | def get_form_class(self):
"""
Returns form class to use in the view.
:rtype: django.forms.ModelForm.
"""
if self.object.link_type == Link.LINK_TYPE_EMAIL:
return EmailLinkForm
elif self.object.link_type == Link.LINK_TYPE_EXTERNAL:
return ExternalL... | python | def get_form_class(self):
"""
Returns form class to use in the view.
:rtype: django.forms.ModelForm.
"""
if self.object.link_type == Link.LINK_TYPE_EMAIL:
return EmailLinkForm
elif self.object.link_type == Link.LINK_TYPE_EXTERNAL:
return ExternalL... | [
"def",
"get_form_class",
"(",
"self",
")",
":",
"if",
"self",
".",
"object",
".",
"link_type",
"==",
"Link",
".",
"LINK_TYPE_EMAIL",
":",
"return",
"EmailLinkForm",
"elif",
"self",
".",
"object",
".",
"link_type",
"==",
"Link",
".",
"LINK_TYPE_EXTERNAL",
":"... | Returns form class to use in the view.
:rtype: django.forms.ModelForm. | [
"Returns",
"form",
"class",
"to",
"use",
"in",
"the",
"view",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtaillinks/views/links.py#L84-L95 |
jaraco/keyrings.alt | keyrings/alt/Windows.py | RegistryKeyring.get_password | def get_password(self, service, username):
"""Get password of the username for the service
"""
try:
# fetch the password
key = self._key_for_service(service)
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key)
password_saved = winreg.QueryValueEx(... | python | def get_password(self, service, username):
"""Get password of the username for the service
"""
try:
# fetch the password
key = self._key_for_service(service)
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key)
password_saved = winreg.QueryValueEx(... | [
"def",
"get_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"try",
":",
"# fetch the password",
"key",
"=",
"self",
".",
"_key_for_service",
"(",
"service",
")",
"hkey",
"=",
"winreg",
".",
"OpenKey",
"(",
"winreg",
".",
"HKEY_CURRENT_USER... | Get password of the username for the service | [
"Get",
"password",
"of",
"the",
"username",
"for",
"the",
"service"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Windows.py#L86-L101 |
jaraco/keyrings.alt | keyrings/alt/Windows.py | RegistryKeyring.set_password | def set_password(self, service, username, password):
"""Write the password to the registry
"""
# encrypt the password
password_encrypted = _win_crypto.encrypt(password.encode('utf-8'))
# encode with base64
password_base64 = base64.encodestring(password_encrypted)
... | python | def set_password(self, service, username, password):
"""Write the password to the registry
"""
# encrypt the password
password_encrypted = _win_crypto.encrypt(password.encode('utf-8'))
# encode with base64
password_base64 = base64.encodestring(password_encrypted)
... | [
"def",
"set_password",
"(",
"self",
",",
"service",
",",
"username",
",",
"password",
")",
":",
"# encrypt the password",
"password_encrypted",
"=",
"_win_crypto",
".",
"encrypt",
"(",
"password",
".",
"encode",
"(",
"'utf-8'",
")",
")",
"# encode with base64",
... | Write the password to the registry | [
"Write",
"the",
"password",
"to",
"the",
"registry"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Windows.py#L103-L116 |
jaraco/keyrings.alt | keyrings/alt/Windows.py | RegistryKeyring.delete_password | def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
try:
key_name = self._key_for_service(service)
hkey = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, key_name, 0,
winreg.KEY_ALL_ACCESS)
... | python | def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
try:
key_name = self._key_for_service(service)
hkey = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, key_name, 0,
winreg.KEY_ALL_ACCESS)
... | [
"def",
"delete_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"try",
":",
"key_name",
"=",
"self",
".",
"_key_for_service",
"(",
"service",
")",
"hkey",
"=",
"winreg",
".",
"OpenKey",
"(",
"winreg",
".",
"HKEY_CURRENT_USER",
",",
"key_n... | Delete the password for the username of the service. | [
"Delete",
"the",
"password",
"for",
"the",
"username",
"of",
"the",
"service",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/Windows.py#L118-L131 |
jaraco/keyrings.alt | keyrings/alt/pyfs.py | BasicKeyring.encrypt | def encrypt(self, password):
"""Encrypt the password.
"""
if not password or not self._crypter:
return password or b''
return self._crypter.encrypt(password) | python | def encrypt(self, password):
"""Encrypt the password.
"""
if not password or not self._crypter:
return password or b''
return self._crypter.encrypt(password) | [
"def",
"encrypt",
"(",
"self",
",",
"password",
")",
":",
"if",
"not",
"password",
"or",
"not",
"self",
".",
"_crypter",
":",
"return",
"password",
"or",
"b''",
"return",
"self",
".",
"_crypter",
".",
"encrypt",
"(",
"password",
")"
] | Encrypt the password. | [
"Encrypt",
"the",
"password",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/pyfs.py#L71-L76 |
jaraco/keyrings.alt | keyrings/alt/pyfs.py | BasicKeyring.decrypt | def decrypt(self, password_encrypted):
"""Decrypt the password.
"""
if not password_encrypted or not self._crypter:
return password_encrypted or b''
return self._crypter.decrypt(password_encrypted) | python | def decrypt(self, password_encrypted):
"""Decrypt the password.
"""
if not password_encrypted or not self._crypter:
return password_encrypted or b''
return self._crypter.decrypt(password_encrypted) | [
"def",
"decrypt",
"(",
"self",
",",
"password_encrypted",
")",
":",
"if",
"not",
"password_encrypted",
"or",
"not",
"self",
".",
"_crypter",
":",
"return",
"password_encrypted",
"or",
"b''",
"return",
"self",
".",
"_crypter",
".",
"decrypt",
"(",
"password_enc... | Decrypt the password. | [
"Decrypt",
"the",
"password",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/pyfs.py#L78-L83 |
jaraco/keyrings.alt | keyrings/alt/pyfs.py | BasicKeyring._open | def _open(self, mode='r'):
"""Open the password file in the specified mode
"""
open_file = None
writeable = 'w' in mode or 'a' in mode or '+' in mode
try:
# NOTE: currently the MemOpener does not split off any filename
# which causes errors on close(... | python | def _open(self, mode='r'):
"""Open the password file in the specified mode
"""
open_file = None
writeable = 'w' in mode or 'a' in mode or '+' in mode
try:
# NOTE: currently the MemOpener does not split off any filename
# which causes errors on close(... | [
"def",
"_open",
"(",
"self",
",",
"mode",
"=",
"'r'",
")",
":",
"open_file",
"=",
"None",
"writeable",
"=",
"'w'",
"in",
"mode",
"or",
"'a'",
"in",
"mode",
"or",
"'+'",
"in",
"mode",
"try",
":",
"# NOTE: currently the MemOpener does not split off any filename"... | Open the password file in the specified mode | [
"Open",
"the",
"password",
"file",
"in",
"the",
"specified",
"mode"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/pyfs.py#L85-L158 |
jaraco/keyrings.alt | keyrings/alt/pyfs.py | BasicKeyring.config | def config(self):
"""load the passwords from the config file
"""
if not hasattr(self, '_config'):
raw_config = configparser.RawConfigParser()
f = self._open()
if f:
raw_config.readfp(f)
f.close()
self._config = raw_c... | python | def config(self):
"""load the passwords from the config file
"""
if not hasattr(self, '_config'):
raw_config = configparser.RawConfigParser()
f = self._open()
if f:
raw_config.readfp(f)
f.close()
self._config = raw_c... | [
"def",
"config",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_config'",
")",
":",
"raw_config",
"=",
"configparser",
".",
"RawConfigParser",
"(",
")",
"f",
"=",
"self",
".",
"_open",
"(",
")",
"if",
"f",
":",
"raw_config",
".",... | load the passwords from the config file | [
"load",
"the",
"passwords",
"from",
"the",
"config",
"file"
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/pyfs.py#L161-L171 |
jaraco/keyrings.alt | keyrings/alt/pyfs.py | BasicKeyring.get_password | def get_password(self, service, username):
"""Read the password from the file.
"""
service = escape_for_ini(service)
username = escape_for_ini(username)
# fetch the password
try:
password_base64 = self.config.get(service, username).encode()
# deco... | python | def get_password(self, service, username):
"""Read the password from the file.
"""
service = escape_for_ini(service)
username = escape_for_ini(username)
# fetch the password
try:
password_base64 = self.config.get(service, username).encode()
# deco... | [
"def",
"get_password",
"(",
"self",
",",
"service",
",",
"username",
")",
":",
"service",
"=",
"escape_for_ini",
"(",
"service",
")",
"username",
"=",
"escape_for_ini",
"(",
"username",
")",
"# fetch the password",
"try",
":",
"password_base64",
"=",
"self",
"... | Read the password from the file. | [
"Read",
"the",
"password",
"from",
"the",
"file",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/pyfs.py#L173-L188 |
jaraco/keyrings.alt | keyrings/alt/pyfs.py | BasicKeyring.set_password | def set_password(self, service, username, password):
"""Write the password in the file.
"""
service = escape_for_ini(service)
username = escape_for_ini(username)
# encrypt the password
password = password or ''
password_encrypted = self.encrypt(password.encode('u... | python | def set_password(self, service, username, password):
"""Write the password in the file.
"""
service = escape_for_ini(service)
username = escape_for_ini(username)
# encrypt the password
password = password or ''
password_encrypted = self.encrypt(password.encode('u... | [
"def",
"set_password",
"(",
"self",
",",
"service",
",",
"username",
",",
"password",
")",
":",
"service",
"=",
"escape_for_ini",
"(",
"service",
")",
"username",
"=",
"escape_for_ini",
"(",
"username",
")",
"# encrypt the password",
"password",
"=",
"password",... | Write the password in the file. | [
"Write",
"the",
"password",
"in",
"the",
"file",
"."
] | train | https://github.com/jaraco/keyrings.alt/blob/5b71223d12bf9ac6abd05b1b395f1efccb5ea660/keyrings/alt/pyfs.py#L190-L208 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/models.py | LiveEntryCategoryManager.get_queryset | def get_queryset(self):
"""
Returns queryset limited to categories with live Entry instances.
:rtype: django.db.models.query.QuerySet.
"""
queryset = super(LiveEntryCategoryManager, self).get_queryset()
return queryset.filter(tag__in=[
entry_tag.tag
... | python | def get_queryset(self):
"""
Returns queryset limited to categories with live Entry instances.
:rtype: django.db.models.query.QuerySet.
"""
queryset = super(LiveEntryCategoryManager, self).get_queryset()
return queryset.filter(tag__in=[
entry_tag.tag
... | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"queryset",
"=",
"super",
"(",
"LiveEntryCategoryManager",
",",
"self",
")",
".",
"get_queryset",
"(",
")",
"return",
"queryset",
".",
"filter",
"(",
"tag__in",
"=",
"[",
"entry_tag",
".",
"tag",
"for",
"entry_... | Returns queryset limited to categories with live Entry instances.
:rtype: django.db.models.query.QuerySet. | [
"Returns",
"queryset",
"limited",
"to",
"categories",
"with",
"live",
"Entry",
"instances",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/models.py#L33-L44 |
rfosterslo/wagtailplus | wagtailplus/wagtailrelations/models.py | EntryManager.get_for_model | def get_for_model(self, model):
"""
Returns tuple (Entry instance, created) for specified
model instance.
:rtype: wagtailplus.wagtailrelations.models.Entry.
"""
return self.get_or_create(
content_type = ContentType.objects.get_for_model(model),
... | python | def get_for_model(self, model):
"""
Returns tuple (Entry instance, created) for specified
model instance.
:rtype: wagtailplus.wagtailrelations.models.Entry.
"""
return self.get_or_create(
content_type = ContentType.objects.get_for_model(model),
... | [
"def",
"get_for_model",
"(",
"self",
",",
"model",
")",
":",
"return",
"self",
".",
"get_or_create",
"(",
"content_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"model",
")",
",",
"object_id",
"=",
"model",
".",
"pk",
")"
] | Returns tuple (Entry instance, created) for specified
model instance.
:rtype: wagtailplus.wagtailrelations.models.Entry. | [
"Returns",
"tuple",
"(",
"Entry",
"instance",
"created",
")",
"for",
"specified",
"model",
"instance",
"."
] | train | https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/models.py#L120-L130 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.