Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
(unused_etag, uid) = self._fname_to_uid[name]
if uid is not None:
del self._uid_to_fname[uid]
del self._fname_to_uid[name]
def calendar(self):
if self._calendar is None:
try:
self._calendar = Calendar.from_ical(b''.join(self.content))
except ValueError as e:
raise InvalidFileContents(
self.content_type, self.content, str(e))
return self._calendar
def validate(self):
c = b''.join(self.content).strip()
# TODO(jelmer): Do more extensive checking of VCards
if not c.startswith((b'BEGIN:VCARD\r\n', b'BEGIN:VCARD\n')) or \
not c.endswith(b'\nEND:VCARD'):
raise InvalidFileContents(
self.content_type, self.content,
"Missing header and trailer lines")
def validate(self):
"""Verify that file contents are valid."""
cal = self.calendar
# TODO(jelmer): return the list of errors to the caller
if cal.is_broken:
raise InvalidFileContents(
self.content_type, self.content,
"Broken calendar file")
errors = list(validate_calendar(cal, strict=False))
if errors:
raise InvalidFileContents(
self.content_type, self.content,
", ".join(errors))
def validate(self):
"""Verify that file contents are valid."""
cal = self.calendar
# TODO(jelmer): return the list of errors to the caller
if cal.is_broken:
raise InvalidFileContents(
self.content_type, self.content,
"Broken calendar file")
errors = list(validate_calendar(cal, strict=False))
if errors:
raise InvalidFileContents(
self.content_type, self.content,
", ".join(errors))
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:
(unused_etag, uid) = self._fname_to_uid[name]
if uid is not None:
del self._uid_to_fname[uid]
del self._fname_to_uid[name]