Пример #1
0
    def render(self, *args, **kwargs):
        self.sandbox['args'] = args
        self.sandbox['kwargs'] = kwargs

        r = copy(self.r)

        if len(self.py_q) == 0:
            return r.tostring()
        else:
            self.code, self.py_str = _compile(self.py_q, self.fn, kwargs)
            self.code = func(self.code.co_consts[0], self.sandbox)

        try:
            py_locals = self.code(**kwargs)
        except Exception as e:
            if isinstance(e, TypeError) or isinstance(e, KeyError):
                import sys
                if self.debug:
                    print self.py_str
                raise RenderException(self.f, self.py_str, *sys.exc_info())
            else:
                raise e

        # Check for empty doc, ussually result of python only code
        if r is None:
            return ''

        py_id = id(self.py_q)
        py_parse = py_locals['__py_parse__']
        doc_py(r, py_id, py_parse)
        return r.tostring()
Пример #2
0
    def render(self, *args, **kwargs):
        self.sandbox['args'] = args
        self.sandbox['kwargs'] = kwargs

        r = copy(self.r)

        if len(self.py_q) == 0:
            return r.tostring()
        else:
            self.code, self.py_str = _compile(self.py_q, self.fn, kwargs)
            self.code = func(self.code.co_consts[0], self.sandbox)

        try:
            py_locals = self.code(**kwargs)
        except Exception as e:
            if isinstance(e, TypeError) or isinstance(e, KeyError):
                import sys
                if self.debug:
                    print self.py_str
                raise RenderException(self.f, self.py_str, *sys.exc_info())
            else:
                raise e

        # Check for empty doc, ussually result of python only code
        if r is None:
            return ''

        py_id = id(self.py_q)
        py_parse = py_locals['__py_parse__']
        doc_py(r, py_id, py_parse)
        return r.tostring()
Пример #3
0
 def __init__(self, filename):
     self.sandbox = {}
     if isinstance(filename, list):
         self.f = filename
         fn = '<string>'
     else:
         self.f = _sandbox._open(filename).read().splitlines()
         fn = filename
     self.r, self.py_q = _pre(self.f)
     if len(self.py_q) == 0:
         self.code = None
         self.py_str = ''
     else:
         self.code, self.py_str = _compile(self.py_q, fn)
         self.code = func(self.code.co_consts[0], self.sandbox)
     self.r = _doc_pre(self.r)
Пример #4
0
if args.template_dir is not None:
    _sandbox._open.template_dir = args.template_dir[0]

if not args.debug:
    parse_templates(args.templates, args.kwargs[0], args._locals[0], args.timed, args.cache, args.repeat[0])
else:
    import pprint
    from _pre import _pre
    from _py import _compile

    pp = pprint.PrettyPrinter(depth=3)

    fn = args.templates[0]
    f = _sandbox._open(fn).read().splitlines()
    r, py_q = _pre(f)
    print('\n!!! r !!!\n')
    pp.pprint(r)
    print('\n@@@ py_q @@@\n')
    pp.pprint(py_q)
    print('\n### py_str ###\n')
    code, py_str = _compile(py_q, fn)
    print(py_str)
    print('\n$$$$$$$$$$\n')





########NEW FILE########
Пример #5
0
)

args = parser.parse_args()

if args.template_dir is not None:
    _sandbox._open.template_dir = args.template_dir[0]

if not args.debug:
    parse_templates(args.templates, args.kwargs[0], args._locals[0],
                    args.timed, args.cache, args.repeat[0])
else:
    import pprint
    from _pre import _pre
    from _py import _compile

    pp = pprint.PrettyPrinter(depth=3)

    fn = args.templates[0]
    f = _sandbox._open(fn).read().splitlines()
    r, py_q = _pre(f)
    print('\n!!! r !!!\n')
    pp.pprint(r)
    print('\n@@@ py_q @@@\n')
    pp.pprint(py_q)
    print('\n### py_str ###\n')
    code, py_str = _compile(py_q, fn)
    print(py_str)
    print('\n$$$$$$$$$$\n')

########NEW FILE########