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/storage/pyfs.py | pyfs_storage_factory | def pyfs_storage_factory(fileinstance=None, default_location=None,
default_storage_class=None,
filestorage_class=PyFSFileStorage, fileurl=None,
size=None, modified=None, clean_dir=True):
"""Get factory function for creating a PyFS file stora... | python | def pyfs_storage_factory(fileinstance=None, default_location=None,
default_storage_class=None,
filestorage_class=PyFSFileStorage, fileurl=None,
size=None, modified=None, clean_dir=True):
"""Get factory function for creating a PyFS file stora... | [
"def",
"pyfs_storage_factory",
"(",
"fileinstance",
"=",
"None",
",",
"default_location",
"=",
"None",
",",
"default_storage_class",
"=",
"None",
",",
"filestorage_class",
"=",
"PyFSFileStorage",
",",
"fileurl",
"=",
"None",
",",
"size",
"=",
"None",
",",
"modif... | Get factory function for creating a PyFS file storage instance. | [
"Get",
"factory",
"function",
"for",
"creating",
"a",
"PyFS",
"file",
"storage",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/pyfs.py#L131-L162 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/pyfs.py | PyFSFileStorage._get_fs | def _get_fs(self, create_dir=True):
"""Return tuple with filesystem and filename."""
filedir = dirname(self.fileurl)
filename = basename(self.fileurl)
return (
opener.opendir(filedir, writeable=True, create_dir=create_dir),
filename
) | python | def _get_fs(self, create_dir=True):
"""Return tuple with filesystem and filename."""
filedir = dirname(self.fileurl)
filename = basename(self.fileurl)
return (
opener.opendir(filedir, writeable=True, create_dir=create_dir),
filename
) | [
"def",
"_get_fs",
"(",
"self",
",",
"create_dir",
"=",
"True",
")",
":",
"filedir",
"=",
"dirname",
"(",
"self",
".",
"fileurl",
")",
"filename",
"=",
"basename",
"(",
"self",
".",
"fileurl",
")",
"return",
"(",
"opener",
".",
"opendir",
"(",
"filedir"... | Return tuple with filesystem and filename. | [
"Return",
"tuple",
"with",
"filesystem",
"and",
"filename",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/pyfs.py#L42-L50 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/pyfs.py | PyFSFileStorage.open | def open(self, mode='rb'):
"""Open file.
The caller is responsible for closing the file.
"""
fs, path = self._get_fs()
return fs.open(path, mode=mode) | python | def open(self, mode='rb'):
"""Open file.
The caller is responsible for closing the file.
"""
fs, path = self._get_fs()
return fs.open(path, mode=mode) | [
"def",
"open",
"(",
"self",
",",
"mode",
"=",
"'rb'",
")",
":",
"fs",
",",
"path",
"=",
"self",
".",
"_get_fs",
"(",
")",
"return",
"fs",
".",
"open",
"(",
"path",
",",
"mode",
"=",
"mode",
")"
] | Open file.
The caller is responsible for closing the file. | [
"Open",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/pyfs.py#L52-L58 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/pyfs.py | PyFSFileStorage.delete | def delete(self):
"""Delete a file.
The base directory is also removed, as it is assumed that only one file
exists in the directory.
"""
fs, path = self._get_fs(create_dir=False)
if fs.exists(path):
fs.remove(path)
if self.clean_dir and fs.exists('.')... | python | def delete(self):
"""Delete a file.
The base directory is also removed, as it is assumed that only one file
exists in the directory.
"""
fs, path = self._get_fs(create_dir=False)
if fs.exists(path):
fs.remove(path)
if self.clean_dir and fs.exists('.')... | [
"def",
"delete",
"(",
"self",
")",
":",
"fs",
",",
"path",
"=",
"self",
".",
"_get_fs",
"(",
"create_dir",
"=",
"False",
")",
"if",
"fs",
".",
"exists",
"(",
"path",
")",
":",
"fs",
".",
"remove",
"(",
"path",
")",
"if",
"self",
".",
"clean_dir",... | Delete a file.
The base directory is also removed, as it is assumed that only one file
exists in the directory. | [
"Delete",
"a",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/pyfs.py#L60-L71 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/pyfs.py | PyFSFileStorage.initialize | def initialize(self, size=0):
"""Initialize file on storage and truncate to given size."""
fs, path = self._get_fs()
# Required for reliably opening the file on certain file systems:
if fs.exists(path):
fp = fs.open(path, mode='r+b')
else:
fp = fs.open(pa... | python | def initialize(self, size=0):
"""Initialize file on storage and truncate to given size."""
fs, path = self._get_fs()
# Required for reliably opening the file on certain file systems:
if fs.exists(path):
fp = fs.open(path, mode='r+b')
else:
fp = fs.open(pa... | [
"def",
"initialize",
"(",
"self",
",",
"size",
"=",
"0",
")",
":",
"fs",
",",
"path",
"=",
"self",
".",
"_get_fs",
"(",
")",
"# Required for reliably opening the file on certain file systems:",
"if",
"fs",
".",
"exists",
"(",
"path",
")",
":",
"fp",
"=",
"... | Initialize file on storage and truncate to given size. | [
"Initialize",
"file",
"on",
"storage",
"and",
"truncate",
"to",
"given",
"size",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/pyfs.py#L73-L94 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/pyfs.py | PyFSFileStorage.save | def save(self, incoming_stream, size_limit=None, size=None,
chunk_size=None, progress_callback=None):
"""Save file in the file system."""
fp = self.open(mode='wb')
try:
bytes_written, checksum = self._write_stream(
incoming_stream, fp, chunk_size=chunk_si... | python | def save(self, incoming_stream, size_limit=None, size=None,
chunk_size=None, progress_callback=None):
"""Save file in the file system."""
fp = self.open(mode='wb')
try:
bytes_written, checksum = self._write_stream(
incoming_stream, fp, chunk_size=chunk_si... | [
"def",
"save",
"(",
"self",
",",
"incoming_stream",
",",
"size_limit",
"=",
"None",
",",
"size",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"progress_callback",
"=",
"None",
")",
":",
"fp",
"=",
"self",
".",
"open",
"(",
"mode",
"=",
"'wb'",
"... | Save file in the file system. | [
"Save",
"file",
"in",
"the",
"file",
"system",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/pyfs.py#L96-L114 |
inveniosoftware/invenio-files-rest | invenio_files_rest/storage/pyfs.py | PyFSFileStorage.update | def update(self, incoming_stream, seek=0, size=None, chunk_size=None,
progress_callback=None):
"""Update a file in the file system."""
fp = self.open(mode='r+b')
try:
fp.seek(seek)
bytes_written, checksum = self._write_stream(
incoming_strea... | python | def update(self, incoming_stream, seek=0, size=None, chunk_size=None,
progress_callback=None):
"""Update a file in the file system."""
fp = self.open(mode='r+b')
try:
fp.seek(seek)
bytes_written, checksum = self._write_stream(
incoming_strea... | [
"def",
"update",
"(",
"self",
",",
"incoming_stream",
",",
"seek",
"=",
"0",
",",
"size",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"progress_callback",
"=",
"None",
")",
":",
"fp",
"=",
"self",
".",
"open",
"(",
"mode",
"=",
"'r+b'",
")",
... | Update a file in the file system. | [
"Update",
"a",
"file",
"in",
"the",
"file",
"system",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/storage/pyfs.py#L116-L128 |
inveniosoftware/invenio-files-rest | invenio_files_rest/permissions.py | permission_factory | def permission_factory(obj, action):
"""Get default permission factory.
:param obj: An instance of :class:`invenio_files_rest.models.Bucket` or
:class:`invenio_files_rest.models.ObjectVersion` or
:class:`invenio_files_rest.models.MultipartObject` or ``None`` if
the action is global.
... | python | def permission_factory(obj, action):
"""Get default permission factory.
:param obj: An instance of :class:`invenio_files_rest.models.Bucket` or
:class:`invenio_files_rest.models.ObjectVersion` or
:class:`invenio_files_rest.models.MultipartObject` or ``None`` if
the action is global.
... | [
"def",
"permission_factory",
"(",
"obj",
",",
"action",
")",
":",
"need_class",
"=",
"_action2need_map",
"[",
"action",
"]",
"if",
"obj",
"is",
"None",
":",
"return",
"Permission",
"(",
"need_class",
"(",
"None",
")",
")",
"arg",
"=",
"None",
"if",
"isin... | Get default permission factory.
:param obj: An instance of :class:`invenio_files_rest.models.Bucket` or
:class:`invenio_files_rest.models.ObjectVersion` or
:class:`invenio_files_rest.models.MultipartObject` or ``None`` if
the action is global.
:param action: The required action.
:ra... | [
"Get",
"default",
"permission",
"factory",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/permissions.py#L112-L138 |
django-cumulus/django-cumulus | cumulus/management/commands/collectstatic.py | Command.delete_file | def delete_file(self, path, prefixed_path, source_storage):
"""
Checks if the target file should be deleted if it already exists
"""
if isinstance(self.storage, CumulusStorage):
if self.storage.exists(prefixed_path):
try:
etag = self.storag... | python | def delete_file(self, path, prefixed_path, source_storage):
"""
Checks if the target file should be deleted if it already exists
"""
if isinstance(self.storage, CumulusStorage):
if self.storage.exists(prefixed_path):
try:
etag = self.storag... | [
"def",
"delete_file",
"(",
"self",
",",
"path",
",",
"prefixed_path",
",",
"source_storage",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"storage",
",",
"CumulusStorage",
")",
":",
"if",
"self",
".",
"storage",
".",
"exists",
"(",
"prefixed_path",
")",... | Checks if the target file should be deleted if it already exists | [
"Checks",
"if",
"the",
"target",
"file",
"should",
"be",
"deleted",
"if",
"it",
"already",
"exists"
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/management/commands/collectstatic.py#L10-L24 |
inveniosoftware/invenio-files-rest | examples/app.py | files | def files():
"""Load files."""
srcroot = dirname(dirname(__file__))
d = current_app.config['DATADIR']
if exists(d):
shutil.rmtree(d)
makedirs(d)
# Clear data
Part.query.delete()
MultipartObject.query.delete()
ObjectVersion.query.delete()
Bucket.query.delete()
FileIns... | python | def files():
"""Load files."""
srcroot = dirname(dirname(__file__))
d = current_app.config['DATADIR']
if exists(d):
shutil.rmtree(d)
makedirs(d)
# Clear data
Part.query.delete()
MultipartObject.query.delete()
ObjectVersion.query.delete()
Bucket.query.delete()
FileIns... | [
"def",
"files",
"(",
")",
":",
"srcroot",
"=",
"dirname",
"(",
"dirname",
"(",
"__file__",
")",
")",
"d",
"=",
"current_app",
".",
"config",
"[",
"'DATADIR'",
"]",
"if",
"exists",
"(",
"d",
")",
":",
"shutil",
".",
"rmtree",
"(",
"d",
")",
"makedir... | Load files. | [
"Load",
"files",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/examples/app.py#L238-L287 |
inveniosoftware/invenio-files-rest | invenio_files_rest/cli.py | touch | def touch():
"""Create new bucket."""
from .models import Bucket
bucket = Bucket.create()
db.session.commit()
click.secho(str(bucket), fg='green') | python | def touch():
"""Create new bucket."""
from .models import Bucket
bucket = Bucket.create()
db.session.commit()
click.secho(str(bucket), fg='green') | [
"def",
"touch",
"(",
")",
":",
"from",
".",
"models",
"import",
"Bucket",
"bucket",
"=",
"Bucket",
".",
"create",
"(",
")",
"db",
".",
"session",
".",
"commit",
"(",
")",
"click",
".",
"secho",
"(",
"str",
"(",
"bucket",
")",
",",
"fg",
"=",
"'gr... | Create new bucket. | [
"Create",
"new",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/cli.py#L34-L39 |
inveniosoftware/invenio-files-rest | invenio_files_rest/cli.py | cp | def cp(source, bucket, checksum, key_prefix):
"""Create new bucket from all files in directory."""
from .models import Bucket
from .helpers import populate_from_path
for object_version in populate_from_path(
Bucket.get(bucket), source, checksum=checksum,
key_prefix=key_prefix):
... | python | def cp(source, bucket, checksum, key_prefix):
"""Create new bucket from all files in directory."""
from .models import Bucket
from .helpers import populate_from_path
for object_version in populate_from_path(
Bucket.get(bucket), source, checksum=checksum,
key_prefix=key_prefix):
... | [
"def",
"cp",
"(",
"source",
",",
"bucket",
",",
"checksum",
",",
"key_prefix",
")",
":",
"from",
".",
"models",
"import",
"Bucket",
"from",
".",
"helpers",
"import",
"populate_from_path",
"for",
"object_version",
"in",
"populate_from_path",
"(",
"Bucket",
".",... | Create new bucket from all files in directory. | [
"Create",
"new",
"bucket",
"from",
"all",
"files",
"in",
"directory",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/cli.py#L48-L56 |
inveniosoftware/invenio-files-rest | invenio_files_rest/cli.py | location | def location(name, uri, default):
"""Create new location."""
from .models import Location
location = Location(name=name, uri=uri, default=default)
db.session.add(location)
db.session.commit()
click.secho(str(location), fg='green') | python | def location(name, uri, default):
"""Create new location."""
from .models import Location
location = Location(name=name, uri=uri, default=default)
db.session.add(location)
db.session.commit()
click.secho(str(location), fg='green') | [
"def",
"location",
"(",
"name",
",",
"uri",
",",
"default",
")",
":",
"from",
".",
"models",
"import",
"Location",
"location",
"=",
"Location",
"(",
"name",
"=",
"name",
",",
"uri",
"=",
"uri",
",",
"default",
"=",
"default",
")",
"db",
".",
"session... | Create new location. | [
"Create",
"new",
"location",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/cli.py#L64-L70 |
django-cumulus/django-cumulus | cumulus/storage.py | get_content_type | def get_content_type(name, content):
"""
Checks if the content_type is already set.
Otherwise uses the mimetypes library to guess.
"""
if hasattr(content, "content_type"):
content_type = content.content_type
else:
mime_type, encoding = mimetypes.guess_type(name)
content_t... | python | def get_content_type(name, content):
"""
Checks if the content_type is already set.
Otherwise uses the mimetypes library to guess.
"""
if hasattr(content, "content_type"):
content_type = content.content_type
else:
mime_type, encoding = mimetypes.guess_type(name)
content_t... | [
"def",
"get_content_type",
"(",
"name",
",",
"content",
")",
":",
"if",
"hasattr",
"(",
"content",
",",
"\"content_type\"",
")",
":",
"content_type",
"=",
"content",
".",
"content_type",
"else",
":",
"mime_type",
",",
"encoding",
"=",
"mimetypes",
".",
"gues... | Checks if the content_type is already set.
Otherwise uses the mimetypes library to guess. | [
"Checks",
"if",
"the",
"content_type",
"is",
"already",
"set",
".",
"Otherwise",
"uses",
"the",
"mimetypes",
"library",
"to",
"guess",
"."
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/storage.py#L42-L52 |
django-cumulus/django-cumulus | cumulus/storage.py | sync_headers | def sync_headers(cloud_obj, headers=None, header_patterns=HEADER_PATTERNS):
"""
Overwrites the given cloud_obj's headers with the ones given as ``headers`
and adds additional headers as defined in the HEADERS setting depending on
the cloud_obj's file name.
"""
if headers is None:
headers... | python | def sync_headers(cloud_obj, headers=None, header_patterns=HEADER_PATTERNS):
"""
Overwrites the given cloud_obj's headers with the ones given as ``headers`
and adds additional headers as defined in the HEADERS setting depending on
the cloud_obj's file name.
"""
if headers is None:
headers... | [
"def",
"sync_headers",
"(",
"cloud_obj",
",",
"headers",
"=",
"None",
",",
"header_patterns",
"=",
"HEADER_PATTERNS",
")",
":",
"if",
"headers",
"is",
"None",
":",
"headers",
"=",
"{",
"}",
"# don't set headers on directories",
"content_type",
"=",
"getattr",
"(... | Overwrites the given cloud_obj's headers with the ones given as ``headers`
and adds additional headers as defined in the HEADERS setting depending on
the cloud_obj's file name. | [
"Overwrites",
"the",
"given",
"cloud_obj",
"s",
"headers",
"with",
"the",
"ones",
"given",
"as",
"headers",
"and",
"adds",
"additional",
"headers",
"as",
"defined",
"in",
"the",
"HEADERS",
"setting",
"depending",
"on",
"the",
"cloud_obj",
"s",
"file",
"name",
... | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/storage.py#L67-L90 |
django-cumulus/django-cumulus | cumulus/storage.py | get_gzipped_contents | def get_gzipped_contents(input_file):
"""
Returns a gzipped version of a previously opened file's buffer.
"""
zbuf = StringIO()
zfile = GzipFile(mode="wb", compresslevel=6, fileobj=zbuf)
zfile.write(input_file.read())
zfile.close()
return ContentFile(zbuf.getvalue()) | python | def get_gzipped_contents(input_file):
"""
Returns a gzipped version of a previously opened file's buffer.
"""
zbuf = StringIO()
zfile = GzipFile(mode="wb", compresslevel=6, fileobj=zbuf)
zfile.write(input_file.read())
zfile.close()
return ContentFile(zbuf.getvalue()) | [
"def",
"get_gzipped_contents",
"(",
"input_file",
")",
":",
"zbuf",
"=",
"StringIO",
"(",
")",
"zfile",
"=",
"GzipFile",
"(",
"mode",
"=",
"\"wb\"",
",",
"compresslevel",
"=",
"6",
",",
"fileobj",
"=",
"zbuf",
")",
"zfile",
".",
"write",
"(",
"input_file... | Returns a gzipped version of a previously opened file's buffer. | [
"Returns",
"a",
"gzipped",
"version",
"of",
"a",
"previously",
"opened",
"file",
"s",
"buffer",
"."
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/storage.py#L93-L101 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | schema_from_context | def schema_from_context(context):
"""Determine which schema to use."""
item_class = context.get('class')
return (
serializer_mapping[item_class] if item_class else BaseSchema,
context.get('many', False)
) | python | def schema_from_context(context):
"""Determine which schema to use."""
item_class = context.get('class')
return (
serializer_mapping[item_class] if item_class else BaseSchema,
context.get('many', False)
) | [
"def",
"schema_from_context",
"(",
"context",
")",
":",
"item_class",
"=",
"context",
".",
"get",
"(",
"'class'",
")",
"return",
"(",
"serializer_mapping",
"[",
"item_class",
"]",
"if",
"item_class",
"else",
"BaseSchema",
",",
"context",
".",
"get",
"(",
"'m... | Determine which schema to use. | [
"Determine",
"which",
"schema",
"to",
"use",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L201-L207 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | wait_for_taskresult | def wait_for_taskresult(task_result, content, interval, max_rounds):
"""Get helper to wait for async task result to finish.
The task will periodically send whitespace to prevent the connection from
being closed.
:param task_result: The async task to wait for.
:param content: The content to return ... | python | def wait_for_taskresult(task_result, content, interval, max_rounds):
"""Get helper to wait for async task result to finish.
The task will periodically send whitespace to prevent the connection from
being closed.
:param task_result: The async task to wait for.
:param content: The content to return ... | [
"def",
"wait_for_taskresult",
"(",
"task_result",
",",
"content",
",",
"interval",
",",
"max_rounds",
")",
":",
"assert",
"max_rounds",
">",
"0",
"def",
"_whitespace_waiting",
"(",
")",
":",
"current",
"=",
"0",
"while",
"current",
"<",
"max_rounds",
"and",
... | Get helper to wait for async task result to finish.
The task will periodically send whitespace to prevent the connection from
being closed.
:param task_result: The async task to wait for.
:param content: The content to return when the task is ready.
:param interval: The duration of a sleep period ... | [
"Get",
"helper",
"to",
"wait",
"for",
"async",
"task",
"result",
"to",
"finish",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L223-L265 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | json_serializer | def json_serializer(data=None, code=200, headers=None, context=None,
etag=None, task_result=None):
"""Build a json flask response using the given data.
:param data: The data to serialize. (Default: ``None``)
:param code: The HTTP status code. (Default: ``200``)
:param headers: The H... | python | def json_serializer(data=None, code=200, headers=None, context=None,
etag=None, task_result=None):
"""Build a json flask response using the given data.
:param data: The data to serialize. (Default: ``None``)
:param code: The HTTP status code. (Default: ``200``)
:param headers: The H... | [
"def",
"json_serializer",
"(",
"data",
"=",
"None",
",",
"code",
"=",
"200",
",",
"headers",
"=",
"None",
",",
"context",
"=",
"None",
",",
"etag",
"=",
"None",
",",
"task_result",
"=",
"None",
")",
":",
"schema_class",
",",
"many",
"=",
"schema_from_c... | Build a json flask response using the given data.
:param data: The data to serialize. (Default: ``None``)
:param code: The HTTP status code. (Default: ``200``)
:param headers: The HTTP headers to include. (Default: ``None``)
:param context: The schema class context. (Default: ``None``)
:param etag:... | [
"Build",
"a",
"json",
"flask",
"response",
"using",
"the",
"given",
"data",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L268-L312 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | BucketSchema.dump_links | def dump_links(self, o):
"""Dump links."""
return {
'self': url_for('.bucket_api', bucket_id=o.id, _external=True),
'versions': url_for(
'.bucket_api', bucket_id=o.id, _external=True) + '?versions',
'uploads': url_for(
'.bucket_api', bu... | python | def dump_links(self, o):
"""Dump links."""
return {
'self': url_for('.bucket_api', bucket_id=o.id, _external=True),
'versions': url_for(
'.bucket_api', bucket_id=o.id, _external=True) + '?versions',
'uploads': url_for(
'.bucket_api', bu... | [
"def",
"dump_links",
"(",
"self",
",",
"o",
")",
":",
"return",
"{",
"'self'",
":",
"url_for",
"(",
"'.bucket_api'",
",",
"bucket_id",
"=",
"o",
".",
"id",
",",
"_external",
"=",
"True",
")",
",",
"'versions'",
":",
"url_for",
"(",
"'.bucket_api'",
","... | Dump links. | [
"Dump",
"links",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L42-L50 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | ObjectVersionSchema.dump_links | def dump_links(self, o):
"""Dump links."""
params = {'versionId': o.version_id}
data = {
'self': url_for(
'.object_api',
bucket_id=o.bucket_id,
key=o.key,
_external=True,
**(params if not o.is_head or o.d... | python | def dump_links(self, o):
"""Dump links."""
params = {'versionId': o.version_id}
data = {
'self': url_for(
'.object_api',
bucket_id=o.bucket_id,
key=o.key,
_external=True,
**(params if not o.is_head or o.d... | [
"def",
"dump_links",
"(",
"self",
",",
"o",
")",
":",
"params",
"=",
"{",
"'versionId'",
":",
"o",
".",
"version_id",
"}",
"data",
"=",
"{",
"'self'",
":",
"url_for",
"(",
"'.object_api'",
",",
"bucket_id",
"=",
"o",
".",
"bucket_id",
",",
"key",
"="... | Dump links. | [
"Dump",
"links",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L69-L97 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | ObjectVersionSchema.wrap | def wrap(self, data, many):
"""Wrap response in envelope."""
if not many:
return data
else:
data = {'contents': data}
bucket = self.context.get('bucket')
if bucket:
data.update(BucketSchema().dump(bucket).data)
return da... | python | def wrap(self, data, many):
"""Wrap response in envelope."""
if not many:
return data
else:
data = {'contents': data}
bucket = self.context.get('bucket')
if bucket:
data.update(BucketSchema().dump(bucket).data)
return da... | [
"def",
"wrap",
"(",
"self",
",",
"data",
",",
"many",
")",
":",
"if",
"not",
"many",
":",
"return",
"data",
"else",
":",
"data",
"=",
"{",
"'contents'",
":",
"data",
"}",
"bucket",
"=",
"self",
".",
"context",
".",
"get",
"(",
"'bucket'",
")",
"i... | Wrap response in envelope. | [
"Wrap",
"response",
"in",
"envelope",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L100-L109 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | MultipartObjectSchema.dump_links | def dump_links(self, o):
"""Dump links."""
links = {
'self': url_for(
'.object_api',
bucket_id=o.bucket_id,
key=o.key,
uploadId=o.upload_id,
_external=True,
),
'object': url_for(
... | python | def dump_links(self, o):
"""Dump links."""
links = {
'self': url_for(
'.object_api',
bucket_id=o.bucket_id,
key=o.key,
uploadId=o.upload_id,
_external=True,
),
'object': url_for(
... | [
"def",
"dump_links",
"(",
"self",
",",
"o",
")",
":",
"links",
"=",
"{",
"'self'",
":",
"url_for",
"(",
"'.object_api'",
",",
"bucket_id",
"=",
"o",
".",
"bucket_id",
",",
"key",
"=",
"o",
".",
"key",
",",
"uploadId",
"=",
"o",
".",
"upload_id",
",... | Dump links. | [
"Dump",
"links",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L126-L166 |
inveniosoftware/invenio-files-rest | invenio_files_rest/serializer.py | PartSchema.wrap | def wrap(self, data, many):
"""Wrap response in envelope."""
if not many:
return data
else:
data = {'parts': data}
multipart = self.context.get('multipart')
if multipart:
data.update(MultipartObjectSchema(context={
... | python | def wrap(self, data, many):
"""Wrap response in envelope."""
if not many:
return data
else:
data = {'parts': data}
multipart = self.context.get('multipart')
if multipart:
data.update(MultipartObjectSchema(context={
... | [
"def",
"wrap",
"(",
"self",
",",
"data",
",",
"many",
")",
":",
"if",
"not",
"many",
":",
"return",
"data",
"else",
":",
"data",
"=",
"{",
"'parts'",
":",
"data",
"}",
"multipart",
"=",
"self",
".",
"context",
".",
"get",
"(",
"'multipart'",
")",
... | Wrap response in envelope. | [
"Wrap",
"response",
"in",
"envelope",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/serializer.py#L180-L190 |
swistakm/python-gmaps | src/gmaps/directions.py | Directions.directions | def directions(self, origin, destination, mode=None, alternatives=None,
waypoints=None, optimize_waypoints=False,
avoid=None, language=None, units=None,
region=None, departure_time=None,
arrival_time=None, sensor=None):
"""Get direction... | python | def directions(self, origin, destination, mode=None, alternatives=None,
waypoints=None, optimize_waypoints=False,
avoid=None, language=None, units=None,
region=None, departure_time=None,
arrival_time=None, sensor=None):
"""Get direction... | [
"def",
"directions",
"(",
"self",
",",
"origin",
",",
"destination",
",",
"mode",
"=",
"None",
",",
"alternatives",
"=",
"None",
",",
"waypoints",
"=",
"None",
",",
"optimize_waypoints",
"=",
"False",
",",
"avoid",
"=",
"None",
",",
"language",
"=",
"Non... | Get directions between locations
:param origin: Origin location - string address; (latitude, longitude)
two-tuple, dict with ("lat", "lon") keys or object with (lat, lon)
attributes
:param destination: Destination location - type same as origin
:param mode: Travel mode a... | [
"Get",
"directions",
"between",
"locations"
] | train | https://github.com/swistakm/python-gmaps/blob/ef3bdea6f02277200f21a09f99d4e2aebad762b9/src/gmaps/directions.py#L8-L61 |
inveniosoftware/invenio-files-rest | invenio_files_rest/alembic/2e97565eba72_create_files_rest_tables.py | upgrade | def upgrade():
"""Upgrade database."""
# Variant types:
def created():
"""Return instance of a column."""
return sa.Column(
'created',
sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
nullable=False
)
def updated():
"""Retur... | python | def upgrade():
"""Upgrade database."""
# Variant types:
def created():
"""Return instance of a column."""
return sa.Column(
'created',
sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
nullable=False
)
def updated():
"""Retur... | [
"def",
"upgrade",
"(",
")",
":",
"# Variant types:",
"def",
"created",
"(",
")",
":",
"\"\"\"Return instance of a column.\"\"\"",
"return",
"sa",
".",
"Column",
"(",
"'created'",
",",
"sa",
".",
"DateTime",
"(",
")",
".",
"with_variant",
"(",
"mysql",
".",
"... | Upgrade database. | [
"Upgrade",
"database",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/alembic/2e97565eba72_create_files_rest_tables.py#L23-L214 |
inveniosoftware/invenio-files-rest | invenio_files_rest/alembic/2e97565eba72_create_files_rest_tables.py | downgrade | def downgrade():
"""Downgrade database."""
op.drop_table('files_multipartobject_part')
op.drop_index(op.f('ix_files_object__mimetype'), table_name='files_object')
op.drop_table('files_object')
op.drop_table('files_multipartobject')
op.drop_table('files_buckettags')
op.drop_table('files_bucke... | python | def downgrade():
"""Downgrade database."""
op.drop_table('files_multipartobject_part')
op.drop_index(op.f('ix_files_object__mimetype'), table_name='files_object')
op.drop_table('files_object')
op.drop_table('files_multipartobject')
op.drop_table('files_buckettags')
op.drop_table('files_bucke... | [
"def",
"downgrade",
"(",
")",
":",
"op",
".",
"drop_table",
"(",
"'files_multipartobject_part'",
")",
"op",
".",
"drop_index",
"(",
"op",
".",
"f",
"(",
"'ix_files_object__mimetype'",
")",
",",
"table_name",
"=",
"'files_object'",
")",
"op",
".",
"drop_table",... | Downgrade database. | [
"Downgrade",
"database",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/alembic/2e97565eba72_create_files_rest_tables.py#L217-L226 |
inveniosoftware/invenio-files-rest | invenio_files_rest/utils.py | guess_mimetype | def guess_mimetype(filename):
"""Map extra mimetype with the encoding provided.
:returns: The extra mimetype.
"""
m, encoding = mimetypes.guess_type(filename)
if encoding:
m = ENCODING_MIMETYPES.get(encoding, None)
return m or 'application/octet-stream' | python | def guess_mimetype(filename):
"""Map extra mimetype with the encoding provided.
:returns: The extra mimetype.
"""
m, encoding = mimetypes.guess_type(filename)
if encoding:
m = ENCODING_MIMETYPES.get(encoding, None)
return m or 'application/octet-stream' | [
"def",
"guess_mimetype",
"(",
"filename",
")",
":",
"m",
",",
"encoding",
"=",
"mimetypes",
".",
"guess_type",
"(",
"filename",
")",
"if",
"encoding",
":",
"m",
"=",
"ENCODING_MIMETYPES",
".",
"get",
"(",
"encoding",
",",
"None",
")",
"return",
"m",
"or"... | Map extra mimetype with the encoding provided.
:returns: The extra mimetype. | [
"Map",
"extra",
"mimetype",
"with",
"the",
"encoding",
"provided",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/utils.py#L50-L58 |
inveniosoftware/invenio-files-rest | invenio_files_rest/admin.py | link | def link(text, link_func):
"""Generate a object formatter for links.."""
def object_formatter(v, c, m, p):
"""Format object view link."""
return Markup('<a href="{0}">{1}</a>'.format(
link_func(m), text))
return object_formatter | python | def link(text, link_func):
"""Generate a object formatter for links.."""
def object_formatter(v, c, m, p):
"""Format object view link."""
return Markup('<a href="{0}">{1}</a>'.format(
link_func(m), text))
return object_formatter | [
"def",
"link",
"(",
"text",
",",
"link_func",
")",
":",
"def",
"object_formatter",
"(",
"v",
",",
"c",
",",
"m",
",",
"p",
")",
":",
"\"\"\"Format object view link.\"\"\"",
"return",
"Markup",
"(",
"'<a href=\"{0}\">{1}</a>'",
".",
"format",
"(",
"link_func",
... | Generate a object formatter for links.. | [
"Generate",
"a",
"object",
"formatter",
"for",
"links",
".."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/admin.py#L40-L46 |
inveniosoftware/invenio-files-rest | invenio_files_rest/admin.py | FileInstanceModelView.action_verify_checksum | def action_verify_checksum(self, ids):
"""Inactivate users."""
try:
count = 0
for file_id in ids:
f = FileInstance.query.filter_by(
id=uuid.UUID(file_id)).one_or_none()
if f is None:
raise ValueError(_("Canno... | python | def action_verify_checksum(self, ids):
"""Inactivate users."""
try:
count = 0
for file_id in ids:
f = FileInstance.query.filter_by(
id=uuid.UUID(file_id)).one_or_none()
if f is None:
raise ValueError(_("Canno... | [
"def",
"action_verify_checksum",
"(",
"self",
",",
"ids",
")",
":",
"try",
":",
"count",
"=",
"0",
"for",
"file_id",
"in",
"ids",
":",
"f",
"=",
"FileInstance",
".",
"query",
".",
"filter_by",
"(",
"id",
"=",
"uuid",
".",
"UUID",
"(",
"file_id",
")",... | Inactivate users. | [
"Inactivate",
"users",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/admin.py#L209-L227 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | validate_tag | def validate_tag(key, value):
"""Validate a tag.
Keys must be less than 128 chars and values must be less than 256 chars.
"""
# Note, parse_sql does not include a keys if the value is an empty string
# (e.g. 'key=&test=a'), and thus technically we should not get strings
# which have zero length... | python | def validate_tag(key, value):
"""Validate a tag.
Keys must be less than 128 chars and values must be less than 256 chars.
"""
# Note, parse_sql does not include a keys if the value is an empty string
# (e.g. 'key=&test=a'), and thus technically we should not get strings
# which have zero length... | [
"def",
"validate_tag",
"(",
"key",
",",
"value",
")",
":",
"# Note, parse_sql does not include a keys if the value is an empty string",
"# (e.g. 'key=&test=a'), and thus technically we should not get strings",
"# which have zero length.",
"klen",
"=",
"len",
"(",
"key",
")",
"vlen"... | Validate a tag.
Keys must be less than 128 chars and values must be less than 256 chars. | [
"Validate",
"a",
"tag",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L67-L78 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | parse_header_tags | def parse_header_tags():
"""Parse tags specified in the HTTP request header."""
# Get the value of the custom HTTP header and interpret it as an query
# string
qs = request.headers.get(
current_app.config['FILES_REST_FILE_TAGS_HEADER'], '')
tags = {}
for key, value in parse_qsl(qs):
... | python | def parse_header_tags():
"""Parse tags specified in the HTTP request header."""
# Get the value of the custom HTTP header and interpret it as an query
# string
qs = request.headers.get(
current_app.config['FILES_REST_FILE_TAGS_HEADER'], '')
tags = {}
for key, value in parse_qsl(qs):
... | [
"def",
"parse_header_tags",
"(",
")",
":",
"# Get the value of the custom HTTP header and interpret it as an query",
"# string",
"qs",
"=",
"request",
".",
"headers",
".",
"get",
"(",
"current_app",
".",
"config",
"[",
"'FILES_REST_FILE_TAGS_HEADER'",
"]",
",",
"''",
")... | Parse tags specified in the HTTP request header. | [
"Parse",
"tags",
"specified",
"in",
"the",
"HTTP",
"request",
"header",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L81-L97 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | default_partfactory | def default_partfactory(part_number=None, content_length=None,
content_type=None, content_md5=None):
"""Get default part factory.
:param part_number: The part number. (Default: ``None``)
:param content_length: The content length. (Default: ``None``)
:param content_type: The HTTP... | python | def default_partfactory(part_number=None, content_length=None,
content_type=None, content_md5=None):
"""Get default part factory.
:param part_number: The part number. (Default: ``None``)
:param content_length: The content length. (Default: ``None``)
:param content_type: The HTTP... | [
"def",
"default_partfactory",
"(",
"part_number",
"=",
"None",
",",
"content_length",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"content_md5",
"=",
"None",
")",
":",
"return",
"content_length",
",",
"part_number",
",",
"request",
".",
"stream",
",",
... | Get default part factory.
:param part_number: The part number. (Default: ``None``)
:param content_length: The content length. (Default: ``None``)
:param content_type: The HTTP Content-Type. (Default: ``None``)
:param content_md5: The content MD5. (Default: ``None``)
:returns: The content length, th... | [
"Get",
"default",
"part",
"factory",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L124-L136 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | stream_uploadfactory | def stream_uploadfactory(content_md5=None, content_length=None,
content_type=None):
"""Get default put factory.
If Content-Type is ``'multipart/form-data'`` then the stream is aborted.
:param content_md5: The content MD5. (Default: ``None``)
:param content_length: The content ... | python | def stream_uploadfactory(content_md5=None, content_length=None,
content_type=None):
"""Get default put factory.
If Content-Type is ``'multipart/form-data'`` then the stream is aborted.
:param content_md5: The content MD5. (Default: ``None``)
:param content_length: The content ... | [
"def",
"stream_uploadfactory",
"(",
"content_md5",
"=",
"None",
",",
"content_length",
"=",
"None",
",",
"content_type",
"=",
"None",
")",
":",
"if",
"content_type",
".",
"startswith",
"(",
"'multipart/form-data'",
")",
":",
"abort",
"(",
"422",
")",
"return",... | Get default put factory.
If Content-Type is ``'multipart/form-data'`` then the stream is aborted.
:param content_md5: The content MD5. (Default: ``None``)
:param content_length: The content length. (Default: ``None``)
:param content_type: The HTTP Content-Type. (Default: ``None``)
:returns: The st... | [
"Get",
"default",
"put",
"factory",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L157-L171 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ngfileupload_partfactory | def ngfileupload_partfactory(part_number=None, content_length=None,
uploaded_file=None):
"""Part factory for ng-file-upload.
:param part_number: The part number. (Default: ``None``)
:param content_length: The content length. (Default: ``None``)
:param uploaded_file: The upl... | python | def ngfileupload_partfactory(part_number=None, content_length=None,
uploaded_file=None):
"""Part factory for ng-file-upload.
:param part_number: The part number. (Default: ``None``)
:param content_length: The content length. (Default: ``None``)
:param uploaded_file: The upl... | [
"def",
"ngfileupload_partfactory",
"(",
"part_number",
"=",
"None",
",",
"content_length",
"=",
"None",
",",
"uploaded_file",
"=",
"None",
")",
":",
"return",
"content_length",
",",
"part_number",
",",
"uploaded_file",
".",
"stream",
",",
"uploaded_file",
".",
"... | Part factory for ng-file-upload.
:param part_number: The part number. (Default: ``None``)
:param content_length: The content length. (Default: ``None``)
:param uploaded_file: The upload request. (Default: ``None``)
:returns: The content length, part number, stream, HTTP Content-Type
header. | [
"Part",
"factory",
"for",
"ng",
"-",
"file",
"-",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L192-L203 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ngfileupload_uploadfactory | def ngfileupload_uploadfactory(content_length=None, content_type=None,
uploaded_file=None):
"""Get default put factory.
If Content-Type is ``'multipart/form-data'`` then the stream is aborted.
:param content_length: The content length. (Default: ``None``)
:param content_... | python | def ngfileupload_uploadfactory(content_length=None, content_type=None,
uploaded_file=None):
"""Get default put factory.
If Content-Type is ``'multipart/form-data'`` then the stream is aborted.
:param content_length: The content length. (Default: ``None``)
:param content_... | [
"def",
"ngfileupload_uploadfactory",
"(",
"content_length",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"uploaded_file",
"=",
"None",
")",
":",
"if",
"not",
"content_type",
".",
"startswith",
"(",
"'multipart/form-data'",
")",
":",
"abort",
"(",
"422",
... | Get default put factory.
If Content-Type is ``'multipart/form-data'`` then the stream is aborted.
:param content_length: The content length. (Default: ``None``)
:param content_type: The HTTP Content-Type. (Default: ``None``)
:param uploaded_file: The upload request. (Default: ``None``)
:param file... | [
"Get",
"default",
"put",
"factory",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L223-L238 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | pass_bucket | def pass_bucket(f):
"""Decorate to retrieve a bucket."""
@wraps(f)
def decorate(*args, **kwargs):
bucket_id = kwargs.pop('bucket_id')
bucket = Bucket.get(as_uuid(bucket_id))
if not bucket:
abort(404, 'Bucket does not exist.')
return f(bucket=bucket, *args, **kwarg... | python | def pass_bucket(f):
"""Decorate to retrieve a bucket."""
@wraps(f)
def decorate(*args, **kwargs):
bucket_id = kwargs.pop('bucket_id')
bucket = Bucket.get(as_uuid(bucket_id))
if not bucket:
abort(404, 'Bucket does not exist.')
return f(bucket=bucket, *args, **kwarg... | [
"def",
"pass_bucket",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"decorate",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"bucket_id",
"=",
"kwargs",
".",
"pop",
"(",
"'bucket_id'",
")",
"bucket",
"=",
"Bucket",
".",
"get",
"... | Decorate to retrieve a bucket. | [
"Decorate",
"to",
"retrieve",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L244-L253 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | pass_multipart | def pass_multipart(with_completed=False):
"""Decorate to retrieve an object."""
def decorate(f):
@wraps(f)
def inner(self, bucket, key, upload_id, *args, **kwargs):
obj = MultipartObject.get(
bucket, key, upload_id, with_completed=with_completed)
if obj is... | python | def pass_multipart(with_completed=False):
"""Decorate to retrieve an object."""
def decorate(f):
@wraps(f)
def inner(self, bucket, key, upload_id, *args, **kwargs):
obj = MultipartObject.get(
bucket, key, upload_id, with_completed=with_completed)
if obj is... | [
"def",
"pass_multipart",
"(",
"with_completed",
"=",
"False",
")",
":",
"def",
"decorate",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"inner",
"(",
"self",
",",
"bucket",
",",
"key",
",",
"upload_id",
",",
"*",
"args",
",",
"*",
"*",
... | Decorate to retrieve an object. | [
"Decorate",
"to",
"retrieve",
"an",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L256-L267 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | check_permission | def check_permission(permission, hidden=True):
"""Check if permission is allowed.
If permission fails then the connection is aborted.
:param permission: The permission to check.
:param hidden: Determine if a 404 error (``True``) or 401/403 error
(``False``) should be returned if the permission... | python | def check_permission(permission, hidden=True):
"""Check if permission is allowed.
If permission fails then the connection is aborted.
:param permission: The permission to check.
:param hidden: Determine if a 404 error (``True``) or 401/403 error
(``False``) should be returned if the permission... | [
"def",
"check_permission",
"(",
"permission",
",",
"hidden",
"=",
"True",
")",
":",
"if",
"permission",
"is",
"not",
"None",
"and",
"not",
"permission",
".",
"can",
"(",
")",
":",
"if",
"hidden",
":",
"abort",
"(",
"404",
")",
"else",
":",
"if",
"cur... | Check if permission is allowed.
If permission fails then the connection is aborted.
:param permission: The permission to check.
:param hidden: Determine if a 404 error (``True``) or 401/403 error
(``False``) should be returned if the permission is rejected (i.e.
hide or reveal the existenc... | [
"Check",
"if",
"permission",
"is",
"allowed",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L273-L290 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | need_permissions | def need_permissions(object_getter, action, hidden=True):
"""Get permission for buckets or abort.
:param object_getter: The function used to retrieve the object and pass it
to the permission factory.
:param action: The action needed.
:param hidden: Determine which kind of error to return. (Defa... | python | def need_permissions(object_getter, action, hidden=True):
"""Get permission for buckets or abort.
:param object_getter: The function used to retrieve the object and pass it
to the permission factory.
:param action: The action needed.
:param hidden: Determine which kind of error to return. (Defa... | [
"def",
"need_permissions",
"(",
"object_getter",
",",
"action",
",",
"hidden",
"=",
"True",
")",
":",
"def",
"decorator_builder",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"decorate",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",... | Get permission for buckets or abort.
:param object_getter: The function used to retrieve the object and pass it
to the permission factory.
:param action: The action needed.
:param hidden: Determine which kind of error to return. (Default: ``True``) | [
"Get",
"permission",
"for",
"buckets",
"or",
"abort",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L293-L311 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | LocationResource.post | def post(self):
"""Create bucket."""
with db.session.begin_nested():
bucket = Bucket.create(
storage_class=current_app.config[
'FILES_REST_DEFAULT_STORAGE_CLASS'
],
)
db.session.commit()
return self.make_response... | python | def post(self):
"""Create bucket."""
with db.session.begin_nested():
bucket = Bucket.create(
storage_class=current_app.config[
'FILES_REST_DEFAULT_STORAGE_CLASS'
],
)
db.session.commit()
return self.make_response... | [
"def",
"post",
"(",
"self",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"bucket",
"=",
"Bucket",
".",
"create",
"(",
"storage_class",
"=",
"current_app",
".",
"config",
"[",
"'FILES_REST_DEFAULT_STORAGE_CLASS'",
"]",
",",
")... | Create bucket. | [
"Create",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L337-L351 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | BucketResource.multipart_listuploads | def multipart_listuploads(self, bucket):
"""List objects in a bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response.
"""
return self.make_response(
data=MultipartObject.query_by_bucket(bucket).limit(1000).all(),
... | python | def multipart_listuploads(self, bucket):
"""List objects in a bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response.
"""
return self.make_response(
data=MultipartObject.query_by_bucket(bucket).limit(1000).all(),
... | [
"def",
"multipart_listuploads",
"(",
"self",
",",
"bucket",
")",
":",
"return",
"self",
".",
"make_response",
"(",
"data",
"=",
"MultipartObject",
".",
"query_by_bucket",
"(",
"bucket",
")",
".",
"limit",
"(",
"1000",
")",
".",
"all",
"(",
")",
",",
"con... | List objects in a bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response. | [
"List",
"objects",
"in",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L371-L384 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | BucketResource.listobjects | def listobjects(self, bucket, versions):
"""List objects in a bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response.
"""
if versions is not missing:
check_permission(
current_permission_factory(bucke... | python | def listobjects(self, bucket, versions):
"""List objects in a bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response.
"""
if versions is not missing:
check_permission(
current_permission_factory(bucke... | [
"def",
"listobjects",
"(",
"self",
",",
"bucket",
",",
"versions",
")",
":",
"if",
"versions",
"is",
"not",
"missing",
":",
"check_permission",
"(",
"current_permission_factory",
"(",
"bucket",
",",
"'bucket-read-versions'",
")",
",",
"hidden",
"=",
"False",
"... | List objects in a bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response. | [
"List",
"objects",
"in",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L390-L409 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | BucketResource.get | def get(self, bucket=None, versions=missing, uploads=missing):
"""Get list of objects in the bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response.
"""
if uploads is not missing:
return self.multipart_listuploads(bu... | python | def get(self, bucket=None, versions=missing, uploads=missing):
"""Get list of objects in the bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response.
"""
if uploads is not missing:
return self.multipart_listuploads(bu... | [
"def",
"get",
"(",
"self",
",",
"bucket",
"=",
"None",
",",
"versions",
"=",
"missing",
",",
"uploads",
"=",
"missing",
")",
":",
"if",
"uploads",
"is",
"not",
"missing",
":",
"return",
"self",
".",
"multipart_listuploads",
"(",
"bucket",
")",
"else",
... | Get list of objects in the bucket.
:param bucket: A :class:`invenio_files_rest.models.Bucket` instance.
:returns: The Flask response. | [
"Get",
"list",
"of",
"objects",
"in",
"the",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L413-L422 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.check_object_permission | def check_object_permission(obj):
"""Retrieve object and abort if it doesn't exists."""
check_permission(current_permission_factory(
obj,
'object-read'
))
if not obj.is_head:
check_permission(
current_permission_factory(obj, 'object-rea... | python | def check_object_permission(obj):
"""Retrieve object and abort if it doesn't exists."""
check_permission(current_permission_factory(
obj,
'object-read'
))
if not obj.is_head:
check_permission(
current_permission_factory(obj, 'object-rea... | [
"def",
"check_object_permission",
"(",
"obj",
")",
":",
"check_permission",
"(",
"current_permission_factory",
"(",
"obj",
",",
"'object-read'",
")",
")",
"if",
"not",
"obj",
".",
"is_head",
":",
"check_permission",
"(",
"current_permission_factory",
"(",
"obj",
"... | Retrieve object and abort if it doesn't exists. | [
"Retrieve",
"object",
"and",
"abort",
"if",
"it",
"doesn",
"t",
"exists",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L497-L507 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.get_object | def get_object(cls, bucket, key, version_id):
"""Retrieve object and abort if it doesn't exists.
If the file is not found, the connection is aborted and the 404
error is returned.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
... | python | def get_object(cls, bucket, key, version_id):
"""Retrieve object and abort if it doesn't exists.
If the file is not found, the connection is aborted and the 404
error is returned.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
... | [
"def",
"get_object",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"version_id",
")",
":",
"obj",
"=",
"ObjectVersion",
".",
"get",
"(",
"bucket",
",",
"key",
",",
"version_id",
"=",
"version_id",
")",
"if",
"not",
"obj",
":",
"abort",
"(",
"404",
",",... | Retrieve object and abort if it doesn't exists.
If the file is not found, the connection is aborted and the 404
error is returned.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
:param version_id: The version ID.
:returns: A... | [
"Retrieve",
"object",
"and",
"abort",
"if",
"it",
"doesn",
"t",
"exists",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L510-L527 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.create_object | def create_object(self, bucket, key):
"""Create a new object.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
:returns: A Flask response.
"""
# Initial validation of size based on Content-Length.
# User can tamper with... | python | def create_object(self, bucket, key):
"""Create a new object.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
:returns: A Flask response.
"""
# Initial validation of size based on Content-Length.
# User can tamper with... | [
"def",
"create_object",
"(",
"self",
",",
"bucket",
",",
"key",
")",
":",
"# Initial validation of size based on Content-Length.",
"# User can tamper with Content-Length, so this is just an initial up",
"# front check. The storage subsystem must validate the size limit as",
"# well.",
"s... | Create a new object.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
:returns: A Flask response. | [
"Create",
"a",
"new",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L529-L566 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.delete_object | def delete_object(self, bucket, obj, version_id):
"""Delete an existing object.
:param bucket: The bucket (instance or id) to get the object from.
:param obj: A :class:`invenio_files_rest.models.ObjectVersion`
instance.
:param version_id: The version ID.
:returns: A ... | python | def delete_object(self, bucket, obj, version_id):
"""Delete an existing object.
:param bucket: The bucket (instance or id) to get the object from.
:param obj: A :class:`invenio_files_rest.models.ObjectVersion`
instance.
:param version_id: The version ID.
:returns: A ... | [
"def",
"delete_object",
"(",
"self",
",",
"bucket",
",",
"obj",
",",
"version_id",
")",
":",
"if",
"version_id",
"is",
"None",
":",
"# Create a delete marker.",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"ObjectVersion",
".",
"delete",... | Delete an existing object.
:param bucket: The bucket (instance or id) to get the object from.
:param obj: A :class:`invenio_files_rest.models.ObjectVersion`
instance.
:param version_id: The version ID.
:returns: A Flask response. | [
"Delete",
"an",
"existing",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L573-L598 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.send_object | def send_object(bucket, obj, expected_chksum=None,
logger_data=None, restricted=True, as_attachment=False):
"""Send an object for a given bucket.
:param bucket: The bucket (instance or id) to get the object from.
:param obj: A :class:`invenio_files_rest.models.ObjectVersion`... | python | def send_object(bucket, obj, expected_chksum=None,
logger_data=None, restricted=True, as_attachment=False):
"""Send an object for a given bucket.
:param bucket: The bucket (instance or id) to get the object from.
:param obj: A :class:`invenio_files_rest.models.ObjectVersion`... | [
"def",
"send_object",
"(",
"bucket",
",",
"obj",
",",
"expected_chksum",
"=",
"None",
",",
"logger_data",
"=",
"None",
",",
"restricted",
"=",
"True",
",",
"as_attachment",
"=",
"False",
")",
":",
"if",
"not",
"obj",
".",
"is_head",
":",
"check_permission"... | Send an object for a given bucket.
:param bucket: The bucket (instance or id) to get the object from.
:param obj: A :class:`invenio_files_rest.models.ObjectVersion`
instance.
:params expected_chksum: Expected checksum.
:param logger_data: The python logger.
:param kw... | [
"Send",
"an",
"object",
"for",
"a",
"given",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L601-L625 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.multipart_listparts | def multipart_listparts(self, multipart):
"""Get parts of a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
return self.make_response(
data=Part.query_by_multipart(
... | python | def multipart_listparts(self, multipart):
"""Get parts of a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
return self.make_response(
data=Part.query_by_multipart(
... | [
"def",
"multipart_listparts",
"(",
"self",
",",
"multipart",
")",
":",
"return",
"self",
".",
"make_response",
"(",
"data",
"=",
"Part",
".",
"query_by_multipart",
"(",
"multipart",
")",
".",
"order_by",
"(",
"Part",
".",
"part_number",
")",
".",
"limit",
... | Get parts of a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response. | [
"Get",
"parts",
"of",
"a",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L635-L650 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.multipart_init | def multipart_init(self, bucket, key, size=None, part_size=None):
"""Initialize a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
:param size: The total size.
:param part_size: The part size.
:raises invenio_... | python | def multipart_init(self, bucket, key, size=None, part_size=None):
"""Initialize a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
:param size: The total size.
:param part_size: The part size.
:raises invenio_... | [
"def",
"multipart_init",
"(",
"self",
",",
"bucket",
",",
"key",
",",
"size",
"=",
"None",
",",
"part_size",
"=",
"None",
")",
":",
"if",
"size",
"is",
"None",
":",
"raise",
"MissingQueryParameter",
"(",
"'size'",
")",
"if",
"part_size",
"is",
"None",
... | Initialize a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
:param key: The file key.
:param size: The total size.
:param part_size: The part size.
:raises invenio_files_rest.errors.MissingQueryParameter: If size or
part_size are... | [
"Initialize",
"a",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L653-L676 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.multipart_uploadpart | def multipart_uploadpart(self, multipart):
"""Upload a part.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
content_length, part_number, stream, content_type, content_md5, tags =\
current_f... | python | def multipart_uploadpart(self, multipart):
"""Upload a part.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
content_length, part_number, stream, content_type, content_md5, tags =\
current_f... | [
"def",
"multipart_uploadpart",
"(",
"self",
",",
"multipart",
")",
":",
"content_length",
",",
"part_number",
",",
"stream",
",",
"content_type",
",",
"content_md5",
",",
"tags",
"=",
"current_files_rest",
".",
"multipart_partfactory",
"(",
")",
"if",
"content_len... | Upload a part.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response. | [
"Upload",
"a",
"part",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L679-L715 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.multipart_complete | def multipart_complete(self, multipart):
"""Complete a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
multipart.complete()
db.session.commit()
version_id = str(uuid.u... | python | def multipart_complete(self, multipart):
"""Complete a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
multipart.complete()
db.session.commit()
version_id = str(uuid.u... | [
"def",
"multipart_complete",
"(",
"self",
",",
"multipart",
")",
":",
"multipart",
".",
"complete",
"(",
")",
"db",
".",
"session",
".",
"commit",
"(",
")",
"version_id",
"=",
"str",
"(",
"uuid",
".",
"uuid4",
"(",
")",
")",
"return",
"self",
".",
"m... | Complete a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response. | [
"Complete",
"a",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L718-L743 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.multipart_delete | def multipart_delete(self, multipart):
"""Abort a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
multipart.delete()
db.session.commit()
if multipart.file_id:
... | python | def multipart_delete(self, multipart):
"""Abort a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response.
"""
multipart.delete()
db.session.commit()
if multipart.file_id:
... | [
"def",
"multipart_delete",
"(",
"self",
",",
"multipart",
")",
":",
"multipart",
".",
"delete",
"(",
")",
"db",
".",
"session",
".",
"commit",
"(",
")",
"if",
"multipart",
".",
"file_id",
":",
"remove_file_data",
".",
"delay",
"(",
"str",
"(",
"multipart... | Abort a multipart upload.
:param multipart: A :class:`invenio_files_rest.models.MultipartObject`
instance.
:returns: A Flask response. | [
"Abort",
"a",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L750-L761 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.get | def get(self, bucket=None, key=None, version_id=None, upload_id=None,
uploads=None, download=None):
"""Get object or list parts of a multpart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default... | python | def get(self, bucket=None, key=None, version_id=None, upload_id=None,
uploads=None, download=None):
"""Get object or list parts of a multpart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default... | [
"def",
"get",
"(",
"self",
",",
"bucket",
"=",
"None",
",",
"key",
"=",
"None",
",",
"version_id",
"=",
"None",
",",
"upload_id",
"=",
"None",
",",
"uploads",
"=",
"None",
",",
"download",
"=",
"None",
")",
":",
"if",
"upload_id",
":",
"return",
"s... | Get object or list parts of a multpart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param version_id: The version ID. (Default: ``None``)
:param upload_id: The upload ID. (Defaul... | [
"Get",
"object",
"or",
"list",
"parts",
"of",
"a",
"multpart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L768-L787 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.post | def post(self, bucket=None, key=None, uploads=missing, upload_id=None):
"""Upload a new object or start/complete a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param up... | python | def post(self, bucket=None, key=None, uploads=missing, upload_id=None):
"""Upload a new object or start/complete a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param up... | [
"def",
"post",
"(",
"self",
",",
"bucket",
"=",
"None",
",",
"key",
"=",
"None",
",",
"uploads",
"=",
"missing",
",",
"upload_id",
"=",
"None",
")",
":",
"if",
"uploads",
"is",
"not",
"missing",
":",
"return",
"self",
".",
"multipart_init",
"(",
"buc... | Upload a new object or start/complete a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param upload_id: The upload ID. (Default: ``None``)
:returns: A Flask response. | [
"Upload",
"a",
"new",
"object",
"or",
"start",
"/",
"complete",
"a",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L792-L805 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.put | def put(self, bucket=None, key=None, upload_id=None):
"""Update a new object or upload a part of a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param upload_id: The upl... | python | def put(self, bucket=None, key=None, upload_id=None):
"""Update a new object or upload a part of a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param upload_id: The upl... | [
"def",
"put",
"(",
"self",
",",
"bucket",
"=",
"None",
",",
"key",
"=",
"None",
",",
"upload_id",
"=",
"None",
")",
":",
"if",
"upload_id",
"is",
"not",
"None",
":",
"return",
"self",
".",
"multipart_uploadpart",
"(",
"bucket",
",",
"key",
",",
"uplo... | Update a new object or upload a part of a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param upload_id: The upload ID. (Default: ``None``)
:returns: A Flask response. | [
"Update",
"a",
"new",
"object",
"or",
"upload",
"a",
"part",
"of",
"a",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L810-L822 |
inveniosoftware/invenio-files-rest | invenio_files_rest/views.py | ObjectResource.delete | def delete(self, bucket=None, key=None, version_id=None, upload_id=None,
uploads=None):
"""Delete an object or abort a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``... | python | def delete(self, bucket=None, key=None, version_id=None, upload_id=None,
uploads=None):
"""Delete an object or abort a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``... | [
"def",
"delete",
"(",
"self",
",",
"bucket",
"=",
"None",
",",
"key",
"=",
"None",
",",
"version_id",
"=",
"None",
",",
"upload_id",
"=",
"None",
",",
"uploads",
"=",
"None",
")",
":",
"if",
"upload_id",
"is",
"not",
"None",
":",
"return",
"self",
... | Delete an object or abort a multipart upload.
:param bucket: The bucket (instance or id) to get the object from.
(Default: ``None``)
:param key: The file key. (Default: ``None``)
:param version_id: The version ID. (Default: ``None``)
:param upload_id: The upload ID. (Default... | [
"Delete",
"an",
"object",
"or",
"abort",
"a",
"multipart",
"upload",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/views.py#L826-L841 |
django-cumulus/django-cumulus | cumulus/authentication.py | Auth._get_container | def _get_container(self):
"""
Gets or creates the container.
"""
if not hasattr(self, "_container"):
if self.use_pyrax:
self._container = self.connection.create_container(self.container_name)
else:
self._container = None
ret... | python | def _get_container(self):
"""
Gets or creates the container.
"""
if not hasattr(self, "_container"):
if self.use_pyrax:
self._container = self.connection.create_container(self.container_name)
else:
self._container = None
ret... | [
"def",
"_get_container",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_container\"",
")",
":",
"if",
"self",
".",
"use_pyrax",
":",
"self",
".",
"_container",
"=",
"self",
".",
"connection",
".",
"create_container",
"(",
"self",
".... | Gets or creates the container. | [
"Gets",
"or",
"creates",
"the",
"container",
"."
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/authentication.py#L101-L110 |
django-cumulus/django-cumulus | cumulus/authentication.py | Auth._set_container | def _set_container(self, container):
"""
Sets the container (and, if needed, the configured TTL on it), making
the container publicly available.
"""
if self.use_pyrax:
if container.cdn_ttl != self.ttl or not container.cdn_enabled:
container.make_public... | python | def _set_container(self, container):
"""
Sets the container (and, if needed, the configured TTL on it), making
the container publicly available.
"""
if self.use_pyrax:
if container.cdn_ttl != self.ttl or not container.cdn_enabled:
container.make_public... | [
"def",
"_set_container",
"(",
"self",
",",
"container",
")",
":",
"if",
"self",
".",
"use_pyrax",
":",
"if",
"container",
".",
"cdn_ttl",
"!=",
"self",
".",
"ttl",
"or",
"not",
"container",
".",
"cdn_enabled",
":",
"container",
".",
"make_public",
"(",
"... | Sets the container (and, if needed, the configured TTL on it), making
the container publicly available. | [
"Sets",
"the",
"container",
"(",
"and",
"if",
"needed",
"the",
"configured",
"TTL",
"on",
"it",
")",
"making",
"the",
"container",
"publicly",
"available",
"."
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/authentication.py#L112-L122 |
django-cumulus/django-cumulus | cumulus/authentication.py | Auth._get_object | def _get_object(self, name):
"""
Helper function to retrieve the requested Object.
"""
if self.use_pyrax:
try:
return self.container.get_object(name)
except pyrax.exceptions.NoSuchObject:
return None
elif swiftclient:
... | python | def _get_object(self, name):
"""
Helper function to retrieve the requested Object.
"""
if self.use_pyrax:
try:
return self.container.get_object(name)
except pyrax.exceptions.NoSuchObject:
return None
elif swiftclient:
... | [
"def",
"_get_object",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"use_pyrax",
":",
"try",
":",
"return",
"self",
".",
"container",
".",
"get_object",
"(",
"name",
")",
"except",
"pyrax",
".",
"exceptions",
".",
"NoSuchObject",
":",
"return",
... | Helper function to retrieve the requested Object. | [
"Helper",
"function",
"to",
"retrieve",
"the",
"requested",
"Object",
"."
] | train | https://github.com/django-cumulus/django-cumulus/blob/64feb07b857af28f226be4899e875c29405e261d/cumulus/authentication.py#L157-L172 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | as_object_version | def as_object_version(value):
"""Get an object version object from an object version ID or an object version.
:param value: A :class:`invenio_files_rest.models.ObjectVersion` or an
object version ID.
:returns: A :class:`invenio_files_rest.models.ObjectVersion` instance.
"""
return value if ... | python | def as_object_version(value):
"""Get an object version object from an object version ID or an object version.
:param value: A :class:`invenio_files_rest.models.ObjectVersion` or an
object version ID.
:returns: A :class:`invenio_files_rest.models.ObjectVersion` instance.
"""
return value if ... | [
"def",
"as_object_version",
"(",
"value",
")",
":",
"return",
"value",
"if",
"isinstance",
"(",
"value",
",",
"ObjectVersion",
")",
"else",
"ObjectVersion",
".",
"query",
".",
"filter_by",
"(",
"version_id",
"=",
"value",
")",
".",
"one_or_none",
"(",
")"
] | Get an object version object from an object version ID or an object version.
:param value: A :class:`invenio_files_rest.models.ObjectVersion` or an
object version ID.
:returns: A :class:`invenio_files_rest.models.ObjectVersion` instance. | [
"Get",
"an",
"object",
"version",
"object",
"from",
"an",
"object",
"version",
"ID",
"or",
"an",
"object",
"version",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L102-L110 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | update_bucket_size | def update_bucket_size(f):
"""Decorate to update bucket size after operation."""
@wraps(f)
def inner(self, *args, **kwargs):
res = f(self, *args, **kwargs)
self.bucket.size += self.file.size
return res
return inner | python | def update_bucket_size(f):
"""Decorate to update bucket size after operation."""
@wraps(f)
def inner(self, *args, **kwargs):
res = f(self, *args, **kwargs)
self.bucket.size += self.file.size
return res
return inner | [
"def",
"update_bucket_size",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"inner",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"res",
"=",
"f",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"sel... | Decorate to update bucket size after operation. | [
"Decorate",
"to",
"update",
"bucket",
"size",
"after",
"operation",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L126-L133 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ensure_state | def ensure_state(default_getter, exc_class, default_msg=None):
"""Create a decorator factory function."""
def decorator(getter=default_getter, msg=default_msg):
def ensure_decorator(f):
@wraps(f)
def inner(self, *args, **kwargs):
if not getter(self):
... | python | def ensure_state(default_getter, exc_class, default_msg=None):
"""Create a decorator factory function."""
def decorator(getter=default_getter, msg=default_msg):
def ensure_decorator(f):
@wraps(f)
def inner(self, *args, **kwargs):
if not getter(self):
... | [
"def",
"ensure_state",
"(",
"default_getter",
",",
"exc_class",
",",
"default_msg",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"getter",
"=",
"default_getter",
",",
"msg",
"=",
"default_msg",
")",
":",
"def",
"ensure_decorator",
"(",
"f",
")",
":",
"@... | Create a decorator factory function. | [
"Create",
"a",
"decorator",
"factory",
"function",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L136-L147 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Location.validate_name | def validate_name(self, key, name):
"""Validate name."""
if not slug_pattern.match(name) or len(name) > 20:
raise ValueError(
'Invalid location name (lower-case alphanumeric + danshes).')
return name | python | def validate_name(self, key, name):
"""Validate name."""
if not slug_pattern.match(name) or len(name) > 20:
raise ValueError(
'Invalid location name (lower-case alphanumeric + danshes).')
return name | [
"def",
"validate_name",
"(",
"self",
",",
"key",
",",
"name",
")",
":",
"if",
"not",
"slug_pattern",
".",
"match",
"(",
"name",
")",
"or",
"len",
"(",
"name",
")",
">",
"20",
":",
"raise",
"ValueError",
"(",
"'Invalid location name (lower-case alphanumeric +... | Validate name. | [
"Validate",
"name",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L277-L282 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Bucket.size_limit | def size_limit(self):
"""Get size limit for this bucket.
The limit is based on the minimum output of the file size limiters.
"""
limits = [
lim for lim in current_files_rest.file_size_limiters(
self)
if lim.limit is not None
]
retu... | python | def size_limit(self):
"""Get size limit for this bucket.
The limit is based on the minimum output of the file size limiters.
"""
limits = [
lim for lim in current_files_rest.file_size_limiters(
self)
if lim.limit is not None
]
retu... | [
"def",
"size_limit",
"(",
"self",
")",
":",
"limits",
"=",
"[",
"lim",
"for",
"lim",
"in",
"current_files_rest",
".",
"file_size_limiters",
"(",
"self",
")",
"if",
"lim",
".",
"limit",
"is",
"not",
"None",
"]",
"return",
"min",
"(",
"limits",
")",
"if"... | Get size limit for this bucket.
The limit is based on the minimum output of the file size limiters. | [
"Get",
"size",
"limit",
"for",
"this",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L397-L407 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Bucket.snapshot | def snapshot(self, lock=False):
"""Create a snapshot of latest objects in bucket.
:param lock: Create the new bucket in a locked state.
:returns: Newly created bucket containing copied ObjectVersion.
"""
with db.session.begin_nested():
bucket = Bucket(
... | python | def snapshot(self, lock=False):
"""Create a snapshot of latest objects in bucket.
:param lock: Create the new bucket in a locked state.
:returns: Newly created bucket containing copied ObjectVersion.
"""
with db.session.begin_nested():
bucket = Bucket(
... | [
"def",
"snapshot",
"(",
"self",
",",
"lock",
"=",
"False",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"bucket",
"=",
"Bucket",
"(",
"default_location",
"=",
"self",
".",
"default_location",
",",
"default_storage_class",
"="... | Create a snapshot of latest objects in bucket.
:param lock: Create the new bucket in a locked state.
:returns: Newly created bucket containing copied ObjectVersion. | [
"Create",
"a",
"snapshot",
"of",
"latest",
"objects",
"in",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L418-L437 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Bucket.sync | def sync(self, bucket, delete_extras=False):
"""Sync self bucket ObjectVersions to the destination bucket.
The bucket is fully mirrored with the destination bucket following the
logic:
* same ObjectVersions are not touched
* new ObjectVersions are added to destination
... | python | def sync(self, bucket, delete_extras=False):
"""Sync self bucket ObjectVersions to the destination bucket.
The bucket is fully mirrored with the destination bucket following the
logic:
* same ObjectVersions are not touched
* new ObjectVersions are added to destination
... | [
"def",
"sync",
"(",
"self",
",",
"bucket",
",",
"delete_extras",
"=",
"False",
")",
":",
"assert",
"not",
"bucket",
".",
"locked",
"src_ovs",
"=",
"ObjectVersion",
".",
"get_by_bucket",
"(",
"bucket",
"=",
"self",
",",
"with_deleted",
"=",
"True",
")",
"... | Sync self bucket ObjectVersions to the destination bucket.
The bucket is fully mirrored with the destination bucket following the
logic:
* same ObjectVersions are not touched
* new ObjectVersions are added to destination
* deleted ObjectVersions are deleted in destination
... | [
"Sync",
"self",
"bucket",
"ObjectVersions",
"to",
"the",
"destination",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L440-L479 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Bucket.create | def create(cls, location=None, storage_class=None, **kwargs):
r"""Create a bucket.
:param location: Location of a bucket (instance or name).
Default: Default location.
:param storage_class: Storage class of a bucket.
Default: Default storage class.
:param \**kwar... | python | def create(cls, location=None, storage_class=None, **kwargs):
r"""Create a bucket.
:param location: Location of a bucket (instance or name).
Default: Default location.
:param storage_class: Storage class of a bucket.
Default: Default storage class.
:param \**kwar... | [
"def",
"create",
"(",
"cls",
",",
"location",
"=",
"None",
",",
"storage_class",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"if",
"location",
"is",
"None",
":",
"location",
"=",
... | r"""Create a bucket.
:param location: Location of a bucket (instance or name).
Default: Default location.
:param storage_class: Storage class of a bucket.
Default: Default storage class.
:param \**kwargs: Keyword arguments are forwarded to the class
:param \**kwa... | [
"r",
"Create",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L486-L511 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Bucket.get | def get(cls, bucket_id):
"""Get a bucket object (excluding deleted).
:param bucket_id: Bucket identifier.
:returns: Bucket instance.
"""
return cls.query.filter_by(
id=bucket_id,
deleted=False
).one_or_none() | python | def get(cls, bucket_id):
"""Get a bucket object (excluding deleted).
:param bucket_id: Bucket identifier.
:returns: Bucket instance.
"""
return cls.query.filter_by(
id=bucket_id,
deleted=False
).one_or_none() | [
"def",
"get",
"(",
"cls",
",",
"bucket_id",
")",
":",
"return",
"cls",
".",
"query",
".",
"filter_by",
"(",
"id",
"=",
"bucket_id",
",",
"deleted",
"=",
"False",
")",
".",
"one_or_none",
"(",
")"
] | Get a bucket object (excluding deleted).
:param bucket_id: Bucket identifier.
:returns: Bucket instance. | [
"Get",
"a",
"bucket",
"object",
"(",
"excluding",
"deleted",
")",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L514-L523 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Bucket.delete | def delete(cls, bucket_id):
"""Delete a bucket.
Does not actually delete the Bucket, just marks it as deleted.
"""
bucket = cls.get(bucket_id)
if not bucket or bucket.deleted:
return False
bucket.deleted = True
return True | python | def delete(cls, bucket_id):
"""Delete a bucket.
Does not actually delete the Bucket, just marks it as deleted.
"""
bucket = cls.get(bucket_id)
if not bucket or bucket.deleted:
return False
bucket.deleted = True
return True | [
"def",
"delete",
"(",
"cls",
",",
"bucket_id",
")",
":",
"bucket",
"=",
"cls",
".",
"get",
"(",
"bucket_id",
")",
"if",
"not",
"bucket",
"or",
"bucket",
".",
"deleted",
":",
"return",
"False",
"bucket",
".",
"deleted",
"=",
"True",
"return",
"True"
] | Delete a bucket.
Does not actually delete the Bucket, just marks it as deleted. | [
"Delete",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L533-L543 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | Bucket.remove | def remove(self):
"""Permanently remove a bucket and all objects (including versions).
.. warning::
This by-passes the normal versioning and should only be used when
you want to permanently delete a bucket and its objects. Otherwise
use :py:data:`Bucket.delete()`.
... | python | def remove(self):
"""Permanently remove a bucket and all objects (including versions).
.. warning::
This by-passes the normal versioning and should only be used when
you want to permanently delete a bucket and its objects. Otherwise
use :py:data:`Bucket.delete()`.
... | [
"def",
"remove",
"(",
"self",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"ObjectVersion",
".",
"query",
".",
"filter_by",
"(",
"bucket_id",
"=",
"self",
".",
"id",
")",
".",
"delete",
"(",
")",
"self",
".",
"query",
... | Permanently remove a bucket and all objects (including versions).
.. warning::
This by-passes the normal versioning and should only be used when
you want to permanently delete a bucket and its objects. Otherwise
use :py:data:`Bucket.delete()`.
Note the method does ... | [
"Permanently",
"remove",
"a",
"bucket",
"and",
"all",
"objects",
"(",
"including",
"versions",
")",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L546-L565 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | BucketTag.get | def get(cls, bucket, key):
"""Get tag object."""
return cls.query.filter_by(
bucket_id=as_bucket_id(bucket),
key=key,
).one_or_none() | python | def get(cls, bucket, key):
"""Get tag object."""
return cls.query.filter_by(
bucket_id=as_bucket_id(bucket),
key=key,
).one_or_none() | [
"def",
"get",
"(",
"cls",
",",
"bucket",
",",
"key",
")",
":",
"return",
"cls",
".",
"query",
".",
"filter_by",
"(",
"bucket_id",
"=",
"as_bucket_id",
"(",
"bucket",
")",
",",
"key",
"=",
"key",
",",
")",
".",
"one_or_none",
"(",
")"
] | Get tag object. | [
"Get",
"tag",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L592-L597 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | BucketTag.create | def create(cls, bucket, key, value):
"""Create a new tag for bucket."""
with db.session.begin_nested():
obj = cls(
bucket_id=as_bucket_id(bucket),
key=key,
value=value
)
db.session.add(obj)
return obj | python | def create(cls, bucket, key, value):
"""Create a new tag for bucket."""
with db.session.begin_nested():
obj = cls(
bucket_id=as_bucket_id(bucket),
key=key,
value=value
)
db.session.add(obj)
return obj | [
"def",
"create",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"value",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"obj",
"=",
"cls",
"(",
"bucket_id",
"=",
"as_bucket_id",
"(",
"bucket",
")",
",",
"key",
"=",
"key",
... | Create a new tag for bucket. | [
"Create",
"a",
"new",
"tag",
"for",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L600-L609 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | BucketTag.create_or_update | def create_or_update(cls, bucket, key, value):
"""Create or update a new tag for bucket."""
obj = cls.get(bucket, key)
if obj:
obj.value = value
db.session.merge(obj)
else:
obj = cls.create(bucket, key, value)
return obj | python | def create_or_update(cls, bucket, key, value):
"""Create or update a new tag for bucket."""
obj = cls.get(bucket, key)
if obj:
obj.value = value
db.session.merge(obj)
else:
obj = cls.create(bucket, key, value)
return obj | [
"def",
"create_or_update",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"value",
")",
":",
"obj",
"=",
"cls",
".",
"get",
"(",
"bucket",
",",
"key",
")",
"if",
"obj",
":",
"obj",
".",
"value",
"=",
"value",
"db",
".",
"session",
".",
"merge",
"(",... | Create or update a new tag for bucket. | [
"Create",
"or",
"update",
"a",
"new",
"tag",
"for",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L612-L620 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | BucketTag.get_value | def get_value(cls, bucket, key):
"""Get tag value."""
obj = cls.get(bucket, key)
return obj.value if obj else None | python | def get_value(cls, bucket, key):
"""Get tag value."""
obj = cls.get(bucket, key)
return obj.value if obj else None | [
"def",
"get_value",
"(",
"cls",
",",
"bucket",
",",
"key",
")",
":",
"obj",
"=",
"cls",
".",
"get",
"(",
"bucket",
",",
"key",
")",
"return",
"obj",
".",
"value",
"if",
"obj",
"else",
"None"
] | Get tag value. | [
"Get",
"tag",
"value",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L623-L626 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | BucketTag.delete | def delete(cls, bucket, key):
"""Delete a tag."""
with db.session.begin_nested():
cls.query.filter_by(
bucket_id=as_bucket_id(bucket),
key=key,
).delete() | python | def delete(cls, bucket, key):
"""Delete a tag."""
with db.session.begin_nested():
cls.query.filter_by(
bucket_id=as_bucket_id(bucket),
key=key,
).delete() | [
"def",
"delete",
"(",
"cls",
",",
"bucket",
",",
"key",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"cls",
".",
"query",
".",
"filter_by",
"(",
"bucket_id",
"=",
"as_bucket_id",
"(",
"bucket",
")",
",",
"key",
"=",
"... | Delete a tag. | [
"Delete",
"a",
"tag",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L629-L635 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.validate_uri | def validate_uri(self, key, uri):
"""Validate uri."""
if len(uri) > current_app.config['FILES_REST_FILE_URI_MAX_LEN']:
raise ValueError(
'FileInstance URI too long ({0}).'.format(len(uri)))
return uri | python | def validate_uri(self, key, uri):
"""Validate uri."""
if len(uri) > current_app.config['FILES_REST_FILE_URI_MAX_LEN']:
raise ValueError(
'FileInstance URI too long ({0}).'.format(len(uri)))
return uri | [
"def",
"validate_uri",
"(",
"self",
",",
"key",
",",
"uri",
")",
":",
"if",
"len",
"(",
"uri",
")",
">",
"current_app",
".",
"config",
"[",
"'FILES_REST_FILE_URI_MAX_LEN'",
"]",
":",
"raise",
"ValueError",
"(",
"'FileInstance URI too long ({0}).'",
".",
"forma... | Validate uri. | [
"Validate",
"uri",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L695-L700 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.get_by_uri | def get_by_uri(cls, uri):
"""Get a file instance by URI."""
assert uri is not None
return cls.query.filter_by(uri=uri).one_or_none() | python | def get_by_uri(cls, uri):
"""Get a file instance by URI."""
assert uri is not None
return cls.query.filter_by(uri=uri).one_or_none() | [
"def",
"get_by_uri",
"(",
"cls",
",",
"uri",
")",
":",
"assert",
"uri",
"is",
"not",
"None",
"return",
"cls",
".",
"query",
".",
"filter_by",
"(",
"uri",
"=",
"uri",
")",
".",
"one_or_none",
"(",
")"
] | Get a file instance by URI. | [
"Get",
"a",
"file",
"instance",
"by",
"URI",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L708-L711 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.create | def create(cls):
"""Create a file instance.
Note, object is only added to the database session.
"""
obj = cls(
id=uuid.uuid4(),
writable=True,
readable=False,
size=0,
)
db.session.add(obj)
return obj | python | def create(cls):
"""Create a file instance.
Note, object is only added to the database session.
"""
obj = cls(
id=uuid.uuid4(),
writable=True,
readable=False,
size=0,
)
db.session.add(obj)
return obj | [
"def",
"create",
"(",
"cls",
")",
":",
"obj",
"=",
"cls",
"(",
"id",
"=",
"uuid",
".",
"uuid4",
"(",
")",
",",
"writable",
"=",
"True",
",",
"readable",
"=",
"False",
",",
"size",
"=",
"0",
",",
")",
"db",
".",
"session",
".",
"add",
"(",
"ob... | Create a file instance.
Note, object is only added to the database session. | [
"Create",
"a",
"file",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L714-L726 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.delete | def delete(self):
"""Delete a file instance.
The file instance can be deleted if it has no references from other
objects. The caller is responsible to test if the file instance is
writable and that the disk file can actually be removed.
.. note::
Normally you should... | python | def delete(self):
"""Delete a file instance.
The file instance can be deleted if it has no references from other
objects. The caller is responsible to test if the file instance is
writable and that the disk file can actually be removed.
.. note::
Normally you should... | [
"def",
"delete",
"(",
"self",
")",
":",
"self",
".",
"query",
".",
"filter_by",
"(",
"id",
"=",
"self",
".",
"id",
")",
".",
"delete",
"(",
")",
"return",
"self"
] | Delete a file instance.
The file instance can be deleted if it has no references from other
objects. The caller is responsible to test if the file instance is
writable and that the disk file can actually be removed.
.. note::
Normally you should use the Celery task to delet... | [
"Delete",
"a",
"file",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L728-L741 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.update_checksum | def update_checksum(self, progress_callback=None, chunk_size=None,
checksum_kwargs=None, **kwargs):
"""Update checksum based on file."""
self.checksum = self.storage(**kwargs).checksum(
progress_callback=progress_callback, chunk_size=chunk_size,
**(checksu... | python | def update_checksum(self, progress_callback=None, chunk_size=None,
checksum_kwargs=None, **kwargs):
"""Update checksum based on file."""
self.checksum = self.storage(**kwargs).checksum(
progress_callback=progress_callback, chunk_size=chunk_size,
**(checksu... | [
"def",
"update_checksum",
"(",
"self",
",",
"progress_callback",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"checksum_kwargs",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"checksum",
"=",
"self",
".",
"storage",
"(",
"*",
"*",
"... | Update checksum based on file. | [
"Update",
"checksum",
"based",
"on",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L754-L759 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.clear_last_check | def clear_last_check(self):
"""Clear the checksum of the file."""
with db.session.begin_nested():
self.last_check = None
self.last_check_at = datetime.utcnow()
return self | python | def clear_last_check(self):
"""Clear the checksum of the file."""
with db.session.begin_nested():
self.last_check = None
self.last_check_at = datetime.utcnow()
return self | [
"def",
"clear_last_check",
"(",
"self",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"self",
".",
"last_check",
"=",
"None",
"self",
".",
"last_check_at",
"=",
"datetime",
".",
"utcnow",
"(",
")",
"return",
"self"
] | Clear the checksum of the file. | [
"Clear",
"the",
"checksum",
"of",
"the",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L761-L766 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.verify_checksum | def verify_checksum(self, progress_callback=None, chunk_size=None,
throws=True, checksum_kwargs=None, **kwargs):
"""Verify checksum of file instance.
:param bool throws: If `True`, exceptions raised during checksum
calculation will be re-raised after logging. If set ... | python | def verify_checksum(self, progress_callback=None, chunk_size=None,
throws=True, checksum_kwargs=None, **kwargs):
"""Verify checksum of file instance.
:param bool throws: If `True`, exceptions raised during checksum
calculation will be re-raised after logging. If set ... | [
"def",
"verify_checksum",
"(",
"self",
",",
"progress_callback",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"throws",
"=",
"True",
",",
"checksum_kwargs",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"real_checksum",
"=",
"self",
".... | Verify checksum of file instance.
:param bool throws: If `True`, exceptions raised during checksum
calculation will be re-raised after logging. If set to `False`, and
an exception occurs, the `last_check` field is set to `None`
(`last_check_at` of course is updated), since n... | [
"Verify",
"checksum",
"of",
"file",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L768-L793 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.init_contents | def init_contents(self, size=0, **kwargs):
"""Initialize file."""
self.set_uri(
*self.storage(**kwargs).initialize(size=size),
readable=False, writable=True) | python | def init_contents(self, size=0, **kwargs):
"""Initialize file."""
self.set_uri(
*self.storage(**kwargs).initialize(size=size),
readable=False, writable=True) | [
"def",
"init_contents",
"(",
"self",
",",
"size",
"=",
"0",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"set_uri",
"(",
"*",
"self",
".",
"storage",
"(",
"*",
"*",
"kwargs",
")",
".",
"initialize",
"(",
"size",
"=",
"size",
")",
",",
"readabl... | Initialize file. | [
"Initialize",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L796-L800 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.update_contents | def update_contents(self, stream, seek=0, size=None, chunk_size=None,
progress_callback=None, **kwargs):
"""Save contents of stream to this file.
:param obj: ObjectVersion instance from where this file is accessed
from.
:param stream: File-like stream.
... | python | def update_contents(self, stream, seek=0, size=None, chunk_size=None,
progress_callback=None, **kwargs):
"""Save contents of stream to this file.
:param obj: ObjectVersion instance from where this file is accessed
from.
:param stream: File-like stream.
... | [
"def",
"update_contents",
"(",
"self",
",",
"stream",
",",
"seek",
"=",
"0",
",",
"size",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"progress_callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"checksum",
"=",
"None",
"re... | Save contents of stream to this file.
:param obj: ObjectVersion instance from where this file is accessed
from.
:param stream: File-like stream. | [
"Save",
"contents",
"of",
"stream",
"to",
"this",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L803-L815 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.set_contents | def set_contents(self, stream, chunk_size=None, size=None, size_limit=None,
progress_callback=None, **kwargs):
"""Save contents of stream to this file.
:param obj: ObjectVersion instance from where this file is accessed
from.
:param stream: File-like stream.
... | python | def set_contents(self, stream, chunk_size=None, size=None, size_limit=None,
progress_callback=None, **kwargs):
"""Save contents of stream to this file.
:param obj: ObjectVersion instance from where this file is accessed
from.
:param stream: File-like stream.
... | [
"def",
"set_contents",
"(",
"self",
",",
"stream",
",",
"chunk_size",
"=",
"None",
",",
"size",
"=",
"None",
",",
"size_limit",
"=",
"None",
",",
"progress_callback",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"set_uri",
"(",
"*",
"... | Save contents of stream to this file.
:param obj: ObjectVersion instance from where this file is accessed
from.
:param stream: File-like stream. | [
"Save",
"contents",
"of",
"stream",
"to",
"this",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L818-L829 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.copy_contents | def copy_contents(self, fileinstance, progress_callback=None,
chunk_size=None, **kwargs):
"""Copy this file instance into another file instance."""
if not fileinstance.readable:
raise ValueError('Source file instance is not readable.')
if not self.size == 0:
... | python | def copy_contents(self, fileinstance, progress_callback=None,
chunk_size=None, **kwargs):
"""Copy this file instance into another file instance."""
if not fileinstance.readable:
raise ValueError('Source file instance is not readable.')
if not self.size == 0:
... | [
"def",
"copy_contents",
"(",
"self",
",",
"fileinstance",
",",
"progress_callback",
"=",
"None",
",",
"chunk_size",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"fileinstance",
".",
"readable",
":",
"raise",
"ValueError",
"(",
"'Source file i... | Copy this file instance into another file instance. | [
"Copy",
"this",
"file",
"instance",
"into",
"another",
"file",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L832-L844 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.send_file | def send_file(self, filename, restricted=True, mimetype=None,
trusted=False, chunk_size=None, as_attachment=False,
**kwargs):
"""Send file to client."""
return self.storage(**kwargs).send_file(
filename,
mimetype=mimetype,
restricte... | python | def send_file(self, filename, restricted=True, mimetype=None,
trusted=False, chunk_size=None, as_attachment=False,
**kwargs):
"""Send file to client."""
return self.storage(**kwargs).send_file(
filename,
mimetype=mimetype,
restricte... | [
"def",
"send_file",
"(",
"self",
",",
"filename",
",",
"restricted",
"=",
"True",
",",
"mimetype",
"=",
"None",
",",
"trusted",
"=",
"False",
",",
"chunk_size",
"=",
"None",
",",
"as_attachment",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"return... | Send file to client. | [
"Send",
"file",
"to",
"client",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L847-L859 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | FileInstance.set_uri | def set_uri(self, uri, size, checksum, readable=True, writable=False,
storage_class=None):
"""Set a location of a file."""
self.uri = uri
self.size = size
self.checksum = checksum
self.writable = writable
self.readable = readable
self.storage_class... | python | def set_uri(self, uri, size, checksum, readable=True, writable=False,
storage_class=None):
"""Set a location of a file."""
self.uri = uri
self.size = size
self.checksum = checksum
self.writable = writable
self.readable = readable
self.storage_class... | [
"def",
"set_uri",
"(",
"self",
",",
"uri",
",",
"size",
",",
"checksum",
",",
"readable",
"=",
"True",
",",
"writable",
"=",
"False",
",",
"storage_class",
"=",
"None",
")",
":",
"self",
".",
"uri",
"=",
"uri",
"self",
".",
"size",
"=",
"size",
"se... | Set a location of a file. | [
"Set",
"a",
"location",
"of",
"a",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L861-L873 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.set_contents | def set_contents(self, stream, chunk_size=None, size=None, size_limit=None,
progress_callback=None):
"""Save contents of stream to file instance.
If a file instance has already been set, this methods raises an
``FileInstanceAlreadySetError`` exception.
:param strea... | python | def set_contents(self, stream, chunk_size=None, size=None, size_limit=None,
progress_callback=None):
"""Save contents of stream to file instance.
If a file instance has already been set, this methods raises an
``FileInstanceAlreadySetError`` exception.
:param strea... | [
"def",
"set_contents",
"(",
"self",
",",
"stream",
",",
"chunk_size",
"=",
"None",
",",
"size",
"=",
"None",
",",
"size_limit",
"=",
"None",
",",
"progress_callback",
"=",
"None",
")",
":",
"if",
"size_limit",
"is",
"None",
":",
"size_limit",
"=",
"self"... | Save contents of stream to file instance.
If a file instance has already been set, this methods raises an
``FileInstanceAlreadySetError`` exception.
:param stream: File-like stream.
:param size: Size of stream if known.
:param chunk_size: Desired chunk size to read stream in. I... | [
"Save",
"contents",
"of",
"stream",
"to",
"file",
"instance",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L979-L1002 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.set_location | def set_location(self, uri, size, checksum, storage_class=None):
"""Set only URI location of for object.
Useful to link files on externally controlled storage. If a file
instance has already been set, this methods raises an
``FileInstanceAlreadySetError`` exception.
:param uri:... | python | def set_location(self, uri, size, checksum, storage_class=None):
"""Set only URI location of for object.
Useful to link files on externally controlled storage. If a file
instance has already been set, this methods raises an
``FileInstanceAlreadySetError`` exception.
:param uri:... | [
"def",
"set_location",
"(",
"self",
",",
"uri",
",",
"size",
",",
"checksum",
",",
"storage_class",
"=",
"None",
")",
":",
"self",
".",
"file",
"=",
"FileInstance",
"(",
")",
"self",
".",
"file",
".",
"set_uri",
"(",
"uri",
",",
"size",
",",
"checksu... | Set only URI location of for object.
Useful to link files on externally controlled storage. If a file
instance has already been set, this methods raises an
``FileInstanceAlreadySetError`` exception.
:param uri: Full URI to object (which can be interpreted by the storage
int... | [
"Set",
"only",
"URI",
"location",
"of",
"for",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1006-L1024 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.send_file | def send_file(self, restricted=True, trusted=False, **kwargs):
"""Wrap around FileInstance's send file."""
return self.file.send_file(
self.basename,
restricted=restricted,
mimetype=self.mimetype,
trusted=trusted,
**kwargs
) | python | def send_file(self, restricted=True, trusted=False, **kwargs):
"""Wrap around FileInstance's send file."""
return self.file.send_file(
self.basename,
restricted=restricted,
mimetype=self.mimetype,
trusted=trusted,
**kwargs
) | [
"def",
"send_file",
"(",
"self",
",",
"restricted",
"=",
"True",
",",
"trusted",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"file",
".",
"send_file",
"(",
"self",
".",
"basename",
",",
"restricted",
"=",
"restricted",
",",
... | Wrap around FileInstance's send file. | [
"Wrap",
"around",
"FileInstance",
"s",
"send",
"file",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1033-L1041 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.copy | def copy(self, bucket=None, key=None):
"""Copy an object version to a given bucket + object key.
The copy operation is handled completely at the metadata level. The
actual data on disk is not copied. Instead, the two object versions
will point to the same physical file (via the same Fil... | python | def copy(self, bucket=None, key=None):
"""Copy an object version to a given bucket + object key.
The copy operation is handled completely at the metadata level. The
actual data on disk is not copied. Instead, the two object versions
will point to the same physical file (via the same Fil... | [
"def",
"copy",
"(",
"self",
",",
"bucket",
"=",
"None",
",",
"key",
"=",
"None",
")",
":",
"new_ob",
"=",
"ObjectVersion",
".",
"create",
"(",
"self",
".",
"bucket",
"if",
"bucket",
"is",
"None",
"else",
"as_bucket",
"(",
"bucket",
")",
",",
"key",
... | Copy an object version to a given bucket + object key.
The copy operation is handled completely at the metadata level. The
actual data on disk is not copied. Instead, the two object versions
will point to the same physical file (via the same FileInstance).
All the tags associated with ... | [
"Copy",
"an",
"object",
"version",
"to",
"a",
"given",
"bucket",
"+",
"object",
"key",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1054-L1086 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.remove | def remove(self):
"""Permanently remove a specific object version from the database.
.. warning::
This by-passes the normal versioning and should only be used when
you want to permanently delete a specific object version. Otherwise
use :py:data:`ObjectVersion.delete()`... | python | def remove(self):
"""Permanently remove a specific object version from the database.
.. warning::
This by-passes the normal versioning and should only be used when
you want to permanently delete a specific object version. Otherwise
use :py:data:`ObjectVersion.delete()`... | [
"def",
"remove",
"(",
"self",
")",
":",
"with",
"db",
".",
"session",
".",
"begin_nested",
"(",
")",
":",
"if",
"self",
".",
"file_id",
":",
"self",
".",
"bucket",
".",
"size",
"-=",
"self",
".",
"file",
".",
"size",
"self",
".",
"query",
".",
"f... | Permanently remove a specific object version from the database.
.. warning::
This by-passes the normal versioning and should only be used when
you want to permanently delete a specific object version. Otherwise
use :py:data:`ObjectVersion.delete()`.
Note the method... | [
"Permanently",
"remove",
"a",
"specific",
"object",
"version",
"from",
"the",
"database",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1089-L1112 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.create | def create(cls, bucket, key, _file_id=None, stream=None, mimetype=None,
version_id=None, **kwargs):
"""Create a new object in a bucket.
The created object is by default created as a delete marker. You must
use ``set_contents()`` or ``set_location()`` in order to change this.
... | python | def create(cls, bucket, key, _file_id=None, stream=None, mimetype=None,
version_id=None, **kwargs):
"""Create a new object in a bucket.
The created object is by default created as a delete marker. You must
use ``set_contents()`` or ``set_location()`` in order to change this.
... | [
"def",
"create",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"_file_id",
"=",
"None",
",",
"stream",
"=",
"None",
",",
"mimetype",
"=",
"None",
",",
"version_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"bucket",
"=",
"as_bucket",
"(",
"buc... | Create a new object in a bucket.
The created object is by default created as a delete marker. You must
use ``set_contents()`` or ``set_location()`` in order to change this.
:param bucket: The bucket (instance or id) to create the object in.
:param key: Key of object.
:param _fi... | [
"Create",
"a",
"new",
"object",
"in",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1115-L1159 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.get | def get(cls, bucket, key, version_id=None):
"""Fetch a specific object.
By default the latest object version is returned, if
``version_id`` is not set.
:param bucket: The bucket (instance or id) to get the object from.
:param key: Key of object.
:param version_id: Speci... | python | def get(cls, bucket, key, version_id=None):
"""Fetch a specific object.
By default the latest object version is returned, if
``version_id`` is not set.
:param bucket: The bucket (instance or id) to get the object from.
:param key: Key of object.
:param version_id: Speci... | [
"def",
"get",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"version_id",
"=",
"None",
")",
":",
"filters",
"=",
"[",
"cls",
".",
"bucket_id",
"==",
"as_bucket_id",
"(",
"bucket",
")",
",",
"cls",
".",
"key",
"==",
"key",
",",
"]",
"if",
"version_id"... | Fetch a specific object.
By default the latest object version is returned, if
``version_id`` is not set.
:param bucket: The bucket (instance or id) to get the object from.
:param key: Key of object.
:param version_id: Specific version of an object. | [
"Fetch",
"a",
"specific",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1162-L1183 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.get_versions | def get_versions(cls, bucket, key, desc=True):
"""Fetch all versions of a specific object.
:param bucket: The bucket (instance or id) to get the object from.
:param key: Key of object.
:param desc: Sort results desc if True, asc otherwise.
:returns: The query to execute to fetch... | python | def get_versions(cls, bucket, key, desc=True):
"""Fetch all versions of a specific object.
:param bucket: The bucket (instance or id) to get the object from.
:param key: Key of object.
:param desc: Sort results desc if True, asc otherwise.
:returns: The query to execute to fetch... | [
"def",
"get_versions",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"desc",
"=",
"True",
")",
":",
"filters",
"=",
"[",
"cls",
".",
"bucket_id",
"==",
"as_bucket_id",
"(",
"bucket",
")",
",",
"cls",
".",
"key",
"==",
"key",
",",
"]",
"order",
"=",
... | Fetch all versions of a specific object.
:param bucket: The bucket (instance or id) to get the object from.
:param key: Key of object.
:param desc: Sort results desc if True, asc otherwise.
:returns: The query to execute to fetch all versions. | [
"Fetch",
"all",
"versions",
"of",
"a",
"specific",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1186-L1201 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.delete | def delete(cls, bucket, key):
"""Delete an object.
Technically works by creating a new version which works as a delete
marker.
:param bucket: The bucket (instance or id) to delete the object from.
:param key: Key of object.
:returns: Created delete marker object if key ... | python | def delete(cls, bucket, key):
"""Delete an object.
Technically works by creating a new version which works as a delete
marker.
:param bucket: The bucket (instance or id) to delete the object from.
:param key: Key of object.
:returns: Created delete marker object if key ... | [
"def",
"delete",
"(",
"cls",
",",
"bucket",
",",
"key",
")",
":",
"bucket_id",
"=",
"as_bucket_id",
"(",
"bucket",
")",
"obj",
"=",
"cls",
".",
"get",
"(",
"bucket_id",
",",
"key",
")",
"if",
"obj",
":",
"return",
"cls",
".",
"create",
"(",
"as_buc... | Delete an object.
Technically works by creating a new version which works as a delete
marker.
:param bucket: The bucket (instance or id) to delete the object from.
:param key: Key of object.
:returns: Created delete marker object if key exists else ``None``. | [
"Delete",
"an",
"object",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1204-L1219 |
inveniosoftware/invenio-files-rest | invenio_files_rest/models.py | ObjectVersion.get_by_bucket | def get_by_bucket(cls, bucket, versions=False, with_deleted=False):
"""Return query that fetches all the objects in a bucket.
:param bucket: The bucket (instance or id) to query.
:param versions: Select all versions if True, only heads otherwise.
:param with_deleted: Select also deleted... | python | def get_by_bucket(cls, bucket, versions=False, with_deleted=False):
"""Return query that fetches all the objects in a bucket.
:param bucket: The bucket (instance or id) to query.
:param versions: Select all versions if True, only heads otherwise.
:param with_deleted: Select also deleted... | [
"def",
"get_by_bucket",
"(",
"cls",
",",
"bucket",
",",
"versions",
"=",
"False",
",",
"with_deleted",
"=",
"False",
")",
":",
"bucket_id",
"=",
"bucket",
".",
"id",
"if",
"isinstance",
"(",
"bucket",
",",
"Bucket",
")",
"else",
"bucket",
"filters",
"=",... | Return query that fetches all the objects in a bucket.
:param bucket: The bucket (instance or id) to query.
:param versions: Select all versions if True, only heads otherwise.
:param with_deleted: Select also deleted objects if True.
:returns: The query to retrieve filtered objects in t... | [
"Return",
"query",
"that",
"fetches",
"all",
"the",
"objects",
"in",
"a",
"bucket",
"."
] | train | https://github.com/inveniosoftware/invenio-files-rest/blob/59a950da61cc8d5882a03c6fde6db2e2ed10befd/invenio_files_rest/models.py#L1222-L1242 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.