repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
lwcolton/falcon-cors | src/falcon_cors/__init__.py | CORS._process_credentials | def _process_credentials(self, req, resp, origin):
"""Adds the Access-Control-Allow-Credentials to the response
if the cors settings indicates it should be set.
"""
if self._cors_config['allow_credentials_all_origins']:
self._set_allow_credentials(resp)
return Tru... | python | def _process_credentials(self, req, resp, origin):
"""Adds the Access-Control-Allow-Credentials to the response
if the cors settings indicates it should be set.
"""
if self._cors_config['allow_credentials_all_origins']:
self._set_allow_credentials(resp)
return Tru... | [
"def",
"_process_credentials",
"(",
"self",
",",
"req",
",",
"resp",
",",
"origin",
")",
":",
"if",
"self",
".",
"_cors_config",
"[",
"'allow_credentials_all_origins'",
"]",
":",
"self",
".",
"_set_allow_credentials",
"(",
"resp",
")",
"return",
"True",
"if",
... | Adds the Access-Control-Allow-Credentials to the response
if the cors settings indicates it should be set. | [
"Adds",
"the",
"Access",
"-",
"Control",
"-",
"Allow",
"-",
"Credentials",
"to",
"the",
"response",
"if",
"the",
"cors",
"settings",
"indicates",
"it",
"should",
"be",
"set",
"."
] | train | https://github.com/lwcolton/falcon-cors/blob/9e1243829078e4c6f8fb8bb895b5cad62bce9d6b/src/falcon_cors/__init__.py#L396-L414 |
azavea/django-amazon-ses | django_amazon_ses.py | EmailBackend.send_messages | def send_messages(self, email_messages):
"""Sends one or more EmailMessage objects and returns the
number of email messages sent.
Args:
email_messages: A list of Django EmailMessage objects.
Returns:
An integer count of the messages sent.
Raises:
... | python | def send_messages(self, email_messages):
"""Sends one or more EmailMessage objects and returns the
number of email messages sent.
Args:
email_messages: A list of Django EmailMessage objects.
Returns:
An integer count of the messages sent.
Raises:
... | [
"def",
"send_messages",
"(",
"self",
",",
"email_messages",
")",
":",
"if",
"not",
"email_messages",
":",
"return",
"sent_message_count",
"=",
"0",
"for",
"email_message",
"in",
"email_messages",
":",
"if",
"self",
".",
"_send",
"(",
"email_message",
")",
":",... | Sends one or more EmailMessage objects and returns the
number of email messages sent.
Args:
email_messages: A list of Django EmailMessage objects.
Returns:
An integer count of the messages sent.
Raises:
ClientError: An interaction with the Amazon SES ... | [
"Sends",
"one",
"or",
"more",
"EmailMessage",
"objects",
"and",
"returns",
"the",
"number",
"of",
"email",
"messages",
"sent",
"."
] | train | https://github.com/azavea/django-amazon-ses/blob/668c2e240ee643d02294d28966a9d44cf30dfc7f/django_amazon_ses.py#L58-L78 |
azavea/django-amazon-ses | django_amazon_ses.py | EmailBackend._send | def _send(self, email_message):
"""Sends an individual message via the Amazon SES HTTP API.
Args:
email_message: A single Django EmailMessage object.
Returns:
True if the EmailMessage was sent successfully, otherwise False.
Raises:
ClientError: An int... | python | def _send(self, email_message):
"""Sends an individual message via the Amazon SES HTTP API.
Args:
email_message: A single Django EmailMessage object.
Returns:
True if the EmailMessage was sent successfully, otherwise False.
Raises:
ClientError: An int... | [
"def",
"_send",
"(",
"self",
",",
"email_message",
")",
":",
"pre_send",
".",
"send",
"(",
"self",
".",
"__class__",
",",
"message",
"=",
"email_message",
")",
"if",
"not",
"email_message",
".",
"recipients",
"(",
")",
":",
"return",
"False",
"from_email",... | Sends an individual message via the Amazon SES HTTP API.
Args:
email_message: A single Django EmailMessage object.
Returns:
True if the EmailMessage was sent successfully, otherwise False.
Raises:
ClientError: An interaction with the Amazon SES HTTP API
... | [
"Sends",
"an",
"individual",
"message",
"via",
"the",
"Amazon",
"SES",
"HTTP",
"API",
"."
] | train | https://github.com/azavea/django-amazon-ses/blob/668c2e240ee643d02294d28966a9d44cf30dfc7f/django_amazon_ses.py#L80-L120 |
datadesk/django-bakery | bakery/static_views.py | serve | def serve(request, path, document_root=None, show_indexes=False, default=''):
"""
Serve static files below a given point in the directory structure.
To use, put a URL pattern such as::
(r'^(?P<path>.*)$', 'django.views.static.serve',
{'document_root' : '/path/to/my/files/'})
in yo... | python | def serve(request, path, document_root=None, show_indexes=False, default=''):
"""
Serve static files below a given point in the directory structure.
To use, put a URL pattern such as::
(r'^(?P<path>.*)$', 'django.views.static.serve',
{'document_root' : '/path/to/my/files/'})
in yo... | [
"def",
"serve",
"(",
"request",
",",
"path",
",",
"document_root",
"=",
"None",
",",
"show_indexes",
"=",
"False",
",",
"default",
"=",
"''",
")",
":",
"# Clean up given path to only allow serving files below document_root.",
"path",
"=",
"posixpath",
".",
"normpath... | Serve static files below a given point in the directory structure.
To use, put a URL pattern such as::
(r'^(?P<path>.*)$', 'django.views.static.serve',
{'document_root' : '/path/to/my/files/'})
in your URLconf. You must provide the ``document_root`` param. You may
also set ``show_inde... | [
"Serve",
"static",
"files",
"below",
"a",
"given",
"point",
"in",
"the",
"directory",
"structure",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/static_views.py#L19-L83 |
datadesk/django-bakery | bakery/static_views.py | was_modified_since | def was_modified_since(header=None, mtime=0, size=0):
"""
Was something modified since the user last downloaded it?
header
This is the value of the If-Modified-Since header. If this is None,
I'll just return True.
mtime
This is the modification time of the item we're talking about.
... | python | def was_modified_since(header=None, mtime=0, size=0):
"""
Was something modified since the user last downloaded it?
header
This is the value of the If-Modified-Since header. If this is None,
I'll just return True.
mtime
This is the modification time of the item we're talking about.
... | [
"def",
"was_modified_since",
"(",
"header",
"=",
"None",
",",
"mtime",
"=",
"0",
",",
"size",
"=",
"0",
")",
":",
"try",
":",
"if",
"header",
"is",
"None",
":",
"raise",
"ValueError",
"matches",
"=",
"re",
".",
"match",
"(",
"r\"^([^;]+)(; length=([0-9]+... | Was something modified since the user last downloaded it?
header
This is the value of the If-Modified-Since header. If this is None,
I'll just return True.
mtime
This is the modification time of the item we're talking about.
size
This is the size of the item we're talking about. | [
"Was",
"something",
"modified",
"since",
"the",
"user",
"last",
"downloaded",
"it?",
"header",
"This",
"is",
"the",
"value",
"of",
"the",
"If",
"-",
"Modified",
"-",
"Since",
"header",
".",
"If",
"this",
"is",
"None",
"I",
"ll",
"just",
"return",
"True",... | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/static_views.py#L135-L159 |
datadesk/django-bakery | bakery/views/detail.py | BuildableDetailView.get_url | def get_url(self, obj):
"""
The URL at which the detail page should appear.
"""
if not hasattr(obj, 'get_absolute_url') or not obj.get_absolute_url():
raise ImproperlyConfigured("No URL configured. You must either \
set a ``get_absolute_url`` method on the %s model or overrid... | python | def get_url(self, obj):
"""
The URL at which the detail page should appear.
"""
if not hasattr(obj, 'get_absolute_url') or not obj.get_absolute_url():
raise ImproperlyConfigured("No URL configured. You must either \
set a ``get_absolute_url`` method on the %s model or overrid... | [
"def",
"get_url",
"(",
"self",
",",
"obj",
")",
":",
"if",
"not",
"hasattr",
"(",
"obj",
",",
"'get_absolute_url'",
")",
"or",
"not",
"obj",
".",
"get_absolute_url",
"(",
")",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"No URL configured. You must either \\\ns... | The URL at which the detail page should appear. | [
"The",
"URL",
"at",
"which",
"the",
"detail",
"page",
"should",
"appear",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/detail.py#L32-L40 |
datadesk/django-bakery | bakery/views/detail.py | BuildableDetailView.unbuild_object | def unbuild_object(self, obj):
"""
Deletes the directory at self.get_build_path.
"""
logger.debug("Unbuilding %s" % obj)
target_path = os.path.split(self.get_build_path(obj))[0]
if self.fs.exists(target_path):
logger.debug("Removing {}".format(target_path))
... | python | def unbuild_object(self, obj):
"""
Deletes the directory at self.get_build_path.
"""
logger.debug("Unbuilding %s" % obj)
target_path = os.path.split(self.get_build_path(obj))[0]
if self.fs.exists(target_path):
logger.debug("Removing {}".format(target_path))
... | [
"def",
"unbuild_object",
"(",
"self",
",",
"obj",
")",
":",
"logger",
".",
"debug",
"(",
"\"Unbuilding %s\"",
"%",
"obj",
")",
"target_path",
"=",
"os",
".",
"path",
".",
"split",
"(",
"self",
".",
"get_build_path",
"(",
"obj",
")",
")",
"[",
"0",
"]... | Deletes the directory at self.get_build_path. | [
"Deletes",
"the",
"directory",
"at",
"self",
".",
"get_build_path",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/detail.py#L74-L82 |
datadesk/django-bakery | bakery/tasks.py | unpublish_object | def unpublish_object(content_type_pk, obj_pk):
"""
Unbuild all views related to a object and then sync to S3.
Accepts primary keys to retrieve a model object that
inherits bakery's BuildableModel class.
"""
ct = ContentType.objects.get_for_id(content_type_pk)
obj = ct.get_object_for_this_ty... | python | def unpublish_object(content_type_pk, obj_pk):
"""
Unbuild all views related to a object and then sync to S3.
Accepts primary keys to retrieve a model object that
inherits bakery's BuildableModel class.
"""
ct = ContentType.objects.get_for_id(content_type_pk)
obj = ct.get_object_for_this_ty... | [
"def",
"unpublish_object",
"(",
"content_type_pk",
",",
"obj_pk",
")",
":",
"ct",
"=",
"ContentType",
".",
"objects",
".",
"get_for_id",
"(",
"content_type_pk",
")",
"obj",
"=",
"ct",
".",
"get_object_for_this_type",
"(",
"pk",
"=",
"obj_pk",
")",
"try",
":"... | Unbuild all views related to a object and then sync to S3.
Accepts primary keys to retrieve a model object that
inherits bakery's BuildableModel class. | [
"Unbuild",
"all",
"views",
"related",
"to",
"a",
"object",
"and",
"then",
"sync",
"to",
"S3",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/tasks.py#L39-L61 |
datadesk/django-bakery | bakery/views/base.py | BuildableMixin.prep_directory | def prep_directory(self, target_dir):
"""
Prepares a new directory to store the file at the provided path, if needed.
"""
dirname = path.dirname(target_dir)
if dirname:
dirname = path.join(settings.BUILD_DIR, dirname)
if not self.fs.exists(dirname):
... | python | def prep_directory(self, target_dir):
"""
Prepares a new directory to store the file at the provided path, if needed.
"""
dirname = path.dirname(target_dir)
if dirname:
dirname = path.join(settings.BUILD_DIR, dirname)
if not self.fs.exists(dirname):
... | [
"def",
"prep_directory",
"(",
"self",
",",
"target_dir",
")",
":",
"dirname",
"=",
"path",
".",
"dirname",
"(",
"target_dir",
")",
"if",
"dirname",
":",
"dirname",
"=",
"path",
".",
"join",
"(",
"settings",
".",
"BUILD_DIR",
",",
"dirname",
")",
"if",
... | Prepares a new directory to store the file at the provided path, if needed. | [
"Prepares",
"a",
"new",
"directory",
"to",
"store",
"the",
"file",
"at",
"the",
"provided",
"path",
"if",
"needed",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/base.py#L55-L64 |
datadesk/django-bakery | bakery/views/base.py | BuildableMixin.write_file | def write_file(self, target_path, html):
"""
Writes out the provided HTML to the provided path.
"""
logger.debug("Building to {}{}".format(self.fs_name, target_path))
with self.fs.open(smart_text(target_path), 'wb') as outfile:
outfile.write(six.binary_type(html))
... | python | def write_file(self, target_path, html):
"""
Writes out the provided HTML to the provided path.
"""
logger.debug("Building to {}{}".format(self.fs_name, target_path))
with self.fs.open(smart_text(target_path), 'wb') as outfile:
outfile.write(six.binary_type(html))
... | [
"def",
"write_file",
"(",
"self",
",",
"target_path",
",",
"html",
")",
":",
"logger",
".",
"debug",
"(",
"\"Building to {}{}\"",
".",
"format",
"(",
"self",
".",
"fs_name",
",",
"target_path",
")",
")",
"with",
"self",
".",
"fs",
".",
"open",
"(",
"sm... | Writes out the provided HTML to the provided path. | [
"Writes",
"out",
"the",
"provided",
"HTML",
"to",
"the",
"provided",
"path",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/base.py#L72-L79 |
datadesk/django-bakery | bakery/views/base.py | BuildableMixin.is_gzippable | def is_gzippable(self, path):
"""
Returns a boolean indicating if the provided file path is a candidate
for gzipping.
"""
# First check if gzipping is allowed by the global setting
if not getattr(settings, 'BAKERY_GZIP', False):
return False
# Then che... | python | def is_gzippable(self, path):
"""
Returns a boolean indicating if the provided file path is a candidate
for gzipping.
"""
# First check if gzipping is allowed by the global setting
if not getattr(settings, 'BAKERY_GZIP', False):
return False
# Then che... | [
"def",
"is_gzippable",
"(",
"self",
",",
"path",
")",
":",
"# First check if gzipping is allowed by the global setting",
"if",
"not",
"getattr",
"(",
"settings",
",",
"'BAKERY_GZIP'",
",",
"False",
")",
":",
"return",
"False",
"# Then check if the content type of this par... | Returns a boolean indicating if the provided file path is a candidate
for gzipping. | [
"Returns",
"a",
"boolean",
"indicating",
"if",
"the",
"provided",
"file",
"path",
"is",
"a",
"candidate",
"for",
"gzipping",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/base.py#L81-L95 |
datadesk/django-bakery | bakery/views/base.py | BuildableMixin.gzip_file | def gzip_file(self, target_path, html):
"""
Zips up the provided HTML as a companion for the provided path.
Intended to take advantage of the peculiarities of
Amazon S3's GZIP service.
mtime, an option that writes a timestamp to the output file
is set to 0, to avoid hav... | python | def gzip_file(self, target_path, html):
"""
Zips up the provided HTML as a companion for the provided path.
Intended to take advantage of the peculiarities of
Amazon S3's GZIP service.
mtime, an option that writes a timestamp to the output file
is set to 0, to avoid hav... | [
"def",
"gzip_file",
"(",
"self",
",",
"target_path",
",",
"html",
")",
":",
"logger",
".",
"debug",
"(",
"\"Gzipping to {}{}\"",
".",
"format",
"(",
"self",
".",
"fs_name",
",",
"target_path",
")",
")",
"# Write GZIP data to an in-memory buffer",
"data_buffer",
... | Zips up the provided HTML as a companion for the provided path.
Intended to take advantage of the peculiarities of
Amazon S3's GZIP service.
mtime, an option that writes a timestamp to the output file
is set to 0, to avoid having s3cmd do unnecessary uploads because
of differen... | [
"Zips",
"up",
"the",
"provided",
"HTML",
"as",
"a",
"companion",
"for",
"the",
"provided",
"path",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/base.py#L97-L125 |
datadesk/django-bakery | bakery/views/base.py | BuildableRedirectView.get_redirect_url | def get_redirect_url(self, *args, **kwargs):
"""
Return the URL redirect to. Keyword arguments from the
URL pattern match generating the redirect request
are provided as kwargs to this method.
"""
if self.url:
url = self.url % kwargs
elif self.pattern_... | python | def get_redirect_url(self, *args, **kwargs):
"""
Return the URL redirect to. Keyword arguments from the
URL pattern match generating the redirect request
are provided as kwargs to this method.
"""
if self.url:
url = self.url % kwargs
elif self.pattern_... | [
"def",
"get_redirect_url",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"url",
":",
"url",
"=",
"self",
".",
"url",
"%",
"kwargs",
"elif",
"self",
".",
"pattern_name",
":",
"try",
":",
"url",
"=",
"reverse",
... | Return the URL redirect to. Keyword arguments from the
URL pattern match generating the redirect request
are provided as kwargs to this method. | [
"Return",
"the",
"URL",
"redirect",
"to",
".",
"Keyword",
"arguments",
"from",
"the",
"URL",
"pattern",
"match",
"generating",
"the",
"redirect",
"request",
"are",
"provided",
"as",
"kwargs",
"to",
"this",
"method",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/base.py#L208-L223 |
datadesk/django-bakery | bakery/models.py | BuildableModel.build | def build(self):
"""
Iterates through the views pointed to by self.detail_views, runs
build_object with `self`, and calls _build_extra()
and _build_related().
"""
for detail_view in self.detail_views:
view = self._get_view(detail_view)
view().build... | python | def build(self):
"""
Iterates through the views pointed to by self.detail_views, runs
build_object with `self`, and calls _build_extra()
and _build_related().
"""
for detail_view in self.detail_views:
view = self._get_view(detail_view)
view().build... | [
"def",
"build",
"(",
"self",
")",
":",
"for",
"detail_view",
"in",
"self",
".",
"detail_views",
":",
"view",
"=",
"self",
".",
"_get_view",
"(",
"detail_view",
")",
"view",
"(",
")",
".",
"build_object",
"(",
"self",
")",
"self",
".",
"_build_extra",
"... | Iterates through the views pointed to by self.detail_views, runs
build_object with `self`, and calls _build_extra()
and _build_related(). | [
"Iterates",
"through",
"the",
"views",
"pointed",
"to",
"by",
"self",
".",
"detail_views",
"runs",
"build_object",
"with",
"self",
"and",
"calls",
"_build_extra",
"()",
"and",
"_build_related",
"()",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/models.py#L51-L61 |
datadesk/django-bakery | bakery/models.py | BuildableModel.unbuild | def unbuild(self):
"""
Iterates through the views pointed to by self.detail_views, runs
unbuild_object with `self`, and calls _build_extra()
and _build_related().
"""
for detail_view in self.detail_views:
view = self._get_view(detail_view)
view().u... | python | def unbuild(self):
"""
Iterates through the views pointed to by self.detail_views, runs
unbuild_object with `self`, and calls _build_extra()
and _build_related().
"""
for detail_view in self.detail_views:
view = self._get_view(detail_view)
view().u... | [
"def",
"unbuild",
"(",
"self",
")",
":",
"for",
"detail_view",
"in",
"self",
".",
"detail_views",
":",
"view",
"=",
"self",
".",
"_get_view",
"(",
"detail_view",
")",
"view",
"(",
")",
".",
"unbuild_object",
"(",
"self",
")",
"self",
".",
"_unbuild_extra... | Iterates through the views pointed to by self.detail_views, runs
unbuild_object with `self`, and calls _build_extra()
and _build_related(). | [
"Iterates",
"through",
"the",
"views",
"pointed",
"to",
"by",
"self",
".",
"detail_views",
"runs",
"unbuild_object",
"with",
"self",
"and",
"calls",
"_build_extra",
"()",
"and",
"_build_related",
"()",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/models.py#L63-L74 |
datadesk/django-bakery | bakery/models.py | AutoPublishingBuildableModel.save | def save(self, *args, **kwargs):
"""
A custom save that publishes or unpublishes the object where
appropriate.
Save with keyword argument obj.save(publish=False) to skip the process.
"""
from bakery import tasks
from django.contrib.contenttypes.models import Cont... | python | def save(self, *args, **kwargs):
"""
A custom save that publishes or unpublishes the object where
appropriate.
Save with keyword argument obj.save(publish=False) to skip the process.
"""
from bakery import tasks
from django.contrib.contenttypes.models import Cont... | [
"def",
"save",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"bakery",
"import",
"tasks",
"from",
"django",
".",
"contrib",
".",
"contenttypes",
".",
"models",
"import",
"ContentType",
"# if obj.save(publish=False) has been passed, we... | A custom save that publishes or unpublishes the object where
appropriate.
Save with keyword argument obj.save(publish=False) to skip the process. | [
"A",
"custom",
"save",
"that",
"publishes",
"or",
"unpublishes",
"the",
"object",
"where",
"appropriate",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/models.py#L117-L167 |
datadesk/django-bakery | bakery/models.py | AutoPublishingBuildableModel.delete | def delete(self, *args, **kwargs):
"""
Triggers a task that will unpublish the object after it is deleted.
Save with keyword argument obj.delete(unpublish=False) to skip it.
"""
from bakery import tasks
from django.contrib.contenttypes.models import ContentType
#... | python | def delete(self, *args, **kwargs):
"""
Triggers a task that will unpublish the object after it is deleted.
Save with keyword argument obj.delete(unpublish=False) to skip it.
"""
from bakery import tasks
from django.contrib.contenttypes.models import ContentType
#... | [
"def",
"delete",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"bakery",
"import",
"tasks",
"from",
"django",
".",
"contrib",
".",
"contenttypes",
".",
"models",
"import",
"ContentType",
"# if obj.save(unpublish=False) has been passed... | Triggers a task that will unpublish the object after it is deleted.
Save with keyword argument obj.delete(unpublish=False) to skip it. | [
"Triggers",
"a",
"task",
"that",
"will",
"unpublish",
"the",
"object",
"after",
"it",
"is",
"deleted",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/models.py#L169-L183 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.handle | def handle(self, *args, **options):
"""
Making it happen.
"""
logger.info("Build started")
# Set options
self.set_options(*args, **options)
# Get the build directory ready
if not options.get("keep_build_dir"):
self.init_build_dir()
#... | python | def handle(self, *args, **options):
"""
Making it happen.
"""
logger.info("Build started")
# Set options
self.set_options(*args, **options)
# Get the build directory ready
if not options.get("keep_build_dir"):
self.init_build_dir()
#... | [
"def",
"handle",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"logger",
".",
"info",
"(",
"\"Build started\"",
")",
"# Set options",
"self",
".",
"set_options",
"(",
"*",
"args",
",",
"*",
"*",
"options",
")",
"# Get the build direc... | Making it happen. | [
"Making",
"it",
"happen",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L90-L115 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.set_options | def set_options(self, *args, **options):
"""
Configure a few global options before things get going.
"""
self.verbosity = int(options.get('verbosity', 1))
# Figure out what build directory to use
if options.get("build_dir"):
self.build_dir = options.get("buil... | python | def set_options(self, *args, **options):
"""
Configure a few global options before things get going.
"""
self.verbosity = int(options.get('verbosity', 1))
# Figure out what build directory to use
if options.get("build_dir"):
self.build_dir = options.get("buil... | [
"def",
"set_options",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"self",
".",
"verbosity",
"=",
"int",
"(",
"options",
".",
"get",
"(",
"'verbosity'",
",",
"1",
")",
")",
"# Figure out what build directory to use",
"if",
"options",
... | Configure a few global options before things get going. | [
"Configure",
"a",
"few",
"global",
"options",
"before",
"things",
"get",
"going",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L117-L155 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.init_build_dir | def init_build_dir(self):
"""
Clear out the build directory and create a new one.
"""
# Destroy the build directory, if it exists
logger.debug("Initializing %s" % self.build_dir)
if self.verbosity > 1:
self.stdout.write("Initializing build directory")
... | python | def init_build_dir(self):
"""
Clear out the build directory and create a new one.
"""
# Destroy the build directory, if it exists
logger.debug("Initializing %s" % self.build_dir)
if self.verbosity > 1:
self.stdout.write("Initializing build directory")
... | [
"def",
"init_build_dir",
"(",
"self",
")",
":",
"# Destroy the build directory, if it exists",
"logger",
".",
"debug",
"(",
"\"Initializing %s\"",
"%",
"self",
".",
"build_dir",
")",
"if",
"self",
".",
"verbosity",
">",
"1",
":",
"self",
".",
"stdout",
".",
"w... | Clear out the build directory and create a new one. | [
"Clear",
"out",
"the",
"build",
"directory",
"and",
"create",
"a",
"new",
"one",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L157-L168 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.build_static | def build_static(self, *args, **options):
"""
Builds the static files directory as well as robots.txt and favicon.ico
"""
logger.debug("Building static directory")
if self.verbosity > 1:
self.stdout.write("Building static directory")
management.call_command(
... | python | def build_static(self, *args, **options):
"""
Builds the static files directory as well as robots.txt and favicon.ico
"""
logger.debug("Building static directory")
if self.verbosity > 1:
self.stdout.write("Building static directory")
management.call_command(
... | [
"def",
"build_static",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"logger",
".",
"debug",
"(",
"\"Building static directory\"",
")",
"if",
"self",
".",
"verbosity",
">",
"1",
":",
"self",
".",
"stdout",
".",
"write",
"(",
"\"Bui... | Builds the static files directory as well as robots.txt and favicon.ico | [
"Builds",
"the",
"static",
"files",
"directory",
"as",
"well",
"as",
"robots",
".",
"txt",
"and",
"favicon",
".",
"ico"
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L170-L211 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.build_media | def build_media(self):
"""
Build the media files.
"""
logger.debug("Building media directory")
if self.verbosity > 1:
self.stdout.write("Building media directory")
if os.path.exists(self.media_root) and settings.MEDIA_URL:
target_dir = path.join(se... | python | def build_media(self):
"""
Build the media files.
"""
logger.debug("Building media directory")
if self.verbosity > 1:
self.stdout.write("Building media directory")
if os.path.exists(self.media_root) and settings.MEDIA_URL:
target_dir = path.join(se... | [
"def",
"build_media",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"\"Building media directory\"",
")",
"if",
"self",
".",
"verbosity",
">",
"1",
":",
"self",
".",
"stdout",
".",
"write",
"(",
"\"Building media directory\"",
")",
"if",
"os",
".",
"p... | Build the media files. | [
"Build",
"the",
"media",
"files",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L213-L223 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.build_views | def build_views(self):
"""
Bake out specified buildable views.
"""
# Then loop through and run them all
for view_str in self.view_list:
logger.debug("Building %s" % view_str)
if self.verbosity > 1:
self.stdout.write("Building %s" % view_str... | python | def build_views(self):
"""
Bake out specified buildable views.
"""
# Then loop through and run them all
for view_str in self.view_list:
logger.debug("Building %s" % view_str)
if self.verbosity > 1:
self.stdout.write("Building %s" % view_str... | [
"def",
"build_views",
"(",
"self",
")",
":",
"# Then loop through and run them all",
"for",
"view_str",
"in",
"self",
".",
"view_list",
":",
"logger",
".",
"debug",
"(",
"\"Building %s\"",
"%",
"view_str",
")",
"if",
"self",
".",
"verbosity",
">",
"1",
":",
... | Bake out specified buildable views. | [
"Bake",
"out",
"specified",
"buildable",
"views",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L231-L241 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.copytree_and_gzip | def copytree_and_gzip(self, source_dir, target_dir):
"""
Copies the provided source directory to the provided target directory.
Gzips JavaScript, CSS and HTML and other files along the way.
"""
# Figure out what we're building...
build_list = []
# Walk through th... | python | def copytree_and_gzip(self, source_dir, target_dir):
"""
Copies the provided source directory to the provided target directory.
Gzips JavaScript, CSS and HTML and other files along the way.
"""
# Figure out what we're building...
build_list = []
# Walk through th... | [
"def",
"copytree_and_gzip",
"(",
"self",
",",
"source_dir",
",",
"target_dir",
")",
":",
"# Figure out what we're building...",
"build_list",
"=",
"[",
"]",
"# Walk through the source directory...",
"for",
"(",
"dirpath",
",",
"dirnames",
",",
"filenames",
")",
"in",
... | Copies the provided source directory to the provided target directory.
Gzips JavaScript, CSS and HTML and other files along the way. | [
"Copies",
"the",
"provided",
"source",
"directory",
"to",
"the",
"provided",
"target",
"directory",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L243-L270 |
datadesk/django-bakery | bakery/management/commands/build.py | Command.copyfile_and_gzip | def copyfile_and_gzip(self, source_path, target_path):
"""
Copies the provided file to the provided target directory.
Gzips JavaScript, CSS and HTML and other files along the way.
"""
# And then where we want to copy it to.
target_dir = path.dirname(target_path)
... | python | def copyfile_and_gzip(self, source_path, target_path):
"""
Copies the provided file to the provided target directory.
Gzips JavaScript, CSS and HTML and other files along the way.
"""
# And then where we want to copy it to.
target_dir = path.dirname(target_path)
... | [
"def",
"copyfile_and_gzip",
"(",
"self",
",",
"source_path",
",",
"target_path",
")",
":",
"# And then where we want to copy it to.",
"target_dir",
"=",
"path",
".",
"dirname",
"(",
"target_path",
")",
"if",
"not",
"self",
".",
"fs",
".",
"exists",
"(",
"target_... | Copies the provided file to the provided target directory.
Gzips JavaScript, CSS and HTML and other files along the way. | [
"Copies",
"the",
"provided",
"file",
"to",
"the",
"provided",
"target",
"directory",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/build.py#L280-L346 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.handle | def handle(self, *args, **options):
"""
Sync files in the build directory to a specified S3 bucket
"""
# Counts and such we can use to keep tabs on this as they progress
self.uploaded_files = 0
self.uploaded_file_list = []
self.deleted_files = 0
self.delet... | python | def handle(self, *args, **options):
"""
Sync files in the build directory to a specified S3 bucket
"""
# Counts and such we can use to keep tabs on this as they progress
self.uploaded_files = 0
self.uploaded_file_list = []
self.deleted_files = 0
self.delet... | [
"def",
"handle",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"# Counts and such we can use to keep tabs on this as they progress",
"self",
".",
"uploaded_files",
"=",
"0",
"self",
".",
"uploaded_file_list",
"=",
"[",
"]",
"self",
".",
"del... | Sync files in the build directory to a specified S3 bucket | [
"Sync",
"files",
"in",
"the",
"build",
"directory",
"to",
"a",
"specified",
"S3",
"bucket"
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L86-L173 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.set_options | def set_options(self, options):
"""
Configure all the many options we'll need to make this happen.
"""
self.verbosity = int(options.get('verbosity'))
# Will we be gzipping?
self.gzip = getattr(settings, 'BAKERY_GZIP', False)
# And if so what content types will w... | python | def set_options(self, options):
"""
Configure all the many options we'll need to make this happen.
"""
self.verbosity = int(options.get('verbosity'))
# Will we be gzipping?
self.gzip = getattr(settings, 'BAKERY_GZIP', False)
# And if so what content types will w... | [
"def",
"set_options",
"(",
"self",
",",
"options",
")",
":",
"self",
".",
"verbosity",
"=",
"int",
"(",
"options",
".",
"get",
"(",
"'verbosity'",
")",
")",
"# Will we be gzipping?",
"self",
".",
"gzip",
"=",
"getattr",
"(",
"settings",
",",
"'BAKERY_GZIP'... | Configure all the many options we'll need to make this happen. | [
"Configure",
"all",
"the",
"many",
"options",
"we",
"ll",
"need",
"to",
"make",
"this",
"happen",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L175-L242 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.get_bucket_file_list | def get_bucket_file_list(self):
"""
Little utility method that handles pagination and returns
all objects in given bucket.
"""
logger.debug("Retrieving bucket object list")
paginator = self.s3_client.get_paginator('list_objects')
options = {
'Bucket':... | python | def get_bucket_file_list(self):
"""
Little utility method that handles pagination and returns
all objects in given bucket.
"""
logger.debug("Retrieving bucket object list")
paginator = self.s3_client.get_paginator('list_objects')
options = {
'Bucket':... | [
"def",
"get_bucket_file_list",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"\"Retrieving bucket object list\"",
")",
"paginator",
"=",
"self",
".",
"s3_client",
".",
"get_paginator",
"(",
"'list_objects'",
")",
"options",
"=",
"{",
"'Bucket'",
":",
"self... | Little utility method that handles pagination and returns
all objects in given bucket. | [
"Little",
"utility",
"method",
"that",
"handles",
"pagination",
"and",
"returns",
"all",
"objects",
"in",
"given",
"bucket",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L244-L264 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.get_local_file_list | def get_local_file_list(self):
"""
Walk the local build directory and create a list of relative and
absolute paths to files.
"""
file_list = []
for (dirpath, dirnames, filenames) in os.walk(self.build_dir):
for fname in filenames:
# relative pa... | python | def get_local_file_list(self):
"""
Walk the local build directory and create a list of relative and
absolute paths to files.
"""
file_list = []
for (dirpath, dirnames, filenames) in os.walk(self.build_dir):
for fname in filenames:
# relative pa... | [
"def",
"get_local_file_list",
"(",
"self",
")",
":",
"file_list",
"=",
"[",
"]",
"for",
"(",
"dirpath",
",",
"dirnames",
",",
"filenames",
")",
"in",
"os",
".",
"walk",
"(",
"self",
".",
"build_dir",
")",
":",
"for",
"fname",
"in",
"filenames",
":",
... | Walk the local build directory and create a list of relative and
absolute paths to files. | [
"Walk",
"the",
"local",
"build",
"directory",
"and",
"create",
"a",
"list",
"of",
"relative",
"and",
"absolute",
"paths",
"to",
"files",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L266-L282 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.sync_with_s3 | def sync_with_s3(self):
"""
Walk through our self.local_files list, and match them with the list
of keys in the S3 bucket.
"""
# Create a list to put all the files we're going to update
self.update_list = []
# Figure out which files need to be updated and upload ... | python | def sync_with_s3(self):
"""
Walk through our self.local_files list, and match them with the list
of keys in the S3 bucket.
"""
# Create a list to put all the files we're going to update
self.update_list = []
# Figure out which files need to be updated and upload ... | [
"def",
"sync_with_s3",
"(",
"self",
")",
":",
"# Create a list to put all the files we're going to update",
"self",
".",
"update_list",
"=",
"[",
"]",
"# Figure out which files need to be updated and upload all these files",
"logger",
".",
"debug",
"(",
"\"Comparing {} local file... | Walk through our self.local_files list, and match them with the list
of keys in the S3 bucket. | [
"Walk",
"through",
"our",
"self",
".",
"local_files",
"list",
"and",
"match",
"them",
"with",
"the",
"list",
"of",
"keys",
"in",
"the",
"S3",
"bucket",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L284-L311 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.get_md5 | def get_md5(self, filename):
"""
Returns the md5 checksum of the provided file name.
"""
with open(filename, 'rb') as f:
m = hashlib.md5(f.read())
return m.hexdigest() | python | def get_md5(self, filename):
"""
Returns the md5 checksum of the provided file name.
"""
with open(filename, 'rb') as f:
m = hashlib.md5(f.read())
return m.hexdigest() | [
"def",
"get_md5",
"(",
"self",
",",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"f",
":",
"m",
"=",
"hashlib",
".",
"md5",
"(",
"f",
".",
"read",
"(",
")",
")",
"return",
"m",
".",
"hexdigest",
"(",
")"
] | Returns the md5 checksum of the provided file name. | [
"Returns",
"the",
"md5",
"checksum",
"of",
"the",
"provided",
"file",
"name",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L313-L319 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.get_multipart_md5 | def get_multipart_md5(self, filename, chunk_size=8 * 1024 * 1024):
"""
Returns the md5 checksum of the provided file name after breaking it into chunks.
This is done to mirror the method used by Amazon S3 after a multipart upload.
"""
# Loop through the file contents ...
... | python | def get_multipart_md5(self, filename, chunk_size=8 * 1024 * 1024):
"""
Returns the md5 checksum of the provided file name after breaking it into chunks.
This is done to mirror the method used by Amazon S3 after a multipart upload.
"""
# Loop through the file contents ...
... | [
"def",
"get_multipart_md5",
"(",
"self",
",",
"filename",
",",
"chunk_size",
"=",
"8",
"*",
"1024",
"*",
"1024",
")",
":",
"# Loop through the file contents ...",
"md5s",
"=",
"[",
"]",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"fp",
":",
... | Returns the md5 checksum of the provided file name after breaking it into chunks.
This is done to mirror the method used by Amazon S3 after a multipart upload. | [
"Returns",
"the",
"md5",
"checksum",
"of",
"the",
"provided",
"file",
"name",
"after",
"breaking",
"it",
"into",
"chunks",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L321-L349 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.compare_local_file | def compare_local_file(self, file_key):
"""
Compares a local version of a file with what's already published.
If an update is needed, the file's key is added self.update_list.
"""
# Where is the file?
file_path = os.path.join(self.build_dir, file_key)
# If we're... | python | def compare_local_file(self, file_key):
"""
Compares a local version of a file with what's already published.
If an update is needed, the file's key is added self.update_list.
"""
# Where is the file?
file_path = os.path.join(self.build_dir, file_key)
# If we're... | [
"def",
"compare_local_file",
"(",
"self",
",",
"file_key",
")",
":",
"# Where is the file?",
"file_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"build_dir",
",",
"file_key",
")",
"# If we're in force_publish mode just add it",
"if",
"self",
".",
... | Compares a local version of a file with what's already published.
If an update is needed, the file's key is added self.update_list. | [
"Compares",
"a",
"local",
"version",
"of",
"a",
"file",
"with",
"what",
"s",
"already",
"published",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L351-L394 |
datadesk/django-bakery | bakery/management/commands/publish.py | Command.upload_to_s3 | def upload_to_s3(self, key, filename):
"""
Set the content type and gzip headers if applicable
and upload the item to S3
"""
extra_args = {'ACL': self.acl}
# determine the mimetype of the file
guess = mimetypes.guess_type(filename)
content_type = guess[0]
... | python | def upload_to_s3(self, key, filename):
"""
Set the content type and gzip headers if applicable
and upload the item to S3
"""
extra_args = {'ACL': self.acl}
# determine the mimetype of the file
guess = mimetypes.guess_type(filename)
content_type = guess[0]
... | [
"def",
"upload_to_s3",
"(",
"self",
",",
"key",
",",
"filename",
")",
":",
"extra_args",
"=",
"{",
"'ACL'",
":",
"self",
".",
"acl",
"}",
"# determine the mimetype of the file",
"guess",
"=",
"mimetypes",
".",
"guess_type",
"(",
"filename",
")",
"content_type"... | Set the content type and gzip headers if applicable
and upload the item to S3 | [
"Set",
"the",
"content",
"type",
"and",
"gzip",
"headers",
"if",
"applicable",
"and",
"upload",
"the",
"item",
"to",
"S3"
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/publish.py#L405-L440 |
datadesk/django-bakery | bakery/feeds.py | BuildableFeed._get_bakery_dynamic_attr | def _get_bakery_dynamic_attr(self, attname, obj, args=None, default=None):
"""
Allows subclasses to provide an attribute (say, 'foo') in three
different ways: As a fixed class-level property or as a method
foo(self) or foo(self, obj). The second argument argument 'obj' is
the "su... | python | def _get_bakery_dynamic_attr(self, attname, obj, args=None, default=None):
"""
Allows subclasses to provide an attribute (say, 'foo') in three
different ways: As a fixed class-level property or as a method
foo(self) or foo(self, obj). The second argument argument 'obj' is
the "su... | [
"def",
"_get_bakery_dynamic_attr",
"(",
"self",
",",
"attname",
",",
"obj",
",",
"args",
"=",
"None",
",",
"default",
"=",
"None",
")",
":",
"try",
":",
"attr",
"=",
"getattr",
"(",
"self",
",",
"attname",
")",
"except",
"AttributeError",
":",
"return",
... | Allows subclasses to provide an attribute (say, 'foo') in three
different ways: As a fixed class-level property or as a method
foo(self) or foo(self, obj). The second argument argument 'obj' is
the "subject" of the current Feed invocation. See the Django Feed
documentation for details.
... | [
"Allows",
"subclasses",
"to",
"provide",
"an",
"attribute",
"(",
"say",
"foo",
")",
"in",
"three",
"different",
"ways",
":",
"As",
"a",
"fixed",
"class",
"-",
"level",
"property",
"or",
"as",
"a",
"method",
"foo",
"(",
"self",
")",
"or",
"foo",
"(",
... | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/feeds.py#L23-L53 |
datadesk/django-bakery | bakery/views/dates.py | BuildableYearArchiveView.get_year | def get_year(self):
"""
Return the year from the database in the format expected by the URL.
"""
year = super(BuildableYearArchiveView, self).get_year()
fmt = self.get_year_format()
return date(int(year), 1, 1).strftime(fmt) | python | def get_year(self):
"""
Return the year from the database in the format expected by the URL.
"""
year = super(BuildableYearArchiveView, self).get_year()
fmt = self.get_year_format()
return date(int(year), 1, 1).strftime(fmt) | [
"def",
"get_year",
"(",
"self",
")",
":",
"year",
"=",
"super",
"(",
"BuildableYearArchiveView",
",",
"self",
")",
".",
"get_year",
"(",
")",
"fmt",
"=",
"self",
".",
"get_year_format",
"(",
")",
"return",
"date",
"(",
"int",
"(",
"year",
")",
",",
"... | Return the year from the database in the format expected by the URL. | [
"Return",
"the",
"year",
"from",
"the",
"database",
"in",
"the",
"format",
"expected",
"by",
"the",
"URL",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L75-L81 |
datadesk/django-bakery | bakery/views/dates.py | BuildableYearArchiveView.build_year | def build_year(self, dt):
"""
Build the page for the provided year.
"""
self.year = str(dt.year)
logger.debug("Building %s" % self.year)
self.request = self.create_request(self.get_url())
target_path = self.get_build_path()
self.build_file(target_path, sel... | python | def build_year(self, dt):
"""
Build the page for the provided year.
"""
self.year = str(dt.year)
logger.debug("Building %s" % self.year)
self.request = self.create_request(self.get_url())
target_path = self.get_build_path()
self.build_file(target_path, sel... | [
"def",
"build_year",
"(",
"self",
",",
"dt",
")",
":",
"self",
".",
"year",
"=",
"str",
"(",
"dt",
".",
"year",
")",
"logger",
".",
"debug",
"(",
"\"Building %s\"",
"%",
"self",
".",
"year",
")",
"self",
".",
"request",
"=",
"self",
".",
"create_re... | Build the page for the provided year. | [
"Build",
"the",
"page",
"for",
"the",
"provided",
"year",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L103-L111 |
datadesk/django-bakery | bakery/views/dates.py | BuildableYearArchiveView.build_dated_queryset | def build_dated_queryset(self):
"""
Build pages for all years in the queryset.
"""
qs = self.get_dated_queryset()
years = self.get_date_list(qs)
[self.build_year(dt) for dt in years] | python | def build_dated_queryset(self):
"""
Build pages for all years in the queryset.
"""
qs = self.get_dated_queryset()
years = self.get_date_list(qs)
[self.build_year(dt) for dt in years] | [
"def",
"build_dated_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"self",
".",
"get_dated_queryset",
"(",
")",
"years",
"=",
"self",
".",
"get_date_list",
"(",
"qs",
")",
"[",
"self",
".",
"build_year",
"(",
"dt",
")",
"for",
"dt",
"in",
"years",
"]"
] | Build pages for all years in the queryset. | [
"Build",
"pages",
"for",
"all",
"years",
"in",
"the",
"queryset",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L113-L119 |
datadesk/django-bakery | bakery/views/dates.py | BuildableMonthArchiveView.get_month | def get_month(self):
"""
Return the month from the database in the format expected by the URL.
"""
year = super(BuildableMonthArchiveView, self).get_year()
month = super(BuildableMonthArchiveView, self).get_month()
fmt = self.get_month_format()
return date(int(yea... | python | def get_month(self):
"""
Return the month from the database in the format expected by the URL.
"""
year = super(BuildableMonthArchiveView, self).get_year()
month = super(BuildableMonthArchiveView, self).get_month()
fmt = self.get_month_format()
return date(int(yea... | [
"def",
"get_month",
"(",
"self",
")",
":",
"year",
"=",
"super",
"(",
"BuildableMonthArchiveView",
",",
"self",
")",
".",
"get_year",
"(",
")",
"month",
"=",
"super",
"(",
"BuildableMonthArchiveView",
",",
"self",
")",
".",
"get_month",
"(",
")",
"fmt",
... | Return the month from the database in the format expected by the URL. | [
"Return",
"the",
"month",
"from",
"the",
"database",
"in",
"the",
"format",
"expected",
"by",
"the",
"URL",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L159-L166 |
datadesk/django-bakery | bakery/views/dates.py | BuildableMonthArchiveView.build_dated_queryset | def build_dated_queryset(self):
"""
Build pages for all years in the queryset.
"""
qs = self.get_dated_queryset()
months = self.get_date_list(qs)
[self.build_month(dt) for dt in months] | python | def build_dated_queryset(self):
"""
Build pages for all years in the queryset.
"""
qs = self.get_dated_queryset()
months = self.get_date_list(qs)
[self.build_month(dt) for dt in months] | [
"def",
"build_dated_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"self",
".",
"get_dated_queryset",
"(",
")",
"months",
"=",
"self",
".",
"get_date_list",
"(",
"qs",
")",
"[",
"self",
".",
"build_month",
"(",
"dt",
")",
"for",
"dt",
"in",
"months",
"]"... | Build pages for all years in the queryset. | [
"Build",
"pages",
"for",
"all",
"years",
"in",
"the",
"queryset",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L200-L206 |
datadesk/django-bakery | bakery/views/dates.py | BuildableMonthArchiveView.unbuild_month | def unbuild_month(self, dt):
"""
Deletes the directory at self.get_build_path.
"""
self.year = str(dt.year)
self.month = str(dt.month)
logger.debug("Building %s-%s" % (self.year, self.month))
target_path = os.path.split(self.get_build_path())[0]
if self.fs... | python | def unbuild_month(self, dt):
"""
Deletes the directory at self.get_build_path.
"""
self.year = str(dt.year)
self.month = str(dt.month)
logger.debug("Building %s-%s" % (self.year, self.month))
target_path = os.path.split(self.get_build_path())[0]
if self.fs... | [
"def",
"unbuild_month",
"(",
"self",
",",
"dt",
")",
":",
"self",
".",
"year",
"=",
"str",
"(",
"dt",
".",
"year",
")",
"self",
".",
"month",
"=",
"str",
"(",
"dt",
".",
"month",
")",
"logger",
".",
"debug",
"(",
"\"Building %s-%s\"",
"%",
"(",
"... | Deletes the directory at self.get_build_path. | [
"Deletes",
"the",
"directory",
"at",
"self",
".",
"get_build_path",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L208-L218 |
datadesk/django-bakery | bakery/views/dates.py | BuildableDayArchiveView.get_year | def get_year(self):
"""
Return the year from the database in the format expected by the URL.
"""
year = super(BuildableDayArchiveView, self).get_year()
fmt = self.get_year_format()
dt = date(int(year), 1, 1)
return dt.strftime(fmt) | python | def get_year(self):
"""
Return the year from the database in the format expected by the URL.
"""
year = super(BuildableDayArchiveView, self).get_year()
fmt = self.get_year_format()
dt = date(int(year), 1, 1)
return dt.strftime(fmt) | [
"def",
"get_year",
"(",
"self",
")",
":",
"year",
"=",
"super",
"(",
"BuildableDayArchiveView",
",",
"self",
")",
".",
"get_year",
"(",
")",
"fmt",
"=",
"self",
".",
"get_year_format",
"(",
")",
"dt",
"=",
"date",
"(",
"int",
"(",
"year",
")",
",",
... | Return the year from the database in the format expected by the URL. | [
"Return",
"the",
"year",
"from",
"the",
"database",
"in",
"the",
"format",
"expected",
"by",
"the",
"URL",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L239-L246 |
datadesk/django-bakery | bakery/views/dates.py | BuildableDayArchiveView.get_month | def get_month(self):
"""
Return the month from the database in the format expected by the URL.
"""
year = super(BuildableDayArchiveView, self).get_year()
month = super(BuildableDayArchiveView, self).get_month()
fmt = self.get_month_format()
dt = date(int(year), in... | python | def get_month(self):
"""
Return the month from the database in the format expected by the URL.
"""
year = super(BuildableDayArchiveView, self).get_year()
month = super(BuildableDayArchiveView, self).get_month()
fmt = self.get_month_format()
dt = date(int(year), in... | [
"def",
"get_month",
"(",
"self",
")",
":",
"year",
"=",
"super",
"(",
"BuildableDayArchiveView",
",",
"self",
")",
".",
"get_year",
"(",
")",
"month",
"=",
"super",
"(",
"BuildableDayArchiveView",
",",
"self",
")",
".",
"get_month",
"(",
")",
"fmt",
"=",... | Return the month from the database in the format expected by the URL. | [
"Return",
"the",
"month",
"from",
"the",
"database",
"in",
"the",
"format",
"expected",
"by",
"the",
"URL",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L248-L256 |
datadesk/django-bakery | bakery/views/dates.py | BuildableDayArchiveView.get_day | def get_day(self):
"""
Return the day from the database in the format expected by the URL.
"""
year = super(BuildableDayArchiveView, self).get_year()
month = super(BuildableDayArchiveView, self).get_month()
day = super(BuildableDayArchiveView, self).get_day()
fmt ... | python | def get_day(self):
"""
Return the day from the database in the format expected by the URL.
"""
year = super(BuildableDayArchiveView, self).get_year()
month = super(BuildableDayArchiveView, self).get_month()
day = super(BuildableDayArchiveView, self).get_day()
fmt ... | [
"def",
"get_day",
"(",
"self",
")",
":",
"year",
"=",
"super",
"(",
"BuildableDayArchiveView",
",",
"self",
")",
".",
"get_year",
"(",
")",
"month",
"=",
"super",
"(",
"BuildableDayArchiveView",
",",
"self",
")",
".",
"get_month",
"(",
")",
"day",
"=",
... | Return the day from the database in the format expected by the URL. | [
"Return",
"the",
"day",
"from",
"the",
"database",
"in",
"the",
"format",
"expected",
"by",
"the",
"URL",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L258-L267 |
datadesk/django-bakery | bakery/views/dates.py | BuildableDayArchiveView.get_url | def get_url(self):
"""
The URL at which the detail page should appear.
By default it is /archive/ + the year in self.year_format + the
month in self.month_format + the day in the self.day_format.
An example would be /archive/2016/01/01/.
"""
return os.path.join(
... | python | def get_url(self):
"""
The URL at which the detail page should appear.
By default it is /archive/ + the year in self.year_format + the
month in self.month_format + the day in the self.day_format.
An example would be /archive/2016/01/01/.
"""
return os.path.join(
... | [
"def",
"get_url",
"(",
"self",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"'/archive'",
",",
"self",
".",
"get_year",
"(",
")",
",",
"self",
".",
"get_month",
"(",
")",
",",
"self",
".",
"get_day",
"(",
")",
")"
] | The URL at which the detail page should appear.
By default it is /archive/ + the year in self.year_format + the
month in self.month_format + the day in the self.day_format.
An example would be /archive/2016/01/01/. | [
"The",
"URL",
"at",
"which",
"the",
"detail",
"page",
"should",
"appear",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L269-L282 |
datadesk/django-bakery | bakery/views/dates.py | BuildableDayArchiveView.get_build_path | def get_build_path(self):
"""
Used to determine where to build the page. Override this if you
would like your page at a different location. By default it
will be built at self.get_url() + "/index.html"
"""
target_path = path.join(settings.BUILD_DIR, self.get_url().lstrip(... | python | def get_build_path(self):
"""
Used to determine where to build the page. Override this if you
would like your page at a different location. By default it
will be built at self.get_url() + "/index.html"
"""
target_path = path.join(settings.BUILD_DIR, self.get_url().lstrip(... | [
"def",
"get_build_path",
"(",
"self",
")",
":",
"target_path",
"=",
"path",
".",
"join",
"(",
"settings",
".",
"BUILD_DIR",
",",
"self",
".",
"get_url",
"(",
")",
".",
"lstrip",
"(",
"'/'",
")",
")",
"if",
"not",
"self",
".",
"fs",
".",
"exists",
"... | Used to determine where to build the page. Override this if you
would like your page at a different location. By default it
will be built at self.get_url() + "/index.html" | [
"Used",
"to",
"determine",
"where",
"to",
"build",
"the",
"page",
".",
"Override",
"this",
"if",
"you",
"would",
"like",
"your",
"page",
"at",
"a",
"different",
"location",
".",
"By",
"default",
"it",
"will",
"be",
"built",
"at",
"self",
".",
"get_url",
... | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L284-L294 |
datadesk/django-bakery | bakery/views/dates.py | BuildableDayArchiveView.build_day | def build_day(self, dt):
"""
Build the page for the provided day.
"""
self.month = str(dt.month)
self.year = str(dt.year)
self.day = str(dt.day)
logger.debug("Building %s-%s-%s" % (self.year, self.month, self.day))
self.request = self.create_request(self.g... | python | def build_day(self, dt):
"""
Build the page for the provided day.
"""
self.month = str(dt.month)
self.year = str(dt.year)
self.day = str(dt.day)
logger.debug("Building %s-%s-%s" % (self.year, self.month, self.day))
self.request = self.create_request(self.g... | [
"def",
"build_day",
"(",
"self",
",",
"dt",
")",
":",
"self",
".",
"month",
"=",
"str",
"(",
"dt",
".",
"month",
")",
"self",
".",
"year",
"=",
"str",
"(",
"dt",
".",
"year",
")",
"self",
".",
"day",
"=",
"str",
"(",
"dt",
".",
"day",
")",
... | Build the page for the provided day. | [
"Build",
"the",
"page",
"for",
"the",
"provided",
"day",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L296-L306 |
datadesk/django-bakery | bakery/views/dates.py | BuildableDayArchiveView.build_dated_queryset | def build_dated_queryset(self):
"""
Build pages for all years in the queryset.
"""
qs = self.get_dated_queryset()
days = self.get_date_list(qs, date_type='day')
[self.build_day(dt) for dt in days] | python | def build_dated_queryset(self):
"""
Build pages for all years in the queryset.
"""
qs = self.get_dated_queryset()
days = self.get_date_list(qs, date_type='day')
[self.build_day(dt) for dt in days] | [
"def",
"build_dated_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"self",
".",
"get_dated_queryset",
"(",
")",
"days",
"=",
"self",
".",
"get_date_list",
"(",
"qs",
",",
"date_type",
"=",
"'day'",
")",
"[",
"self",
".",
"build_day",
"(",
"dt",
")",
"for... | Build pages for all years in the queryset. | [
"Build",
"pages",
"for",
"all",
"years",
"in",
"the",
"queryset",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/views/dates.py#L308-L314 |
datadesk/django-bakery | bakery/management/commands/__init__.py | get_s3_client | def get_s3_client():
"""
A DRY place to make sure AWS credentials in settings override
environment based credentials. Boto3 will fall back to:
http://boto3.readthedocs.io/en/latest/guide/configuration.html
"""
session_kwargs = {}
if hasattr(settings, 'AWS_ACCESS_KEY_ID'):
session_kw... | python | def get_s3_client():
"""
A DRY place to make sure AWS credentials in settings override
environment based credentials. Boto3 will fall back to:
http://boto3.readthedocs.io/en/latest/guide/configuration.html
"""
session_kwargs = {}
if hasattr(settings, 'AWS_ACCESS_KEY_ID'):
session_kw... | [
"def",
"get_s3_client",
"(",
")",
":",
"session_kwargs",
"=",
"{",
"}",
"if",
"hasattr",
"(",
"settings",
",",
"'AWS_ACCESS_KEY_ID'",
")",
":",
"session_kwargs",
"[",
"'aws_access_key_id'",
"]",
"=",
"settings",
".",
"AWS_ACCESS_KEY_ID",
"if",
"hasattr",
"(",
... | A DRY place to make sure AWS credentials in settings override
environment based credentials. Boto3 will fall back to:
http://boto3.readthedocs.io/en/latest/guide/configuration.html | [
"A",
"DRY",
"place",
"to",
"make",
"sure",
"AWS",
"credentials",
"in",
"settings",
"override",
"environment",
"based",
"credentials",
".",
"Boto3",
"will",
"fall",
"back",
"to",
":",
"http",
":",
"//",
"boto3",
".",
"readthedocs",
".",
"io",
"/",
"en",
"... | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/__init__.py#L8-L38 |
datadesk/django-bakery | bakery/management/commands/__init__.py | get_bucket_page | def get_bucket_page(page):
"""
Returns all the keys in a s3 bucket paginator page.
"""
key_list = page.get('Contents', [])
logger.debug("Retrieving page with {} keys".format(
len(key_list),
))
return dict((k.get('Key'), k) for k in key_list) | python | def get_bucket_page(page):
"""
Returns all the keys in a s3 bucket paginator page.
"""
key_list = page.get('Contents', [])
logger.debug("Retrieving page with {} keys".format(
len(key_list),
))
return dict((k.get('Key'), k) for k in key_list) | [
"def",
"get_bucket_page",
"(",
"page",
")",
":",
"key_list",
"=",
"page",
".",
"get",
"(",
"'Contents'",
",",
"[",
"]",
")",
"logger",
".",
"debug",
"(",
"\"Retrieving page with {} keys\"",
".",
"format",
"(",
"len",
"(",
"key_list",
")",
",",
")",
")",
... | Returns all the keys in a s3 bucket paginator page. | [
"Returns",
"all",
"the",
"keys",
"in",
"a",
"s3",
"bucket",
"paginator",
"page",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/__init__.py#L41-L49 |
datadesk/django-bakery | bakery/management/commands/__init__.py | get_all_objects_in_bucket | def get_all_objects_in_bucket(
aws_bucket_name,
s3_client=None,
max_keys=1000
):
"""
Little utility method that handles pagination and returns
all objects in given bucket.
"""
logger.debug("Retrieving bucket object list")
if not s3_client:
s3_client, s3_resource ... | python | def get_all_objects_in_bucket(
aws_bucket_name,
s3_client=None,
max_keys=1000
):
"""
Little utility method that handles pagination and returns
all objects in given bucket.
"""
logger.debug("Retrieving bucket object list")
if not s3_client:
s3_client, s3_resource ... | [
"def",
"get_all_objects_in_bucket",
"(",
"aws_bucket_name",
",",
"s3_client",
"=",
"None",
",",
"max_keys",
"=",
"1000",
")",
":",
"logger",
".",
"debug",
"(",
"\"Retrieving bucket object list\"",
")",
"if",
"not",
"s3_client",
":",
"s3_client",
",",
"s3_resource"... | Little utility method that handles pagination and returns
all objects in given bucket. | [
"Little",
"utility",
"method",
"that",
"handles",
"pagination",
"and",
"returns",
"all",
"objects",
"in",
"given",
"bucket",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/__init__.py#L52-L74 |
datadesk/django-bakery | bakery/management/commands/__init__.py | batch_delete_s3_objects | def batch_delete_s3_objects(
keys,
aws_bucket_name,
chunk_size=100,
s3_client=None
):
"""
Utility method that batch deletes objects in given bucket.
"""
if s3_client is None:
s3_client, s3_resource = get_s3_client()
key_chunks = []
for i in range(0, len(k... | python | def batch_delete_s3_objects(
keys,
aws_bucket_name,
chunk_size=100,
s3_client=None
):
"""
Utility method that batch deletes objects in given bucket.
"""
if s3_client is None:
s3_client, s3_resource = get_s3_client()
key_chunks = []
for i in range(0, len(k... | [
"def",
"batch_delete_s3_objects",
"(",
"keys",
",",
"aws_bucket_name",
",",
"chunk_size",
"=",
"100",
",",
"s3_client",
"=",
"None",
")",
":",
"if",
"s3_client",
"is",
"None",
":",
"s3_client",
",",
"s3_resource",
"=",
"get_s3_client",
"(",
")",
"key_chunks",
... | Utility method that batch deletes objects in given bucket. | [
"Utility",
"method",
"that",
"batch",
"deletes",
"objects",
"in",
"given",
"bucket",
"."
] | train | https://github.com/datadesk/django-bakery/blob/e2feb13a66552a388fbcfaaacdd504bba08d3c69/bakery/management/commands/__init__.py#L77-L99 |
python-parsy/parsy | examples/proto3.py | lexeme | def lexeme(p):
"""
From a parser (or string), make a parser that consumes
whitespace on either side.
"""
if isinstance(p, str):
p = string(p)
return regex(r'\s*') >> p << regex(r'\s*') | python | def lexeme(p):
"""
From a parser (or string), make a parser that consumes
whitespace on either side.
"""
if isinstance(p, str):
p = string(p)
return regex(r'\s*') >> p << regex(r'\s*') | [
"def",
"lexeme",
"(",
"p",
")",
":",
"if",
"isinstance",
"(",
"p",
",",
"str",
")",
":",
"p",
"=",
"string",
"(",
"p",
")",
"return",
"regex",
"(",
"r'\\s*'",
")",
">>",
"p",
"<<",
"regex",
"(",
"r'\\s*'",
")"
] | From a parser (or string), make a parser that consumes
whitespace on either side. | [
"From",
"a",
"parser",
"(",
"or",
"string",
")",
"make",
"a",
"parser",
"that",
"consumes",
"whitespace",
"on",
"either",
"side",
"."
] | train | https://github.com/python-parsy/parsy/blob/04216ed25b6cdb389a36e16998592ba476237f86/examples/proto3.py#L39-L46 |
python-parsy/parsy | examples/proto3.py | is_present | def is_present(p):
"""
Given a parser or string, make a parser that returns
True if the parser matches, False otherwise
"""
return lexeme(p).optional().map(lambda v: False if v is None else True) | python | def is_present(p):
"""
Given a parser or string, make a parser that returns
True if the parser matches, False otherwise
"""
return lexeme(p).optional().map(lambda v: False if v is None else True) | [
"def",
"is_present",
"(",
"p",
")",
":",
"return",
"lexeme",
"(",
"p",
")",
".",
"optional",
"(",
")",
".",
"map",
"(",
"lambda",
"v",
":",
"False",
"if",
"v",
"is",
"None",
"else",
"True",
")"
] | Given a parser or string, make a parser that returns
True if the parser matches, False otherwise | [
"Given",
"a",
"parser",
"or",
"string",
"make",
"a",
"parser",
"that",
"returns",
"True",
"if",
"the",
"parser",
"matches",
"False",
"otherwise"
] | train | https://github.com/python-parsy/parsy/blob/04216ed25b6cdb389a36e16998592ba476237f86/examples/proto3.py#L49-L54 |
python-parsy/parsy | src/parsy/__init__.py | Parser.parse | def parse(self, stream):
"""Parse a string or list of tokens and return the result or raise a ParseError."""
(result, _) = (self << eof).parse_partial(stream)
return result | python | def parse(self, stream):
"""Parse a string or list of tokens and return the result or raise a ParseError."""
(result, _) = (self << eof).parse_partial(stream)
return result | [
"def",
"parse",
"(",
"self",
",",
"stream",
")",
":",
"(",
"result",
",",
"_",
")",
"=",
"(",
"self",
"<<",
"eof",
")",
".",
"parse_partial",
"(",
"stream",
")",
"return",
"result"
] | Parse a string or list of tokens and return the result or raise a ParseError. | [
"Parse",
"a",
"string",
"or",
"list",
"of",
"tokens",
"and",
"return",
"the",
"result",
"or",
"raise",
"a",
"ParseError",
"."
] | train | https://github.com/python-parsy/parsy/blob/04216ed25b6cdb389a36e16998592ba476237f86/src/parsy/__init__.py#L88-L91 |
python-parsy/parsy | src/parsy/__init__.py | Parser.parse_partial | def parse_partial(self, stream):
"""
Parse the longest possible prefix of a given string.
Return a tuple of the result and the rest of the string,
or raise a ParseError.
"""
result = self(stream, 0)
if result.status:
return (result.value, stream[resul... | python | def parse_partial(self, stream):
"""
Parse the longest possible prefix of a given string.
Return a tuple of the result and the rest of the string,
or raise a ParseError.
"""
result = self(stream, 0)
if result.status:
return (result.value, stream[resul... | [
"def",
"parse_partial",
"(",
"self",
",",
"stream",
")",
":",
"result",
"=",
"self",
"(",
"stream",
",",
"0",
")",
"if",
"result",
".",
"status",
":",
"return",
"(",
"result",
".",
"value",
",",
"stream",
"[",
"result",
".",
"index",
":",
"]",
")",... | Parse the longest possible prefix of a given string.
Return a tuple of the result and the rest of the string,
or raise a ParseError. | [
"Parse",
"the",
"longest",
"possible",
"prefix",
"of",
"a",
"given",
"string",
".",
"Return",
"a",
"tuple",
"of",
"the",
"result",
"and",
"the",
"rest",
"of",
"the",
"string",
"or",
"raise",
"a",
"ParseError",
"."
] | train | https://github.com/python-parsy/parsy/blob/04216ed25b6cdb389a36e16998592ba476237f86/src/parsy/__init__.py#L93-L104 |
scrapinghub/flatson | flatson/flatson.py | extract_key_values | def extract_key_values(array_value, separators=(';', ',', ':'), **kwargs):
"""Serialize array of objects with simple key-values
"""
items_sep, fields_sep, keys_sep = separators
return items_sep.join(fields_sep.join(keys_sep.join(x) for x in sorted(it.items()))
for it in array_v... | python | def extract_key_values(array_value, separators=(';', ',', ':'), **kwargs):
"""Serialize array of objects with simple key-values
"""
items_sep, fields_sep, keys_sep = separators
return items_sep.join(fields_sep.join(keys_sep.join(x) for x in sorted(it.items()))
for it in array_v... | [
"def",
"extract_key_values",
"(",
"array_value",
",",
"separators",
"=",
"(",
"';'",
",",
"','",
",",
"':'",
")",
",",
"*",
"*",
"kwargs",
")",
":",
"items_sep",
",",
"fields_sep",
",",
"keys_sep",
"=",
"separators",
"return",
"items_sep",
".",
"join",
"... | Serialize array of objects with simple key-values | [
"Serialize",
"array",
"of",
"objects",
"with",
"simple",
"key",
"-",
"values"
] | train | https://github.com/scrapinghub/flatson/blob/dcbcea32ad6d4df1df85fff8366bce40438d469a/flatson/flatson.py#L48-L53 |
scrapinghub/flatson | flatson/flatson.py | Flatson.from_schemafile | def from_schemafile(cls, schemafile):
"""Create a Flatson instance from a schemafile
"""
with open(schemafile) as f:
return cls(json.load(f)) | python | def from_schemafile(cls, schemafile):
"""Create a Flatson instance from a schemafile
"""
with open(schemafile) as f:
return cls(json.load(f)) | [
"def",
"from_schemafile",
"(",
"cls",
",",
"schemafile",
")",
":",
"with",
"open",
"(",
"schemafile",
")",
"as",
"f",
":",
"return",
"cls",
"(",
"json",
".",
"load",
"(",
"f",
")",
")"
] | Create a Flatson instance from a schemafile | [
"Create",
"a",
"Flatson",
"instance",
"from",
"a",
"schemafile"
] | train | https://github.com/scrapinghub/flatson/blob/dcbcea32ad6d4df1df85fff8366bce40438d469a/flatson/flatson.py#L93-L97 |
scrapinghub/flatson | flatson/flatson.py | Flatson.register_serialization_method | def register_serialization_method(self, name, serialize_func):
"""Register a custom serialization method that can be
used via schema configuration
"""
if name in self._default_serialization_methods:
raise ValueError("Can't replace original %s serialization method")
se... | python | def register_serialization_method(self, name, serialize_func):
"""Register a custom serialization method that can be
used via schema configuration
"""
if name in self._default_serialization_methods:
raise ValueError("Can't replace original %s serialization method")
se... | [
"def",
"register_serialization_method",
"(",
"self",
",",
"name",
",",
"serialize_func",
")",
":",
"if",
"name",
"in",
"self",
".",
"_default_serialization_methods",
":",
"raise",
"ValueError",
"(",
"\"Can't replace original %s serialization method\"",
")",
"self",
".",... | Register a custom serialization method that can be
used via schema configuration | [
"Register",
"a",
"custom",
"serialization",
"method",
"that",
"can",
"be",
"used",
"via",
"schema",
"configuration"
] | train | https://github.com/scrapinghub/flatson/blob/dcbcea32ad6d4df1df85fff8366bce40438d469a/flatson/flatson.py#L123-L129 |
scrapinghub/flatson | flatson/flatson.py | Flatson.flatten | def flatten(self, obj):
"""Return a list with the field values
"""
return [self._serialize(f, obj) for f in self.fields] | python | def flatten(self, obj):
"""Return a list with the field values
"""
return [self._serialize(f, obj) for f in self.fields] | [
"def",
"flatten",
"(",
"self",
",",
"obj",
")",
":",
"return",
"[",
"self",
".",
"_serialize",
"(",
"f",
",",
"obj",
")",
"for",
"f",
"in",
"self",
".",
"fields",
"]"
] | Return a list with the field values | [
"Return",
"a",
"list",
"with",
"the",
"field",
"values"
] | train | https://github.com/scrapinghub/flatson/blob/dcbcea32ad6d4df1df85fff8366bce40438d469a/flatson/flatson.py#L131-L134 |
scrapinghub/flatson | flatson/flatson.py | Flatson.flatten_dict | def flatten_dict(self, obj):
"""Return an OrderedDict dict preserving order of keys in fieldnames
"""
return OrderedDict(zip(self.fieldnames, self.flatten(obj))) | python | def flatten_dict(self, obj):
"""Return an OrderedDict dict preserving order of keys in fieldnames
"""
return OrderedDict(zip(self.fieldnames, self.flatten(obj))) | [
"def",
"flatten_dict",
"(",
"self",
",",
"obj",
")",
":",
"return",
"OrderedDict",
"(",
"zip",
"(",
"self",
".",
"fieldnames",
",",
"self",
".",
"flatten",
"(",
"obj",
")",
")",
")"
] | Return an OrderedDict dict preserving order of keys in fieldnames | [
"Return",
"an",
"OrderedDict",
"dict",
"preserving",
"order",
"of",
"keys",
"in",
"fieldnames"
] | train | https://github.com/scrapinghub/flatson/blob/dcbcea32ad6d4df1df85fff8366bce40438d469a/flatson/flatson.py#L136-L139 |
gmr/queries | queries/pool.py | Connection.close | def close(self):
"""Close the connection
:raises: ConnectionBusyError
"""
LOGGER.debug('Connection %s closing', self.id)
if self.busy:
raise ConnectionBusyError(self)
with self._lock:
if not self.handle.closed:
try:
... | python | def close(self):
"""Close the connection
:raises: ConnectionBusyError
"""
LOGGER.debug('Connection %s closing', self.id)
if self.busy:
raise ConnectionBusyError(self)
with self._lock:
if not self.handle.closed:
try:
... | [
"def",
"close",
"(",
"self",
")",
":",
"LOGGER",
".",
"debug",
"(",
"'Connection %s closing'",
",",
"self",
".",
"id",
")",
"if",
"self",
".",
"busy",
":",
"raise",
"ConnectionBusyError",
"(",
"self",
")",
"with",
"self",
".",
"_lock",
":",
"if",
"not"... | Close the connection
:raises: ConnectionBusyError | [
"Close",
"the",
"connection"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L33-L47 |
gmr/queries | queries/pool.py | Connection.busy | def busy(self):
"""Return if the connection is currently executing a query or is locked
by a session that still exists.
:rtype: bool
"""
if self.handle.isexecuting():
return True
elif self.used_by is None:
return False
return not self.use... | python | def busy(self):
"""Return if the connection is currently executing a query or is locked
by a session that still exists.
:rtype: bool
"""
if self.handle.isexecuting():
return True
elif self.used_by is None:
return False
return not self.use... | [
"def",
"busy",
"(",
"self",
")",
":",
"if",
"self",
".",
"handle",
".",
"isexecuting",
"(",
")",
":",
"return",
"True",
"elif",
"self",
".",
"used_by",
"is",
"None",
":",
"return",
"False",
"return",
"not",
"self",
".",
"used_by",
"(",
")",
"is",
"... | Return if the connection is currently executing a query or is locked
by a session that still exists.
:rtype: bool | [
"Return",
"if",
"the",
"connection",
"is",
"currently",
"executing",
"a",
"query",
"or",
"is",
"locked",
"by",
"a",
"session",
"that",
"still",
"exists",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L59-L70 |
gmr/queries | queries/pool.py | Connection.free | def free(self):
"""Remove the lock on the connection if the connection is not active
:raises: ConnectionBusyError
"""
LOGGER.debug('Connection %s freeing', self.id)
if self.handle.isexecuting():
raise ConnectionBusyError(self)
with self._lock:
se... | python | def free(self):
"""Remove the lock on the connection if the connection is not active
:raises: ConnectionBusyError
"""
LOGGER.debug('Connection %s freeing', self.id)
if self.handle.isexecuting():
raise ConnectionBusyError(self)
with self._lock:
se... | [
"def",
"free",
"(",
"self",
")",
":",
"LOGGER",
".",
"debug",
"(",
"'Connection %s freeing'",
",",
"self",
".",
"id",
")",
"if",
"self",
".",
"handle",
".",
"isexecuting",
"(",
")",
":",
"raise",
"ConnectionBusyError",
"(",
"self",
")",
"with",
"self",
... | Remove the lock on the connection if the connection is not active
:raises: ConnectionBusyError | [
"Remove",
"the",
"lock",
"on",
"the",
"connection",
"if",
"the",
"connection",
"is",
"not",
"active"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L81-L92 |
gmr/queries | queries/pool.py | Connection.lock | def lock(self, session):
"""Lock the connection, ensuring that it is not busy and storing
a weakref for the session.
:param queries.Session session: The session to lock the connection with
:raises: ConnectionBusyError
"""
if self.busy:
raise ConnectionBusyEr... | python | def lock(self, session):
"""Lock the connection, ensuring that it is not busy and storing
a weakref for the session.
:param queries.Session session: The session to lock the connection with
:raises: ConnectionBusyError
"""
if self.busy:
raise ConnectionBusyEr... | [
"def",
"lock",
"(",
"self",
",",
"session",
")",
":",
"if",
"self",
".",
"busy",
":",
"raise",
"ConnectionBusyError",
"(",
"self",
")",
"with",
"self",
".",
"_lock",
":",
"self",
".",
"used_by",
"=",
"weakref",
".",
"ref",
"(",
"session",
")",
"LOGGE... | Lock the connection, ensuring that it is not busy and storing
a weakref for the session.
:param queries.Session session: The session to lock the connection with
:raises: ConnectionBusyError | [
"Lock",
"the",
"connection",
"ensuring",
"that",
"it",
"is",
"not",
"busy",
"and",
"storing",
"a",
"weakref",
"for",
"the",
"session",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L103-L115 |
gmr/queries | queries/pool.py | Pool.add | def add(self, connection):
"""Add a new connection to the pool
:param connection: The connection to add to the pool
:type connection: psycopg2.extensions.connection
:raises: PoolFullError
"""
if id(connection) in self.connections:
raise ValueError('Connectio... | python | def add(self, connection):
"""Add a new connection to the pool
:param connection: The connection to add to the pool
:type connection: psycopg2.extensions.connection
:raises: PoolFullError
"""
if id(connection) in self.connections:
raise ValueError('Connectio... | [
"def",
"add",
"(",
"self",
",",
"connection",
")",
":",
"if",
"id",
"(",
"connection",
")",
"in",
"self",
".",
"connections",
":",
"raise",
"ValueError",
"(",
"'Connection already exists in pool'",
")",
"if",
"len",
"(",
"self",
".",
"connections",
")",
"=... | Add a new connection to the pool
:param connection: The connection to add to the pool
:type connection: psycopg2.extensions.connection
:raises: PoolFullError | [
"Add",
"a",
"new",
"connection",
"to",
"the",
"pool"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L154-L175 |
gmr/queries | queries/pool.py | Pool.busy_connections | def busy_connections(self):
"""Return a list of active/busy connections
:rtype: list
"""
return [c for c in self.connections.values()
if c.busy and not c.closed] | python | def busy_connections(self):
"""Return a list of active/busy connections
:rtype: list
"""
return [c for c in self.connections.values()
if c.busy and not c.closed] | [
"def",
"busy_connections",
"(",
"self",
")",
":",
"return",
"[",
"c",
"for",
"c",
"in",
"self",
".",
"connections",
".",
"values",
"(",
")",
"if",
"c",
".",
"busy",
"and",
"not",
"c",
".",
"closed",
"]"
] | Return a list of active/busy connections
:rtype: list | [
"Return",
"a",
"list",
"of",
"active",
"/",
"busy",
"connections"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L178-L185 |
gmr/queries | queries/pool.py | Pool.clean | def clean(self):
"""Clean the pool by removing any closed connections and if the pool's
idle has exceeded its idle TTL, remove all connections.
"""
LOGGER.debug('Cleaning the pool')
for connection in [self.connections[k] for k in self.connections if
se... | python | def clean(self):
"""Clean the pool by removing any closed connections and if the pool's
idle has exceeded its idle TTL, remove all connections.
"""
LOGGER.debug('Cleaning the pool')
for connection in [self.connections[k] for k in self.connections if
se... | [
"def",
"clean",
"(",
"self",
")",
":",
"LOGGER",
".",
"debug",
"(",
"'Cleaning the pool'",
")",
"for",
"connection",
"in",
"[",
"self",
".",
"connections",
"[",
"k",
"]",
"for",
"k",
"in",
"self",
".",
"connections",
"if",
"self",
".",
"connections",
"... | Clean the pool by removing any closed connections and if the pool's
idle has exceeded its idle TTL, remove all connections. | [
"Clean",
"the",
"pool",
"by",
"removing",
"any",
"closed",
"connections",
"and",
"if",
"the",
"pool",
"s",
"idle",
"has",
"exceeded",
"its",
"idle",
"TTL",
"remove",
"all",
"connections",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L187-L201 |
gmr/queries | queries/pool.py | Pool.close | def close(self):
"""Close the pool by closing and removing all of the connections"""
for cid in list(self.connections.keys()):
self.remove(self.connections[cid].handle)
LOGGER.debug('Pool %s closed', self.id) | python | def close(self):
"""Close the pool by closing and removing all of the connections"""
for cid in list(self.connections.keys()):
self.remove(self.connections[cid].handle)
LOGGER.debug('Pool %s closed', self.id) | [
"def",
"close",
"(",
"self",
")",
":",
"for",
"cid",
"in",
"list",
"(",
"self",
".",
"connections",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"remove",
"(",
"self",
".",
"connections",
"[",
"cid",
"]",
".",
"handle",
")",
"LOGGER",
".",
"debu... | Close the pool by closing and removing all of the connections | [
"Close",
"the",
"pool",
"by",
"closing",
"and",
"removing",
"all",
"of",
"the",
"connections"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L203-L207 |
gmr/queries | queries/pool.py | Pool.free | def free(self, connection):
"""Free the connection from use by the session that was using it.
:param connection: The connection to free
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError
"""
LOGGER.debug('Pool %s freeing connection %s', se... | python | def free(self, connection):
"""Free the connection from use by the session that was using it.
:param connection: The connection to free
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError
"""
LOGGER.debug('Pool %s freeing connection %s', se... | [
"def",
"free",
"(",
"self",
",",
"connection",
")",
":",
"LOGGER",
".",
"debug",
"(",
"'Pool %s freeing connection %s'",
",",
"self",
".",
"id",
",",
"id",
"(",
"connection",
")",
")",
"try",
":",
"self",
".",
"connection_handle",
"(",
"connection",
")",
... | Free the connection from use by the session that was using it.
:param connection: The connection to free
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError | [
"Free",
"the",
"connection",
"from",
"use",
"by",
"the",
"session",
"that",
"was",
"using",
"it",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L237-L254 |
gmr/queries | queries/pool.py | Pool.get | def get(self, session):
"""Return an idle connection and assign the session to the connection
:param queries.Session session: The session to assign
:rtype: psycopg2.extensions.connection
:raises: NoIdleConnectionsError
"""
idle = self.idle_connections
if idle:
... | python | def get(self, session):
"""Return an idle connection and assign the session to the connection
:param queries.Session session: The session to assign
:rtype: psycopg2.extensions.connection
:raises: NoIdleConnectionsError
"""
idle = self.idle_connections
if idle:
... | [
"def",
"get",
"(",
"self",
",",
"session",
")",
":",
"idle",
"=",
"self",
".",
"idle_connections",
"if",
"idle",
":",
"connection",
"=",
"idle",
".",
"pop",
"(",
"0",
")",
"connection",
".",
"lock",
"(",
"session",
")",
"if",
"self",
".",
"idle_start... | Return an idle connection and assign the session to the connection
:param queries.Session session: The session to assign
:rtype: psycopg2.extensions.connection
:raises: NoIdleConnectionsError | [
"Return",
"an",
"idle",
"connection",
"and",
"assign",
"the",
"session",
"to",
"the",
"connection"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L256-L272 |
gmr/queries | queries/pool.py | Pool.idle_connections | def idle_connections(self):
"""Return a list of idle connections
:rtype: list
"""
return [c for c in self.connections.values()
if not c.busy and not c.closed] | python | def idle_connections(self):
"""Return a list of idle connections
:rtype: list
"""
return [c for c in self.connections.values()
if not c.busy and not c.closed] | [
"def",
"idle_connections",
"(",
"self",
")",
":",
"return",
"[",
"c",
"for",
"c",
"in",
"self",
".",
"connections",
".",
"values",
"(",
")",
"if",
"not",
"c",
".",
"busy",
"and",
"not",
"c",
".",
"closed",
"]"
] | Return a list of idle connections
:rtype: list | [
"Return",
"a",
"list",
"of",
"idle",
"connections"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L284-L291 |
gmr/queries | queries/pool.py | Pool.lock | def lock(self, connection, session):
"""Explicitly lock the specified connection
:type connection: psycopg2.extensions.connection
:param connection: The connection to lock
:param queries.Session session: The session to hold the lock
"""
cid = id(connection)
try:... | python | def lock(self, connection, session):
"""Explicitly lock the specified connection
:type connection: psycopg2.extensions.connection
:param connection: The connection to lock
:param queries.Session session: The session to hold the lock
"""
cid = id(connection)
try:... | [
"def",
"lock",
"(",
"self",
",",
"connection",
",",
"session",
")",
":",
"cid",
"=",
"id",
"(",
"connection",
")",
"try",
":",
"self",
".",
"connection_handle",
"(",
"connection",
")",
".",
"lock",
"(",
"session",
")",
"except",
"KeyError",
":",
"raise... | Explicitly lock the specified connection
:type connection: psycopg2.extensions.connection
:param connection: The connection to lock
:param queries.Session session: The session to hold the lock | [
"Explicitly",
"lock",
"the",
"specified",
"connection"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L314-L331 |
gmr/queries | queries/pool.py | Pool.remove | def remove(self, connection):
"""Remove the connection from the pool
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError
:raises: ConnectionBusyError
"""
cid = id(connection)
if ci... | python | def remove(self, connection):
"""Remove the connection from the pool
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError
:raises: ConnectionBusyError
"""
cid = id(connection)
if ci... | [
"def",
"remove",
"(",
"self",
",",
"connection",
")",
":",
"cid",
"=",
"id",
"(",
"connection",
")",
"if",
"cid",
"not",
"in",
"self",
".",
"connections",
":",
"raise",
"ConnectionNotFoundError",
"(",
"self",
".",
"id",
",",
"cid",
")",
"self",
".",
... | Remove the connection from the pool
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError
:raises: ConnectionBusyError | [
"Remove",
"the",
"connection",
"from",
"the",
"pool"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L342-L357 |
gmr/queries | queries/pool.py | Pool.report | def report(self):
"""Return a report about the pool state and configuration.
:rtype: dict
"""
return {
'connections': {
'busy': len(self.busy_connections),
'closed': len(self.closed_connections),
'executing': len(self.executin... | python | def report(self):
"""Return a report about the pool state and configuration.
:rtype: dict
"""
return {
'connections': {
'busy': len(self.busy_connections),
'closed': len(self.closed_connections),
'executing': len(self.executin... | [
"def",
"report",
"(",
"self",
")",
":",
"return",
"{",
"'connections'",
":",
"{",
"'busy'",
":",
"len",
"(",
"self",
".",
"busy_connections",
")",
",",
"'closed'",
":",
"len",
"(",
"self",
".",
"closed_connections",
")",
",",
"'executing'",
":",
"len",
... | Return a report about the pool state and configuration.
:rtype: dict | [
"Return",
"a",
"report",
"about",
"the",
"pool",
"state",
"and",
"configuration",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L359-L383 |
gmr/queries | queries/pool.py | Pool.shutdown | def shutdown(self):
"""Forcefully shutdown the entire pool, closing all non-executing
connections.
:raises: ConnectionBusyError
"""
with self._lock:
for cid in list(self.connections.keys()):
if self.connections[cid].executing:
rai... | python | def shutdown(self):
"""Forcefully shutdown the entire pool, closing all non-executing
connections.
:raises: ConnectionBusyError
"""
with self._lock:
for cid in list(self.connections.keys()):
if self.connections[cid].executing:
rai... | [
"def",
"shutdown",
"(",
"self",
")",
":",
"with",
"self",
".",
"_lock",
":",
"for",
"cid",
"in",
"list",
"(",
"self",
".",
"connections",
".",
"keys",
"(",
")",
")",
":",
"if",
"self",
".",
"connections",
"[",
"cid",
"]",
".",
"executing",
":",
"... | Forcefully shutdown the entire pool, closing all non-executing
connections.
:raises: ConnectionBusyError | [
"Forcefully",
"shutdown",
"the",
"entire",
"pool",
"closing",
"all",
"non",
"-",
"executing",
"connections",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L385-L399 |
gmr/queries | queries/pool.py | PoolManager.add | def add(cls, pid, connection):
"""Add a new connection and session to a pool.
:param str pid: The pool id
:type connection: psycopg2.extensions.connection
:param connection: The connection to add to the pool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
... | python | def add(cls, pid, connection):
"""Add a new connection and session to a pool.
:param str pid: The pool id
:type connection: psycopg2.extensions.connection
:param connection: The connection to add to the pool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
... | [
"def",
"add",
"(",
"cls",
",",
"pid",
",",
"connection",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"add",
"(",
"connection",
")"
] | Add a new connection and session to a pool.
:param str pid: The pool id
:type connection: psycopg2.extensions.connection
:param connection: The connection to add to the pool | [
"Add",
"a",
"new",
"connection",
"and",
"session",
"to",
"a",
"pool",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L454-L464 |
gmr/queries | queries/pool.py | PoolManager.clean | def clean(cls, pid):
"""Clean the specified pool, removing any closed connections or
stale locks.
:param str pid: The pool id to clean
"""
with cls._lock:
try:
cls._ensure_pool_exists(pid)
except KeyError:
LOGGER.debug('Po... | python | def clean(cls, pid):
"""Clean the specified pool, removing any closed connections or
stale locks.
:param str pid: The pool id to clean
"""
with cls._lock:
try:
cls._ensure_pool_exists(pid)
except KeyError:
LOGGER.debug('Po... | [
"def",
"clean",
"(",
"cls",
",",
"pid",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"try",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"except",
"KeyError",
":",
"LOGGER",
".",
"debug",
"(",
"'Pool clean invoked against missing pool %s'",
",",
... | Clean the specified pool, removing any closed connections or
stale locks.
:param str pid: The pool id to clean | [
"Clean",
"the",
"specified",
"pool",
"removing",
"any",
"closed",
"connections",
"or",
"stale",
"locks",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L467-L481 |
gmr/queries | queries/pool.py | PoolManager.create | def create(cls, pid, idle_ttl=DEFAULT_IDLE_TTL, max_size=DEFAULT_MAX_SIZE,
time_method=None):
"""Create a new pool, with the ability to pass in values to override
the default idle TTL and the default maximum size.
A pool's idle TTL defines the amount of time that a pool can be op... | python | def create(cls, pid, idle_ttl=DEFAULT_IDLE_TTL, max_size=DEFAULT_MAX_SIZE,
time_method=None):
"""Create a new pool, with the ability to pass in values to override
the default idle TTL and the default maximum size.
A pool's idle TTL defines the amount of time that a pool can be op... | [
"def",
"create",
"(",
"cls",
",",
"pid",
",",
"idle_ttl",
"=",
"DEFAULT_IDLE_TTL",
",",
"max_size",
"=",
"DEFAULT_MAX_SIZE",
",",
"time_method",
"=",
"None",
")",
":",
"if",
"pid",
"in",
"cls",
".",
"_pools",
":",
"raise",
"KeyError",
"(",
"'Pool %s alread... | Create a new pool, with the ability to pass in values to override
the default idle TTL and the default maximum size.
A pool's idle TTL defines the amount of time that a pool can be open
without any sessions before it is removed.
A pool's max size defines the maximum number of connectio... | [
"Create",
"a",
"new",
"pool",
"with",
"the",
"ability",
"to",
"pass",
"in",
"values",
"to",
"override",
"the",
"default",
"idle",
"TTL",
"and",
"the",
"default",
"maximum",
"size",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L484-L507 |
gmr/queries | queries/pool.py | PoolManager.free | def free(cls, pid, connection):
"""Free a connection that was locked by a session
:param str pid: The pool ID
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
"""
with cls._lock:
LOGGER.debug('Freeing %s from pool ... | python | def free(cls, pid, connection):
"""Free a connection that was locked by a session
:param str pid: The pool ID
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
"""
with cls._lock:
LOGGER.debug('Freeing %s from pool ... | [
"def",
"free",
"(",
"cls",
",",
"pid",
",",
"connection",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"LOGGER",
".",
"debug",
"(",
"'Freeing %s from pool %s'",
",",
"id",
"(",
"connection",
")",
",",
"pid",
")",
"cls",
".",
"_ensure_pool_exists",
"(",
... | Free a connection that was locked by a session
:param str pid: The pool ID
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection | [
"Free",
"a",
"connection",
"that",
"was",
"locked",
"by",
"a",
"session"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L510-L521 |
gmr/queries | queries/pool.py | PoolManager.get | def get(cls, pid, session):
"""Get an idle, unused connection from the pool. Once a connection has
been retrieved, it will be marked as in-use until it is freed.
:param str pid: The pool ID
:param queries.Session session: The session to assign to the connection
:rtype: psycopg2.... | python | def get(cls, pid, session):
"""Get an idle, unused connection from the pool. Once a connection has
been retrieved, it will be marked as in-use until it is freed.
:param str pid: The pool ID
:param queries.Session session: The session to assign to the connection
:rtype: psycopg2.... | [
"def",
"get",
"(",
"cls",
",",
"pid",
",",
"session",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"return",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"get",
"(",
"session",
")"
] | Get an idle, unused connection from the pool. Once a connection has
been retrieved, it will be marked as in-use until it is freed.
:param str pid: The pool ID
:param queries.Session session: The session to assign to the connection
:rtype: psycopg2.extensions.connection | [
"Get",
"an",
"idle",
"unused",
"connection",
"from",
"the",
"pool",
".",
"Once",
"a",
"connection",
"has",
"been",
"retrieved",
"it",
"will",
"be",
"marked",
"as",
"in",
"-",
"use",
"until",
"it",
"is",
"freed",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L524-L535 |
gmr/queries | queries/pool.py | PoolManager.get_connection | def get_connection(cls, pid, connection):
"""Return the specified :class:`~queries.pool.Connection` from the
pool.
:param str pid: The pool ID
:param connection: The connection to return for
:type connection: psycopg2.extensions.connection
:rtype: queries.pool.Connection... | python | def get_connection(cls, pid, connection):
"""Return the specified :class:`~queries.pool.Connection` from the
pool.
:param str pid: The pool ID
:param connection: The connection to return for
:type connection: psycopg2.extensions.connection
:rtype: queries.pool.Connection... | [
"def",
"get_connection",
"(",
"cls",
",",
"pid",
",",
"connection",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"return",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"connection_handle",
"(",
"connection",
")"
] | Return the specified :class:`~queries.pool.Connection` from the
pool.
:param str pid: The pool ID
:param connection: The connection to return for
:type connection: psycopg2.extensions.connection
:rtype: queries.pool.Connection | [
"Return",
"the",
"specified",
":",
"class",
":",
"~queries",
".",
"pool",
".",
"Connection",
"from",
"the",
"pool",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L538-L549 |
gmr/queries | queries/pool.py | PoolManager.has_connection | def has_connection(cls, pid, connection):
"""Check to see if a pool has the specified connection
:param str pid: The pool ID
:param connection: The connection to check for
:type connection: psycopg2.extensions.connection
:rtype: bool
"""
with cls._lock:
... | python | def has_connection(cls, pid, connection):
"""Check to see if a pool has the specified connection
:param str pid: The pool ID
:param connection: The connection to check for
:type connection: psycopg2.extensions.connection
:rtype: bool
"""
with cls._lock:
... | [
"def",
"has_connection",
"(",
"cls",
",",
"pid",
",",
"connection",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"return",
"connection",
"in",
"cls",
".",
"_pools",
"[",
"pid",
"]"
] | Check to see if a pool has the specified connection
:param str pid: The pool ID
:param connection: The connection to check for
:type connection: psycopg2.extensions.connection
:rtype: bool | [
"Check",
"to",
"see",
"if",
"a",
"pool",
"has",
"the",
"specified",
"connection"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L552-L563 |
gmr/queries | queries/pool.py | PoolManager.has_idle_connection | def has_idle_connection(cls, pid):
"""Check to see if a pool has an idle connection
:param str pid: The pool ID
:rtype: bool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
return bool(cls._pools[pid].idle_connections) | python | def has_idle_connection(cls, pid):
"""Check to see if a pool has an idle connection
:param str pid: The pool ID
:rtype: bool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
return bool(cls._pools[pid].idle_connections) | [
"def",
"has_idle_connection",
"(",
"cls",
",",
"pid",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"return",
"bool",
"(",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"idle_connections",
")"
] | Check to see if a pool has an idle connection
:param str pid: The pool ID
:rtype: bool | [
"Check",
"to",
"see",
"if",
"a",
"pool",
"has",
"an",
"idle",
"connection"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L566-L575 |
gmr/queries | queries/pool.py | PoolManager.is_full | def is_full(cls, pid):
"""Return a bool indicating if the specified pool is full
:param str pid: The pool id
:rtype: bool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
return cls._pools[pid].is_full | python | def is_full(cls, pid):
"""Return a bool indicating if the specified pool is full
:param str pid: The pool id
:rtype: bool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
return cls._pools[pid].is_full | [
"def",
"is_full",
"(",
"cls",
",",
"pid",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"return",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"is_full"
] | Return a bool indicating if the specified pool is full
:param str pid: The pool id
:rtype: bool | [
"Return",
"a",
"bool",
"indicating",
"if",
"the",
"specified",
"pool",
"is",
"full"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L578-L587 |
gmr/queries | queries/pool.py | PoolManager.lock | def lock(cls, pid, connection, session):
"""Explicitly lock the specified connection in the pool
:param str pid: The pool id
:type connection: psycopg2.extensions.connection
:param connection: The connection to add to the pool
:param queries.Session session: The session to hold ... | python | def lock(cls, pid, connection, session):
"""Explicitly lock the specified connection in the pool
:param str pid: The pool id
:type connection: psycopg2.extensions.connection
:param connection: The connection to add to the pool
:param queries.Session session: The session to hold ... | [
"def",
"lock",
"(",
"cls",
",",
"pid",
",",
"connection",
",",
"session",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"lock",
"(",
"connection",
",",
"s... | Explicitly lock the specified connection in the pool
:param str pid: The pool id
:type connection: psycopg2.extensions.connection
:param connection: The connection to add to the pool
:param queries.Session session: The session to hold the lock | [
"Explicitly",
"lock",
"the",
"specified",
"connection",
"in",
"the",
"pool"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L590-L601 |
gmr/queries | queries/pool.py | PoolManager.remove | def remove(cls, pid):
"""Remove a pool, closing all connections
:param str pid: The pool ID
"""
with cls._lock:
cls._ensure_pool_exists(pid)
cls._pools[pid].close()
del cls._pools[pid] | python | def remove(cls, pid):
"""Remove a pool, closing all connections
:param str pid: The pool ID
"""
with cls._lock:
cls._ensure_pool_exists(pid)
cls._pools[pid].close()
del cls._pools[pid] | [
"def",
"remove",
"(",
"cls",
",",
"pid",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"close",
"(",
")",
"del",
"cls",
".",
"_pools",
"[",
"pid",
"]"
] | Remove a pool, closing all connections
:param str pid: The pool ID | [
"Remove",
"a",
"pool",
"closing",
"all",
"connections"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L604-L613 |
gmr/queries | queries/pool.py | PoolManager.remove_connection | def remove_connection(cls, pid, connection):
"""Remove a connection from the pool, closing it if is open.
:param str pid: The pool ID
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError
"""
... | python | def remove_connection(cls, pid, connection):
"""Remove a connection from the pool, closing it if is open.
:param str pid: The pool ID
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError
"""
... | [
"def",
"remove_connection",
"(",
"cls",
",",
"pid",
",",
"connection",
")",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"remove",
"(",
"connection",
")"
] | Remove a connection from the pool, closing it if is open.
:param str pid: The pool ID
:param connection: The connection to remove
:type connection: psycopg2.extensions.connection
:raises: ConnectionNotFoundError | [
"Remove",
"a",
"connection",
"from",
"the",
"pool",
"closing",
"it",
"if",
"is",
"open",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L616-L626 |
gmr/queries | queries/pool.py | PoolManager.set_idle_ttl | def set_idle_ttl(cls, pid, ttl):
"""Set the idle TTL for a pool, after which it will be destroyed.
:param str pid: The pool id
:param int ttl: The TTL for an idle pool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
cls._pools[pid].set_idle_ttl(ttl) | python | def set_idle_ttl(cls, pid, ttl):
"""Set the idle TTL for a pool, after which it will be destroyed.
:param str pid: The pool id
:param int ttl: The TTL for an idle pool
"""
with cls._lock:
cls._ensure_pool_exists(pid)
cls._pools[pid].set_idle_ttl(ttl) | [
"def",
"set_idle_ttl",
"(",
"cls",
",",
"pid",
",",
"ttl",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"set_idle_ttl",
"(",
"ttl",
")"
] | Set the idle TTL for a pool, after which it will be destroyed.
:param str pid: The pool id
:param int ttl: The TTL for an idle pool | [
"Set",
"the",
"idle",
"TTL",
"for",
"a",
"pool",
"after",
"which",
"it",
"will",
"be",
"destroyed",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L629-L638 |
gmr/queries | queries/pool.py | PoolManager.set_max_size | def set_max_size(cls, pid, size):
"""Set the maximum number of connections for the specified pool
:param str pid: The pool to set the size for
:param int size: The maximum number of connections
"""
with cls._lock:
cls._ensure_pool_exists(pid)
cls._pools[... | python | def set_max_size(cls, pid, size):
"""Set the maximum number of connections for the specified pool
:param str pid: The pool to set the size for
:param int size: The maximum number of connections
"""
with cls._lock:
cls._ensure_pool_exists(pid)
cls._pools[... | [
"def",
"set_max_size",
"(",
"cls",
",",
"pid",
",",
"size",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"set_max_size",
"(",
"size",
")"
] | Set the maximum number of connections for the specified pool
:param str pid: The pool to set the size for
:param int size: The maximum number of connections | [
"Set",
"the",
"maximum",
"number",
"of",
"connections",
"for",
"the",
"specified",
"pool"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L641-L650 |
gmr/queries | queries/pool.py | PoolManager.shutdown | def shutdown(cls):
"""Close all connections on in all pools"""
for pid in list(cls._pools.keys()):
cls._pools[pid].shutdown()
LOGGER.info('Shutdown complete, all pooled connections closed') | python | def shutdown(cls):
"""Close all connections on in all pools"""
for pid in list(cls._pools.keys()):
cls._pools[pid].shutdown()
LOGGER.info('Shutdown complete, all pooled connections closed') | [
"def",
"shutdown",
"(",
"cls",
")",
":",
"for",
"pid",
"in",
"list",
"(",
"cls",
".",
"_pools",
".",
"keys",
"(",
")",
")",
":",
"cls",
".",
"_pools",
"[",
"pid",
"]",
".",
"shutdown",
"(",
")",
"LOGGER",
".",
"info",
"(",
"'Shutdown complete, all ... | Close all connections on in all pools | [
"Close",
"all",
"connections",
"on",
"in",
"all",
"pools"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L653-L657 |
gmr/queries | queries/pool.py | PoolManager.size | def size(cls, pid):
"""Return the number of connections in the pool
:param str pid: The pool id
:rtype int
"""
with cls._lock:
cls._ensure_pool_exists(pid)
return len(cls._pools[pid]) | python | def size(cls, pid):
"""Return the number of connections in the pool
:param str pid: The pool id
:rtype int
"""
with cls._lock:
cls._ensure_pool_exists(pid)
return len(cls._pools[pid]) | [
"def",
"size",
"(",
"cls",
",",
"pid",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"cls",
".",
"_ensure_pool_exists",
"(",
"pid",
")",
"return",
"len",
"(",
"cls",
".",
"_pools",
"[",
"pid",
"]",
")"
] | Return the number of connections in the pool
:param str pid: The pool id
:rtype int | [
"Return",
"the",
"number",
"of",
"connections",
"in",
"the",
"pool"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L660-L669 |
gmr/queries | queries/pool.py | PoolManager.report | def report(cls):
"""Return the state of the all of the registered pools.
:rtype: dict
"""
return {
'timestamp': datetime.datetime.utcnow().isoformat(),
'process': os.getpid(),
'pools': dict([(i, p.report()) for i, p in cls._pools.items()])
} | python | def report(cls):
"""Return the state of the all of the registered pools.
:rtype: dict
"""
return {
'timestamp': datetime.datetime.utcnow().isoformat(),
'process': os.getpid(),
'pools': dict([(i, p.report()) for i, p in cls._pools.items()])
} | [
"def",
"report",
"(",
"cls",
")",
":",
"return",
"{",
"'timestamp'",
":",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
".",
"isoformat",
"(",
")",
",",
"'process'",
":",
"os",
".",
"getpid",
"(",
")",
",",
"'pools'",
":",
"dict",
"(",
"[",... | Return the state of the all of the registered pools.
:rtype: dict | [
"Return",
"the",
"state",
"of",
"the",
"all",
"of",
"the",
"registered",
"pools",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L672-L682 |
gmr/queries | queries/pool.py | PoolManager._maybe_remove_pool | def _maybe_remove_pool(cls, pid):
"""If the pool has no open connections, remove it
:param str pid: The pool id to clean
"""
if not len(cls._pools[pid]):
del cls._pools[pid] | python | def _maybe_remove_pool(cls, pid):
"""If the pool has no open connections, remove it
:param str pid: The pool id to clean
"""
if not len(cls._pools[pid]):
del cls._pools[pid] | [
"def",
"_maybe_remove_pool",
"(",
"cls",
",",
"pid",
")",
":",
"if",
"not",
"len",
"(",
"cls",
".",
"_pools",
"[",
"pid",
"]",
")",
":",
"del",
"cls",
".",
"_pools",
"[",
"pid",
"]"
] | If the pool has no open connections, remove it
:param str pid: The pool id to clean | [
"If",
"the",
"pool",
"has",
"no",
"open",
"connections",
"remove",
"it"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/pool.py#L697-L704 |
gmr/queries | queries/session.py | Session.callproc | def callproc(self, name, args=None):
"""Call a stored procedure on the server, returning the results in a
:py:class:`queries.Results` instance.
:param str name: The procedure name
:param list args: The list of arguments to pass in
:rtype: queries.Results
:raises: queries... | python | def callproc(self, name, args=None):
"""Call a stored procedure on the server, returning the results in a
:py:class:`queries.Results` instance.
:param str name: The procedure name
:param list args: The list of arguments to pass in
:rtype: queries.Results
:raises: queries... | [
"def",
"callproc",
"(",
"self",
",",
"name",
",",
"args",
"=",
"None",
")",
":",
"try",
":",
"self",
".",
"_cursor",
".",
"callproc",
"(",
"name",
",",
"args",
")",
"except",
"psycopg2",
".",
"Error",
"as",
"err",
":",
"self",
".",
"_incr_exceptions"... | Call a stored procedure on the server, returning the results in a
:py:class:`queries.Results` instance.
:param str name: The procedure name
:param list args: The list of arguments to pass in
:rtype: queries.Results
:raises: queries.DataError
:raises: queries.DatabaseErro... | [
"Call",
"a",
"stored",
"procedure",
"on",
"the",
"server",
"returning",
"the",
"results",
"in",
"a",
":",
"py",
":",
"class",
":",
"queries",
".",
"Results",
"instance",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/session.py#L105-L129 |
gmr/queries | queries/session.py | Session.close | def close(self):
"""Explicitly close the connection and remove it from the connection
pool if pooling is enabled. If the connection is already closed
:raises: psycopg2.InterfaceError
"""
if not self._conn:
raise psycopg2.InterfaceError('Connection not open')
... | python | def close(self):
"""Explicitly close the connection and remove it from the connection
pool if pooling is enabled. If the connection is already closed
:raises: psycopg2.InterfaceError
"""
if not self._conn:
raise psycopg2.InterfaceError('Connection not open')
... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_conn",
":",
"raise",
"psycopg2",
".",
"InterfaceError",
"(",
"'Connection not open'",
")",
"LOGGER",
".",
"info",
"(",
"'Closing connection %r in %s'",
",",
"self",
".",
"_conn",
",",
"self",... | Explicitly close the connection and remove it from the connection
pool if pooling is enabled. If the connection is already closed
:raises: psycopg2.InterfaceError | [
"Explicitly",
"close",
"the",
"connection",
"and",
"remove",
"it",
"from",
"the",
"connection",
"pool",
"if",
"pooling",
"is",
"enabled",
".",
"If",
"the",
"connection",
"is",
"already",
"closed"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/session.py#L131-L145 |
gmr/queries | queries/session.py | Session.pid | def pid(self):
"""Return the pool ID used for connection pooling.
:rtype: str
"""
return hashlib.md5(':'.join([self.__class__.__name__,
self._uri]).encode('utf-8')).hexdigest() | python | def pid(self):
"""Return the pool ID used for connection pooling.
:rtype: str
"""
return hashlib.md5(':'.join([self.__class__.__name__,
self._uri]).encode('utf-8')).hexdigest() | [
"def",
"pid",
"(",
"self",
")",
":",
"return",
"hashlib",
".",
"md5",
"(",
"':'",
".",
"join",
"(",
"[",
"self",
".",
"__class__",
".",
"__name__",
",",
"self",
".",
"_uri",
"]",
")",
".",
"encode",
"(",
"'utf-8'",
")",
")",
".",
"hexdigest",
"("... | Return the pool ID used for connection pooling.
:rtype: str | [
"Return",
"the",
"pool",
"ID",
"used",
"for",
"connection",
"pooling",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/session.py#L184-L191 |
gmr/queries | queries/session.py | Session.query | def query(self, sql, parameters=None):
"""A generator to issue a query on the server, mogrifying the
parameters against the sql statement. Results are returned as a
:py:class:`queries.Results` object which can act as an iterator and
has multiple ways to access the result data.
:... | python | def query(self, sql, parameters=None):
"""A generator to issue a query on the server, mogrifying the
parameters against the sql statement. Results are returned as a
:py:class:`queries.Results` object which can act as an iterator and
has multiple ways to access the result data.
:... | [
"def",
"query",
"(",
"self",
",",
"sql",
",",
"parameters",
"=",
"None",
")",
":",
"try",
":",
"self",
".",
"_cursor",
".",
"execute",
"(",
"sql",
",",
"parameters",
")",
"except",
"psycopg2",
".",
"Error",
"as",
"err",
":",
"self",
".",
"_incr_excep... | A generator to issue a query on the server, mogrifying the
parameters against the sql statement. Results are returned as a
:py:class:`queries.Results` object which can act as an iterator and
has multiple ways to access the result data.
:param str sql: The SQL statement
:param di... | [
"A",
"generator",
"to",
"issue",
"a",
"query",
"on",
"the",
"server",
"mogrifying",
"the",
"parameters",
"against",
"the",
"sql",
"statement",
".",
"Results",
"are",
"returned",
"as",
"a",
":",
"py",
":",
"class",
":",
"queries",
".",
"Results",
"object",
... | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/session.py#L193-L219 |
gmr/queries | queries/session.py | Session.set_encoding | def set_encoding(self, value=DEFAULT_ENCODING):
"""Set the client encoding for the session if the value specified
is different than the current client encoding.
:param str value: The encoding value to use
"""
if self._conn.encoding != value:
self._conn.set_client_en... | python | def set_encoding(self, value=DEFAULT_ENCODING):
"""Set the client encoding for the session if the value specified
is different than the current client encoding.
:param str value: The encoding value to use
"""
if self._conn.encoding != value:
self._conn.set_client_en... | [
"def",
"set_encoding",
"(",
"self",
",",
"value",
"=",
"DEFAULT_ENCODING",
")",
":",
"if",
"self",
".",
"_conn",
".",
"encoding",
"!=",
"value",
":",
"self",
".",
"_conn",
".",
"set_client_encoding",
"(",
"value",
")"
] | Set the client encoding for the session if the value specified
is different than the current client encoding.
:param str value: The encoding value to use | [
"Set",
"the",
"client",
"encoding",
"for",
"the",
"session",
"if",
"the",
"value",
"specified",
"is",
"different",
"than",
"the",
"current",
"client",
"encoding",
"."
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/session.py#L221-L229 |
gmr/queries | queries/session.py | Session._cleanup | def _cleanup(self):
"""Remove the connection from the stack, closing out the cursor"""
if self._cursor:
LOGGER.debug('Closing the cursor on %s', self.pid)
self._cursor.close()
self._cursor = None
if self._conn:
LOGGER.debug('Freeing %s in the pool... | python | def _cleanup(self):
"""Remove the connection from the stack, closing out the cursor"""
if self._cursor:
LOGGER.debug('Closing the cursor on %s', self.pid)
self._cursor.close()
self._cursor = None
if self._conn:
LOGGER.debug('Freeing %s in the pool... | [
"def",
"_cleanup",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cursor",
":",
"LOGGER",
".",
"debug",
"(",
"'Closing the cursor on %s'",
",",
"self",
".",
"pid",
")",
"self",
".",
"_cursor",
".",
"close",
"(",
")",
"self",
".",
"_cursor",
"=",
"None",
... | Remove the connection from the stack, closing out the cursor | [
"Remove",
"the",
"connection",
"from",
"the",
"stack",
"closing",
"out",
"the",
"cursor"
] | train | https://github.com/gmr/queries/blob/a68855013dc6aaf9ed7b6909a4701f8da8796a0a/queries/session.py#L258-L271 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.