MobileBlur

Diff
Login

Differences From Artifact [77197379d7]:

To Artifact [f463c4874e]:


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    response._vars = html
    sys.stdout = stdout
_TEST()
"""

class mybuiltin(object):
    """
    NOTE could simple use a dict and populate it, 
    NOTE not sure if this changes things though if monkey patching import.....
    """
    #__builtins__
    def __getitem__(self, key):
        try:
            return getattr(__builtin__, key)
        except AttributeError:
            raise KeyError, key            
    def __setitem__(self, key, value):
        setattr(self, key, value)

class LoadFactory(object):
    """
    Attention: this helper is new and experimental
    """
    def __init__(self,environment):
        self.environment = environment
    def __call__(self, c=None, f='index', args=[], vars={},
                 extension=None, target=None,ajax=False,ajax_trap=False,
                 url=None,user_signature=False, content='loading...',**attr):


        import globals
        target = target or 'c'+str(random.random())[2:]
        attr['_id']=target
        request = self.environment['request']
        if not isinstance(vars,Storage):
            vars = Storage(vars)
        if '.' in f:
            f, extension = f.split('.',1)
        if url or ajax:
            url = url or html.URL(request.application, c, f, r=request,
                                  args=args, vars=vars, extension=extension,
                                  user_signature=user_signature)
            script = html.SCRIPT('web2py_component("%s","%s")' % (url, target),
                                 _type="text/javascript")
            return html.TAG[''](script, html.DIV(content,**attr))
        else:
            if not isinstance(args,(list,tuple)):
                args = [args]
            c = c or request.controller

            other_request = Storage()
            for key, value in request.items():
                other_request[key] = value
            other_request['env'] = Storage()
            for key, value in request.env.items():
                other_request.env['key'] = value 
            other_request.controller = c
            other_request.function = f
            other_request.extension = extension or request.extension
            other_request.args = List(args)
            other_request.vars = vars
            other_request.get_vars = vars
            other_request.post_vars = Storage()
            other_response = globals.Response()
            other_request.env.path_info = '/' + \
                '/'.join([request.application,c,f] + \
                             map(str, other_request.args))
            other_request.env.query_string = \
                vars and html.URL(vars=vars).split('?')[1] or ''
            other_request.env.http_web2py_component_location = \
                request.env.path_info            
            other_request.cid = target
            other_request.env.http_web2py_component_element = target
            other_response.view = '%s/%s.%s' % (c,f, other_request.extension)
            other_environment = copy.copy(self.environment)
            other_response._view_environment = other_environment
            other_response.generic_patterns = \
                copy.copy(current.response.generic_patterns)







|







|









|


>
>




<
<



















|














|







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    response._vars = html
    sys.stdout = stdout
_TEST()
"""

class mybuiltin(object):
    """
    NOTE could simple use a dict and populate it,
    NOTE not sure if this changes things though if monkey patching import.....
    """
    #__builtins__
    def __getitem__(self, key):
        try:
            return getattr(__builtin__, key)
        except AttributeError:
            raise KeyError, key
    def __setitem__(self, key, value):
        setattr(self, key, value)

class LoadFactory(object):
    """
    Attention: this helper is new and experimental
    """
    def __init__(self,environment):
        self.environment = environment
    def __call__(self, c=None, f='index', args=None, vars=None,
                 extension=None, target=None,ajax=False,ajax_trap=False,
                 url=None,user_signature=False, content='loading...',**attr):
        if args is None: args = []
        vars = Storage(vars or {})
        import globals
        target = target or 'c'+str(random.random())[2:]
        attr['_id']=target
        request = self.environment['request']


        if '.' in f:
            f, extension = f.split('.',1)
        if url or ajax:
            url = url or html.URL(request.application, c, f, r=request,
                                  args=args, vars=vars, extension=extension,
                                  user_signature=user_signature)
            script = html.SCRIPT('web2py_component("%s","%s")' % (url, target),
                                 _type="text/javascript")
            return html.TAG[''](script, html.DIV(content,**attr))
        else:
            if not isinstance(args,(list,tuple)):
                args = [args]
            c = c or request.controller

            other_request = Storage()
            for key, value in request.items():
                other_request[key] = value
            other_request['env'] = Storage()
            for key, value in request.env.items():
                other_request.env['key'] = value
            other_request.controller = c
            other_request.function = f
            other_request.extension = extension or request.extension
            other_request.args = List(args)
            other_request.vars = vars
            other_request.get_vars = vars
            other_request.post_vars = Storage()
            other_response = globals.Response()
            other_request.env.path_info = '/' + \
                '/'.join([request.application,c,f] + \
                             map(str, other_request.args))
            other_request.env.query_string = \
                vars and html.URL(vars=vars).split('?')[1] or ''
            other_request.env.http_web2py_component_location = \
                request.env.path_info
            other_request.cid = target
            other_request.env.http_web2py_component_element = target
            other_response.view = '%s/%s.%s' % (c,f, other_request.extension)
            other_environment = copy.copy(self.environment)
            other_response._view_environment = other_environment
            other_response.generic_patterns = \
                copy.copy(current.response.generic_patterns)
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
        current.T = t
        current.cache = c

    global __builtins__
    if is_jython: # jython hack
        __builtins__ = mybuiltin()
    else:
        __builtins__['__import__'] = __builtin__.__import__
    environment['__builtins__'] = __builtins__
    environment['HTTP'] = HTTP
    environment['redirect'] = redirect
    environment['request'] = request
    environment['response'] = response
    environment['session'] = session
    environment['DAL'] = DAL







|







262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
        current.T = t
        current.cache = c

    global __builtins__
    if is_jython: # jython hack
        __builtins__ = mybuiltin()
    else:
        __builtins__['__import__'] = __builtin__.__import__ ### WHY?
    environment['__builtins__'] = __builtins__
    environment['HTTP'] = HTTP
    environment['redirect'] = redirect
    environment['request'] = request
    environment['response'] = response
    environment['session'] = session
    environment['DAL'] = DAL
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

def compile_views(folder):
    """
    Compiles all the views in the application specified by `folder`
    """

    path = os.path.join(folder, 'views')
    for file in listdir(path, '^[\w/]+\.\w+$'):
        data = parse_template(file, path)
        filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_')
        filename = os.path.join(folder, 'compiled', filename)
        write_file(filename, data)
        save_pyc(filename)
        os.unlink(filename)








|







310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

def compile_views(folder):
    """
    Compiles all the views in the application specified by `folder`
    """

    path = os.path.join(folder, 'views')
    for file in listdir(path, '^[\w/\-]+(\.\w+)+$'):
        data = parse_template(file, path)
        filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_')
        filename = os.path.join(folder, 'compiled', filename)
        write_file(filename, data)
        save_pyc(filename)
        os.unlink(filename)

564
565
566
567
568
569
570
571



    return


if __name__ == '__main__':
    import doctest
    doctest.testmod()











>
>
564
565
566
567
568
569
570
571
572
573

    return


if __name__ == '__main__':
    import doctest
    doctest.testmod()