from connector.elfinder.commands import COMMANDS_MAP

class HttpRequestParser(object):
	def __init__(self, request, get=None, post=None, files=None):
		print '' # u'building RREEEE ===================================================================================================='
		self._req = request
		print '' # u'building YYFTaj ===================================================================================================='
		self.post = post or {}
		self.get = get or {}
		self.files = files or {}
		self.command = ''
		self.params = {}
		try:
			self.parse()
		except Exception, e:
			print '' # u'EXCCCCC ::: %s' % e
		
	def parse(self):
		self.params = dict(self.get)
		self.params.update(self.post)
		print 'HHHHH ++++  KKKK'
		try:
			self.params.update(self.files)
		except:
			pass
		print 'HHHHH ++++  KKKK 2'
		print repr(self.params)
		
		print '' # u'building Request PASRRE ===================================================================================================='
		self.command = self.params.get('cmd', None)
		if type(self.command) == type([]):
			self.command = self.command[0]
		print 'Command BNow %s'%self.command # u'>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>'
		if self.command in COMMANDS_MAP:
			self.command = COMMANDS_MAP[self.command]
			print '' # u'9000000000000000000000000000000000000000000000999999999999999999999999999999999999999999900000000000000'
		else:
			self.command = None
		print '' # u'777777777777777777777777777777777777777777777777777777777777777777777777777   ' + repr(self.params)
		#self.params = dict([(key, val) for key, val in self.get if key != 'cmd'])
		print '' # u'building AFTER COMMANDS MAP ===================================================================================================='
	def ok(self):
		if not type(self.command) == type(object):
			return False
		return True
		
		
	