repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.relink_all | def relink_all(cls, old_file, new_file):
"""Relink all object versions (for a given file) to a new file.
.. warning::
Use this method with great care.
"""
assert old_file.checksum == new_file.checksum
assert old_file.id
assert new_file.id
with db.ses... | python | def relink_all(cls, old_file, new_file):
"""Relink all object versions (for a given file) to a new file.
.. warning::
Use this method with great care.
"""
assert old_file.checksum == new_file.checksum
assert old_file.id
assert new_file.id
with db.ses... | [
"def",
"relink_all",
"(",
"cls",
",",
"old_file",
",",
"new_file",
")",
":",
"assert",
"old_file",
".",
"checksum",
"==",
"new_file",
".",
"checksum",
"assert",
"old_file",
".",
"id",
"assert",
"new_file",
".",
"id",
"with",
"db",
".",
"session",
".",
"b... | Relink all object versions (for a given file) to a new file.
.. warning::
Use this method with great care. | [
"Relink",
"all",
"object",
"versions",
"(",
"for",
"a",
"given",
"file",
")",
"to",
"a",
"new",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1245-L1258 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersionTag.copy | def copy(self, object_version=None, key=None):
"""Copy a tag to a given object version.
:param object_version: The object version instance to copy the tag to.
Default: current object version.
:param key: Key of destination tag.
Default: current tag key.
:return: ... | python | def copy(self, object_version=None, key=None):
"""Copy a tag to a given object version.
:param object_version: The object version instance to copy the tag to.
Default: current object version.
:param key: Key of destination tag.
Default: current tag key.
:return: ... | [
"def",
"copy",
"(",
"self",
",",
"object_version",
"=",
"None",
",",
"key",
"=",
"None",
")",
":",
"return",
"ObjectVersionTag",
".",
"create",
"(",
"self",
".",
"object_version",
"if",
"object_version",
"is",
"None",
"else",
"object_version",
",",
"key",
... | Copy a tag to a given object version.
:param object_version: The object version instance to copy the tag to.
Default: current object version.
:param key: Key of destination tag.
Default: current tag key.
:return: The copied object version tag. | [
"Copy",
"a",
"tag",
"to",
"a",
"given",
"object",
"version",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1298-L1311 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersionTag.get | def get(cls, object_version, key):
"""Get the tag object."""
return cls.query.filter_by(
version_id=as_object_version_id(object_version),
key=key,
).one_or_none() | python | def get(cls, object_version, key):
"""Get the tag object."""
return cls.query.filter_by(
version_id=as_object_version_id(object_version),
key=key,
).one_or_none() | [
"def",
"get",
"(",
"cls",
",",
"object_version",
",",
"key",
")",
":",
"return",
"cls",
".",
"query",
".",
"filter_by",
"(",
"version_id",
"=",
"as_object_version_id",
"(",
"object_version",
")",
",",
"key",
"=",
"key",
",",
")",
".",
"one_or_none",
"(",... | Get the tag object. | [
"Get",
"the",
"tag",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1314-L1319 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersionTag.create | def create(cls, object_version, key, value):
"""Create a new tag for a given object version."""
assert len(key) < 256
assert len(value) < 256
with db.session.begin_nested():
obj = cls(version_id=as_object_version_id(object_version),
key=key,
... | python | def create(cls, object_version, key, value):
"""Create a new tag for a given object version."""
assert len(key) < 256
assert len(value) < 256
with db.session.begin_nested():
obj = cls(version_id=as_object_version_id(object_version),
key=key,
... | [
"def",
"create",
"(",
"cls",
",",
"object_version",
",",
"key",
",",
"value",
")",
":",
"assert",
"len",
"(",
"key",
")",
"<",
"256",
"assert",
"len",
"(",
"value",
")",
"<",
"256",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
... | Create a new tag for a given object version. | [
"Create",
"a",
"new",
"tag",
"for",
"a",
"given",
"object",
"version",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1322-L1331 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersionTag.create_or_update | def create_or_update(cls, object_version, key, value):
"""Create or update a new tag for a given object version."""
assert len(key) < 256
assert len(value) < 256
obj = cls.get(object_version, key)
if obj:
obj.value = value
db.session.merge(obj)
els... | python | def create_or_update(cls, object_version, key, value):
"""Create or update a new tag for a given object version."""
assert len(key) < 256
assert len(value) < 256
obj = cls.get(object_version, key)
if obj:
obj.value = value
db.session.merge(obj)
els... | [
"def",
"create_or_update",
"(",
"cls",
",",
"object_version",
",",
"key",
",",
"value",
")",
":",
"assert",
"len",
"(",
"key",
")",
"<",
"256",
"assert",
"len",
"(",
"value",
")",
"<",
"256",
"obj",
"=",
"cls",
".",
"get",
"(",
"object_version",
",",... | Create or update a new tag for a given object version. | [
"Create",
"or",
"update",
"a",
"new",
"tag",
"for",
"a",
"given",
"object",
"version",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1334-L1344 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersionTag.get_value | def get_value(cls, object_version, key):
"""Get the tag value."""
obj = cls.get(object_version, key)
return obj.value if obj else None | python | def get_value(cls, object_version, key):
"""Get the tag value."""
obj = cls.get(object_version, key)
return obj.value if obj else None | [
"def",
"get_value",
"(",
"cls",
",",
"object_version",
",",
"key",
")",
":",
"obj",
"=",
"cls",
".",
"get",
"(",
"object_version",
",",
"key",
")",
"return",
"obj",
".",
"value",
"if",
"obj",
"else",
"None"
] | Get the tag value. | [
"Get",
"the",
"tag",
"value",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1347-L1350 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersionTag.delete | def delete(cls, object_version, key=None):
"""Delete tags.
:param object_version: The object version instance or id.
:param key: Key of the tag to delete.
Default: delete all tags.
"""
with db.session.begin_nested():
q = cls.query.filter_by(
... | python | def delete(cls, object_version, key=None):
"""Delete tags.
:param object_version: The object version instance or id.
:param key: Key of the tag to delete.
Default: delete all tags.
"""
with db.session.begin_nested():
q = cls.query.filter_by(
... | [
"def",
"delete",
"(",
"cls",
",",
"object_version",
",",
"key",
"=",
"None",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"q",
"=",
"cls",
".",
"query",
".",
"filter_by",
"(",
"version_id",
"=",
"as_object_version_id",
"(... | Delete tags.
:param object_version: The object version instance or id.
:param key: Key of the tag to delete.
Default: delete all tags. | [
"Delete",
"tags",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1353-L1365 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.last_part_number | def last_part_number(self):
"""Get last part number."""
return int(self.size / self.chunk_size) \
if self.size % self.chunk_size else \
int(self.size / self.chunk_size) - 1 | python | def last_part_number(self):
"""Get last part number."""
return int(self.size / self.chunk_size) \
if self.size % self.chunk_size else \
int(self.size / self.chunk_size) - 1 | [
"def",
"last_part_number",
"(",
"self",
")",
":",
"return",
"int",
"(",
"self",
".",
"size",
"/",
"self",
".",
"chunk_size",
")",
"if",
"self",
".",
"size",
"%",
"self",
".",
"chunk_size",
"else",
"int",
"(",
"self",
".",
"size",
"/",
"self",
".",
... | Get last part number. | [
"Get",
"last",
"part",
"number",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1435-L1439 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.is_valid_chunksize | def is_valid_chunksize(chunk_size):
"""Check if size is valid."""
min_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MIN']
max_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MAX']
return chunk_size >= min_csize and chunk_size <= max_csize | python | def is_valid_chunksize(chunk_size):
"""Check if size is valid."""
min_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MIN']
max_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MAX']
return chunk_size >= min_csize and chunk_size <= max_csize | [
"def",
"is_valid_chunksize",
"(",
"chunk_size",
")",
":",
"min_csize",
"=",
"current_app",
".",
"config",
"[",
"'FILES_REST_MULTIPART_CHUNKSIZE_MIN'",
"]",
"max_csize",
"=",
"current_app",
".",
"config",
"[",
"'FILES_REST_MULTIPART_CHUNKSIZE_MAX'",
"]",
"return",
"chunk... | Check if size is valid. | [
"Check",
"if",
"size",
"is",
"valid",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1452-L1456 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.is_valid_size | def is_valid_size(size, chunk_size):
"""Validate max theoretical size."""
min_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MIN']
max_size = \
chunk_size * current_app.config['FILES_REST_MULTIPART_MAX_PARTS']
return size > min_csize and size <= max_size | python | def is_valid_size(size, chunk_size):
"""Validate max theoretical size."""
min_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MIN']
max_size = \
chunk_size * current_app.config['FILES_REST_MULTIPART_MAX_PARTS']
return size > min_csize and size <= max_size | [
"def",
"is_valid_size",
"(",
"size",
",",
"chunk_size",
")",
":",
"min_csize",
"=",
"current_app",
".",
"config",
"[",
"'FILES_REST_MULTIPART_CHUNKSIZE_MIN'",
"]",
"max_size",
"=",
"chunk_size",
"*",
"current_app",
".",
"config",
"[",
"'FILES_REST_MULTIPART_MAX_PARTS'... | Validate max theoretical size. | [
"Validate",
"max",
"theoretical",
"size",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1459-L1464 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.expected_part_size | def expected_part_size(self, part_number):
"""Get expected part size for a particular part number."""
last_part = self.multipart.last_part_number
if part_number == last_part:
return self.multipart.last_part_size
elif part_number >= 0 and part_number < last_part:
... | python | def expected_part_size(self, part_number):
"""Get expected part size for a particular part number."""
last_part = self.multipart.last_part_number
if part_number == last_part:
return self.multipart.last_part_size
elif part_number >= 0 and part_number < last_part:
... | [
"def",
"expected_part_size",
"(",
"self",
",",
"part_number",
")",
":",
"last_part",
"=",
"self",
".",
"multipart",
".",
"last_part_number",
"if",
"part_number",
"==",
"last_part",
":",
"return",
"self",
".",
"multipart",
".",
"last_part_size",
"elif",
"part_num... | Get expected part size for a particular part number. | [
"Get",
"expected",
"part",
"size",
"for",
"a",
"particular",
"part",
"number",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1466-L1475 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.complete | def complete(self):
"""Mark a multipart object as complete."""
if Part.count(self) != self.last_part_number + 1:
raise MultipartMissingParts()
with db.session.begin_nested():
self.completed = True
self.file.readable = True
self.file.writable = Fal... | python | def complete(self):
"""Mark a multipart object as complete."""
if Part.count(self) != self.last_part_number + 1:
raise MultipartMissingParts()
with db.session.begin_nested():
self.completed = True
self.file.readable = True
self.file.writable = Fal... | [
"def",
"complete",
"(",
"self",
")",
":",
"if",
"Part",
".",
"count",
"(",
"self",
")",
"!=",
"self",
".",
"last_part_number",
"+",
"1",
":",
"raise",
"MultipartMissingParts",
"(",
")",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
... | Mark a multipart object as complete. | [
"Mark",
"a",
"multipart",
"object",
"as",
"complete",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1478-L1487 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.merge_parts | def merge_parts(self, version_id=None, **kwargs):
"""Merge parts into object version."""
self.file.update_checksum(**kwargs)
with db.session.begin_nested():
obj = ObjectVersion.create(
self.bucket,
self.key,
_file_id=self.file_id,
... | python | def merge_parts(self, version_id=None, **kwargs):
"""Merge parts into object version."""
self.file.update_checksum(**kwargs)
with db.session.begin_nested():
obj = ObjectVersion.create(
self.bucket,
self.key,
_file_id=self.file_id,
... | [
"def",
"merge_parts",
"(",
"self",
",",
"version_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"file",
".",
"update_checksum",
"(",
"*",
"*",
"kwargs",
")",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"obj",
... | Merge parts into object version. | [
"Merge",
"parts",
"into",
"object",
"version",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1490-L1501 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.delete | def delete(self):
"""Delete a multipart object."""
# Update bucket size.
self.bucket.size -= self.size
# Remove parts
Part.query_by_multipart(self).delete()
# Remove self
self.query.filter_by(upload_id=self.upload_id).delete() | python | def delete(self):
"""Delete a multipart object."""
# Update bucket size.
self.bucket.size -= self.size
# Remove parts
Part.query_by_multipart(self).delete()
# Remove self
self.query.filter_by(upload_id=self.upload_id).delete() | [
"def",
"delete",
"(",
"self",
")",
":",
"# Update bucket size.",
"self",
".",
"bucket",
".",
"size",
"-=",
"self",
".",
"size",
"# Remove parts",
"Part",
".",
"query_by_multipart",
"(",
"self",
")",
".",
"delete",
"(",
")",
"# Remove self",
"self",
".",
"q... | Delete a multipart object. | [
"Delete",
"a",
"multipart",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1503-L1510 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.create | def create(cls, bucket, key, size, chunk_size):
"""Create a new object in a bucket."""
bucket = as_bucket(bucket)
if bucket.locked:
raise BucketLockedError()
# Validate chunk size.
if not cls.is_valid_chunksize(chunk_size):
raise MultipartInvalidChunkSiz... | python | def create(cls, bucket, key, size, chunk_size):
"""Create a new object in a bucket."""
bucket = as_bucket(bucket)
if bucket.locked:
raise BucketLockedError()
# Validate chunk size.
if not cls.is_valid_chunksize(chunk_size):
raise MultipartInvalidChunkSiz... | [
"def",
"create",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"size",
",",
"chunk_size",
")",
":",
"bucket",
"=",
"as_bucket",
"(",
"bucket",
")",
"if",
"bucket",
".",
"locked",
":",
"raise",
"BucketLockedError",
"(",
")",
"# Validate chunk size.",
"if",
... | Create a new object in a bucket. | [
"Create",
"a",
"new",
"object",
"in",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1513-L1554 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.get | def get(cls, bucket, key, upload_id, with_completed=False):
"""Fetch a specific multipart object."""
q = cls.query.filter_by(
upload_id=upload_id,
bucket_id=as_bucket_id(bucket),
key=key,
)
if not with_completed:
q = q.filter(cls.completed.... | python | def get(cls, bucket, key, upload_id, with_completed=False):
"""Fetch a specific multipart object."""
q = cls.query.filter_by(
upload_id=upload_id,
bucket_id=as_bucket_id(bucket),
key=key,
)
if not with_completed:
q = q.filter(cls.completed.... | [
"def",
"get",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"upload_id",
",",
"with_completed",
"=",
"False",
")",
":",
"q",
"=",
"cls",
".",
"query",
".",
"filter_by",
"(",
"upload_id",
"=",
"upload_id",
",",
"bucket_id",
"=",
"as_bucket_id",
"(",
"buck... | Fetch a specific multipart object. | [
"Fetch",
"a",
"specific",
"multipart",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1557-L1567 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.query_expired | def query_expired(cls, dt, bucket=None):
"""Query all uncompleted multipart uploads."""
q = cls.query.filter(cls.created < dt).filter_by(completed=True)
if bucket:
q = q.filter(cls.bucket_id == as_bucket_id(bucket))
return q | python | def query_expired(cls, dt, bucket=None):
"""Query all uncompleted multipart uploads."""
q = cls.query.filter(cls.created < dt).filter_by(completed=True)
if bucket:
q = q.filter(cls.bucket_id == as_bucket_id(bucket))
return q | [
"def",
"query_expired",
"(",
"cls",
",",
"dt",
",",
"bucket",
"=",
"None",
")",
":",
"q",
"=",
"cls",
".",
"query",
".",
"filter",
"(",
"cls",
".",
"created",
"<",
"dt",
")",
".",
"filter_by",
"(",
"completed",
"=",
"True",
")",
"if",
"bucket",
"... | Query all uncompleted multipart uploads. | [
"Query",
"all",
"uncompleted",
"multipart",
"uploads",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1570-L1575 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | MultipartObject.query_by_bucket | def query_by_bucket(cls, bucket):
"""Query all uncompleted multipart uploads."""
return cls.query.filter(cls.bucket_id == as_bucket_id(bucket)) | python | def query_by_bucket(cls, bucket):
"""Query all uncompleted multipart uploads."""
return cls.query.filter(cls.bucket_id == as_bucket_id(bucket)) | [
"def",
"query_by_bucket",
"(",
"cls",
",",
"bucket",
")",
":",
"return",
"cls",
".",
"query",
".",
"filter",
"(",
"cls",
".",
"bucket_id",
"==",
"as_bucket_id",
"(",
"bucket",
")",
")"
] | Query all uncompleted multipart uploads. | [
"Query",
"all",
"uncompleted",
"multipart",
"uploads",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1578-L1580 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Part.end_byte | def end_byte(self):
"""Get end byte in file for this part."""
return min(
(self.part_number + 1) * self.multipart.chunk_size,
self.multipart.size
) | python | def end_byte(self):
"""Get end byte in file for this part."""
return min(
(self.part_number + 1) * self.multipart.chunk_size,
self.multipart.size
) | [
"def",
"end_byte",
"(",
"self",
")",
":",
"return",
"min",
"(",
"(",
"self",
".",
"part_number",
"+",
"1",
")",
"*",
"self",
".",
"multipart",
".",
"chunk_size",
",",
"self",
".",
"multipart",
".",
"size",
")"
] | Get end byte in file for this part. | [
"Get",
"end",
"byte",
"in",
"file",
"for",
"this",
"part",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1611-L1616 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Part.create | def create(cls, mp, part_number, stream=None, **kwargs):
"""Create a new part object in a multipart object."""
if part_number < 0 or part_number > mp.last_part_number:
raise MultipartInvalidPartNumber()
with db.session.begin_nested():
obj = cls(
multipart... | python | def create(cls, mp, part_number, stream=None, **kwargs):
"""Create a new part object in a multipart object."""
if part_number < 0 or part_number > mp.last_part_number:
raise MultipartInvalidPartNumber()
with db.session.begin_nested():
obj = cls(
multipart... | [
"def",
"create",
"(",
"cls",
",",
"mp",
",",
"part_number",
",",
"stream",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"part_number",
"<",
"0",
"or",
"part_number",
">",
"mp",
".",
"last_part_number",
":",
"raise",
"MultipartInvalidPartNumber",
... | Create a new part object in a multipart object. | [
"Create",
"a",
"new",
"part",
"object",
"in",
"a",
"multipart",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1624-L1637 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Part.get_or_none | def get_or_none(cls, mp, part_number):
"""Get part number."""
return cls.query.filter_by(
upload_id=mp.upload_id,
part_number=part_number
).one_or_none() | python | def get_or_none(cls, mp, part_number):
"""Get part number."""
return cls.query.filter_by(
upload_id=mp.upload_id,
part_number=part_number
).one_or_none() | [
"def",
"get_or_none",
"(",
"cls",
",",
"mp",
",",
"part_number",
")",
":",
"return",
"cls",
".",
"query",
".",
"filter_by",
"(",
"upload_id",
"=",
"mp",
".",
"upload_id",
",",
"part_number",
"=",
"part_number",
")",
".",
"one_or_none",
"(",
")"
] | Get part number. | [
"Get",
"part",
"number",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1640-L1645 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Part.get_or_create | def get_or_create(cls, mp, part_number):
"""Get or create a part."""
obj = cls.get_or_none(mp, part_number)
if obj:
return obj
return cls.create(mp, part_number) | python | def get_or_create(cls, mp, part_number):
"""Get or create a part."""
obj = cls.get_or_none(mp, part_number)
if obj:
return obj
return cls.create(mp, part_number) | [
"def",
"get_or_create",
"(",
"cls",
",",
"mp",
",",
"part_number",
")",
":",
"obj",
"=",
"cls",
".",
"get_or_none",
"(",
"mp",
",",
"part_number",
")",
"if",
"obj",
":",
"return",
"obj",
"return",
"cls",
".",
"create",
"(",
"mp",
",",
"part_number",
... | Get or create a part. | [
"Get",
"or",
"create",
"a",
"part",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1648-L1653 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Part.delete | def delete(cls, mp, part_number):
"""Get part number."""
return cls.query.filter_by(
upload_id=mp.upload_id,
part_number=part_number
).delete() | python | def delete(cls, mp, part_number):
"""Get part number."""
return cls.query.filter_by(
upload_id=mp.upload_id,
part_number=part_number
).delete() | [
"def",
"delete",
"(",
"cls",
",",
"mp",
",",
"part_number",
")",
":",
"return",
"cls",
".",
"query",
".",
"filter_by",
"(",
"upload_id",
"=",
"mp",
".",
"upload_id",
",",
"part_number",
"=",
"part_number",
")",
".",
"delete",
"(",
")"
] | Get part number. | [
"Get",
"part",
"number",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1656-L1661 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Part.query_by_multipart | def query_by_multipart(cls, multipart):
"""Get all parts for a specific multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A :class:`invenio_files_rest.models.Part` instance.
"""
upload_id = multipart.upload_i... | python | def query_by_multipart(cls, multipart):
"""Get all parts for a specific multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A :class:`invenio_files_rest.models.Part` instance.
"""
upload_id = multipart.upload_i... | [
"def",
"query_by_multipart",
"(",
"cls",
",",
"multipart",
")",
":",
"upload_id",
"=",
"multipart",
".",
"upload_id",
"if",
"isinstance",
"(",
"multipart",
",",
"MultipartObject",
")",
"else",
"multipart",
"return",
"cls",
".",
"query",
".",
"filter_by",
"(",
... | Get all parts for a specific multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A :class:`invenio_files_rest.models.Part` instance. | [
"Get",
"all",
"parts",
"for",
"a",
"specific",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1664-L1675 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Part.set_contents | def set_contents(self, stream, progress_callback=None):
"""Save contents of stream to part of file instance.
If a the MultipartObject is completed this methods raises an
``MultipartAlreadyCompleted`` exception.
:param stream: File-like stream.
:param size: Size of stream if kno... | python | def set_contents(self, stream, progress_callback=None):
"""Save contents of stream to part of file instance.
If a the MultipartObject is completed this methods raises an
``MultipartAlreadyCompleted`` exception.
:param stream: File-like stream.
:param size: Size of stream if kno... | [
"def",
"set_contents",
"(",
"self",
",",
"stream",
",",
"progress_callback",
"=",
"None",
")",
":",
"size",
",",
"checksum",
"=",
"self",
".",
"multipart",
".",
"file",
".",
"update_contents",
"(",
"stream",
",",
"seek",
"=",
"self",
".",
"start_byte",
"... | Save contents of stream to part of file instance.
If a the MultipartObject is completed this methods raises an
``MultipartAlreadyCompleted`` exception.
:param stream: File-like stream.
:param size: Size of stream if known.
:param chunk_size: Desired chunk size to read stream in... | [
"Save",
"contents",
"of",
"stream",
"to",
"part",
"of",
"file",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1683-L1699 |
django-cumulus/django-cumulus | cumulus/context_processors.py | cdn_url | def cdn_url(request):
"""
A context processor that exposes the full CDN URL in templates.
"""
cdn_url, ssl_url = _get_container_urls(CumulusStorage())
static_url = settings.STATIC_URL
return {
"CDN_URL": cdn_url + static_url,
"CDN_SSL_URL": ssl_url + static_url,
} | python | def cdn_url(request):
"""
A context processor that exposes the full CDN URL in templates.
"""
cdn_url, ssl_url = _get_container_urls(CumulusStorage())
static_url = settings.STATIC_URL
return {
"CDN_URL": cdn_url + static_url,
"CDN_SSL_URL": ssl_url + static_url,
} | [
"def",
"cdn_url",
"(",
"request",
")",
":",
"cdn_url",
",",
"ssl_url",
"=",
"_get_container_urls",
"(",
"CumulusStorage",
"(",
")",
")",
"static_url",
"=",
"settings",
".",
"STATIC_URL",
"return",
"{",
"\"CDN_URL\"",
":",
"cdn_url",
"+",
"static_url",
",",
"... | A context processor that exposes the full CDN URL in templates. | [
"A",
"context",
"processor",
"that",
"exposes",
"the",
"full",
"CDN",
"URL",
"in",
"templates",
"."
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/context_processors.py#L19-L29 |
django-cumulus/django-cumulus | cumulus/context_processors.py | static_cdn_url | def static_cdn_url(request):
"""
A context processor that exposes the full static CDN URL
as static URL in templates.
"""
cdn_url, ssl_url = _get_container_urls(CumulusStaticStorage())
static_url = settings.STATIC_URL
return {
"STATIC_URL": cdn_url + static_url,
"STATIC_SSL_... | python | def static_cdn_url(request):
"""
A context processor that exposes the full static CDN URL
as static URL in templates.
"""
cdn_url, ssl_url = _get_container_urls(CumulusStaticStorage())
static_url = settings.STATIC_URL
return {
"STATIC_URL": cdn_url + static_url,
"STATIC_SSL_... | [
"def",
"static_cdn_url",
"(",
"request",
")",
":",
"cdn_url",
",",
"ssl_url",
"=",
"_get_container_urls",
"(",
"CumulusStaticStorage",
"(",
")",
")",
"static_url",
"=",
"settings",
".",
"STATIC_URL",
"return",
"{",
"\"STATIC_URL\"",
":",
"cdn_url",
"+",
"static_... | A context processor that exposes the full static CDN URL
as static URL in templates. | [
"A",
"context",
"processor",
"that",
"exposes",
"the",
"full",
"static",
"CDN",
"URL",
"as",
"static",
"URL",
"in",
"templates",
"."
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/context_processors.py#L32-L44 |
swistakm/python-gmaps | src/gmaps/client.py | Client._serialize_parameters | def _serialize_parameters(parameters):
"""Serialize some parameters to match python native types with formats
specified in google api docs like:
* True/False -> "true"/"false",
* {"a": 1, "b":2} -> "a:1|b:2"
:type parameters: dict oif query parameters
"""
for ke... | python | def _serialize_parameters(parameters):
"""Serialize some parameters to match python native types with formats
specified in google api docs like:
* True/False -> "true"/"false",
* {"a": 1, "b":2} -> "a:1|b:2"
:type parameters: dict oif query parameters
"""
for ke... | [
"def",
"_serialize_parameters",
"(",
"parameters",
")",
":",
"for",
"key",
",",
"value",
"in",
"parameters",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"parameters",
"[",
"key",
"]",
"=",
"\"true\"",
"if",
"va... | Serialize some parameters to match python native types with formats
specified in google api docs like:
* True/False -> "true"/"false",
* {"a": 1, "b":2} -> "a:1|b:2"
:type parameters: dict oif query parameters | [
"Serialize",
"some",
"parameters",
"to",
"match",
"python",
"native",
"types",
"with",
"formats",
"specified",
"in",
"google",
"api",
"docs",
"like",
":",
"*",
"True",
"/",
"False",
"-",
">",
"true",
"/",
"false",
"*",
"{",
"a",
":",
"1",
"b",
":",
"... | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/client.py#L36-L53 |
swistakm/python-gmaps | src/gmaps/client.py | Client._make_request | def _make_request(self, url, parameters, result_key):
"""Make http/https request to Google API.
Method prepares url parameters, drops None values, and gets default
values. Finally makes request using protocol assigned to client and
returns data.
:param url: url part - specifies... | python | def _make_request(self, url, parameters, result_key):
"""Make http/https request to Google API.
Method prepares url parameters, drops None values, and gets default
values. Finally makes request using protocol assigned to client and
returns data.
:param url: url part - specifies... | [
"def",
"_make_request",
"(",
"self",
",",
"url",
",",
"parameters",
",",
"result_key",
")",
":",
"url",
"=",
"urlparse",
".",
"urljoin",
"(",
"urlparse",
".",
"urljoin",
"(",
"self",
".",
"base",
",",
"url",
")",
",",
"\"json\"",
")",
"# drop all None va... | Make http/https request to Google API.
Method prepares url parameters, drops None values, and gets default
values. Finally makes request using protocol assigned to client and
returns data.
:param url: url part - specifies API endpoint
:param parameters: dictionary of url parame... | [
"Make",
"http",
"/",
"https",
"request",
"to",
"Google",
"API",
"."
] | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/client.py#L55-L89 |
swistakm/python-gmaps | src/gmaps/geocoding.py | Geocoding.geocode | def geocode(self, address=None, components=None, region=None,
language=None, bounds=None, sensor=None):
"""Geocode given address. Geocoder can queried using address and/or
components. Components when used with address will restrict your query
to specific area. When used without a... | python | def geocode(self, address=None, components=None, region=None,
language=None, bounds=None, sensor=None):
"""Geocode given address. Geocoder can queried using address and/or
components. Components when used with address will restrict your query
to specific area. When used without a... | [
"def",
"geocode",
"(",
"self",
",",
"address",
"=",
"None",
",",
"components",
"=",
"None",
",",
"region",
"=",
"None",
",",
"language",
"=",
"None",
",",
"bounds",
"=",
"None",
",",
"sensor",
"=",
"None",
")",
":",
"# noqa",
"parameters",
"=",
"dict... | Geocode given address. Geocoder can queried using address and/or
components. Components when used with address will restrict your query
to specific area. When used without address they act like more precise
query. For full details see
`Google docs <https://developers.google.com/maps/docu... | [
"Geocode",
"given",
"address",
".",
"Geocoder",
"can",
"queried",
"using",
"address",
"and",
"/",
"or",
"components",
".",
"Components",
"when",
"used",
"with",
"address",
"will",
"restrict",
"your",
"query",
"to",
"specific",
"area",
".",
"When",
"used",
"w... | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/geocoding.py#L8-L37 |
swistakm/python-gmaps | src/gmaps/geocoding.py | Geocoding.reverse | def reverse(self, lat, lon, result_type=None, location_type=None,
language=None, sensor=None):
"""Reverse geocode with given latitude and longitude.
:param lat: latitude of queried point
:param lon: longitude of queried point
:param result_type: list of result_type for f... | python | def reverse(self, lat, lon, result_type=None, location_type=None,
language=None, sensor=None):
"""Reverse geocode with given latitude and longitude.
:param lat: latitude of queried point
:param lon: longitude of queried point
:param result_type: list of result_type for f... | [
"def",
"reverse",
"(",
"self",
",",
"lat",
",",
"lon",
",",
"result_type",
"=",
"None",
",",
"location_type",
"=",
"None",
",",
"language",
"=",
"None",
",",
"sensor",
"=",
"None",
")",
":",
"parameters",
"=",
"dict",
"(",
"latlng",
"=",
"\"%f,%f\"",
... | Reverse geocode with given latitude and longitude.
:param lat: latitude of queried point
:param lon: longitude of queried point
:param result_type: list of result_type for filtered search.
Accepted values:
https://developers.google.com/maps/documentation/geocoding/intr... | [
"Reverse",
"geocode",
"with",
"given",
"latitude",
"and",
"longitude",
"."
] | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/geocoding.py#L39-L65 |
inveniosoftware/invenio-files-rest | invenio_files_rest/ext.py | InvenioFilesREST.init_app | def init_app(self, app):
"""Flask application initialization."""
self.init_config(app)
if hasattr(app, 'cli'):
app.cli.add_command(files_cmd)
app.extensions['invenio-files-rest'] = _FilesRESTState(app) | python | def init_app(self, app):
"""Flask application initialization."""
self.init_config(app)
if hasattr(app, 'cli'):
app.cli.add_command(files_cmd)
app.extensions['invenio-files-rest'] = _FilesRESTState(app) | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"self",
".",
"init_config",
"(",
"app",
")",
"if",
"hasattr",
"(",
"app",
",",
"'cli'",
")",
":",
"app",
".",
"cli",
".",
"add_command",
"(",
"files_cmd",
")",
"app",
".",
"extensions",
"[",
"'i... | Flask application initialization. | [
"Flask",
"application",
"initialization",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/ext.py#L106-L111 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/base.py | check_sizelimit | def check_sizelimit(size_limit, bytes_written, total_size):
"""Check if size limit was exceeded.
:param size_limit: The size limit.
:param bytes_written: The total number of bytes written.
:param total_size: The total file size.
:raises invenio_files_rest.errors.UnexpectedFileSizeError: If the byte... | python | def check_sizelimit(size_limit, bytes_written, total_size):
"""Check if size limit was exceeded.
:param size_limit: The size limit.
:param bytes_written: The total number of bytes written.
:param total_size: The total file size.
:raises invenio_files_rest.errors.UnexpectedFileSizeError: If the byte... | [
"def",
"check_sizelimit",
"(",
"size_limit",
",",
"bytes_written",
",",
"total_size",
")",
":",
"if",
"size_limit",
"is",
"not",
"None",
"and",
"bytes_written",
">",
"size_limit",
":",
"desc",
"=",
"'File size limit exceeded.'",
"if",
"isinstance",
"(",
"size_limi... | Check if size limit was exceeded.
:param size_limit: The size limit.
:param bytes_written: The total number of bytes written.
:param total_size: The total file size.
:raises invenio_files_rest.errors.UnexpectedFileSizeError: If the bytes
written exceed the total size.
:raises invenio_files_... | [
"Check",
"if",
"size",
"limit",
"was",
"exceeded",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/base.py#L21-L40 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/base.py | FileStorage.send_file | def send_file(self, filename, mimetype=None, restricted=True,
checksum=None, trusted=False, chunk_size=None,
as_attachment=False):
"""Send the file to the client."""
try:
fp = self.open(mode='rb')
except Exception as e:
raise StorageErr... | python | def send_file(self, filename, mimetype=None, restricted=True,
checksum=None, trusted=False, chunk_size=None,
as_attachment=False):
"""Send the file to the client."""
try:
fp = self.open(mode='rb')
except Exception as e:
raise StorageErr... | [
"def",
"send_file",
"(",
"self",
",",
"filename",
",",
"mimetype",
"=",
"None",
",",
"restricted",
"=",
"True",
",",
"checksum",
"=",
"None",
",",
"trusted",
"=",
"False",
",",
"chunk_size",
"=",
"None",
",",
"as_attachment",
"=",
"False",
")",
":",
"t... | Send the file to the client. | [
"Send",
"the",
"file",
"to",
"the",
"client",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/base.py#L92-L124 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/base.py | FileStorage.checksum | def checksum(self, chunk_size=None, progress_callback=None, **kwargs):
"""Compute checksum of file."""
fp = self.open(mode='rb')
try:
value = self._compute_checksum(
fp, size=self._size, chunk_size=None,
progress_callback=progress_callback)
exc... | python | def checksum(self, chunk_size=None, progress_callback=None, **kwargs):
"""Compute checksum of file."""
fp = self.open(mode='rb')
try:
value = self._compute_checksum(
fp, size=self._size, chunk_size=None,
progress_callback=progress_callback)
exc... | [
"def",
"checksum",
"(",
"self",
",",
"chunk_size",
"=",
"None",
",",
"progress_callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"fp",
"=",
"self",
".",
"open",
"(",
"mode",
"=",
"'rb'",
")",
"try",
":",
"value",
"=",
"self",
".",
"_comput... | Compute checksum of file. | [
"Compute",
"checksum",
"of",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/base.py#L126-L137 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/base.py | FileStorage.copy | def copy(self, src, chunk_size=None, progress_callback=None):
"""Copy data from another file instance.
:param src: Source stream.
:param chunk_size: Chunk size to read from source stream.
"""
fp = src.open(mode='rb')
try:
return self.save(
fp,... | python | def copy(self, src, chunk_size=None, progress_callback=None):
"""Copy data from another file instance.
:param src: Source stream.
:param chunk_size: Chunk size to read from source stream.
"""
fp = src.open(mode='rb')
try:
return self.save(
fp,... | [
"def",
"copy",
"(",
"self",
",",
"src",
",",
"chunk_size",
"=",
"None",
",",
"progress_callback",
"=",
"None",
")",
":",
"fp",
"=",
"src",
".",
"open",
"(",
"mode",
"=",
"'rb'",
")",
"try",
":",
"return",
"self",
".",
"save",
"(",
"fp",
",",
"chu... | Copy data from another file instance.
:param src: Source stream.
:param chunk_size: Chunk size to read from source stream. | [
"Copy",
"data",
"from",
"another",
"file",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/base.py#L139-L150 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/base.py | FileStorage._compute_checksum | def _compute_checksum(self, stream, size=None, chunk_size=None,
progress_callback=None, **kwargs):
"""Get helper method to compute checksum from a stream.
Naive implementation that can be overwritten by subclasses in order to
provide more efficient implementation.
... | python | def _compute_checksum(self, stream, size=None, chunk_size=None,
progress_callback=None, **kwargs):
"""Get helper method to compute checksum from a stream.
Naive implementation that can be overwritten by subclasses in order to
provide more efficient implementation.
... | [
"def",
"_compute_checksum",
"(",
"self",
",",
"stream",
",",
"size",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"progress_callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"progress_callback",
"and",
"size",
":",
"progress_callback",
... | Get helper method to compute checksum from a stream.
Naive implementation that can be overwritten by subclasses in order to
provide more efficient implementation. | [
"Get",
"helper",
"method",
"to",
"compute",
"checksum",
"from",
"a",
"stream",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/base.py#L163-L185 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/base.py | FileStorage._write_stream | def _write_stream(self, src, dst, size=None, size_limit=None,
chunk_size=None, progress_callback=None):
"""Get helper to save stream from src to dest + compute checksum.
:param src: Source stream.
:param dst: Destination stream.
:param size: If provided, this exact... | python | def _write_stream(self, src, dst, size=None, size_limit=None,
chunk_size=None, progress_callback=None):
"""Get helper to save stream from src to dest + compute checksum.
:param src: Source stream.
:param dst: Destination stream.
:param size: If provided, this exact... | [
"def",
"_write_stream",
"(",
"self",
",",
"src",
",",
"dst",
",",
"size",
"=",
"None",
",",
"size_limit",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"progress_callback",
"=",
"None",
")",
":",
"chunk_size",
"=",
"chunk_size_or_default",
"(",
"chunk_... | Get helper to save stream from src to dest + compute checksum.
:param src: Source stream.
:param dst: Destination stream.
:param size: If provided, this exact amount of bytes will be
written to the destination file.
:param size_limit: ``FileSizeLimit`` instance to limit numb... | [
"Get",
"helper",
"to",
"save",
"stream",
"from",
"src",
"to",
"dest",
"+",
"compute",
"checksum",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/base.py#L187-L227 |
inveniosoftware/invenio-files-rest | invenio_files_rest/alembic/8ae99b034410_create_files_objecttags_table.py | upgrade | def upgrade():
"""Upgrade database."""
# table ObjectVersion: modify primary_key
if op.get_context().dialect.name == 'mysql':
Fk = 'fk_files_object_bucket_id_files_bucket'
op.execute(
'ALTER TABLE files_object '
'DROP FOREIGN KEY {0}, DROP PRIMARY KEY, '
'... | python | def upgrade():
"""Upgrade database."""
# table ObjectVersion: modify primary_key
if op.get_context().dialect.name == 'mysql':
Fk = 'fk_files_object_bucket_id_files_bucket'
op.execute(
'ALTER TABLE files_object '
'DROP FOREIGN KEY {0}, DROP PRIMARY KEY, '
'... | [
"def",
"upgrade",
"(",
")",
":",
"# table ObjectVersion: modify primary_key",
"if",
"op",
".",
"get_context",
"(",
")",
".",
"dialect",
".",
"name",
"==",
"'mysql'",
":",
"Fk",
"=",
"'fk_files_object_bucket_id_files_bucket'",
"op",
".",
"execute",
"(",
"'ALTER TAB... | Upgrade database. | [
"Upgrade",
"database",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/alembic/8ae99b034410_create_files_objecttags_table.py#L23-L63 |
inveniosoftware/invenio-files-rest | invenio_files_rest/alembic/8ae99b034410_create_files_objecttags_table.py | downgrade | def downgrade():
"""Downgrade database."""
# table ObjectVersionTag
op.drop_table('files_objecttags')
# table ObjectVersion: modify primary_key
if op.get_context().dialect.name == 'mysql':
op.execute(
'ALTER TABLE files_object '
'DROP INDEX uq_files_object_bucket_id, ... | python | def downgrade():
"""Downgrade database."""
# table ObjectVersionTag
op.drop_table('files_objecttags')
# table ObjectVersion: modify primary_key
if op.get_context().dialect.name == 'mysql':
op.execute(
'ALTER TABLE files_object '
'DROP INDEX uq_files_object_bucket_id, ... | [
"def",
"downgrade",
"(",
")",
":",
"# table ObjectVersionTag",
"op",
".",
"drop_table",
"(",
"'files_objecttags'",
")",
"# table ObjectVersion: modify primary_key",
"if",
"op",
".",
"get_context",
"(",
")",
".",
"dialect",
".",
"name",
"==",
"'mysql'",
":",
"op",
... | Downgrade database. | [
"Downgrade",
"database",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/alembic/8ae99b034410_create_files_objecttags_table.py#L66-L81 |
swistakm/python-gmaps | src/gmaps/timezone.py | unixtimestamp | def unixtimestamp(datetime):
"""Get unix time stamp from that given datetime. If datetime
is not tzaware then it's assumed that it is UTC
"""
epoch = UTC.localize(datetime.utcfromtimestamp(0))
if not datetime.tzinfo:
dt = UTC.localize(datetime)
else:
dt = UTC.normalize(datetime)
... | python | def unixtimestamp(datetime):
"""Get unix time stamp from that given datetime. If datetime
is not tzaware then it's assumed that it is UTC
"""
epoch = UTC.localize(datetime.utcfromtimestamp(0))
if not datetime.tzinfo:
dt = UTC.localize(datetime)
else:
dt = UTC.normalize(datetime)
... | [
"def",
"unixtimestamp",
"(",
"datetime",
")",
":",
"epoch",
"=",
"UTC",
".",
"localize",
"(",
"datetime",
".",
"utcfromtimestamp",
"(",
"0",
")",
")",
"if",
"not",
"datetime",
".",
"tzinfo",
":",
"dt",
"=",
"UTC",
".",
"localize",
"(",
"datetime",
")",... | Get unix time stamp from that given datetime. If datetime
is not tzaware then it's assumed that it is UTC | [
"Get",
"unix",
"time",
"stamp",
"from",
"that",
"given",
"datetime",
".",
"If",
"datetime",
"is",
"not",
"tzaware",
"then",
"it",
"s",
"assumed",
"that",
"it",
"is",
"UTC"
] | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/timezone.py#L14-L24 |
swistakm/python-gmaps | src/gmaps/timezone.py | Timezone.timezone | def timezone(self, lat, lon, datetime,
language=None, sensor=None):
"""Get time offset data for given location.
:param lat: Latitude of queried point
:param lon: Longitude of queried point
:param language: The language in which to return results. For full list
... | python | def timezone(self, lat, lon, datetime,
language=None, sensor=None):
"""Get time offset data for given location.
:param lat: Latitude of queried point
:param lon: Longitude of queried point
:param language: The language in which to return results. For full list
... | [
"def",
"timezone",
"(",
"self",
",",
"lat",
",",
"lon",
",",
"datetime",
",",
"language",
"=",
"None",
",",
"sensor",
"=",
"None",
")",
":",
"parameters",
"=",
"dict",
"(",
"location",
"=",
"\"%f,%f\"",
"%",
"(",
"lat",
",",
"lon",
")",
",",
"times... | Get time offset data for given location.
:param lat: Latitude of queried point
:param lon: Longitude of queried point
:param language: The language in which to return results. For full list
of laguages go to Google Maps API docs
:param datetime: Desired time. The Time Zone ... | [
"Get",
"time",
"offset",
"data",
"for",
"given",
"location",
"."
] | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/timezone.py#L30-L52 |
swistakm/python-gmaps | src/gmaps/polyline.py | encode | def encode(locations):
"""
:param locations: locations list containig (lat, lon) two-tuples
:return: encoded polyline string
"""
encoded = (
(_encode_value(lat, prev_lat), _encode_value(lon, prev_lon))
for (prev_lat, prev_lon), (lat, lon)
in _iterate_with_previous(locations, ... | python | def encode(locations):
"""
:param locations: locations list containig (lat, lon) two-tuples
:return: encoded polyline string
"""
encoded = (
(_encode_value(lat, prev_lat), _encode_value(lon, prev_lon))
for (prev_lat, prev_lon), (lat, lon)
in _iterate_with_previous(locations, ... | [
"def",
"encode",
"(",
"locations",
")",
":",
"encoded",
"=",
"(",
"(",
"_encode_value",
"(",
"lat",
",",
"prev_lat",
")",
",",
"_encode_value",
"(",
"lon",
",",
"prev_lon",
")",
")",
"for",
"(",
"prev_lat",
",",
"prev_lon",
")",
",",
"(",
"lat",
",",... | :param locations: locations list containig (lat, lon) two-tuples
:return: encoded polyline string | [
":",
"param",
"locations",
":",
"locations",
"list",
"containig",
"(",
"lat",
"lon",
")",
"two",
"-",
"tuples",
":",
"return",
":",
"encoded",
"polyline",
"string"
] | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/polyline.py#L13-L24 |
inveniosoftware/invenio-records-files | invenio_records_files/alembic/1ba76da94103_create_records_files_tables.py | upgrade | def upgrade():
"""Upgrade database."""
op.create_table(
'records_buckets',
sa.Column(
'record_id',
sqlalchemy_utils.types.uuid.UUIDType(),
nullable=False),
sa.Column(
'bucket_id',
sqlalchemy_utils.types.uuid.UUIDType(),
... | python | def upgrade():
"""Upgrade database."""
op.create_table(
'records_buckets',
sa.Column(
'record_id',
sqlalchemy_utils.types.uuid.UUIDType(),
nullable=False),
sa.Column(
'bucket_id',
sqlalchemy_utils.types.uuid.UUIDType(),
... | [
"def",
"upgrade",
"(",
")",
":",
"op",
".",
"create_table",
"(",
"'records_buckets'",
",",
"sa",
".",
"Column",
"(",
"'record_id'",
",",
"sqlalchemy_utils",
".",
"types",
".",
"uuid",
".",
"UUIDType",
"(",
")",
",",
"nullable",
"=",
"False",
")",
",",
... | Upgrade database. | [
"Upgrade",
"database",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/alembic/1ba76da94103_create_records_files_tables.py#L25-L40 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | _writable | def _writable(method):
"""Check that record is in defined status.
:param method: Method to be decorated.
:returns: Function decorated.
"""
@wraps(method)
def wrapper(self, *args, **kwargs):
"""Send record for indexing.
:returns: Execution result of the decorated method.
... | python | def _writable(method):
"""Check that record is in defined status.
:param method: Method to be decorated.
:returns: Function decorated.
"""
@wraps(method)
def wrapper(self, *args, **kwargs):
"""Send record for indexing.
:returns: Execution result of the decorated method.
... | [
"def",
"_writable",
"(",
"method",
")",
":",
"@",
"wraps",
"(",
"method",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Send record for indexing.\n\n :returns: Execution result of the decorated method.\n\n ... | Check that record is in defined status.
:param method: Method to be decorated.
:returns: Function decorated. | [
"Check",
"that",
"record",
"is",
"in",
"defined",
"status",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L80-L98 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FileObject.get_version | def get_version(self, version_id=None):
"""Return specific version ``ObjectVersion`` instance or HEAD.
:param version_id: Version ID of the object.
:returns: :class:`~invenio_files_rest.models.ObjectVersion` instance or
HEAD of the stored object.
"""
return ObjectVer... | python | def get_version(self, version_id=None):
"""Return specific version ``ObjectVersion`` instance or HEAD.
:param version_id: Version ID of the object.
:returns: :class:`~invenio_files_rest.models.ObjectVersion` instance or
HEAD of the stored object.
"""
return ObjectVer... | [
"def",
"get_version",
"(",
"self",
",",
"version_id",
"=",
"None",
")",
":",
"return",
"ObjectVersion",
".",
"get",
"(",
"bucket",
"=",
"self",
".",
"obj",
".",
"bucket",
",",
"key",
"=",
"self",
".",
"obj",
".",
"key",
",",
"version_id",
"=",
"versi... | Return specific version ``ObjectVersion`` instance or HEAD.
:param version_id: Version ID of the object.
:returns: :class:`~invenio_files_rest.models.ObjectVersion` instance or
HEAD of the stored object. | [
"Return",
"specific",
"version",
"ObjectVersion",
"instance",
"or",
"HEAD",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L32-L40 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FileObject.get | def get(self, key, default=None):
"""Proxy to ``obj``.
:param key: Metadata key which holds the value.
:returns: Metadata value of the specified key or default.
"""
if hasattr(self.obj, key):
return getattr(self.obj, key)
return self.data.get(key, default) | python | def get(self, key, default=None):
"""Proxy to ``obj``.
:param key: Metadata key which holds the value.
:returns: Metadata value of the specified key or default.
"""
if hasattr(self.obj, key):
return getattr(self.obj, key)
return self.data.get(key, default) | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"if",
"hasattr",
"(",
"self",
".",
"obj",
",",
"key",
")",
":",
"return",
"getattr",
"(",
"self",
".",
"obj",
",",
"key",
")",
"return",
"self",
".",
"data",
".",
"ge... | Proxy to ``obj``.
:param key: Metadata key which holds the value.
:returns: Metadata value of the specified key or default. | [
"Proxy",
"to",
"obj",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L42-L50 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FileObject.dumps | def dumps(self):
"""Create a dump of the metadata associated to the record."""
self.data.update({
'bucket': str(self.obj.bucket_id),
'checksum': self.obj.file.checksum,
'key': self.obj.key, # IMPORTANT it must stay here!
'size': self.obj.file.size,
... | python | def dumps(self):
"""Create a dump of the metadata associated to the record."""
self.data.update({
'bucket': str(self.obj.bucket_id),
'checksum': self.obj.file.checksum,
'key': self.obj.key, # IMPORTANT it must stay here!
'size': self.obj.file.size,
... | [
"def",
"dumps",
"(",
"self",
")",
":",
"self",
".",
"data",
".",
"update",
"(",
"{",
"'bucket'",
":",
"str",
"(",
"self",
".",
"obj",
".",
"bucket_id",
")",
",",
"'checksum'",
":",
"self",
".",
"obj",
".",
"file",
".",
"checksum",
",",
"'key'",
"... | Create a dump of the metadata associated to the record. | [
"Create",
"a",
"dump",
"of",
"the",
"metadata",
"associated",
"to",
"the",
"record",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L68-L77 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FilesIterator.flush | def flush(self):
"""Flush changes to record."""
files = self.dumps()
# Do not create `_files` when there has not been `_files` field before
# and the record still has no files attached.
if files or '_files' in self.record:
self.record['_files'] = files | python | def flush(self):
"""Flush changes to record."""
files = self.dumps()
# Do not create `_files` when there has not been `_files` field before
# and the record still has no files attached.
if files or '_files' in self.record:
self.record['_files'] = files | [
"def",
"flush",
"(",
"self",
")",
":",
"files",
"=",
"self",
".",
"dumps",
"(",
")",
"# Do not create `_files` when there has not been `_files` field before",
"# and the record still has no files attached.",
"if",
"files",
"or",
"'_files'",
"in",
"self",
".",
"record",
... | Flush changes to record. | [
"Flush",
"changes",
"to",
"record",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L150-L156 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FilesIterator.sort_by | def sort_by(self, *ids):
"""Update files order.
:param ids: List of ids specifying the final status of the list.
"""
# Support sorting by file_ids or keys.
files = {str(f_.file_id): f_.key for f_ in self}
# self.record['_files'] = [{'key': files.get(id_, id_)} for id_ in... | python | def sort_by(self, *ids):
"""Update files order.
:param ids: List of ids specifying the final status of the list.
"""
# Support sorting by file_ids or keys.
files = {str(f_.file_id): f_.key for f_ in self}
# self.record['_files'] = [{'key': files.get(id_, id_)} for id_ in... | [
"def",
"sort_by",
"(",
"self",
",",
"*",
"ids",
")",
":",
"# Support sorting by file_ids or keys.",
"files",
"=",
"{",
"str",
"(",
"f_",
".",
"file_id",
")",
":",
"f_",
".",
"key",
"for",
"f_",
"in",
"self",
"}",
"# self.record['_files'] = [{'key': files.get(i... | Update files order.
:param ids: List of ids specifying the final status of the list. | [
"Update",
"files",
"order",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L180-L192 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FilesIterator.rename | def rename(self, old_key, new_key):
"""Rename a file.
:param old_key: Old key that holds the object.
:param new_key: New key that will hold the object.
:returns: The object that has been renamed.
"""
assert new_key not in self
assert old_key != new_key
f... | python | def rename(self, old_key, new_key):
"""Rename a file.
:param old_key: Old key that holds the object.
:param new_key: New key that will hold the object.
:returns: The object that has been renamed.
"""
assert new_key not in self
assert old_key != new_key
f... | [
"def",
"rename",
"(",
"self",
",",
"old_key",
",",
"new_key",
")",
":",
"assert",
"new_key",
"not",
"in",
"self",
"assert",
"old_key",
"!=",
"new_key",
"file_",
"=",
"self",
"[",
"old_key",
"]",
"old_data",
"=",
"self",
".",
"filesmap",
"[",
"old_key",
... | Rename a file.
:param old_key: Old key that holds the object.
:param new_key: New key that will hold the object.
:returns: The object that has been renamed. | [
"Rename",
"a",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L195-L218 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FilesIterator.dumps | def dumps(self, bucket=None):
"""Serialize files from a bucket.
:param bucket: Instance of files
:class:`invenio_files_rest.models.Bucket`. (Default:
``self.bucket``)
:returns: List of serialized files.
"""
return [
self.file_cls(o, self.files... | python | def dumps(self, bucket=None):
"""Serialize files from a bucket.
:param bucket: Instance of files
:class:`invenio_files_rest.models.Bucket`. (Default:
``self.bucket``)
:returns: List of serialized files.
"""
return [
self.file_cls(o, self.files... | [
"def",
"dumps",
"(",
"self",
",",
"bucket",
"=",
"None",
")",
":",
"return",
"[",
"self",
".",
"file_cls",
"(",
"o",
",",
"self",
".",
"filesmap",
".",
"get",
"(",
"o",
".",
"key",
",",
"{",
"}",
")",
")",
".",
"dumps",
"(",
")",
"for",
"o",
... | Serialize files from a bucket.
:param bucket: Instance of files
:class:`invenio_files_rest.models.Bucket`. (Default:
``self.bucket``)
:returns: List of serialized files. | [
"Serialize",
"files",
"from",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L220-L231 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FilesMixin.files | def files(self):
"""Get files iterator.
:returns: Files iterator.
"""
if self.model is None:
raise MissingModelError()
records_buckets = RecordsBuckets.query.filter_by(
record_id=self.id).first()
if not records_buckets:
bucket = self... | python | def files(self):
"""Get files iterator.
:returns: Files iterator.
"""
if self.model is None:
raise MissingModelError()
records_buckets = RecordsBuckets.query.filter_by(
record_id=self.id).first()
if not records_buckets:
bucket = self... | [
"def",
"files",
"(",
"self",
")",
":",
"if",
"self",
".",
"model",
"is",
"None",
":",
"raise",
"MissingModelError",
"(",
")",
"records_buckets",
"=",
"RecordsBuckets",
".",
"query",
".",
"filter_by",
"(",
"record_id",
"=",
"self",
".",
"id",
")",
".",
... | Get files iterator.
:returns: Files iterator. | [
"Get",
"files",
"iterator",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L263-L282 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | FilesMixin.files | def files(self, data):
"""Set files from data."""
current_files = self.files
if current_files:
raise RuntimeError('Can not update existing files.')
for key in data:
current_files[key] = data[key] | python | def files(self, data):
"""Set files from data."""
current_files = self.files
if current_files:
raise RuntimeError('Can not update existing files.')
for key in data:
current_files[key] = data[key] | [
"def",
"files",
"(",
"self",
",",
"data",
")",
":",
"current_files",
"=",
"self",
".",
"files",
"if",
"current_files",
":",
"raise",
"RuntimeError",
"(",
"'Can not update existing files.'",
")",
"for",
"key",
"in",
"data",
":",
"current_files",
"[",
"key",
"... | Set files from data. | [
"Set",
"files",
"from",
"data",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L285-L291 |
inveniosoftware/invenio-records-files | invenio_records_files/api.py | Record.delete | def delete(self, force=False):
"""Delete a record and also remove the RecordsBuckets if necessary.
:param force: True to remove also the
:class:`~invenio_records_files.models.RecordsBuckets` object.
:returns: Deleted record.
"""
if force:
RecordsBuckets.q... | python | def delete(self, force=False):
"""Delete a record and also remove the RecordsBuckets if necessary.
:param force: True to remove also the
:class:`~invenio_records_files.models.RecordsBuckets` object.
:returns: Deleted record.
"""
if force:
RecordsBuckets.q... | [
"def",
"delete",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"force",
":",
"RecordsBuckets",
".",
"query",
".",
"filter_by",
"(",
"record",
"=",
"self",
".",
"model",
",",
"bucket",
"=",
"self",
".",
"files",
".",
"bucket",
")",
".",
"... | Delete a record and also remove the RecordsBuckets if necessary.
:param force: True to remove also the
:class:`~invenio_records_files.models.RecordsBuckets` object.
:returns: Deleted record. | [
"Delete",
"a",
"record",
"and",
"also",
"remove",
"the",
"RecordsBuckets",
"if",
"necessary",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/api.py#L297-L309 |
inveniosoftware/invenio-records-files | invenio_records_files/models.py | RecordsBuckets.create | def create(cls, record, bucket):
"""Create a new RecordsBuckets and adds it to the session.
:param record: Record used to relate with the ``Bucket``.
:param bucket: Bucket used to relate with the ``Record``.
:returns: The :class:`~invenio_records_files.models.RecordsBuckets`
... | python | def create(cls, record, bucket):
"""Create a new RecordsBuckets and adds it to the session.
:param record: Record used to relate with the ``Bucket``.
:param bucket: Bucket used to relate with the ``Record``.
:returns: The :class:`~invenio_records_files.models.RecordsBuckets`
... | [
"def",
"create",
"(",
"cls",
",",
"record",
",",
"bucket",
")",
":",
"rb",
"=",
"cls",
"(",
"record",
"=",
"record",
",",
"bucket",
"=",
"bucket",
")",
"db",
".",
"session",
".",
"add",
"(",
"rb",
")",
"return",
"rb"
] | Create a new RecordsBuckets and adds it to the session.
:param record: Record used to relate with the ``Bucket``.
:param bucket: Bucket used to relate with the ``Record``.
:returns: The :class:`~invenio_records_files.models.RecordsBuckets`
object created. | [
"Create",
"a",
"new",
"RecordsBuckets",
"and",
"adds",
"it",
"to",
"the",
"session",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/models.py#L48-L58 |
inveniosoftware/invenio-records-files | invenio_records_files/utils.py | sorted_files_from_bucket | def sorted_files_from_bucket(bucket, keys=None):
"""Return files from bucket sorted by given keys.
:param bucket: :class:`~invenio_files_rest.models.Bucket` containing the
files.
:param keys: Keys order to be used.
:returns: Sorted list of bucket items.
"""
keys = keys or []
total =... | python | def sorted_files_from_bucket(bucket, keys=None):
"""Return files from bucket sorted by given keys.
:param bucket: :class:`~invenio_files_rest.models.Bucket` containing the
files.
:param keys: Keys order to be used.
:returns: Sorted list of bucket items.
"""
keys = keys or []
total =... | [
"def",
"sorted_files_from_bucket",
"(",
"bucket",
",",
"keys",
"=",
"None",
")",
":",
"keys",
"=",
"keys",
"or",
"[",
"]",
"total",
"=",
"len",
"(",
"keys",
")",
"sortby",
"=",
"dict",
"(",
"zip",
"(",
"keys",
",",
"range",
"(",
"total",
")",
")",
... | Return files from bucket sorted by given keys.
:param bucket: :class:`~invenio_files_rest.models.Bucket` containing the
files.
:param keys: Keys order to be used.
:returns: Sorted list of bucket items. | [
"Return",
"files",
"from",
"bucket",
"sorted",
"by",
"given",
"keys",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/utils.py#L19-L31 |
inveniosoftware/invenio-records-files | invenio_records_files/utils.py | record_file_factory | def record_file_factory(pid, record, filename):
"""Get file from a record.
:param pid: Not used. It keeps the function signature.
:param record: Record which contains the files.
:param filename: Name of the file to be returned.
:returns: File object or ``None`` if not found.
"""
try:
... | python | def record_file_factory(pid, record, filename):
"""Get file from a record.
:param pid: Not used. It keeps the function signature.
:param record: Record which contains the files.
:param filename: Name of the file to be returned.
:returns: File object or ``None`` if not found.
"""
try:
... | [
"def",
"record_file_factory",
"(",
"pid",
",",
"record",
",",
"filename",
")",
":",
"try",
":",
"if",
"not",
"(",
"hasattr",
"(",
"record",
",",
"'files'",
")",
"and",
"record",
".",
"files",
")",
":",
"return",
"None",
"except",
"MissingModelError",
":"... | Get file from a record.
:param pid: Not used. It keeps the function signature.
:param record: Record which contains the files.
:param filename: Name of the file to be returned.
:returns: File object or ``None`` if not found. | [
"Get",
"file",
"from",
"a",
"record",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/utils.py#L34-L51 |
inveniosoftware/invenio-records-files | invenio_records_files/utils.py | file_download_ui | def file_download_ui(pid, record, _record_file_factory=None, **kwargs):
"""File download view for a given record.
Plug this method into your ``RECORDS_UI_ENDPOINTS`` configuration:
.. code-block:: python
RECORDS_UI_ENDPOINTS = dict(
recid=dict(
# ...
ro... | python | def file_download_ui(pid, record, _record_file_factory=None, **kwargs):
"""File download view for a given record.
Plug this method into your ``RECORDS_UI_ENDPOINTS`` configuration:
.. code-block:: python
RECORDS_UI_ENDPOINTS = dict(
recid=dict(
# ...
ro... | [
"def",
"file_download_ui",
"(",
"pid",
",",
"record",
",",
"_record_file_factory",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_record_file_factory",
"=",
"_record_file_factory",
"or",
"record_file_factory",
"# Extract file from record.",
"fileobj",
"=",
"_record... | File download view for a given record.
Plug this method into your ``RECORDS_UI_ENDPOINTS`` configuration:
.. code-block:: python
RECORDS_UI_ENDPOINTS = dict(
recid=dict(
# ...
route='/records/<pid_value/files/<filename>',
view_imp='invenio_r... | [
"File",
"download",
"view",
"for",
"a",
"given",
"record",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/utils.py#L54-L101 |
inveniosoftware/invenio-records-files | invenio_records_files/links.py | default_bucket_link_factory | def default_bucket_link_factory(pid):
"""Factory for record bucket generation."""
try:
record = Record.get_record(pid.get_assigned_object())
bucket = record.files.bucket
return url_for('invenio_files_rest.bucket_api',
bucket_id=bucket.id, _external=True)
excep... | python | def default_bucket_link_factory(pid):
"""Factory for record bucket generation."""
try:
record = Record.get_record(pid.get_assigned_object())
bucket = record.files.bucket
return url_for('invenio_files_rest.bucket_api',
bucket_id=bucket.id, _external=True)
excep... | [
"def",
"default_bucket_link_factory",
"(",
"pid",
")",
":",
"try",
":",
"record",
"=",
"Record",
".",
"get_record",
"(",
"pid",
".",
"get_assigned_object",
"(",
")",
")",
"bucket",
"=",
"record",
".",
"files",
".",
"bucket",
"return",
"url_for",
"(",
"'inv... | Factory for record bucket generation. | [
"Factory",
"for",
"record",
"bucket",
"generation",
"."
] | train | https://github.com/inveniosoftware/invenio-records-files/blob/c410eba986ea43be7e97082d5dcbbdc19ccec39c/invenio_records_files/links.py#L16-L25 |
timothycrosley/deprecated.frosted | frosted/reporter.py | Reporter.flake | def flake(self, message):
"""Print an error message to stdout."""
self.stdout.write(str(message))
self.stdout.write('\n') | python | def flake(self, message):
"""Print an error message to stdout."""
self.stdout.write(str(message))
self.stdout.write('\n') | [
"def",
"flake",
"(",
"self",
",",
"message",
")",
":",
"self",
".",
"stdout",
".",
"write",
"(",
"str",
"(",
"message",
")",
")",
"self",
".",
"stdout",
".",
"write",
"(",
"'\\n'",
")"
] | Print an error message to stdout. | [
"Print",
"an",
"error",
"message",
"to",
"stdout",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/reporter.py#L34-L37 |
timothycrosley/deprecated.frosted | frosted/checker.py | node_name | def node_name(node):
"""
Convenience function: Returns node.id, or node.name, or None
"""
return hasattr(node, 'id') and node.id or hasattr(node, 'name') and node.name | python | def node_name(node):
"""
Convenience function: Returns node.id, or node.name, or None
"""
return hasattr(node, 'id') and node.id or hasattr(node, 'name') and node.name | [
"def",
"node_name",
"(",
"node",
")",
":",
"return",
"hasattr",
"(",
"node",
",",
"'id'",
")",
"and",
"node",
".",
"id",
"or",
"hasattr",
"(",
"node",
",",
"'name'",
")",
"and",
"node",
".",
"name"
] | Convenience function: Returns node.id, or node.name, or None | [
"Convenience",
"function",
":",
"Returns",
"node",
".",
"id",
"or",
"node",
".",
"name",
"or",
"None"
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L39-L43 |
timothycrosley/deprecated.frosted | frosted/checker.py | ExportBinding.names | def names(self):
"""Return a list of the names referenced by this binding."""
names = []
if isinstance(self.source, ast.List):
for node in self.source.elts:
if isinstance(node, ast.Str):
names.append(node.s)
return names | python | def names(self):
"""Return a list of the names referenced by this binding."""
names = []
if isinstance(self.source, ast.List):
for node in self.source.elts:
if isinstance(node, ast.Str):
names.append(node.s)
return names | [
"def",
"names",
"(",
"self",
")",
":",
"names",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"self",
".",
"source",
",",
"ast",
".",
"List",
")",
":",
"for",
"node",
"in",
"self",
".",
"source",
".",
"elts",
":",
"if",
"isinstance",
"(",
"node",
",",
... | Return a list of the names referenced by this binding. | [
"Return",
"a",
"list",
"of",
"the",
"names",
"referenced",
"by",
"this",
"binding",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L128-L135 |
timothycrosley/deprecated.frosted | frosted/checker.py | FunctionScope.unusedAssignments | def unusedAssignments(self):
"""Return a generator for the assignments which have not been used."""
for name, binding in self.items():
if (not binding.used and name not in self.globals
and not self.uses_locals
and isinstance(binding, Assignment)):
... | python | def unusedAssignments(self):
"""Return a generator for the assignments which have not been used."""
for name, binding in self.items():
if (not binding.used and name not in self.globals
and not self.uses_locals
and isinstance(binding, Assignment)):
... | [
"def",
"unusedAssignments",
"(",
"self",
")",
":",
"for",
"name",
",",
"binding",
"in",
"self",
".",
"items",
"(",
")",
":",
"if",
"(",
"not",
"binding",
".",
"used",
"and",
"name",
"not",
"in",
"self",
".",
"globals",
"and",
"not",
"self",
".",
"u... | Return a generator for the assignments which have not been used. | [
"Return",
"a",
"generator",
"for",
"the",
"assignments",
"which",
"have",
"not",
"been",
"used",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L159-L165 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.check_plugins | def check_plugins(self):
""" collect plugins from entry point 'frosted.plugins'
and run their check() method, passing the filename
"""
checkers = {}
for ep in pkg_resources.iter_entry_points(group='frosted.plugins'):
checkers.update({ep.name: ep.load()})
for... | python | def check_plugins(self):
""" collect plugins from entry point 'frosted.plugins'
and run their check() method, passing the filename
"""
checkers = {}
for ep in pkg_resources.iter_entry_points(group='frosted.plugins'):
checkers.update({ep.name: ep.load()})
for... | [
"def",
"check_plugins",
"(",
"self",
")",
":",
"checkers",
"=",
"{",
"}",
"for",
"ep",
"in",
"pkg_resources",
".",
"iter_entry_points",
"(",
"group",
"=",
"'frosted.plugins'",
")",
":",
"checkers",
".",
"update",
"(",
"{",
"ep",
".",
"name",
":",
"ep",
... | collect plugins from entry point 'frosted.plugins'
and run their check() method, passing the filename | [
"collect",
"plugins",
"from",
"entry",
"point",
"frosted",
".",
"plugins"
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L276-L289 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.defer_function | def defer_function(self, callable):
"""Schedule a function handler to be called just before completion.
This is used for handling function bodies, which must be deferred because code later in the file might modify
the global scope. When 'callable' is called, the scope at the time this is called... | python | def defer_function(self, callable):
"""Schedule a function handler to be called just before completion.
This is used for handling function bodies, which must be deferred because code later in the file might modify
the global scope. When 'callable' is called, the scope at the time this is called... | [
"def",
"defer_function",
"(",
"self",
",",
"callable",
")",
":",
"self",
".",
"_deferred_functions",
".",
"append",
"(",
"(",
"callable",
",",
"self",
".",
"scope_stack",
"[",
":",
"]",
",",
"self",
".",
"offset",
")",
")"
] | Schedule a function handler to be called just before completion.
This is used for handling function bodies, which must be deferred because code later in the file might modify
the global scope. When 'callable' is called, the scope at the time this is called will be restored, however it
will cont... | [
"Schedule",
"a",
"function",
"handler",
"to",
"be",
"called",
"just",
"before",
"completion",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L291-L299 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.defer_assignment | def defer_assignment(self, callable):
"""Schedule an assignment handler to be called just after deferred
function handlers."""
self._deferred_assignments.append((callable, self.scope_stack[:], self.offset)) | python | def defer_assignment(self, callable):
"""Schedule an assignment handler to be called just after deferred
function handlers."""
self._deferred_assignments.append((callable, self.scope_stack[:], self.offset)) | [
"def",
"defer_assignment",
"(",
"self",
",",
"callable",
")",
":",
"self",
".",
"_deferred_assignments",
".",
"append",
"(",
"(",
"callable",
",",
"self",
".",
"scope_stack",
"[",
":",
"]",
",",
"self",
".",
"offset",
")",
")"
] | Schedule an assignment handler to be called just after deferred
function handlers. | [
"Schedule",
"an",
"assignment",
"handler",
"to",
"be",
"called",
"just",
"after",
"deferred",
"function",
"handlers",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L301-L304 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.run_deferred | def run_deferred(self, deferred):
"""Run the callables in deferred using their associated scope stack."""
for handler, scope, offset in deferred:
self.scope_stack = scope
self.offset = offset
handler() | python | def run_deferred(self, deferred):
"""Run the callables in deferred using their associated scope stack."""
for handler, scope, offset in deferred:
self.scope_stack = scope
self.offset = offset
handler() | [
"def",
"run_deferred",
"(",
"self",
",",
"deferred",
")",
":",
"for",
"handler",
",",
"scope",
",",
"offset",
"in",
"deferred",
":",
"self",
".",
"scope_stack",
"=",
"scope",
"self",
".",
"offset",
"=",
"offset",
"handler",
"(",
")"
] | Run the callables in deferred using their associated scope stack. | [
"Run",
"the",
"callables",
"in",
"deferred",
"using",
"their",
"associated",
"scope",
"stack",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L306-L311 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.check_dead_scopes | def check_dead_scopes(self):
"""Look at scopes which have been fully examined and report names in
them which were imported but unused."""
for scope in self.dead_scopes:
export = isinstance(scope.get('__all__'), ExportBinding)
if export:
all = scope['__all_... | python | def check_dead_scopes(self):
"""Look at scopes which have been fully examined and report names in
them which were imported but unused."""
for scope in self.dead_scopes:
export = isinstance(scope.get('__all__'), ExportBinding)
if export:
all = scope['__all_... | [
"def",
"check_dead_scopes",
"(",
"self",
")",
":",
"for",
"scope",
"in",
"self",
".",
"dead_scopes",
":",
"export",
"=",
"isinstance",
"(",
"scope",
".",
"get",
"(",
"'__all__'",
")",
",",
"ExportBinding",
")",
"if",
"export",
":",
"all",
"=",
"scope",
... | Look at scopes which have been fully examined and report names in
them which were imported but unused. | [
"Look",
"at",
"scopes",
"which",
"have",
"been",
"fully",
"examined",
"and",
"report",
"names",
"in",
"them",
"which",
"were",
"imported",
"but",
"unused",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L320-L338 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.different_forks | def different_forks(self, lnode, rnode):
"""True, if lnode and rnode are located on different forks of
IF/TRY."""
ancestor = self.get_common_ancestor(lnode, rnode)
if isinstance(ancestor, ast.If):
for fork in (ancestor.body, ancestor.orelse):
if self.on_fork(a... | python | def different_forks(self, lnode, rnode):
"""True, if lnode and rnode are located on different forks of
IF/TRY."""
ancestor = self.get_common_ancestor(lnode, rnode)
if isinstance(ancestor, ast.If):
for fork in (ancestor.body, ancestor.orelse):
if self.on_fork(a... | [
"def",
"different_forks",
"(",
"self",
",",
"lnode",
",",
"rnode",
")",
":",
"ancestor",
"=",
"self",
".",
"get_common_ancestor",
"(",
"lnode",
",",
"rnode",
")",
"if",
"isinstance",
"(",
"ancestor",
",",
"ast",
".",
"If",
")",
":",
"for",
"fork",
"in"... | True, if lnode and rnode are located on different forks of
IF/TRY. | [
"True",
"if",
"lnode",
"and",
"rnode",
"are",
"located",
"on",
"different",
"forks",
"of",
"IF",
"/",
"TRY",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L389-L405 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.add_binding | def add_binding(self, node, value, report_redef=True):
"""Called when a binding is altered.
- `node` is the statement responsible for the change
- `value` is the optional new value, a Binding instance, associated
with the binding; if None, the binding is deleted if it exists.
- ... | python | def add_binding(self, node, value, report_redef=True):
"""Called when a binding is altered.
- `node` is the statement responsible for the change
- `value` is the optional new value, a Binding instance, associated
with the binding; if None, the binding is deleted if it exists.
- ... | [
"def",
"add_binding",
"(",
"self",
",",
"node",
",",
"value",
",",
"report_redef",
"=",
"True",
")",
":",
"redefinedWhileUnused",
"=",
"False",
"if",
"not",
"isinstance",
"(",
"self",
".",
"scope",
",",
"ClassScope",
")",
":",
"for",
"scope",
"in",
"self... | Called when a binding is altered.
- `node` is the statement responsible for the change
- `value` is the optional new value, a Binding instance, associated
with the binding; if None, the binding is deleted if it exists.
- if `report_redef` is True (default), rebinding while unused will b... | [
"Called",
"when",
"a",
"binding",
"is",
"altered",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L407-L445 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.is_docstring | def is_docstring(self, node):
"""Determine if the given node is a docstring, as long as it is at the
correct place in the node tree."""
return isinstance(node, ast.Str) or (isinstance(node, ast.Expr) and
isinstance(node.value, ast.Str)) | python | def is_docstring(self, node):
"""Determine if the given node is a docstring, as long as it is at the
correct place in the node tree."""
return isinstance(node, ast.Str) or (isinstance(node, ast.Expr) and
isinstance(node.value, ast.Str)) | [
"def",
"is_docstring",
"(",
"self",
",",
"node",
")",
":",
"return",
"isinstance",
"(",
"node",
",",
"ast",
".",
"Str",
")",
"or",
"(",
"isinstance",
"(",
"node",
",",
"ast",
".",
"Expr",
")",
"and",
"isinstance",
"(",
"node",
".",
"value",
",",
"a... | Determine if the given node is a docstring, as long as it is at the
correct place in the node tree. | [
"Determine",
"if",
"the",
"given",
"node",
"is",
"a",
"docstring",
"as",
"long",
"as",
"it",
"is",
"at",
"the",
"correct",
"place",
"in",
"the",
"node",
"tree",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L539-L543 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.find_return_with_argument | def find_return_with_argument(self, node):
"""Finds and returns a return statment that has an argument.
Note that we should use node.returns in Python 3, but this method is never called in Python 3 so we don't bother
checking.
"""
for item in node.body:
if isinstanc... | python | def find_return_with_argument(self, node):
"""Finds and returns a return statment that has an argument.
Note that we should use node.returns in Python 3, but this method is never called in Python 3 so we don't bother
checking.
"""
for item in node.body:
if isinstanc... | [
"def",
"find_return_with_argument",
"(",
"self",
",",
"node",
")",
":",
"for",
"item",
"in",
"node",
".",
"body",
":",
"if",
"isinstance",
"(",
"item",
",",
"ast",
".",
"Return",
")",
"and",
"item",
".",
"value",
":",
"return",
"item",
"elif",
"not",
... | Finds and returns a return statment that has an argument.
Note that we should use node.returns in Python 3, but this method is never called in Python 3 so we don't bother
checking. | [
"Finds",
"and",
"returns",
"a",
"return",
"statment",
"that",
"has",
"an",
"argument",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L605-L618 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.is_generator | def is_generator(self, node):
"""Checks whether a function is a generator by looking for a yield
statement or expression."""
if not isinstance(node.body, list):
# lambdas can not be generators
return False
for item in node.body:
if isinstance(item, (as... | python | def is_generator(self, node):
"""Checks whether a function is a generator by looking for a yield
statement or expression."""
if not isinstance(node.body, list):
# lambdas can not be generators
return False
for item in node.body:
if isinstance(item, (as... | [
"def",
"is_generator",
"(",
"self",
",",
"node",
")",
":",
"if",
"not",
"isinstance",
"(",
"node",
".",
"body",
",",
"list",
")",
":",
"# lambdas can not be generators",
"return",
"False",
"for",
"item",
"in",
"node",
".",
"body",
":",
"if",
"isinstance",
... | Checks whether a function is a generator by looking for a yield
statement or expression. | [
"Checks",
"whether",
"a",
"function",
"is",
"a",
"generator",
"by",
"looking",
"for",
"a",
"yield",
"statement",
"or",
"expression",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L620-L633 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.GLOBAL | def GLOBAL(self, node):
"""Keep track of globals declarations."""
if isinstance(self.scope, FunctionScope):
self.scope.globals.update(node.names) | python | def GLOBAL(self, node):
"""Keep track of globals declarations."""
if isinstance(self.scope, FunctionScope):
self.scope.globals.update(node.names) | [
"def",
"GLOBAL",
"(",
"self",
",",
"node",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"scope",
",",
"FunctionScope",
")",
":",
"self",
".",
"scope",
".",
"globals",
".",
"update",
"(",
"node",
".",
"names",
")"
] | Keep track of globals declarations. | [
"Keep",
"track",
"of",
"globals",
"declarations",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L662-L665 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.FOR | def FOR(self, node):
"""Process bindings for loop variables."""
vars = []
def collectLoopVars(n):
if isinstance(n, ast.Name):
vars.append(n.id)
elif isinstance(n, ast.expr_context):
return
else:
for c in ast.ite... | python | def FOR(self, node):
"""Process bindings for loop variables."""
vars = []
def collectLoopVars(n):
if isinstance(n, ast.Name):
vars.append(n.id)
elif isinstance(n, ast.expr_context):
return
else:
for c in ast.ite... | [
"def",
"FOR",
"(",
"self",
",",
"node",
")",
":",
"vars",
"=",
"[",
"]",
"def",
"collectLoopVars",
"(",
"n",
")",
":",
"if",
"isinstance",
"(",
"n",
",",
"ast",
".",
"Name",
")",
":",
"vars",
".",
"append",
"(",
"n",
".",
"id",
")",
"elif",
"... | Process bindings for loop variables. | [
"Process",
"bindings",
"for",
"loop",
"variables",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L693-L714 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.NAME | def NAME(self, node):
"""Handle occurrence of Name (which can be a load/store/delete
access.)"""
# Locate the name in locals / function / globals scopes.
if isinstance(node.ctx, (ast.Load, ast.AugLoad)):
self.handle_node_load(node)
if (node.id == 'locals' and isin... | python | def NAME(self, node):
"""Handle occurrence of Name (which can be a load/store/delete
access.)"""
# Locate the name in locals / function / globals scopes.
if isinstance(node.ctx, (ast.Load, ast.AugLoad)):
self.handle_node_load(node)
if (node.id == 'locals' and isin... | [
"def",
"NAME",
"(",
"self",
",",
"node",
")",
":",
"# Locate the name in locals / function / globals scopes.",
"if",
"isinstance",
"(",
"node",
".",
"ctx",
",",
"(",
"ast",
".",
"Load",
",",
"ast",
".",
"AugLoad",
")",
")",
":",
"self",
".",
"handle_node_loa... | Handle occurrence of Name (which can be a load/store/delete
access.) | [
"Handle",
"occurrence",
"of",
"Name",
"(",
"which",
"can",
"be",
"a",
"load",
"/",
"store",
"/",
"delete",
"access",
".",
")"
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L716-L733 |
timothycrosley/deprecated.frosted | frosted/checker.py | Checker.CLASSDEF | def CLASSDEF(self, node):
"""Check names used in a class definition, including its decorators,
base classes, and the body of its definition.
Additionally, add its name to the current scope.
"""
for deco in node.decorator_list:
self.handleNode(deco, node)
for... | python | def CLASSDEF(self, node):
"""Check names used in a class definition, including its decorators,
base classes, and the body of its definition.
Additionally, add its name to the current scope.
"""
for deco in node.decorator_list:
self.handleNode(deco, node)
for... | [
"def",
"CLASSDEF",
"(",
"self",
",",
"node",
")",
":",
"for",
"deco",
"in",
"node",
".",
"decorator_list",
":",
"self",
".",
"handleNode",
"(",
"deco",
",",
"node",
")",
"for",
"baseNode",
"in",
"node",
".",
"bases",
":",
"self",
".",
"handleNode",
"... | Check names used in a class definition, including its decorators,
base classes, and the body of its definition.
Additionally, add its name to the current scope. | [
"Check",
"names",
"used",
"in",
"a",
"class",
"definition",
"including",
"its",
"decorators",
"base",
"classes",
"and",
"the",
"body",
"of",
"its",
"definition",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/checker.py#L837-L857 |
timothycrosley/deprecated.frosted | frosted/api.py | check | def check(codeString, filename, reporter=modReporter.Default, settings_path=None, **setting_overrides):
"""Check the Python source given by codeString for unfrosted flakes."""
if not settings_path and filename:
settings_path = os.path.dirname(os.path.abspath(filename))
settings_path = settings_path... | python | def check(codeString, filename, reporter=modReporter.Default, settings_path=None, **setting_overrides):
"""Check the Python source given by codeString for unfrosted flakes."""
if not settings_path and filename:
settings_path = os.path.dirname(os.path.abspath(filename))
settings_path = settings_path... | [
"def",
"check",
"(",
"codeString",
",",
"filename",
",",
"reporter",
"=",
"modReporter",
".",
"Default",
",",
"settings_path",
"=",
"None",
",",
"*",
"*",
"setting_overrides",
")",
":",
"if",
"not",
"settings_path",
"and",
"filename",
":",
"settings_path",
"... | Check the Python source given by codeString for unfrosted flakes. | [
"Check",
"the",
"Python",
"source",
"given",
"by",
"codeString",
"for",
"unfrosted",
"flakes",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/api.py#L62-L118 |
timothycrosley/deprecated.frosted | frosted/api.py | check_path | def check_path(filename, reporter=modReporter.Default, settings_path=None, **setting_overrides):
"""Check the given path, printing out any warnings detected."""
try:
with open(filename, 'U') as f:
codestr = f.read() + '\n'
except UnicodeError:
reporter.unexpected_error(filename, ... | python | def check_path(filename, reporter=modReporter.Default, settings_path=None, **setting_overrides):
"""Check the given path, printing out any warnings detected."""
try:
with open(filename, 'U') as f:
codestr = f.read() + '\n'
except UnicodeError:
reporter.unexpected_error(filename, ... | [
"def",
"check_path",
"(",
"filename",
",",
"reporter",
"=",
"modReporter",
".",
"Default",
",",
"settings_path",
"=",
"None",
",",
"*",
"*",
"setting_overrides",
")",
":",
"try",
":",
"with",
"open",
"(",
"filename",
",",
"'U'",
")",
"as",
"f",
":",
"c... | Check the given path, printing out any warnings detected. | [
"Check",
"the",
"given",
"path",
"printing",
"out",
"any",
"warnings",
"detected",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/api.py#L121-L133 |
timothycrosley/deprecated.frosted | frosted/api.py | check_recursive | def check_recursive(paths, reporter=modReporter.Default, settings_path=None, **setting_overrides):
"""Recursively check all source files defined in paths."""
warnings = 0
for source_path in iter_source_code(paths):
warnings += check_path(source_path, reporter, settings_path=None, **setting_overrides... | python | def check_recursive(paths, reporter=modReporter.Default, settings_path=None, **setting_overrides):
"""Recursively check all source files defined in paths."""
warnings = 0
for source_path in iter_source_code(paths):
warnings += check_path(source_path, reporter, settings_path=None, **setting_overrides... | [
"def",
"check_recursive",
"(",
"paths",
",",
"reporter",
"=",
"modReporter",
".",
"Default",
",",
"settings_path",
"=",
"None",
",",
"*",
"*",
"setting_overrides",
")",
":",
"warnings",
"=",
"0",
"for",
"source_path",
"in",
"iter_source_code",
"(",
"paths",
... | Recursively check all source files defined in paths. | [
"Recursively",
"check",
"all",
"source",
"files",
"defined",
"in",
"paths",
"."
] | train | https://github.com/timothycrosley/deprecated.frosted/blob/61ba7f341fc55676c3580c8c4e52117986cd5e12/frosted/api.py#L148-L153 |
codingjoe/django-s3file | s3file/middleware.py | S3FileMiddleware.get_files_from_storage | def get_files_from_storage(paths):
"""Return S3 file where the name does not include the path."""
for path in paths:
f = default_storage.open(path)
f.name = os.path.basename(path)
try:
yield f
except ClientError:
logger.exce... | python | def get_files_from_storage(paths):
"""Return S3 file where the name does not include the path."""
for path in paths:
f = default_storage.open(path)
f.name = os.path.basename(path)
try:
yield f
except ClientError:
logger.exce... | [
"def",
"get_files_from_storage",
"(",
"paths",
")",
":",
"for",
"path",
"in",
"paths",
":",
"f",
"=",
"default_storage",
".",
"open",
"(",
"path",
")",
"f",
".",
"name",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"path",
")",
"try",
":",
"yield",
... | Return S3 file where the name does not include the path. | [
"Return",
"S3",
"file",
"where",
"the",
"name",
"does",
"not",
"include",
"the",
"path",
"."
] | train | https://github.com/codingjoe/django-s3file/blob/53c55543a6589bd906d2c28c683f8f182b33d2fa/s3file/middleware.py#L24-L32 |
balemessenger/bale-bot-python | examples/echobot.py | echo | def echo(bot, update):
"""Echo the user message."""
message = update.get_effective_message()
bot.reply(update, message) | python | def echo(bot, update):
"""Echo the user message."""
message = update.get_effective_message()
bot.reply(update, message) | [
"def",
"echo",
"(",
"bot",
",",
"update",
")",
":",
"message",
"=",
"update",
".",
"get_effective_message",
"(",
")",
"bot",
".",
"reply",
"(",
"update",
",",
"message",
")"
] | Echo the user message. | [
"Echo",
"the",
"user",
"message",
"."
] | train | https://github.com/balemessenger/bale-bot-python/blob/92bfd60016b075179f16c212fc3fc20a4e5f16f4/examples/echobot.py#L38-L41 |
balemessenger/bale-bot-python | examples/echobot.py | error | def error(bot, update, error):
"""Log Errors caused by Updates."""
logger.error('Update {} caused error {}'.format(update, error), extra={"tag": "err"}) | python | def error(bot, update, error):
"""Log Errors caused by Updates."""
logger.error('Update {} caused error {}'.format(update, error), extra={"tag": "err"}) | [
"def",
"error",
"(",
"bot",
",",
"update",
",",
"error",
")",
":",
"logger",
".",
"error",
"(",
"'Update {} caused error {}'",
".",
"format",
"(",
"update",
",",
"error",
")",
",",
"extra",
"=",
"{",
"\"tag\"",
":",
"\"err\"",
"}",
")"
] | Log Errors caused by Updates. | [
"Log",
"Errors",
"caused",
"by",
"Updates",
"."
] | train | https://github.com/balemessenger/bale-bot-python/blob/92bfd60016b075179f16c212fc3fc20a4e5f16f4/examples/echobot.py#L44-L46 |
balemessenger/bale-bot-python | examples/echobot.py | main | def main():
"""Start the bot."""
# Bale Bot Authorization Token
updater = Updater("TOKEN")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Bale
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", hel... | python | def main():
"""Start the bot."""
# Bale Bot Authorization Token
updater = Updater("TOKEN")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Bale
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", hel... | [
"def",
"main",
"(",
")",
":",
"# Bale Bot Authorization Token",
"updater",
"=",
"Updater",
"(",
"\"TOKEN\"",
")",
"# Get the dispatcher to register handlers",
"dp",
"=",
"updater",
".",
"dispatcher",
"# on different commands - answer in Bale",
"dp",
".",
"add_handler",
"(... | Start the bot. | [
"Start",
"the",
"bot",
"."
] | train | https://github.com/balemessenger/bale-bot-python/blob/92bfd60016b075179f16c212fc3fc20a4e5f16f4/examples/echobot.py#L49-L68 |
hozn/coilmq | coilmq/start.py | server_from_config | def server_from_config(config=None, server_class=None, additional_kwargs=None):
"""
Gets a configured L{coilmq.server.StompServer} from specified config.
If `config` is None, global L{coilmq.config.config} var will be used instead.
The `server_class` and `additional_kwargs` are primarily hooks for usi... | python | def server_from_config(config=None, server_class=None, additional_kwargs=None):
"""
Gets a configured L{coilmq.server.StompServer} from specified config.
If `config` is None, global L{coilmq.config.config} var will be used instead.
The `server_class` and `additional_kwargs` are primarily hooks for usi... | [
"def",
"server_from_config",
"(",
"config",
"=",
"None",
",",
"server_class",
"=",
"None",
",",
"additional_kwargs",
"=",
"None",
")",
":",
"global",
"global_config",
"if",
"not",
"config",
":",
"config",
"=",
"global_config",
"queue_store_factory",
"=",
"resolv... | Gets a configured L{coilmq.server.StompServer} from specified config.
If `config` is None, global L{coilmq.config.config} var will be used instead.
The `server_class` and `additional_kwargs` are primarily hooks for using this method
from a testing environment.
@param config: A C{ConfigParser.ConfigPa... | [
"Gets",
"a",
"configured",
"L",
"{",
"coilmq",
".",
"server",
".",
"StompServer",
"}",
"from",
"specified",
"config",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/start.py#L46-L92 |
hozn/coilmq | coilmq/start.py | context_serve | def context_serve(context, configfile, listen_addr, listen_port, logfile,
debug, daemon, uid, gid, pidfile, umask, rundir):
"""
Takes a context object, which implements the __enter__/__exit__ "with" interface
and starts a server within that context.
This method is a refactored single... | python | def context_serve(context, configfile, listen_addr, listen_port, logfile,
debug, daemon, uid, gid, pidfile, umask, rundir):
"""
Takes a context object, which implements the __enter__/__exit__ "with" interface
and starts a server within that context.
This method is a refactored single... | [
"def",
"context_serve",
"(",
"context",
",",
"configfile",
",",
"listen_addr",
",",
"listen_port",
",",
"logfile",
",",
"debug",
",",
"daemon",
",",
"uid",
",",
"gid",
",",
"pidfile",
",",
"umask",
",",
"rundir",
")",
":",
"global",
"global_config",
"serve... | Takes a context object, which implements the __enter__/__exit__ "with" interface
and starts a server within that context.
This method is a refactored single-place for handling the server-run code whether
running in daemon or non-daemon mode. It is invoked with a dummy (passthrough)
context object fo... | [
"Takes",
"a",
"context",
"object",
"which",
"implements",
"the",
"__enter__",
"/",
"__exit__",
"with",
"interface",
"and",
"starts",
"a",
"server",
"within",
"that",
"context",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/start.py#L95-L164 |
hozn/coilmq | coilmq/start.py | main | def main(config, host, port, logfile, debug, daemon, uid, gid, pidfile, umask, rundir):
"""
Main entry point for running a socket server from the commandline.
This method will read in options from the commandline and call the L{config.init_config} method
to get everything setup. Then, depending on whe... | python | def main(config, host, port, logfile, debug, daemon, uid, gid, pidfile, umask, rundir):
"""
Main entry point for running a socket server from the commandline.
This method will read in options from the commandline and call the L{config.init_config} method
to get everything setup. Then, depending on whe... | [
"def",
"main",
"(",
"config",
",",
"host",
",",
"port",
",",
"logfile",
",",
"debug",
",",
"daemon",
",",
"uid",
",",
"gid",
",",
"pidfile",
",",
"umask",
",",
"rundir",
")",
":",
"_main",
"(",
"*",
"*",
"locals",
"(",
")",
")"
] | Main entry point for running a socket server from the commandline.
This method will read in options from the commandline and call the L{config.init_config} method
to get everything setup. Then, depending on whether deamon mode was specified or not,
the process may be forked (or not) and the server will b... | [
"Main",
"entry",
"point",
"for",
"running",
"a",
"socket",
"server",
"from",
"the",
"commandline",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/start.py#L207-L216 |
hozn/coilmq | coilmq/store/sa/__init__.py | make_sa | def make_sa():
"""
Factory to creates a SQLAlchemy queue store, pulling config values from the CoilMQ configuration.
"""
configuration = dict(config.items('coilmq'))
engine = engine_from_config(configuration, 'qstore.sqlalchemy.')
init_model(engine)
store = SAQueue()
return store | python | def make_sa():
"""
Factory to creates a SQLAlchemy queue store, pulling config values from the CoilMQ configuration.
"""
configuration = dict(config.items('coilmq'))
engine = engine_from_config(configuration, 'qstore.sqlalchemy.')
init_model(engine)
store = SAQueue()
return store | [
"def",
"make_sa",
"(",
")",
":",
"configuration",
"=",
"dict",
"(",
"config",
".",
"items",
"(",
"'coilmq'",
")",
")",
"engine",
"=",
"engine_from_config",
"(",
"configuration",
",",
"'qstore.sqlalchemy.'",
")",
"init_model",
"(",
"engine",
")",
"store",
"="... | Factory to creates a SQLAlchemy queue store, pulling config values from the CoilMQ configuration. | [
"Factory",
"to",
"creates",
"a",
"SQLAlchemy",
"queue",
"store",
"pulling",
"config",
"values",
"from",
"the",
"CoilMQ",
"configuration",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/__init__.py#L44-L52 |
hozn/coilmq | coilmq/store/sa/__init__.py | init_model | def init_model(engine, create=True, drop=False):
"""
Initializes the shared SQLAlchemy state in the L{coilmq.store.sa.model} module.
@param engine: The SQLAlchemy engine instance.
@type engine: C{sqlalchemy.Engine}
@param create: Whether to create the tables (if they do not exist).
@type creat... | python | def init_model(engine, create=True, drop=False):
"""
Initializes the shared SQLAlchemy state in the L{coilmq.store.sa.model} module.
@param engine: The SQLAlchemy engine instance.
@type engine: C{sqlalchemy.Engine}
@param create: Whether to create the tables (if they do not exist).
@type creat... | [
"def",
"init_model",
"(",
"engine",
",",
"create",
"=",
"True",
",",
"drop",
"=",
"False",
")",
":",
"meta",
".",
"engine",
"=",
"engine",
"meta",
".",
"metadata",
"=",
"MetaData",
"(",
"bind",
"=",
"meta",
".",
"engine",
")",
"meta",
".",
"Session",... | Initializes the shared SQLAlchemy state in the L{coilmq.store.sa.model} module.
@param engine: The SQLAlchemy engine instance.
@type engine: C{sqlalchemy.Engine}
@param create: Whether to create the tables (if they do not exist).
@type create: C{bool}
@param drop: Whether to drop the tables (if t... | [
"Initializes",
"the",
"shared",
"SQLAlchemy",
"state",
"in",
"the",
"L",
"{",
"coilmq",
".",
"store",
".",
"sa",
".",
"model",
"}",
"module",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/__init__.py#L55-L71 |
hozn/coilmq | coilmq/store/sa/__init__.py | SAQueue.enqueue | def enqueue(self, destination, frame):
"""
Store message (frame) for specified destinationination.
@param destination: The destinationination queue name for this message (frame).
@type destination: C{str}
@param frame: The message (frame) to send to specified destinationination... | python | def enqueue(self, destination, frame):
"""
Store message (frame) for specified destinationination.
@param destination: The destinationination queue name for this message (frame).
@type destination: C{str}
@param frame: The message (frame) to send to specified destinationination... | [
"def",
"enqueue",
"(",
"self",
",",
"destination",
",",
"frame",
")",
":",
"session",
"=",
"meta",
".",
"Session",
"(",
")",
"message_id",
"=",
"frame",
".",
"headers",
".",
"get",
"(",
"'message-id'",
")",
"if",
"not",
"message_id",
":",
"raise",
"Val... | Store message (frame) for specified destinationination.
@param destination: The destinationination queue name for this message (frame).
@type destination: C{str}
@param frame: The message (frame) to send to specified destinationination.
@type frame: C{stompclient.frame.Frame} | [
"Store",
"message",
"(",
"frame",
")",
"for",
"specified",
"destinationination",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/__init__.py#L92-L109 |
hozn/coilmq | coilmq/store/sa/__init__.py | SAQueue.dequeue | def dequeue(self, destination):
"""
Removes and returns an item from the queue (or C{None} if no items in queue).
@param destination: The queue name (destinationination).
@type destination: C{str}
@return: The first frame in the specified queue, or C{None} if there are none.
... | python | def dequeue(self, destination):
"""
Removes and returns an item from the queue (or C{None} if no items in queue).
@param destination: The queue name (destinationination).
@type destination: C{str}
@return: The first frame in the specified queue, or C{None} if there are none.
... | [
"def",
"dequeue",
"(",
"self",
",",
"destination",
")",
":",
"session",
"=",
"meta",
".",
"Session",
"(",
")",
"try",
":",
"selstmt",
"=",
"select",
"(",
"[",
"model",
".",
"frames_table",
".",
"c",
".",
"message_id",
",",
"model",
".",
"frames_table",... | Removes and returns an item from the queue (or C{None} if no items in queue).
@param destination: The queue name (destinationination).
@type destination: C{str}
@return: The first frame in the specified queue, or C{None} if there are none.
@rtype: C{stompclient.frame.Frame} | [
"Removes",
"and",
"returns",
"an",
"item",
"from",
"the",
"queue",
"(",
"or",
"C",
"{",
"None",
"}",
"if",
"no",
"items",
"in",
"queue",
")",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/__init__.py#L111-L149 |
hozn/coilmq | coilmq/store/sa/__init__.py | SAQueue.has_frames | def has_frames(self, destination):
"""
Whether specified queue has any frames.
@param destination: The queue name (destinationination).
@type destination: C{str}
@return: Whether there are any frames in the specified queue.
@rtype: C{bool}
"""
session = ... | python | def has_frames(self, destination):
"""
Whether specified queue has any frames.
@param destination: The queue name (destinationination).
@type destination: C{str}
@return: Whether there are any frames in the specified queue.
@rtype: C{bool}
"""
session = ... | [
"def",
"has_frames",
"(",
"self",
",",
"destination",
")",
":",
"session",
"=",
"meta",
".",
"Session",
"(",
")",
"sel",
"=",
"select",
"(",
"[",
"model",
".",
"frames_table",
".",
"c",
".",
"message_id",
"]",
")",
".",
"where",
"(",
"model",
".",
... | Whether specified queue has any frames.
@param destination: The queue name (destinationination).
@type destination: C{str}
@return: Whether there are any frames in the specified queue.
@rtype: C{bool} | [
"Whether",
"specified",
"queue",
"has",
"any",
"frames",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/__init__.py#L151-L167 |
hozn/coilmq | coilmq/store/sa/__init__.py | SAQueue.size | def size(self, destination):
"""
Size of the queue for specified destination.
@param destination: The queue destination (e.g. /queue/foo)
@type destination: C{str}
@return: The number of frames in specified queue.
@rtype: C{int}
"""
session = meta.Sessio... | python | def size(self, destination):
"""
Size of the queue for specified destination.
@param destination: The queue destination (e.g. /queue/foo)
@type destination: C{str}
@return: The number of frames in specified queue.
@rtype: C{int}
"""
session = meta.Sessio... | [
"def",
"size",
"(",
"self",
",",
"destination",
")",
":",
"session",
"=",
"meta",
".",
"Session",
"(",
")",
"sel",
"=",
"select",
"(",
"[",
"func",
".",
"count",
"(",
"model",
".",
"frames_table",
".",
"c",
".",
"message_id",
")",
"]",
")",
".",
... | Size of the queue for specified destination.
@param destination: The queue destination (e.g. /queue/foo)
@type destination: C{str}
@return: The number of frames in specified queue.
@rtype: C{int} | [
"Size",
"of",
"the",
"queue",
"for",
"specified",
"destination",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/__init__.py#L169-L187 |
hozn/coilmq | coilmq/store/sa/__init__.py | SAQueue.destinations | def destinations(self):
"""
Provides a list of destinations (queue "addresses") available.
@return: A list of the detinations available.
@rtype: C{set}
"""
session = meta.Session()
sel = select([distinct(model.frames_table.c.destination)])
result = sessio... | python | def destinations(self):
"""
Provides a list of destinations (queue "addresses") available.
@return: A list of the detinations available.
@rtype: C{set}
"""
session = meta.Session()
sel = select([distinct(model.frames_table.c.destination)])
result = sessio... | [
"def",
"destinations",
"(",
"self",
")",
":",
"session",
"=",
"meta",
".",
"Session",
"(",
")",
"sel",
"=",
"select",
"(",
"[",
"distinct",
"(",
"model",
".",
"frames_table",
".",
"c",
".",
"destination",
")",
"]",
")",
"result",
"=",
"session",
".",... | Provides a list of destinations (queue "addresses") available.
@return: A list of the detinations available.
@rtype: C{set} | [
"Provides",
"a",
"list",
"of",
"destinations",
"(",
"queue",
"addresses",
")",
"available",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/__init__.py#L189-L199 |
hozn/coilmq | coilmq/store/sa/model.py | setup_tables | def setup_tables(create=True, drop=False):
"""
Binds the model classes to registered metadata and engine and (potentially)
creates the db tables.
This function expects that you have bound the L{meta.metadata} and L{meta.engine}.
@param create: Whether to create the tables (if they do not exist).
... | python | def setup_tables(create=True, drop=False):
"""
Binds the model classes to registered metadata and engine and (potentially)
creates the db tables.
This function expects that you have bound the L{meta.metadata} and L{meta.engine}.
@param create: Whether to create the tables (if they do not exist).
... | [
"def",
"setup_tables",
"(",
"create",
"=",
"True",
",",
"drop",
"=",
"False",
")",
":",
"global",
"frames_table",
"frames_table",
"=",
"Table",
"(",
"'frames'",
",",
"meta",
".",
"metadata",
",",
"Column",
"(",
"'message_id'",
",",
"String",
"(",
"255",
... | Binds the model classes to registered metadata and engine and (potentially)
creates the db tables.
This function expects that you have bound the L{meta.metadata} and L{meta.engine}.
@param create: Whether to create the tables (if they do not exist).
@type create: C{bool}
@param drop: Whether to ... | [
"Binds",
"the",
"model",
"classes",
"to",
"registered",
"metadata",
"and",
"engine",
"and",
"(",
"potentially",
")",
"creates",
"the",
"db",
"tables",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/store/sa/model.py#L27-L53 |
hozn/coilmq | coilmq/topic.py | TopicManager.subscribe | def subscribe(self, connection, destination):
"""
Subscribes a connection to the specified topic destination.
@param connection: The client connection to subscribe.
@type connection: L{coilmq.server.StompConnection}
@param destination: The topic destination (e.g. '/topic/foo')... | python | def subscribe(self, connection, destination):
"""
Subscribes a connection to the specified topic destination.
@param connection: The client connection to subscribe.
@type connection: L{coilmq.server.StompConnection}
@param destination: The topic destination (e.g. '/topic/foo')... | [
"def",
"subscribe",
"(",
"self",
",",
"connection",
",",
"destination",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Subscribing %s to %s\"",
"%",
"(",
"connection",
",",
"destination",
")",
")",
"self",
".",
"_topics",
"[",
"destination",
"]",
".",... | Subscribes a connection to the specified topic destination.
@param connection: The client connection to subscribe.
@type connection: L{coilmq.server.StompConnection}
@param destination: The topic destination (e.g. '/topic/foo')
@type destination: C{str} | [
"Subscribes",
"a",
"connection",
"to",
"the",
"specified",
"topic",
"destination",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/topic.py#L67-L78 |
hozn/coilmq | coilmq/topic.py | TopicManager.unsubscribe | def unsubscribe(self, connection, destination):
"""
Unsubscribes a connection from the specified topic destination.
@param connection: The client connection to unsubscribe.
@type connection: L{coilmq.server.StompConnection}
@param destination: The topic destination (e.g. '/top... | python | def unsubscribe(self, connection, destination):
"""
Unsubscribes a connection from the specified topic destination.
@param connection: The client connection to unsubscribe.
@type connection: L{coilmq.server.StompConnection}
@param destination: The topic destination (e.g. '/top... | [
"def",
"unsubscribe",
"(",
"self",
",",
"connection",
",",
"destination",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Unsubscribing %s from %s\"",
"%",
"(",
"connection",
",",
"destination",
")",
")",
"if",
"connection",
"in",
"self",
".",
"_topics",... | Unsubscribes a connection from the specified topic destination.
@param connection: The client connection to unsubscribe.
@type connection: L{coilmq.server.StompConnection}
@param destination: The topic destination (e.g. '/topic/foo')
@type destination: C{str} | [
"Unsubscribes",
"a",
"connection",
"from",
"the",
"specified",
"topic",
"destination",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/topic.py#L81-L96 |
hozn/coilmq | coilmq/topic.py | TopicManager.disconnect | def disconnect(self, connection):
"""
Removes a subscriber connection.
@param connection: The client connection to unsubscribe.
@type connection: L{coilmq.server.StompConnection}
"""
self.log.debug("Disconnecting %s" % connection)
for dest in list(self._topics.ke... | python | def disconnect(self, connection):
"""
Removes a subscriber connection.
@param connection: The client connection to unsubscribe.
@type connection: L{coilmq.server.StompConnection}
"""
self.log.debug("Disconnecting %s" % connection)
for dest in list(self._topics.ke... | [
"def",
"disconnect",
"(",
"self",
",",
"connection",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Disconnecting %s\"",
"%",
"connection",
")",
"for",
"dest",
"in",
"list",
"(",
"self",
".",
"_topics",
".",
"keys",
"(",
")",
")",
":",
"if",
"co... | Removes a subscriber connection.
@param connection: The client connection to unsubscribe.
@type connection: L{coilmq.server.StompConnection} | [
"Removes",
"a",
"subscriber",
"connection",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/topic.py#L99-L112 |
hozn/coilmq | coilmq/topic.py | TopicManager.send | def send(self, message):
"""
Sends a message to all subscribers of destination.
@param message: The message frame. (The frame will be modified to set command
to MESSAGE and set a message id.)
@type message: L{stompclient.frame.Frame}
"""
des... | python | def send(self, message):
"""
Sends a message to all subscribers of destination.
@param message: The message frame. (The frame will be modified to set command
to MESSAGE and set a message id.)
@type message: L{stompclient.frame.Frame}
"""
des... | [
"def",
"send",
"(",
"self",
",",
"message",
")",
":",
"dest",
"=",
"message",
".",
"headers",
".",
"get",
"(",
"'destination'",
")",
"if",
"not",
"dest",
":",
"raise",
"ValueError",
"(",
"\"Cannot send frame with no destination: %s\"",
"%",
"message",
")",
"... | Sends a message to all subscribers of destination.
@param message: The message frame. (The frame will be modified to set command
to MESSAGE and set a message id.)
@type message: L{stompclient.frame.Frame} | [
"Sends",
"a",
"message",
"to",
"all",
"subscribers",
"of",
"destination",
"."
] | train | https://github.com/hozn/coilmq/blob/76b7fcf347144b3a5746423a228bed121dc564b5/coilmq/topic.py#L115-L144 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.