Ejemplo n.º 1
0
	def logException(self, env_dict) :
		request = ( "Protocol: %(SERVER_PROTOCOL)s\n"
			"Method: %(REQUEST_METHOD)s\n"
			"Path: %(PATH_INFO)s\n"
			"Query: %(QUERY_STRING)s\n" % (env_dict) )
		request += "User-Agent: %s" % (env_dict.get("HTTP_USER_AGENT", ""))
		logger.attachException(request)
Ejemplo n.º 2
0
Archivo: page.py Proyecto: mdevaev/slib
def replaceWidgets(text, widgets_list, args_dict, css_dir_path, js_dir_path) :
	cache_dict = {}
	for widget in widgets_list :
		for name in widgetlib.widgetProvides(widget) :
			cache_dict[name] = { None : widget }

	css_list = []
	js_list = []
	content_type = DEFAULT_CONTENT_TYPE
	define_args_dict = {}

	for match in re.finditer(r"{([a-zA-Z_]+[^}\n]+)}", text) :
		macros_tuple = tuple(match.group(1).split())
		name = macros_tuple[0]
		args_tuple = macros_tuple[1:]

		if name.startswith("__") :
			if name == "__include_css__" :
				css_list += includeResources(args_tuple)
			elif name == "__include_js__" :
				js_list += includeResources(args_tuple)
			elif name == "__set_css_dir__" :
				css_dir_path = resourceDir(args_tuple, css_dir_path)
			elif name == "__set_js_dir__" :
				js_dir_path = resourceDir(args_tuple, js_dir_path)
			elif name == "__set_content_type__" :
				content_type = contentType(args_tuple, content_type)
			elif name == "__define_args__" :
				updateDefineArgs(define_args_dict, args_tuple)
			else :
				continue
			text = re.sub(r"\s*{%s[^}\n]+}\s*" % (name), "", text)
		else :
			widget = cache_dict.get(name, {}).get(None, None)
			if widget is None :
				continue

			args_tuple = define_args_dict.get(name, args_tuple)
			if cache_dict[name].get(args_tuple, None) is None :
				try :
					args_list = list(args_tuple)
					for (index, item) in enumerate(args_list) :
						if item.startswith("$") :
							variable = validators.system.validVariableName(item[1:])
							if variable in args_dict :
								args_list[index] = args_dict[variable]
							else :
								raise RuntimeError("Missing required argument \"%s\"" % (variable))

					result_dict = widget(*args_list)
					required_dict = widgetlib.widgetRequired(widget)
					css_list += required_dict["css"]
					js_list += required_dict["js"]
				except Exception, err :
					message = "{%s :: %s: %s}" % (name, type(err).__name__, str(err))
					result_dict = dict.fromkeys(widgetlib.widgetProvides(widget), message)
					logger.attachException("Error while processing widget %s(%s)" % (name, str(args_tuple)))
				for (key, value) in result_dict.iteritems() :
					cache_dict[key][args_tuple] = ulib.tools.coding.utf8(value)

			text = text.replace("{%s}" % (match.group(1)), cache_dict[name][args_tuple])