Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _scan_uids(self):
removed = set(self._fname_to_uid.keys())
for (name, content_type, etag) in self.iter_with_etag():
if name in removed:
removed.remove(name)
if (name in self._fname_to_uid and
self._fname_to_uid[name][0] == etag):
continue
fi = open_by_extension(self._get_raw(name, etag), name,
self.extra_file_handlers)
try:
uid = fi.get_uid()
except KeyError:
logger.warning('No UID found in file %s', name)
uid = None
except InvalidFileContents:
logging.warning('Unable to parse file %s', name)
uid = None
except NotImplementedError:
# This file type doesn't support UIDs
uid = None
self._fname_to_uid[name] = (etag, uid)
if uid is not None:
self._uid_to_fname[uid] = (name, etag)
for name in removed:
def _scan_uids(self):
removed = set(self._fname_to_uid.keys())
for (name, mode, sha) in self._iterblobs():
etag = sha.decode('ascii')
if name in removed:
removed.remove(name)
if (name in self._fname_to_uid and
self._fname_to_uid[name][0] == etag):
continue
blob = self.repo.object_store[sha]
fi = open_by_extension(blob.chunked, name,
self.extra_file_handlers)
try:
uid = fi.get_uid()
except KeyError:
logger.warning('No UID found in file %s', name)
uid = None
except InvalidFileContents:
logging.warning('Unable to parse file %s', name)
uid = None
except NotImplementedError:
# This file type doesn't support UIDs
uid = None
self._fname_to_uid[name] = (etag, uid)
if uid is not None:
self._uid_to_fname[uid] = (name, etag)
for name in removed:
:param etag: Optional mandatory etag of object to remove
:raise NoSuchItem: when the item doesn't exist
:raise InvalidETag: If the specified ETag doesn't match the curren
"""
tree = self._get_current_tree()
name_enc = name.encode(DEFAULT_ENCODING)
try:
current_sha = tree[name_enc][1]
except KeyError:
raise NoSuchItem(name)
if etag is not None and current_sha != etag.encode('ascii'):
raise InvalidETag(name, etag, current_sha.decode('ascii'))
del tree[name_enc]
self.repo.object_store.add_objects([(tree, '')])
if message is None:
fi = open_by_extension(
self.repo.object_store[current_sha].chunked, name,
self.extra_file_handlers)
message = "Delete " + fi.describe(name)
self._commit_tree(tree.id, message.encode(DEFAULT_ENCODING),
author=author)
replace_etag=None):
"""Import a single object.
:param name: name of the object
:param content_type: Content type
:param data: serialized object as list of bytes
:param message: Commit message
:param author: Optional author
:param replace_etag: optional etag of object to replace
:raise InvalidETag: when the name already exists but with different
etag
:raise DuplicateUidError: when the uid already exists
:return: etag
"""
if content_type is None:
fi = open_by_extension(data, name, self.extra_file_handlers)
else:
fi = open_by_content_type(
data, content_type, self.extra_file_handlers)
if name is None:
name = str(uuid.uuid4())
extension = MIMETYPES.guess_extension(content_type)
if extension is not None:
name += extension
fi.validate()
try:
uid = fi.get_uid()
except (KeyError, NotImplementedError):
uid = None
self._check_duplicate(uid, name, replace_etag)
if message is None:
try:
replace_etag=None):
"""Import a single object.
:param name: name of the object
:param content_type: Content type
:param data: serialized object as list of bytes
:param message: Commit message
:param author: Optional author
:param replace_etag: optional etag of object to replace
:raise InvalidETag: when the name already exists but with different
etag
:raise DuplicateUidError: when the uid already exists
:return: etag
"""
if content_type is None:
fi = open_by_extension(data, name, self.extra_file_handlers)
else:
fi = open_by_content_type(
data, content_type, self.extra_file_handlers)
if name is None:
name = str(uuid.uuid4())
extension = MIMETYPES.guess_extension(content_type)
if extension is not None:
name += extension
fi.validate()
try:
uid = fi.get_uid()
except (KeyError, NotImplementedError):
uid = None
self._check_duplicate(uid, name, replace_etag)
# TODO(jelmer): Check that extensions match content type: