Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
self.assertTrue(issubclass(errors.Error, Exception))
def get(self, header):
"""Get value by header.
Parameters
----------
header: str
Header name.
"""
# If no headers
if self.__mapping is None:
raise errors.Error('No headers are available.')
return self.__mapping[header]
def headers(self, headers):
"""Set item headers.
"""
if self.__count != 0:
message = 'Headers could be set only before first item is emited.'
raise errors.Error(message)
self.__headers = headers
encoding = self.DEFAULT_ENCODING
# Prepare bytes
bytes = io.BufferedRandom(io.BytesIO())
bytes.write(source.encode(encoding))
bytes.seek(0)
# Return or raise
if mode == 'b':
return bytes
elif mode == 't':
chars = io.TextIOWrapper(bytes, encoding, **self.__options)
return chars
else:
message = 'Mode %s is not supported' % mode
raise errors.Error(message)
if self.__dimension is None:
self.__dimension = len(iterator.values)
else:
if self.__dimension != len(iterator.values):
error = 'dimensions are not consistent'
# Check headers/dimension
if self.__headers is not None:
if self.__dimension != len(self.__headers):
error = 'headers/values have different dimensions'
# Skip or raise exception
if error:
if self.__skip:
return iterator.skip()
raise errors.Error('Strict error: %s' % error)