# -*- coding: utf-8 -*-

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)

@@ -223,51 +223,34 @@
 rset
-) if charset is not None else data.decode()
+ or 'ascii')%0A%09%09return data
 %0A%0A%09@
@@ -399,50 +399,19 @@
 rset
-) if charset is not None else data.encode(
+ or 'ascii'
 )%0A%09%09

Make encoding and decoding strict