# Path: httoop/codecs/application/json.py
# class JSON(Codec):
# 	mimetype = 'application/json'
# 
# 	@classmethod
# 	def encode(cls, data, charset=None, mimetype=None):
# 		data = json_encode(data)
# 		if not isinstance(data, bytes):  # python3
# 			data = data.encode(charset or 'UTF-8')
# 		return data
# 
# 	@classmethod
# 	def decode(cls, data, charset=None, mimetype=None):
# 		return json_decode(data.decode(charset or 'ASCII'))
# 
# Path: httoop/exceptions.py
# class DecodeError(_Translateable, ValueError):
# 	u"""error raised when decoding failed"""
# 
# class EncodeError(_Translateable, ValueError):
# 	u"""error raised when encoding failed"""
# 
# Path: httoop/six.py



	from uritemplate import expand
from httoop.codecs.application.json import JSON
from httoop.exceptions import DecodeError, EncodeError
from httoop.six import string_types
		for templ, value in templates.items():
			href = href.replace('{%s}' % (templ, ), value)
		return href




class Resource(dict):
	"""A JSON Hypertext Application Language resource"""

	def __init__(self, *args, **kwargs):
		super(Resource, self).__init__(*args, **kwargs)
		self.setdefault('_links', {})
		self.setdefault('_embedded', {})
		if not isinstance(self['_links'], dict):
			raise DecodeError(u'HAL links must be JSON objects.')
		if not isinstance(self['_embedded'], dict):
			raise DecodeError(u'HAL embedded must be JSON objects.')

	@property
	def self(self):
		return self.expand(self.get_link('self')['href'])

	def get_links(self, relation, name=None):
		links = self['_links'].get(relation)
		if links is None:
			return
		if isinstance(links, dict):
			links = [links]
		if not isinstance(links, (list, tuple)):

# Path: httoop/codecs/application/json.py
# class JSON(Codec):
# 	mimetype = 'application/json'
# 
# 	@classmethod
# 	def encode(cls, data, charset=None, mimetype=None):
# 		data = json_encode(data)
# 		if not isinstance(data, bytes):  # python3
# 			data = data.encode(charset or 'UTF-8')
# 		return data
# 
# 	@classmethod
# 	def decode(cls, data, charset=None, mimetype=None):
# 		return json_decode(data.decode(charset or 'ASCII'))
# 
# Path: httoop/exceptions.py
# class DecodeError(_Translateable, ValueError):
# 	u"""error raised when decoding failed"""
# 
# class EncodeError(_Translateable, ValueError):
# 	u"""error raised when encoding failed"""
# 
# Path: httoop/six.py



# Path: httoop/codecs/application/hal_json.py
	from uritemplate import expand
from httoop.codecs.application.json import JSON
from httoop.exceptions import DecodeError, EncodeError
from httoop.six import string_types

		for templ, value in templates.items():
			href = href.replace('{%s}' % (templ, ), value)
		return href




class Resource(dict):
	"""A JSON Hypertext Application Language resource"""

	def __init__(self, *args, **kwargs):
		super(Resource, self).__init__(*args, **kwargs)
		self.setdefault('_links', {})
		self.setdefault('_embedded', {})
		if not isinstance(self['_links'], dict):
			raise DecodeError(u'HAL links must be JSON objects.')
		if not isinstance(self['_embedded'], dict):
			raise DecodeError(u'HAL embedded must be JSON objects.')

	@property
	def self(self):
		return self.expand(self.get_link('self')['href'])

	def get_links(self, relation, name=None):
		links = self['_links'].get(relation)
		if links is None:
			return
		if isinstance(links, dict):
			links = [links]
		if not isinstance(links, (list, tuple)):

			raise DecodeError(u'HAL links must be arrays or objects')