# Path: httoop/exceptions.py
# class InvalidLine(Invalid):
# 	u"""error raised when first line is invalid"""
# 
# class InvalidURI(Invalid):
# 	u"""error raised when URI is invalid"""
# 
# Path: httoop/messages/message.py
# class Message(with_metaclass(HTTPSemantic)):
# 	u"""A HTTP message
# 
# 		.. seealso:: :rfc:`2616#section-4`
# 	"""
# 	__slots__ = ('__protocol', '__headers', '__body')
# 
# 	@property
# 	def protocol(self):
# 		return self.__protocol
# 
# 	@protocol.setter
# 	def protocol(self, protocol):
# 		self.__protocol.set(protocol)
# 
# 	@property
# 	def headers(self):
# 		return self.__headers
# 
# 	@headers.setter
# 	def headers(self, headers):
# 		self.__headers.set(headers)
# 
# 	@property
# 	def body(self):
# 		return self.__body
# 
# 	@body.setter
# 	def body(self, body):
# 		self.__body.set(body)
# 
# 	@property
# 	def trailer(self):
# 		return Headers((key, self.headers[key]) for key in self.headers.values('Trailer') if key in self.headers)
# 
# 	# @trailer.setter
# 	# def trailer(self, trailer):
# 	# 	self.headers.pop('Trailer', None)
# 	# 	if trailer:
# 	# 		trailer = Headers(trailer)
# 	# 		for key in trailer:
# 	# 			self.headers.append('Trailer', key)
# 	# 		self.headers.elements('Trailer')  # sanitize
# 	# 		self.headers.merge(trailer)
# 
# 	def __init__(self, protocol=None, headers=None, body=None):
# 		u"""Initiates a new Message to hold information about the message.
# 
# 			:param protocol: the requested protocol
# 			:type  protocol: str|tuple
# 
# 			:param headers: the request headers
# 			:type  headers: dict or :class:`Headers`
# 
# 			:param body: the request body
# 			:type  body: any
# 		"""
# 		self.__protocol = Protocol(protocol or (1, 1))
# 		self.__headers = Headers(headers or {})
# 		self.__body = Body(body or b'')
# 
# 	def parse(self, protocol):
# 		u"""parses the HTTP protocol version
# 
# 			:param protocol: the protocol version string
# 			:type  protocol: bytes
# 		"""
# 
# 		self.protocol.parse(protocol)
# 
# 	def __repr__(self):
# 		return '<HTTP Message(protocol=%s)>' % (self.protocol, )
# 
# Path: httoop/messages/method.py
# class Method(with_metaclass(HTTPSemantic)):
# 	u"""A HTTP request method"""
# 	__slots__ = ('__method')
# 
# 	@property
# 	def safe(self):
# 		return self in self.safe_methods
# 
# 	@property
# 	def idempotent(self):
# 		return self in self.idempotent_methods
# 
# 	safe_methods = (u'GET', u'HEAD', u'SEARCH')
# 	idempotent_methods = (u'GET', u'HEAD', u'PUT', u'DELETE', u'OPTIONS', u'TRACE', u'SEARCH')
# 	METHOD_RE = re.compile(br"^[A-Z0-9$-_.]{1,20}\Z", re.IGNORECASE)
# 
# 	def __init__(self, method=None):
# 		self.set(method or u'GET')
# 
# 	def __hash__(self):
# 		return hash(bytes(self))
# 
# 	def set(self, method):
# 		if isinstance(method, Unicode):
# 			method = method.encode('ASCII')
# 		self.parse(method)
# 
# 	def parse(self, method):
# 		if not self.METHOD_RE.match(method):
# 			raise InvalidLine(_(u"Invalid method: %r"), method.decode('ISO8859-1'))
# 		self.__method = method
# 
# 	def compose(self):
# 		return self.__method
# 
# Path: httoop/uri/http.py
# class HTTP(URI):
# 	__slots__ = ()
# 	SCHEME = b'http'
# 	PORT = 80
# 
# Path: httoop/util.py
# def _(x):
# 	return x


from httoop.exceptions import InvalidLine, InvalidURI
from httoop.messages.message import Message
from httoop.messages.method import Method
from httoop.uri import HTTP as URI
from httoop.util import _
		self.__uri = URI(uri or '/')

	def parse(self, line):
		"""parses the request line and sets method, uri and protocol version
			:param line: the request line
			:type  line: bytes
		"""
		bits = line.strip().split(None, 2)
		try:
			method, uri, version = bits
		except ValueError:
			raise InvalidLine(_(u'Invalid request line: %r'), line.decode('ISO8859-1'))

		# protocol version
		super(Request, self).parse(version)

		# method
		self.method.parse(method)

		# URI
		if uri.startswith(b'//'):
			raise InvalidURI(_(u'The request URI must be an absolute path or contain a scheme.'))
		if self.method == u'CONNECT':
			uri = b'//%s' % (uri, )
		self.uri.parse(uri)
		self.validate_request_uri()

	def validate_request_uri(self):
		uri = self.uri
		if not isinstance(uri, (uri.SCHEMES[b'http'], uri.SCHEMES[b'https'])):

# Path: httoop/exceptions.py
# class InvalidLine(Invalid):
# 	u"""error raised when first line is invalid"""
# 
# class InvalidURI(Invalid):
# 	u"""error raised when URI is invalid"""
# 
# Path: httoop/messages/message.py
# class Message(with_metaclass(HTTPSemantic)):
# 	u"""A HTTP message
# 
# 		.. seealso:: :rfc:`2616#section-4`
# 	"""
# 	__slots__ = ('__protocol', '__headers', '__body')
# 
# 	@property
# 	def protocol(self):
# 		return self.__protocol
# 
# 	@protocol.setter
# 	def protocol(self, protocol):
# 		self.__protocol.set(protocol)
# 
# 	@property
# 	def headers(self):
# 		return self.__headers
# 
# 	@headers.setter
# 	def headers(self, headers):
# 		self.__headers.set(headers)
# 
# 	@property
# 	def body(self):
# 		return self.__body
# 
# 	@body.setter
# 	def body(self, body):
# 		self.__body.set(body)
# 
# 	@property
# 	def trailer(self):
# 		return Headers((key, self.headers[key]) for key in self.headers.values('Trailer') if key in self.headers)
# 
# 	# @trailer.setter
# 	# def trailer(self, trailer):
# 	# 	self.headers.pop('Trailer', None)
# 	# 	if trailer:
# 	# 		trailer = Headers(trailer)
# 	# 		for key in trailer:
# 	# 			self.headers.append('Trailer', key)
# 	# 		self.headers.elements('Trailer')  # sanitize
# 	# 		self.headers.merge(trailer)
# 
# 	def __init__(self, protocol=None, headers=None, body=None):
# 		u"""Initiates a new Message to hold information about the message.
# 
# 			:param protocol: the requested protocol
# 			:type  protocol: str|tuple
# 
# 			:param headers: the request headers
# 			:type  headers: dict or :class:`Headers`
# 
# 			:param body: the request body
# 			:type  body: any
# 		"""
# 		self.__protocol = Protocol(protocol or (1, 1))
# 		self.__headers = Headers(headers or {})
# 		self.__body = Body(body or b'')
# 
# 	def parse(self, protocol):
# 		u"""parses the HTTP protocol version
# 
# 			:param protocol: the protocol version string
# 			:type  protocol: bytes
# 		"""
# 
# 		self.protocol.parse(protocol)
# 
# 	def __repr__(self):
# 		return '<HTTP Message(protocol=%s)>' % (self.protocol, )
# 
# Path: httoop/messages/method.py
# class Method(with_metaclass(HTTPSemantic)):
# 	u"""A HTTP request method"""
# 	__slots__ = ('__method')
# 
# 	@property
# 	def safe(self):
# 		return self in self.safe_methods
# 
# 	@property
# 	def idempotent(self):
# 		return self in self.idempotent_methods
# 
# 	safe_methods = (u'GET', u'HEAD', u'SEARCH')
# 	idempotent_methods = (u'GET', u'HEAD', u'PUT', u'DELETE', u'OPTIONS', u'TRACE', u'SEARCH')
# 	METHOD_RE = re.compile(br"^[A-Z0-9$-_.]{1,20}\Z", re.IGNORECASE)
# 
# 	def __init__(self, method=None):
# 		self.set(method or u'GET')
# 
# 	def __hash__(self):
# 		return hash(bytes(self))
# 
# 	def set(self, method):
# 		if isinstance(method, Unicode):
# 			method = method.encode('ASCII')
# 		self.parse(method)
# 
# 	def parse(self, method):
# 		if not self.METHOD_RE.match(method):
# 			raise InvalidLine(_(u"Invalid method: %r"), method.decode('ISO8859-1'))
# 		self.__method = method
# 
# 	def compose(self):
# 		return self.__method
# 
# Path: httoop/uri/http.py
# class HTTP(URI):
# 	__slots__ = ()
# 	SCHEME = b'http'
# 	PORT = 80
# 
# Path: httoop/util.py
# def _(x):
# 	return x


# Path: httoop/messages/request.py
from httoop.exceptions import InvalidLine, InvalidURI
from httoop.messages.message import Message
from httoop.messages.method import Method
from httoop.uri import HTTP as URI
from httoop.util import _

		self.__uri = URI(uri or '/')

	def parse(self, line):
		"""parses the request line and sets method, uri and protocol version
			:param line: the request line
			:type  line: bytes
		"""
		bits = line.strip().split(None, 2)
		try:
			method, uri, version = bits
		except ValueError:
			raise InvalidLine(_(u'Invalid request line: %r'), line.decode('ISO8859-1'))

		# protocol version
		super(Request, self).parse(version)

		# method
		self.method.parse(method)

		# URI
		if uri.startswith(b'//'):
			raise InvalidURI(_(u'The request URI must be an absolute path or contain a scheme.'))
		if self.method == u'CONNECT':
			uri = b'//%s' % (uri, )
		self.uri.parse(uri)
		self.validate_request_uri()

	def validate_request_uri(self):
		uri = self.uri
		if not isinstance(uri, (uri.SCHEMES[b'http'], uri.SCHEMES[b'https'])):

			raise InvalidURI(_(u'The request URI scheme must be HTTP based.'))