
from httoop.util import Unicode


class Codec(object):
	@classmethod
	def decode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, bytes):
			data = data.decode(charset) if charset is not None else data.decode()

	@classmethod
	def encode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, Unicode):
			data = data.encode(charset) if charset is not None else data.encode()
		return data

	@classmethod
	def iterencode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.encode(data, charset, mimetype)

	@classmethod
	def iterdecode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.decode(data, charset, mimetype)


from httoop.util import Unicode


class Codec(object):
	@classmethod
	def decode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, bytes):
			data = data.decode(charset or 'ascii')
		return data

	@classmethod
	def encode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, Unicode):
			data = data.encode(charset or 'ascii')
		return data

	@classmethod
	def iterencode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.encode(data, charset, mimetype)

	@classmethod
	def iterdecode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.decode(data, charset, mimetype)

Make encoding and decoding strict
Make encoding and decoding strict

* programmers must know what kind of data they use
* don't guess encodings anymore

  
  from httoop.util import Unicode
  
  
  class Codec(object):
  	@classmethod
  	def decode(cls, data, charset=None, mimetype=None):  # pragma: no cover
  		if isinstance(data, bytes):
- 			data = data.decode(charset) if charset is not None else data.decode()
+ 			data = data.decode(charset or 'ascii')
+ 		return data
  
  	@classmethod
  	def encode(cls, data, charset=None, mimetype=None):  # pragma: no cover
  		if isinstance(data, Unicode):
- 			data = data.encode(charset) if charset is not None else data.encode()
+ 			data = data.encode(charset or 'ascii')
  		return data
  
  	@classmethod
  	def iterencode(cls, data, charset=None, mimetype=None):  # pragma: no cover
  		return cls.encode(data, charset, mimetype)
  
  	@classmethod
  	def iterdecode(cls, data, charset=None, mimetype=None):  # pragma: no cover
  		return cls.decode(data, charset, mimetype)
  
Make encoding and decoding strict
## Code Before:

from httoop.util import Unicode


class Codec(object):
	@classmethod
	def decode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, bytes):
			data = data.decode(charset) if charset is not None else data.decode()

	@classmethod
	def encode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, Unicode):
			data = data.encode(charset) if charset is not None else data.encode()
		return data

	@classmethod
	def iterencode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.encode(data, charset, mimetype)

	@classmethod
	def iterdecode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.decode(data, charset, mimetype)

## Instruction:
Make encoding and decoding strict
## Code After:

from httoop.util import Unicode


class Codec(object):
	@classmethod
	def decode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, bytes):
			data = data.decode(charset or 'ascii')
		return data

	@classmethod
	def encode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		if isinstance(data, Unicode):
			data = data.encode(charset or 'ascii')
		return data

	@classmethod
	def iterencode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.encode(data, charset, mimetype)

	@classmethod
	def iterdecode(cls, data, charset=None, mimetype=None):  # pragma: no cover
		return cls.decode(data, charset, mimetype)
