Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
callopts['volume'] = volume
while True:
lap = time.time()
chunk = fo.read(blocksize)
if not chunk and not first_cycle:
break
first_cycle = False
result = self._callMethod('rawUpload', (chunk, ofs, path, name), callopts)
if self.retries > 1:
problems = True
hexdigest = util.adler32_constructor(chunk).hexdigest()
full_chksum.update(chunk)
if result['size'] != len(chunk):
raise GenericError("server returned wrong chunk size: %s != %s" % (result['size'], len(chunk)))
if result['hexdigest'] != hexdigest:
raise GenericError('upload checksum failed: %s != %s' \
% (result['hexdigest'], hexdigest))
ofs += len(chunk)
now = time.time()
t1 = max(now - lap, 0.00001)
t2 = max(now - start, 0.00001)
# max is to prevent possible divide by zero in callback function
if callback:
callback(ofs, size, len(chunk), t1, t2)
if ofs != size:
self.logger.error("Local file changed size: %s, %s -> %s", localfile, size, ofs)
chk_opts = {}
if volume and volume != 'DEFAULT':
chk_opts['volume'] = volume
if problems:
chk_opts['verify'] = 'adler32'
result = self._callMethod('checkUpload', (path, name), chk_opts)
def _check_NVRA(nvra):
if isinstance(nvra, six.string_types):
nvra = parse_NVRA(nvra)
if '-' in nvra['version']:
raise GenericError('The "-" character not allowed in version field')
if '-' in nvra['release']:
raise GenericError('The "-" character not allowed in release field')
if '.' in nvra['arch']:
raise GenericError('The "." character not allowed in arch field')
return True
def rpm_hdr_size(f, ofs=None):
"""Returns the length (in bytes) of the rpm header
f = filename or file object
ofs = offset of the header
"""
if isinstance(f, six.string_types):
fo = open(f, 'rb')
else:
fo = f
if ofs != None:
fo.seek(ofs, 0)
magic = fo.read(3)
if magic != RPM_HEADER_MAGIC:
raise GenericError("Invalid rpm: bad magic: %r" % magic)
# skip past section magic and such
# (3 bytes magic, 1 byte version number, 4 bytes reserved)
fo.seek(ofs + 8, 0)
# now read two 4-byte integers which tell us
# - # of index entries
# - bytes of data in header
data = [_ord(x) for x in fo.read(8)]
il = multibyte(data[0:4])
dl = multibyte(data[4:8])
#this is what the section data says the size should be
hdrsize = 8 + 16 * il + dl
# hdrsize rounded up to nearest 8 bytes
class AuthError(GenericError):
"""Raised when there is an error in authentication"""
faultCode = 1002
class TagError(GenericError):
"""Raised when a tagging operation fails"""
faultCode = 1003
class ActionNotAllowed(GenericError):
"""Raised when the session does not have permission to take some action"""
faultCode = 1004
## BEGIN kojikamid dup
class BuildError(GenericError):
"""Raised when a build fails"""
faultCode = 1005
## END kojikamid dup
class AuthLockError(AuthError):
"""Raised when a lock prevents authentication"""
faultCode = 1006
class AuthExpired(AuthError):
"""Raised when a session has expired"""
faultCode = 1007
class SequenceError(AuthError):
"""Raised when requests are received out of sequence"""
faultCode = 1008
def _check_NVR(nvr):
if isinstance(nvr, six.string_types):
nvr = parse_NVR(nvr)
if '-' in nvr['version']:
raise GenericError('The "-" character not allowed in version field')
if '-' in nvr['release']:
raise GenericError('The "-" character not allowed in release field')
# anything else?
return True
def parse_NVR(nvr):
"""split N-V-R into dictionary of data"""
ret = {}
p2 = nvr.rfind("-", 0)
if p2 == -1 or p2 == len(nvr) - 1:
raise GenericError("invalid format: %s" % nvr)
p1 = nvr.rfind("-", 0, p2)
if p1 == -1 or p1 == p2 - 1:
raise GenericError("invalid format: %s" % nvr)
ret['release'] = nvr[p2+1:]
ret['version'] = nvr[p1+1:p2]
ret['name'] = nvr[:p1]
epochIndex = ret['name'].find(':')
if epochIndex == -1:
ret['epoch'] = ''
else:
ret['epoch'] = ret['name'][:epochIndex]
ret['name'] = ret['name'][epochIndex + 1:]
return ret
now = time.time()
t1 = max(now - lap, 0.00001)
t2 = max(now - start, 0.00001)
# max is to prevent possible divide by zero in callback function
if callback:
callback(ofs, size, len(chunk), t1, t2)
if ofs != size:
self.logger.error("Local file changed size: %s, %s -> %s", localfile, size, ofs)
chk_opts = {}
if volume and volume != 'DEFAULT':
chk_opts['volume'] = volume
if problems:
chk_opts['verify'] = 'adler32'
result = self._callMethod('checkUpload', (path, name), chk_opts)
if result is None:
raise GenericError("File upload failed: %s/%s" % (path, name))
if int(result['size']) != ofs:
raise GenericError("Uploaded file is wrong length: %s/%s, %s != %s" \
% (path, name, result['size'], ofs))
if problems and result['hexdigest'] != full_chksum.hexdigest():
raise GenericError("Uploaded file has wrong checksum: %s/%s, %s != %s" \
% (path, name, result['hexdigest'], full_chksum.hexdigest()))
self.logger.debug("Fast upload: %s complete. %i bytes in %.1f seconds", localfile, size, t2)
def _get_header_field(hdr, name):
'''Just get the header field'''
hdr_key = getattr(rpm, "RPMTAG_%s" % name, None)
if hdr_key is None:
# HACK: nosource and nopatch may not be in exported rpm tags
if name == "NOSOURCE":
hdr_key = 1051
elif name == "NOPATCH":
hdr_key = 1052
else:
raise GenericError("No such rpm header field: %s" % name)
return hdr[hdr_key]
return "src"
result = _get_header_field(hdr, name)
if name in ("NOSOURCE", "NOPATCH"):
# HACK: workaround for https://bugzilla.redhat.com/show_bug.cgi?id=991329
if result is None:
result = []
elif isinstance(result, six.integer_types):
result = [result]
sizetags = ('SIZE', 'ARCHIVESIZE', 'FILESIZES', 'SIGSIZE')
if name in sizetags and (result is None or result == []):
try:
result = _get_header_field(hdr, 'LONG' + name)
except GenericError:
# no such header
pass
return _decode_item(result)
def convertFault(fault):
"""Convert a fault to the corresponding Exception type, if possible"""
code = getattr(fault, 'faultCode', None)
if code is None:
return fault
for v in globals().values():
if isinstance(v, type(Exception)) and issubclass(v, GenericError) and \
code == getattr(v, 'faultCode', None):
ret = v(fault.faultString)
ret.fromFault = True
return ret
#otherwise...
return fault