def __init__(exc, msg='Page not found', content=None): Exception.__init__(exc, msg) if content: pass elif not routing.user_routes: content = html(filename=welcome_template_filename) else: content = html(filename=notfound_template_filename) exc.content = content or msg
def _get_error_text(form): if not form.is_submitted: return None if form._cleared or form._request.form_processed: return None if form._error_text is not None: return form._error_text form._validate() for f in form.fields: if f.error_text: return html('@{Some fields below contain errors}') if form.is_valid is None: return html('@{The form has already been submitted}')
def process_queue(debugger, frame): from pony.webutils import button result = None if debugger.__state == 0: debugger.__state = 1 debugger.set_continue() return global last if last is None: debugger.set_quit() return lock, app, environ, result_holder, url, command, expr = last if url != debugger.url: debugger.set_quit() return if debugger.__state == 1: module = frame.f_globals.get('__name__') or '?' if module == 'pony' or module.startswith('pony.'): debugger.set_step() return debugger.__top_user_frame = frame debugger.__state = 2 headers = [('Content-Type', 'text/html; charset=UTF-8'), ('X-Debug', 'Step')] if not url.endswith('?'): url += '&' record = Record.from_frame(frame, context=9) if record.index is None: debugger.set_step() return result_holder.append(('200 OK', headers, html().encode('utf8'))) lock.release() while True: last = queue.get() lock, app, environ, result_holder, url, command, expr = last environ['debugger'] = weakref.ref(debugger) if command == 'step': debugger.set_step() elif command == 'next': debugger.set_next(frame) elif command == 'return': debugger.set_return(frame) elif command == 'cont': debugger.set_continue() elif expr: try: result = repr1( eval(expr, frame.f_globals, frame.f_locals)) except: result = traceback.format_exc() result_holder.append( ('200 OK', headers, html().encode('utf8'))) lock.release() continue break
def _get_value(field): value = BaseWidget._get_value(field) if value is None: return None if field.regex is not None: match = field.regex.match(value) if match is None: field._auto_error_text = html('@{Invalid data}') return None try: return str2py(value, field.type) except ValidationError as e: err_msg = e.args[0] translated_msg = html('@{%s}' % err_msg) # possible template injection? field._auto_error_text = translated_msg return None
def _get_value(field): value = BaseWidget._get_value(field) if not value: return None try: return str2date(value) except: field._auto_error_text = html('@{Incorrect date}') return None
def process_queue(debugger, frame): from pony.webutils import button result = None if debugger.__state == 0: debugger.__state = 1 debugger.set_continue() return global last if last is None: debugger.set_quit(); return lock, app, environ, result_holder, url, command, expr = last if url != debugger.url: debugger.set_quit(); return if debugger.__state == 1: module = frame.f_globals.get('__name__') or '?' if module == 'pony' or module.startswith('pony.'): debugger.set_step(); return debugger.__top_user_frame = frame debugger.__state = 2 headers = [('Content-Type', 'text/html; charset=UTF-8'), ('X-Debug', 'Step')] if not url.endswith('?'): url += '&' record = Record.from_frame(frame, context=9) if record.index is None: debugger.set_step(); return result_holder.append(('200 OK', headers, html().encode('utf8'))) lock.release() while True: last = queue.get() lock, app, environ, result_holder, url, command, expr = last environ['debugger'] = weakref.ref(debugger) if command == 'step': debugger.set_step() elif command == 'next': debugger.set_next(frame) elif command == 'return': debugger.set_return(frame) elif command == 'cont': debugger.set_continue() elif expr: try: result = repr1(eval(expr, frame.f_globals, frame.f_locals)) except: result = traceback.format_exc() result_holder.append(('200 OK', headers, html().encode('utf8'))) lock.release() continue break
def format_exc(info=None, context=5): if info: exc_type, exc_value, tb = info else: exc_type, exc_value, tb = sys.exc_info() try: exc_msg = restore_escapes(exc_value) while tb.tb_next is not None: module = tb.tb_frame.f_globals.get('__name__') or '?' if module == 'pony' or module.startswith('pony.'): tb = tb.tb_next else: break records = [] if issubclass(exc_type, SyntaxError) and exc_value.filename and exc_value.filename != '<?>': lines, index = getlines2(exc_value.filename, exc_value.lineno, context=5) source_encoding = detect_source_encoding(exc_value.filename) formatted_lines = [] for i, line in enumerate(lines): syntax_error_offset = None if i == index: syntax_error_offset = exc_value.offset - 1 formatted_lines.append(format_line(None, line.decode(source_encoding, 'replace'), syntax_error_offset)) record = Record(module='<?>', filename=exc_value.filename, lineno=exc_value.lineno, lines=formatted_lines, index=index) records = [ record ] else: frames = inspect.getinnerframes(tb, context) prev_frame = None for frame, filename, lineno, func, lines, index in frames: if index is None: continue module = frame.f_globals.get('__name__') or '?' source_encoding = detect_source_encoding(filename) formatted_lines = [ format_line(frame, line.decode(source_encoding, 'replace')) for line in lines ] record = Record(module=module, filename=filename, lineno=lineno, lines=formatted_lines, index=index, func=func) records.append(record) if module != 'pony.templating': pass elif func in ('_eval', '_compile'): element = prev_frame.f_locals['elem'] # instance of SyntaxElement subclass text, offsets, filename = (element.source + (None,))[:3] lineno, offset = pos2lineno(element.start, offsets) lines, index = getlines(text, offsets, lineno, context=5) record = Record(module='<template>', filename=filename, lineno=lineno, lines=lines, index=index) records.append(record) prev_frame = frame if issubclass(exc_type, ParseError): text, offsets = exc_value.source[:2] lines, index = getlines(text, offsets, exc_value.lineno, context=5) record = Record(module='<template>', filename='<?>', lineno=exc_value.lineno, lines=lines, index=index) records.append(record) return html() finally: del tb
def format_record(record): return html()
def format_exc(info=None, context=5): if info: exc_type, exc_value, tb = info else: exc_type, exc_value, tb = sys.exc_info() try: exc_msg = restore_escapes(exc_value) while tb.tb_next is not None: module = tb.tb_frame.f_globals.get('__name__') or '?' if module == 'pony' or module.startswith('pony.'): tb = tb.tb_next else: break records = [] if issubclass(exc_type, SyntaxError ) and exc_value.filename and exc_value.filename != '<?>': lines, index = getlines2(exc_value.filename, exc_value.lineno, context=5) source_encoding = detect_source_encoding(exc_value.filename) formatted_lines = [] for i, line in enumerate(lines): syntax_error_offset = None if i == index: syntax_error_offset = exc_value.offset - 1 formatted_lines.append( format_line(None, line.decode(source_encoding, 'replace'), syntax_error_offset)) record = Record(module='<?>', filename=exc_value.filename, lineno=exc_value.lineno, lines=formatted_lines, index=index) records = [record] else: frames = inspect.getinnerframes(tb, context) prev_frame = None for frame, filename, lineno, func, lines, index in frames: if index is None: continue module = frame.f_globals.get('__name__') or '?' source_encoding = detect_source_encoding(filename) formatted_lines = [ format_line(frame, line.decode(source_encoding, 'replace')) for line in lines ] record = Record(module=module, filename=filename, lineno=lineno, lines=formatted_lines, index=index, func=func) records.append(record) if module != 'pony.templating': pass elif func in ('_eval', '_compile'): element = prev_frame.f_locals[ 'elem'] # instance of SyntaxElement subclass text, offsets, filename = (element.source + (None, ))[:3] lineno, offset = pos2lineno(element.start, offsets) lines, index = getlines(text, offsets, lineno, context=5) record = Record(module='<template>', filename=filename, lineno=lineno, lines=lines, index=index) records.append(record) prev_frame = frame if issubclass(exc_type, ParseError): text, offsets = exc_value.source[:2] lines, index = getlines(text, offsets, exc_value.lineno, context=5) record = Record(module='<template>', filename='<?>', lineno=exc_value.lineno, lines=lines, index=index) records.append(record) return html() finally: del tb
def _check_error(field): value = field.value if field._auto_error_text: return field._auto_error_text if field.required and not value: return html('@{This field is required}')