示例#1
0
	def __init__(self, console_widget, locals = {}):
	
		self.__console_widget = console_widget
			
		self.__ps1 = ">>> " 
		self.__ps2 = "... "
		self.__ps = self.__ps1
		self.__partial_source = ""
		
		# se encarga de ejecutar los comandos
		self.__command_procesor = ItemProcesorPipeline(1)
		
		self.__locals = self.__init_locals(locals)
		InteractiveInterpreter.__init__(self, locals)
示例#2
0
class _StrangeInteractiveConsole(InteractiveInterpreter):
	'''
	Se encarga de mantener una consola activada y de ejecutar los comandos
	'''
	def __init__(self, console_widget, locals = {}):
	
		self.__console_widget = console_widget
			
		self.__ps1 = ">>> " 
		self.__ps2 = "... "
		self.__ps = self.__ps1
		self.__partial_source = ""
		
		# se encarga de ejecutar los comandos
		self.__command_procesor = ItemProcesorPipeline(1)
		
		self.__locals = self.__init_locals(locals)
		InteractiveInterpreter.__init__(self, locals)

	def help(self):
		"Imprime las variables disponibles en la consola"
		message = """Variables disponibles:
Alias               Descripción
-----               -----------
find                browser.find
find_many           browser.find_many
load_page           browser.load_page
get_basic_browser   Devuelve un basic_browser nuevo

Alias para los helpers:
DateHelper, EmailHelper, ErrorHelper, PhoneHelper, StringHelper, TextHelper, UrlHelper
"""
		self.__console_widget.write(message, color = 'green')
		# -------- Fin Help ---------	

	def __init_locals(self, locals):
		from sdf.browsers import BrowserFactory
		
		if '__name __' not in locals:
			locals['__name__'] = '__browser_console__'
		if '__doc__' not in locals:
			locals['__doc__'] = "Dummy browser console module"
		
		# chequea que pasen bien el webkitbrowser
		if 'browser' not in locals:
			raise LogicError("locals must have a browser variable")
		
		browser = locals['browser']
		
		def get_basic_browser():
			"Devuelve un basic_browser"
			return BrowserFactory.get_instance().get_basicbrowser()
		
		locals['find']				= browser.find
		locals['find_many']			= browser.find_many
		locals['load_page']			= browser.load_page
		locals['get_basic_browser']	= get_basic_browser
				
		locals['DateHelper'] 	= DateHelper
		locals['EmailHelper'] 	= EmailHelper
		locals['ErrorHelper']	= ErrorHelper
		locals['PhoneHelper']	= PhoneHelper
		locals['StringHelper']	= StringHelper
		locals['TextHelper']	= TextHelper
		locals['UrlHelper']		= UrlHelper
		
		help = self.help
		
		locals['help'] 			= self.help
					
		return locals
		
	def write(self, data):
		self.__console_widget.write(data, color = 'red')
	
	def push_command(self, command):
		"Procesa un comando, lo hace en segundo plano"
		self.__command_procesor.push(self.__synchro_push_command, command)
	
	def __synchro_push_command(self, command):
		"""
		Esta función se llama cuando el ItemProcesorPipeline pone a correr
		el comando
		"""
		self.__console_widget.write(self.__ps + command + '\n', color = "blue",
			bold = True)
		
		if self.__partial_source:
			self.__partial_source += "\n" + command
		else:
			self.__partial_source += command
		
		if self.runsource(self.__partial_source, "<browser console>"):
			# faltan más líneas de código
			self.__ps = self.__ps2
		else:
			self.__partial_source = ""
			self.__ps = self.__ps1