MobileBlur

Changes On Branch feature/web2py_auth
Login

Changes On Branch feature/web2py_auth

Changes In Branch feature/web2py_auth Excluding Merge-Ins

This is equivalent to a diff from b33aaf3ac3 to 0a19da60e0

2011-11-20
13:37
Merged in support for a real auth system, not a one-user DB kludge check-in: 57cc1847b3 user: spiffy tags: develop
13:31
Fixed bug that kept login form from working on non-localhost (turns out web2py 1.96.1 disabled generic views for other hosts) Closed-Leaf check-in: 0a19da60e0 user: spiffy tags: feature/web2py_auth
05:28
Upgraded to web2py 1.99.2 check-in: 5e6e1e2c0a user: spiffy tags: feature/web2py_auth
03:42
Merged in change from branch develop that fixes the app check-in: a162dcef14 user: spiffy tags: feature/web2py_auth
03:41
Removed web2py import calls from the Newsblur module check-in: b33aaf3ac3 user: spiffy tags: develop
03:12
Added a button to mark a feed as read check-in: b74e6c434b user: spiffy tags: develop

Modified Makefile from [72d1f69846] to [33942ab9ac].
1
2
3
4
5


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24



25
26
27
28
29
30
31
32
33
clean:
	rm -f httpserver.log 
	rm -f parameters*.py 
	rm -f -r applications/*/compiled     	
	find ./ -name '*~' -exec rm -f {} \; 


	find ./ -name '#*' -exec rm -f {} \;
	find ./ -name 'Thumbs.db' -exec rm -f {} \; 
	find ./gluon/ -name '.*' -exec rm -f {} \;
	find ./gluon/ -name '*class' -exec rm -f {} \; 
	find ./applications/admin/ -name '.*' -exec rm -f {} \; 
	find ./applications/examples/ -name '.*' -exec rm -f {} \; 
	find ./applications/welcome/ -name '.*' -exec rm -f {} \; 
	find ./ -name '*.pyc' -exec rm -f {} \;
all:
	echo "The Makefile is used to build the distribution."
	echo "In order to run web2py you do not need to make anything."
	echo "just run web2py.py"
epydoc:
	### build epydoc
	rm -f -r applications/examples/static/epydoc/ 
	epydoc --config epydoc.conf
	cp applications/examples/static/title.png applications/examples/static/epydoc
tests:
	cd gluon/tests; ./test.sh 1>tests.log 2>&1 



src:
	echo 'Version 1.98.2 ('`date +%Y-%m-%d\ %H:%M:%S`')' > VERSION
	### rm -f all junk files
	make clean
	### clean up baisc apps
	rm -f routes.py 
	rm -f applications/*/sessions/*       
	rm -f applications/*/errors/* | echo 'too many files'
	rm -f applications/*/cache/*                  





>
>



















>
>
>

|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
clean:
	rm -f httpserver.log 
	rm -f parameters*.py 
	rm -f -r applications/*/compiled     	
	find ./ -name '*~' -exec rm -f {} \; 
	find ./ -name '*.orig' -exec rm -f {} \; 
	find ./ -name '*.rej' -exec rm -f {} \; 
	find ./ -name '#*' -exec rm -f {} \;
	find ./ -name 'Thumbs.db' -exec rm -f {} \; 
	find ./gluon/ -name '.*' -exec rm -f {} \;
	find ./gluon/ -name '*class' -exec rm -f {} \; 
	find ./applications/admin/ -name '.*' -exec rm -f {} \; 
	find ./applications/examples/ -name '.*' -exec rm -f {} \; 
	find ./applications/welcome/ -name '.*' -exec rm -f {} \; 
	find ./ -name '*.pyc' -exec rm -f {} \;
all:
	echo "The Makefile is used to build the distribution."
	echo "In order to run web2py you do not need to make anything."
	echo "just run web2py.py"
epydoc:
	### build epydoc
	rm -f -r applications/examples/static/epydoc/ 
	epydoc --config epydoc.conf
	cp applications/examples/static/title.png applications/examples/static/epydoc
tests:
	cd gluon/tests; ./test.sh 1>tests.log 2>&1 
update:
	wget -O gluon/contrib/feedparser.py http://feedparser.googlecode.com/svn/trunk/feedparser/feedparser.py
	wget -O gluon/contrib/simplejsonrpc.py http://rad2py.googlecode.com/hg/ide2py/simplejsonrpc.py
src:
	echo 'Version 1.99.2 ('`date +%Y-%m-%d\ %H:%M:%S`') stable' > VERSION
	### rm -f all junk files
	make clean
	### clean up baisc apps
	rm -f routes.py 
	rm -f applications/*/sessions/*       
	rm -f applications/*/errors/* | echo 'too many files'
	rm -f applications/*/cache/*                  
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	cp ABOUT applications/admin/
	cp ABOUT applications/examples/
	cp LICENSE applications/admin/
	cp LICENSE applications/examples/
	### build web2py_src.zip
	echo '' > NEWINSTALL
	mv web2py_src.zip web2py_src_old.zip | echo 'no old'
	cd ..; zip -r web2py/web2py_src.zip web2py/gluon/*.py web2py/gluon/contrib/* web2py/splashlogo.gif web2py/*.py web2py/ABOUT  web2py/LICENSE web2py/README web2py/NEWINSTALL web2py/VERSION web2py/Makefile web2py/epydoc.css web2py/epydoc.conf web2py/app.example.yaml web2py/logging.example.conf web2py_exe.conf web2py/queue.example.yaml MANIFEST.in mkweb2pyenv startweb2py web2py/scripts/*.sh web2py/scripts/*.py web2py/applications/admin web2py/applications/examples/ web2py/applications/welcome web2py/applications/__init__.py web2py/site-packages/__init__.py web2py/gluon/tests/*.sh web2py/gluon/tests/*.py

mdp:
	make epydoc
	make src
	make app
	make win
app:







|







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	cp ABOUT applications/admin/
	cp ABOUT applications/examples/
	cp LICENSE applications/admin/
	cp LICENSE applications/examples/
	### build web2py_src.zip
	echo '' > NEWINSTALL
	mv web2py_src.zip web2py_src_old.zip | echo 'no old'
	cd ..; zip -r web2py/web2py_src.zip web2py/gluon/*.py web2py/gluon/contrib/* web2py/splashlogo.gif web2py/*.py web2py/ABOUT  web2py/LICENSE web2py/README web2py/NEWINSTALL web2py/VERSION web2py/Makefile web2py/epydoc.css web2py/epydoc.conf web2py/app.example.yaml web2py/logging.example.conf web2py_exe.conf web2py/queue.example.yaml MANIFEST.in w2p_apps w2p_clone w2p_run startweb2py web2py/scripts/*.sh web2py/scripts/*.py web2py/applications/admin web2py/applications/examples/ web2py/applications/welcome web2py/applications/__init__.py web2py/site-packages/__init__.py web2py/gluon/tests/*.sh web2py/gluon/tests/*.py

mdp:
	make epydoc
	make src
	make app
	make win
app:
100
101
102
103
104
105
106




107
108
109
110
111
112
113
114
	cp queue.example.yaml ../web2py_win/web2py/
	cp -r applications/admin ../web2py_win/web2py/applications
	cp -r applications/welcome ../web2py_win/web2py/applications
	cp -r applications/examples ../web2py_win/web2py/applications
	cp applications/__init__.py ../web2py_win/web2py/applications
	cd ../web2py_win; zip -r web2py_win.zip web2py
	mv ../web2py_win/web2py_win.zip .




run:
	python2.5 web2py.py -a hello
push:
	make src
	echo '' > NEWINSTALL
	hg push
	bzr push bzr+ssh://mdipierro@bazaar.launchpad.net/~mdipierro/web2py/devel --use-existing-dir








>
>
>
>








105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	cp queue.example.yaml ../web2py_win/web2py/
	cp -r applications/admin ../web2py_win/web2py/applications
	cp -r applications/welcome ../web2py_win/web2py/applications
	cp -r applications/examples ../web2py_win/web2py/applications
	cp applications/__init__.py ../web2py_win/web2py/applications
	cd ../web2py_win; zip -r web2py_win.zip web2py
	mv ../web2py_win/web2py_win.zip .
pip:
	# create Web2py distribution for upload to Pypi
	# after upload clean Web2py sources with rm -R ./dist
	python setup.py sdist
run:
	python2.5 web2py.py -a hello
push:
	make src
	echo '' > NEWINSTALL
	hg push
	bzr push bzr+ssh://mdipierro@bazaar.launchpad.net/~mdipierro/web2py/devel --use-existing-dir

Modified README from [b3e52ddfca] to [6434318c11].
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144


































- improved cas_auth.py, thanks Sergio
- IS_DATE and IS_DATETIME validators now work with native types
- better description of --shell, thanks Anthony
- extra SQLTABLE columns, thanks Martin
- fixed toolbar conflics, thanks Simon
- GAE password shows with ****

# 1.98.1
- fixed some problems with LOAD(ajax=False), thanks Anthony
- jquery 1.6.2
- gevent.pywsgi adds ssl support, thanks Vasile
- import/export of blobs are base64 encoded
- max number of login attemts in admin, thanks Ross
- fixed joins with alias tables
- new field.custom_delete attribute
- removed resctions on large 'text fields, thanks Martin
- field.represent = lambda value,record: .... (record is optional)
- FORM.validate() and FORM.process(), thanks Bruno
- faster visrtualfields, thanks Howsec
- mail has ssl support separate from tls, thanks Eric
- TAG objects are now pickable
- new CAT tag for no tags
- request.user_agent(), thanks Ross
- fixed fawps support
- SQLFORM(...,separator=': ') now customizable
- many small bug fixes









































|


















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
- improved cas_auth.py, thanks Sergio
- IS_DATE and IS_DATETIME validators now work with native types
- better description of --shell, thanks Anthony
- extra SQLTABLE columns, thanks Martin
- fixed toolbar conflics, thanks Simon
- GAE password shows with ****

# 1.98.1-1.98.2
- fixed some problems with LOAD(ajax=False), thanks Anthony
- jquery 1.6.2
- gevent.pywsgi adds ssl support, thanks Vasile
- import/export of blobs are base64 encoded
- max number of login attemts in admin, thanks Ross
- fixed joins with alias tables
- new field.custom_delete attribute
- removed resctions on large 'text fields, thanks Martin
- field.represent = lambda value,record: .... (record is optional)
- FORM.validate() and FORM.process(), thanks Bruno
- faster visrtualfields, thanks Howsec
- mail has ssl support separate from tls, thanks Eric
- TAG objects are now pickable
- new CAT tag for no tags
- request.user_agent(), thanks Ross
- fixed fawps support
- SQLFORM(...,separator=': ') now customizable
- many small bug fixes

## 1.99.1
- gluon/contrib/simplejsonrpc.py
- gluon/contrib/redis_cache.py
- support for A(name,callback=url,target='id',delete='tr')
- support for A(name,component=url,target='id',delete='tr')
- new pip installer, thanks Chris Steel
- isapiwsgihandler.py
- dal expression.coalesce(*options)
- gluon/contrib/simplejsonrpc.py, thanks Mariano
- expire_sessions.py respects expiration time, thanks iceberg
- addressed this issue: http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/
- x509 support (thanks Michele)
- form.process() and for.validate()
- rocket upgrade (1.2.4)
- jQuery upgrade (1.6.3)
- new syntax rows[i]('tablename.fieldname')
- new query syntax field.contains(list,all=True or False)
- new SQLFORM.grid and SQLFORM.smartgrid (should replace crud.search and crud.select)
- support for natural language queries (english only) in SQLFORM.grid
- support for computed columns and additional links in SQLFORM.grid
- new style virtual fields (experimental): db.table.field=Field.Lazy(...)
- request.utcnow
- cleaner/simpler welcome/models/db.py and welcome layout.html
- response.include_meta() and response.include_files(), thanks Denes
- dal auto-reconnect on time-out connections
- COL and COLGROUP helpers
- addresed OWASP #10, thanks Anthony and Eric
- auth.settings.login_after_registration=True
- detection of mobile devices and @mobilize helper (view.mobile.html), thanks Angelo
- experimental gluon/scheduler.py
- scripts/make_min_web2py.py
- crud.search has more options, thanks Denes
- many bug fixes (thanks Jonathan, Michele, Fran and others)
Modified VERSION from [2164f2cc2a] to [822b08660f].
1
Version 1.98.2 (2011-08-04 00:47:09)
|
1
Version 1.99.2 (2011-09-26 06:55:33) stable
Modified __init__.py from [adc83b19e7] to [7c338ed284].


1



>
>

1
2
3



Modified anyserver.py from [b44d99a317] to [10139316d2].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

This file is based, althought a rewrite, on MIT code from the Bottle web framework.
"""

import os, sys, optparse
path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
sys.path = [path]+[p for p in sys.path if not p==path]
import gluon.main
from gluon.fileutils import read_file, write_file

class Servers:











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

This file is based, althought a rewrite, on MIT code from the Bottle web framework.
"""

import os, sys, optparse, urllib
path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
sys.path = [path]+[p for p in sys.path if not p==path]
import gluon.main
from gluon.fileutils import read_file, write_file

class Servers:
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
162
163
164
165
166
167
168
169
170
        import gunicorn.arbiter
        gunicorn.arbiter.Arbiter(address, 4, app).run()

    @staticmethod
    def eventlet(app,address, **options):
        from eventlet import wsgi, listen
        wsgi.server(listen(address), app)












def run(servername,ip,port,softcron=True,logging=False,profiler=None):
    if logging:
        application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
                                            logfilename='httpserver.log',
                                            profilerfilename=profiler)
    else:
        application = gluon.main.wsgibase
    if softcron:
        from gluon.settings import global_settings
        global_settings.web2py_crontype = 'soft'
    getattr(Servers,servername)(application,(ip,int(port)))
































































































def main():
    usage = "python anyserver.py -s tornado -i 127.0.0.1 -p 8000 -l -P"
    try:
        version = read_file('VERSION')
    except IOError:
        version = ''
    parser = optparse.OptionParser(usage, None, optparse.Option, version)
    parser.add_option('-l',
                      '--logging',
                      action='store_true',
                      default=False,
                      dest='logging',
                      help='log into httpserver.log')
    parser.add_option('-P',
                      '--profiler',                      
                      default=False,
                      dest='profiler',
                      help='profiler filename')
    servers = ', '.join(x for x in dir(Servers) if not x[0]=='_')
    parser.add_option('-s',
                      '--server',
                      default='rocket',







|
>
>
>
>
>
>
>
>
>
>













>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>














|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
        import gunicorn.arbiter
        gunicorn.arbiter.Arbiter(address, 4, app).run()

    @staticmethod
    def eventlet(app,address, **options):
        from eventlet import wsgi, listen
        wsgi.server(listen(address), app)
        
    @staticmethod
    def mongrel2(app,address,**options):
        import uuid
        sys.path.append(os.path.abspath(os.path.dirname(__file__)))
        from mongrel2 import handler
        conn = handler.Connection(str(uuid.uuid4()), 
                                  "tcp://127.0.0.1:9997",
                                  "tcp://127.0.0.1:9996")
        mongrel2_handler(app,conn,debug=False)
        

def run(servername,ip,port,softcron=True,logging=False,profiler=None):
    if logging:
        application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
                                            logfilename='httpserver.log',
                                            profilerfilename=profiler)
    else:
        application = gluon.main.wsgibase
    if softcron:
        from gluon.settings import global_settings
        global_settings.web2py_crontype = 'soft'
    getattr(Servers,servername)(application,(ip,int(port)))

def mongrel2_handler(application,conn,debug=False):
    """
    Based on :
    https://github.com/berry/Mongrel2-WSGI-Handler/blob/master/wsgi-handler.py

    WSGI handler based on the Python wsgiref SimpleHandler.    
    A WSGI application should return a iterable op StringTypes. 
    Any encoding must be handled by the WSGI application itself.
    """
    from wsgiref.handlers import SimpleHandler
    try:
        import cStringIO as StringIO
    except:
        import StringIO
    
    # TODO - this wsgi handler executes the application and renders a page 
    # in memory completely before returning it as a response to the client. 
    # Thus, it does not "stream" the result back to the client. It should be 
    # possible though. The SimpleHandler accepts file-like stream objects. So, 
    # it should be just a matter of connecting 0MQ requests/response streams to 
    # the SimpleHandler requests and response streams. However, the Python API 
    # for Mongrel2 doesn't seem to support file-like stream objects for requests 
    # and responses. Unless I have missed something.
    
    while True:
        if debug: print "WAITING FOR REQUEST"
        
        # receive a request
        req = conn.recv()
        if debug: print "REQUEST BODY: %r\n" % req.body
        
        if req.is_disconnect():
            if debug: print "DISCONNECT"
            continue #effectively ignore the disconnect from the client
        
        # Set a couple of environment attributes a.k.a. header attributes 
        # that are a must according to PEP 333
        environ = req.headers
        environ['SERVER_PROTOCOL'] = 'HTTP/1.1' # SimpleHandler expects a server_protocol, lets assume it is HTTP 1.1
        environ['REQUEST_METHOD'] = environ['METHOD']
        if ':' in environ['Host']:
            environ['SERVER_NAME'] = environ['Host'].split(':')[0]
            environ['SERVER_PORT'] = environ['Host'].split(':')[1]
        else:
            environ['SERVER_NAME'] = environ['Host']
            environ['SERVER_PORT'] = ''
        environ['SCRIPT_NAME'] = '' # empty for now
        environ['PATH_INFO'] = urllib.unquote(environ['PATH'])
        if '?' in environ['URI']:
            environ['QUERY_STRING'] = environ['URI'].split('?')[1]
        else:
            environ['QUERY_STRING'] = ''
        if environ.has_key('Content-Length'):
            environ['CONTENT_LENGTH'] = environ['Content-Length'] # necessary for POST to work with Django
        environ['wsgi.input'] = req.body
        
        if debug: print "ENVIRON: %r\n" % environ
        
        # SimpleHandler needs file-like stream objects for
        # requests, errors and reponses
        reqIO = StringIO.StringIO(req.body)
        errIO = StringIO.StringIO()
        respIO = StringIO.StringIO()
        
        # execute the application
        handler = SimpleHandler(reqIO, respIO, errIO, environ, multithread = False, multiprocess = False)
        handler.run(application)
        
        # Get the response and filter out the response (=data) itself,
        # the response headers, 
        # the response status code and the response status description
        response = respIO.getvalue()
        response = response.split("\r\n")
        data = response[-1]
        headers = dict([r.split(": ") for r in response[1:-2]])
        code = response[0][9:12]
        status = response[0][13:]
        
        # strip BOM's from response data
        # Especially the WSGI handler from Django seems to generate them (2 actually, huh?)
        # a BOM isn't really necessary and cause HTML parsing errors in Chrome and Safari
        # See also: http://www.xs4all.nl/~mechiel/projects/bomstrip/
        # Although I still find this a ugly hack, it does work.
        data = data.replace('\xef\xbb\xbf', '')
        
        # Get the generated errors
        errors = errIO.getvalue()
        
        # return the response
        if debug: print "RESPONSE: %r\n" % response
        if errors:
            if debug: print "ERRORS: %r" % errors
            data = "%s\r\n\r\n%s" % (data, errors)            
        conn.reply_http(req, data, code = code, status = status, headers = headers)

def main():
    usage = "python anyserver.py -s tornado -i 127.0.0.1 -p 8000 -l -P"
    try:
        version = read_file('VERSION')
    except IOError:
        version = ''
    parser = optparse.OptionParser(usage, None, optparse.Option, version)
    parser.add_option('-l',
                      '--logging',
                      action='store_true',
                      default=False,
                      dest='logging',
                      help='log into httpserver.log')
    parser.add_option('-P',
                      '--profiler',
                      default=False,
                      dest='profiler',
                      help='profiler filename')
    servers = ', '.join(x for x in dir(Servers) if not x[0]=='_')
    parser.add_option('-s',
                      '--server',
                      default='rocket',
184
185
186
187
188
189
190

191
192
193

                      '--workers',
                      default='',
                      dest='workers',
                      help='number of workers number')
    (options, args) = parser.parse_args()
    print 'starting %s on %s:%s...' % (options.server,options.ip,options.port)
    run(options.server,options.ip,options.port,logging=options.logging,profiler=options.profiler)


if __name__=='__main__':
    main()








>



>
289
290
291
292
293
294
295
296
297
298
299
300
                      '--workers',
                      default='',
                      dest='workers',
                      help='number of workers number')
    (options, args) = parser.parse_args()
    print 'starting %s on %s:%s...' % (options.server,options.ip,options.port)
    run(options.server,options.ip,options.port,logging=options.logging,profiler=options.profiler)


if __name__=='__main__':
    main()

Modified appengine_config.py from [72d08f192b] to [ca79cefe48].
1
2
3
4

def webapp_add_wsgi_middleware(app):
    from google.appengine.ext.appstats import recording
    app = recording.appstats_wsgi_middleware(app)
    return app





>
1
2
3
4
5
def webapp_add_wsgi_middleware(app):
    from google.appengine.ext.appstats import recording
    app = recording.appstats_wsgi_middleware(app)
    return app

Added applications/admin/controllers/debug.py version [462582b868].
Modified applications/admin/controllers/default.py from [a84fa2354b] to [8dabb76ea1].
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
            return 'normal'
        if item[0] == '+':
            return 'plus'
        if item[0] == '-':
            return 'minus'

    if request.vars:
        c = ''.join([item[2:] for (i, item) in enumerate(d) if item[0] \
                     == ' ' or 'line%i' % i in request.vars])
        safe_write(path, c)
        session.flash = 'files merged'
        redirect(URL('edit', args=request.args))
    else:
        # Making the short circuit compatible with <= python2.4
        gen_data = lambda index,item: not item[:1] in ['+','-'] and "" \
                   or INPUT(_type='checkbox',







|
|







584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
            return 'normal'
        if item[0] == '+':
            return 'plus'
        if item[0] == '-':
            return 'minus'

    if request.vars:
        c = '\n'.join([item[2:].rstrip() for (i, item) in enumerate(d) if item[0] \
                           == ' ' or 'line%i' % i in request.vars])
        safe_write(path, c)
        session.flash = 'files merged'
        redirect(URL('edit', args=request.args))
    else:
        # Making the short circuit compatible with <= python2.4
        gen_data = lambda index,item: not item[:1] in ['+','-'] and "" \
                   or INPUT(_type='checkbox',
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
    functions = {}
    for c in controllers:
        data = safe_read(apath('%s/controllers/%s' % (app, c), r=request))
        items = regex_expose.findall(data)
        functions[c] = items

    # Get all views
    views = sorted(listdir(apath('%s/views/' % app, r=request), '[\w/\-]+\.\w+$'))
    views = [x.replace('\\','/') for x in views]
    extend = {}
    include = {}
    for c in views:
        data = safe_read(apath('%s/views/%s' % (app, c), r=request))
        items = regex_extend.findall(data)

        if items:







|
|







706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
    functions = {}
    for c in controllers:
        data = safe_read(apath('%s/controllers/%s' % (app, c), r=request))
        items = regex_expose.findall(data)
        functions[c] = items

    # Get all views
    views = sorted(listdir(apath('%s/views/' % app, r=request), '[\w/\-]+(\.\w+)+$'))
    views = [x.replace('\\','/') for x in views if not x.endswith('.bak')]
    extend = {}
    include = {}
    for c in views:
        data = safe_read(apath('%s/views/%s' % (app, c), r=request))
        items = regex_extend.findall(data)

        if items:
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202

def update_languages():
    """ Update available languages """

    app = get_app()
    update_all_languages(apath(app, r=request))
    session.flash = T('Language files (static strings) updated')
    redirect(URL('design',args=app))

def twitter():
    session.forget()
    session._unlock(response)
    import gluon.tools
    import gluon.contrib.simplejson as sj
    try:







|







1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202

def update_languages():
    """ Update available languages """

    app = get_app()
    update_all_languages(apath(app, r=request))
    session.flash = T('Language files (static strings) updated')
    redirect(URL('design',args=app,anchor='languages'))

def twitter():
    session.forget()
    session._unlock(response)
    import gluon.tools
    import gluon.contrib.simplejson as sj
    try:
1213
1214
1215
1216
1217
1218
1219
1220

1221
1222
        if not db(db.auth_user).count():
            auth.settings.registration_requires_approval = False            
        return dict(form=auth())
    else:
        return dict(form=T("Disabled"))

def reload_routes():
   """ Reload routes.py """

   gluon.rewrite.load()
   redirect(URL('site'))







|
>
|
|
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
        if not db(db.auth_user).count():
            auth.settings.registration_requires_approval = False            
        return dict(form=auth())
    else:
        return dict(form=T("Disabled"))

def reload_routes():
    """ Reload routes.py """
    import gluon.rewrite
    gluon.rewrite.load()
    redirect(URL('site'))
Modified applications/admin/controllers/wizard.py from [60791b7dca] to [0948ae43fd].
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
                  ('email_server','localhost'),
                  ('email_sender','you@example.com'),
                  ('email_login',''),
                  ('login_method','local'),
                  ('login_config',''),
                  ('plugins',[])],
        'tables':['auth_user'],
        'table_auth_user':['username','first_name','last_name','email','password'],

        'pages':['index','error'],
        'page_index':'# Welcome to my new app',
        'page_error':'# Error: the document does not exist',
        }

if not session.app: reset(session)

def listify(x):
    if not isinstance(x,(list,tuple)):
        return x and [x] or []
    return x

def clean(name):
    return re.sub('\W+','_',name.strip().lower())

def index():
    response.view='wizard/step.html'
    reset(session)
    apps=os.listdir(os.path.join(request.folder,'..'))
    form=SQLFORM.factory(Field('name',requires=[IS_NOT_EMPTY(),IS_ALPHANUMERIC()]))

    if form.accepts(request.vars):
        app = form.vars.name
        session.app['name'] = app
        if MULTI_USER_MODE and db(db.app.name==app)(db.app.owner!=auth.user.id).count():

            session.flash = 'App belongs already to other user'
        elif app in apps:
            meta = os.path.normpath(\
                os.path.join(os.path.normpath(request.folder),
                             '..',app,'wizard.metadata'))
            if os.path.exists(meta):
                try:
                    metafile = open(meta,'rb')
                    try:
                        session.app = pickle.load(metafile)
                    finally:
                        metafile.close()
                    session.flash = "The app exists, was created by wizard, continue to overwrite!"
                except:
                    session.flash = "The app exists, was NOT created by wizard, continue to overwrite!"
        redirect(URL('step1'))
    return dict(step='Start',form=form)


def step1():
    from gluon.contrib.simplejson import loads
    import urllib







|
>



















|
>



|
>












|

|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
                  ('email_server','localhost'),
                  ('email_sender','you@example.com'),
                  ('email_login',''),
                  ('login_method','local'),
                  ('login_config',''),
                  ('plugins',[])],
        'tables':['auth_user'],
        'table_auth_user':['username','first_name',
                           'last_name','email','password'],
        'pages':['index','error'],
        'page_index':'# Welcome to my new app',
        'page_error':'# Error: the document does not exist',
        }

if not session.app: reset(session)

def listify(x):
    if not isinstance(x,(list,tuple)):
        return x and [x] or []
    return x

def clean(name):
    return re.sub('\W+','_',name.strip().lower())

def index():
    response.view='wizard/step.html'
    reset(session)
    apps=os.listdir(os.path.join(request.folder,'..'))
    form=SQLFORM.factory(Field('name',requires=[IS_NOT_EMPTY(),
                                                IS_ALPHANUMERIC()]))
    if form.accepts(request.vars):
        app = form.vars.name
        session.app['name'] = app
        if MULTI_USER_MODE and db(db.app.name==app)\
                (db.app.owner!=auth.user.id).count():
            session.flash = 'App belongs already to other user'
        elif app in apps:
            meta = os.path.normpath(\
                os.path.join(os.path.normpath(request.folder),
                             '..',app,'wizard.metadata'))
            if os.path.exists(meta):
                try:
                    metafile = open(meta,'rb')
                    try:
                        session.app = pickle.load(metafile)
                    finally:
                        metafile.close()
                    session.flash = T("The app exists, was created by wizard, continue to overwrite!")
                except:
                    session.flash = T("The app exists, was NOT created by wizard, continue to overwrite!")
        redirect(URL('step1'))
    return dict(step='Start',form=form)


def step1():
    from gluon.contrib.simplejson import loads
    import urllib
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
    return dict(step='1: Setting Parameters',form=form)

def step2():
    response.view='wizard/step.html'
    form=SQLFORM.factory(Field('table_names','list:string',
                               default=session.app['tables']))
    if form.accepts(request.vars):
        table_names = [clean(t) for t in listify(form.vars.table_names) if t.strip()]

        if [t for t in table_names if t.startswith('auth_') and not t=='auth_user']:


            form.error.table_names = T('invalid table names (auth_* tables already defined)')
        else:
            session.app['tables']=table_names
            for table in session.app['tables']:
                if not 'table_'+table in session.app:
                    session.app['table_'+table]=['name']
                if not table=='auth_user':
                    for key in ['create','read','update','select','search']:
                        name = table+'_'+key
                        if not name in session.app['pages']:
                            session.app['pages'].append(name)
                            session.app['page_'+name]='## %s %s' % (key.capitalize(),table)

            if session.app['tables']:
                redirect(URL('step3',args=0))
            else:
                redirect(URL('step4'))
    return dict(step='2: Tables',form=form)

def step3():







|
>
|
>
>
|






<
|
|
|
|
>







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
    return dict(step='1: Setting Parameters',form=form)

def step2():
    response.view='wizard/step.html'
    form=SQLFORM.factory(Field('table_names','list:string',
                               default=session.app['tables']))
    if form.accepts(request.vars):
        table_names = [clean(t) for t in listify(form.vars.table_names) \
                           if t.strip()]
        if [t for t in table_names if t.startswith('auth_') and \
                not t=='auth_user']:
            form.error.table_names = \
                T('invalid table names (auth_* tables already defined)')
        else:
            session.app['tables']=table_names
            for table in session.app['tables']:
                if not 'table_'+table in session.app:
                    session.app['table_'+table]=['name']
                if not table=='auth_user':

                    name = table+'_manage'
                    if not name in session.app['pages']:
                        session.app['pages'].append(name)
                        session.app['page_'+name] = \
                            '## Manage %s\n{{=form}}' % (table)
            if session.app['tables']:
                redirect(URL('step3',args=0))
            else:
                redirect(URL('step4'))
    return dict(step='2: Tables',form=form)

def step3():
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
        except RuntimeError:
            response.flash=T('invalid circual reference')
        else:
            if n<m-1:
                redirect(URL('step3',args=n+1))
            else:
                redirect(URL('step4'))
    return dict(step='3: Fields for table "%s" (%s of %s)' % (table,n+1,m),table=table,form=form)


def step4():
    response.view='wizard/step.html'
    form=SQLFORM.factory(Field('pages','list:string',
                               default=session.app['pages']))
    if form.accepts(request.vars):
        session.app['pages']=[clean(t)







|
>







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
        except RuntimeError:
            response.flash=T('invalid circual reference')
        else:
            if n<m-1:
                redirect(URL('step3',args=n+1))
            else:
                redirect(URL('step4'))
    return dict(step='3: Fields for table "%s" (%s of %s)' \
                    % (table,n+1,m),table=table,form=form)

def step4():
    response.view='wizard/step.html'
    form=SQLFORM.factory(Field('pages','list:string',
                               default=session.app['pages']))
    if form.accepts(request.vars):
        session.app['pages']=[clean(t)
187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
    n=int(request.args(0) or 0)
    m=len(session.app['pages'])
    if n>=m: redirect(URL('step4'))
    page=session.app['pages'][n]
    markmin_url='http://web2py.com/examples/static/markmin.html'
    form=SQLFORM.factory(Field('content','text',
                               default=session.app.get('page_'+page,[]),
                               comment=A('use markmin',_href=markmin_url,_target='_blank')),

                         formstyle='table2cols')
    if form.accepts(request.vars):
        session.app['page_'+page]=form.vars.content
        if n<m-1:
            redirect(URL('step5',args=n+1))
        else:
            redirect(URL('step6'))







|
>







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    n=int(request.args(0) or 0)
    m=len(session.app['pages'])
    if n>=m: redirect(URL('step4'))
    page=session.app['pages'][n]
    markmin_url='http://web2py.com/examples/static/markmin.html'
    form=SQLFORM.factory(Field('content','text',
                               default=session.app.get('page_'+page,[]),
                               comment=A('use markmin',
                                         _href=markmin_url,_target='_blank')),
                         formstyle='table2cols')
    if form.accepts(request.vars):
        session.app['page_'+page]=form.vars.content
        if n<m-1:
            redirect(URL('step5',args=n+1))
        else:
            redirect(URL('step6'))
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

def make_table(table,fields):
    rawtable=table
    if table!='auth_user': table='t_'+table
    s=''
    s+='\n'+'#'*40+'\n'
    s+="db.define_table('%s',\n" % table
    s+="    Field('id','id',\n"
    s+="          represent=lambda id:SPAN(id,' ',A('view',_href=URL('%s_read',args=id)))),\n"%rawtable
    first_field='id'
    for field in fields:
        items=[x.lower() for x in field.split()]
        has = {}
        keys = []
        for key in ['notnull','unique','integer','double','boolean','float',
                    'boolean', 'date','time','datetime','text','wiki',
                    'html','file','upload','image','true',
                    'hidden','readonly','writeonly','multiple',
                    'notempty','required']:
            if key in items[1:]:
                keys.append(key)
                has[key] = True
        tables = session.app['tables']
        refs = [t for t in tables if t in items]
        items = items[:1] + [x for x in items[1:] if not x in keys and not x in tables]

        barename = name = '_'.join(items)
        if table[:2]=='t_': name='f_'+name
        if first_field=='id': first_field=name

        ### determine field type
        ftype='string'
        deftypes={'integer':'integer','double':'double','boolean':'boolean',
                  'float':'double','bool':'boolean',
                  'date':'date','time':'time','datetime':'datetime',
                  'text':'text','file':'upload','image':'upload','upload':'upload',
                  'wiki':'text', 'html':'text'}
        for key,t in deftypes.items():
            if key in has:                
                ftype = t
        if refs:
            key = refs[0]
            if not key=='auth_user': key='t_'+key
            if 'multiple' in has:







<
<















|
>









|
|







255
256
257
258
259
260
261


262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296

def make_table(table,fields):
    rawtable=table
    if table!='auth_user': table='t_'+table
    s=''
    s+='\n'+'#'*40+'\n'
    s+="db.define_table('%s',\n" % table


    first_field='id'
    for field in fields:
        items=[x.lower() for x in field.split()]
        has = {}
        keys = []
        for key in ['notnull','unique','integer','double','boolean','float',
                    'boolean', 'date','time','datetime','text','wiki',
                    'html','file','upload','image','true',
                    'hidden','readonly','writeonly','multiple',
                    'notempty','required']:
            if key in items[1:]:
                keys.append(key)
                has[key] = True
        tables = session.app['tables']
        refs = [t for t in tables if t in items]
        items = items[:1] + [x for x in items[1:] \
                                 if not x in keys and not x in tables]
        barename = name = '_'.join(items)
        if table[:2]=='t_': name='f_'+name
        if first_field=='id': first_field=name

        ### determine field type
        ftype='string'
        deftypes={'integer':'integer','double':'double','boolean':'boolean',
                  'float':'double','bool':'boolean',
                  'date':'date','time':'time','datetime':'datetime',
                  'text':'text','file':'upload','image':'upload',
                  'upload':'upload','wiki':'text', 'html':'text'}
        for key,t in deftypes.items():
            if key in has:                
                ftype = t
        if refs:
            key = refs[0]
            if not key=='auth_user': key='t_'+key
            if 'multiple' in has:
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351


352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
            s+=', notnull=True'
        if 'unique' in has:
            s+=', unique=True'
        if ftype=='boolean' and 'true' in has:
            s+=",\n          default=True"

        ### determine field representation
        if 'image' in has:
            s+=",\n          represent=lambda x: x and IMG(_alt='image',_src=URL('download',args=x), _width='200px') or ''"
        elif ftype in ('file','upload'):
            s+=",\n          represent=lambda x: x and A('download',_href=URL('download',args=x)) or ''"
        elif 'wiki' in has:
            s+=",\n          represent=lambda x: MARKMIN(x)"
            s+=",\n          comment='WIKI (markmin)'"
        elif 'html' in has:
            s+=",\n          represent=lambda x: XML(x,sanitize=True)"
            s+=",\n          comment='HTML (sanitized)'"
        ### determine field access
        if name=='password' or 'writeonly' in has:
            s+=",\n          readable=False"
        elif 'hidden' in has:
            s+=",\n          writable=False, readable=False"
        elif 'readonly' in has:
            s+=",\n          writable=False"

        ### make up a label
        s+=",\n          label=T('%s')),\n" % \
            ' '.join(x.capitalize() for x in barename.split('_'))
    if table!='auth_user':
        s+="    Field('is_active','boolean',default=True,\n"
        s+="          label=T('Active'),writable=False,readable=False),\n"
    s+="    Field('created_on','datetime',default=request.now,\n"
    s+="          label=T('Created On'),writable=False,readable=False),\n"
    s+="    Field('modified_on','datetime',default=request.now,\n"
    s+="          label=T('Modified On'),writable=False,readable=False,\n"
    s+="          update=request.now),\n"
    if not table=='auth_user' and 'auth_user' in session.app['tables']:
        s+="    Field('created_by',db.auth_user,default=auth.user_id,\n"
        s+="          label=T('Created By'),writable=False,readable=False),\n"
        s+="    Field('modified_by',db.auth_user,default=auth.user_id,\n"
        s+="          label=T('Modified By'),writable=False,readable=False,\n"
        s+="          update=auth.user_id),\n"
    elif table=='auth_user':
        s+="    Field('registration_key',default='',\n"
        s+="          writable=False,readable=False),\n"
        s+="    Field('reset_password_key',default='',\n"
        s+="          writable=False,readable=False),\n"
        s+="    Field('registration_id',default='',\n"
        s+="          writable=False,readable=False),\n"


    s+="    format='%("+first_field+")s',\n"
    s+="    migrate=settings.migrate)\n\n"
    if table=='auth_user':
        s+="""
db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
"""
    else:
        s+="db.define_table('%s_archive',db.%s,Field('current_record','reference %s'))\n" % (table,table,table)
    return s


def fix_db(filename):
    params = dict(session.app['params'])
    content = read_file(filename,'rb')
    if 'auth_user' in session.app['tables']:
        auth_user = make_table('auth_user',session.app['table_auth_user'])
        content = content.replace('sqlite://storage.sqlite',







<
<
<
<

















|
<
<
|
|
|
|
|
<
<
<
<
<
<
<






>
>













|

<







310
311
312
313
314
315
316




317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334


335
336
337
338
339







340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
            s+=', notnull=True'
        if 'unique' in has:
            s+=', unique=True'
        if ftype=='boolean' and 'true' in has:
            s+=",\n          default=True"

        ### determine field representation




        elif 'wiki' in has:
            s+=",\n          represent=lambda x: MARKMIN(x)"
            s+=",\n          comment='WIKI (markmin)'"
        elif 'html' in has:
            s+=",\n          represent=lambda x: XML(x,sanitize=True)"
            s+=",\n          comment='HTML (sanitized)'"
        ### determine field access
        if name=='password' or 'writeonly' in has:
            s+=",\n          readable=False"
        elif 'hidden' in has:
            s+=",\n          writable=False, readable=False"
        elif 'readonly' in has:
            s+=",\n          writable=False"

        ### make up a label
        s+=",\n          label=T('%s')),\n" % \
            ' '.join(x.capitalize() for x in barename.split('_'))
    if table=='auth_user':


        s+="    Field('created_on','datetime',default=request.now,\n"
        s+="          label=T('Created On'),writable=False,readable=False),\n"
        s+="    Field('modified_on','datetime',default=request.now,\n"
        s+="          label=T('Modified On'),writable=False,readable=False,\n"
        s+="          update=request.now),\n"







        s+="    Field('registration_key',default='',\n"
        s+="          writable=False,readable=False),\n"
        s+="    Field('reset_password_key',default='',\n"
        s+="          writable=False,readable=False),\n"
        s+="    Field('registration_id',default='',\n"
        s+="          writable=False,readable=False),\n"
    elif 'auth_user' in session.app['tables']:
        s+="    auth.signature,\n"
    s+="    format='%("+first_field+")s',\n"
    s+="    migrate=settings.migrate)\n\n"
    if table=='auth_user':
        s+="""
db.auth_user.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
"""
    else:
        s+="db.define_table('%s_archive',db.%s,Field('current_record','reference %s',readable=False,writable=False))\n" % (table,table,table)
    return s


def fix_db(filename):
    params = dict(session.app['params'])
    content = read_file(filename,'rb')
    if 'auth_user' in session.app['tables']:
        auth_user = make_table('auth_user',session.app['table_auth_user'])
        content = content.replace('sqlite://storage.sqlite',
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

407

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
    api_key = settings.login_config.split(':')[-1],
    domain = settings.login_config.split(':')[0],
    url = "http://%s/%s/default/user/login" % (request.env.http_host,request.application))
"""
    write_file(filename, content, 'wb')

def make_menu(pages):
    s="""
response.title = settings.title
response.subtitle = settings.subtitle
response.meta.author = '%s <%s>' % (settings.author, settings.author_email)
response.meta.keywords = settings.keywords
response.meta.description = settings.description
response.menu = [
"""
    for page in pages:
        if not page.endswith('_read') and \
                not page.endswith('_update') and \
                not page.endswith('_search') and \

                not page.startswith('_') and not page.startswith('error'):

            s+="    (T('%s'),URL('default','%s')==URL(),URL('default','%s'),[]),\n" % \
                (' '.join(x.capitalize() for x in page.split('_')),page,page)
    s+=']'
    return s

def make_page(page,contents):
    if 'auth_user' in session.app['tables'] and not page in ('index','error'):
        s="@auth.requires_login()\ndef %s():\n" % page
    else:
        s="def %s():\n" % page
    items=page.rsplit('_',1)
    if items[0] in session.app['tables'] and len(items)==2:
        t=items[0]
        if items[1]=='read':
            s+="    record = db.t_%s(request.args(0)) or redirect(URL('error'))\n" % t
            s+="    form=crud.read(db.t_%s,record)\n" % t
            s+="    return dict(form=form)\n\n"
        elif items[1]=='update':
            s+="    record = db.t_%s(request.args(0),is_active=True) or redirect(URL('error'))\n" % t
            s+="    form=crud.update(db.t_%s,record,next='%s_read/[id]',\n"  % (t,t)
            s+="                     ondelete=lambda form: redirect(URL('%s_select')),\n" % t
            s+="                     onaccept=crud.archive)\n"
            s+="    return dict(form=form)\n\n"
        elif items[1]=='create':
            s+="    form=crud.create(db.t_%s,next='%s_read/[id]')\n" % (t,t)
            s+="    return dict(form=form)\n\n"
        elif items[1]=='select':
            s+="    f,v=request.args(0),request.args(1)\n"
            s+="    try: query=f and db.t_%s[f]==v or db.t_%s\n" % (t,t)
            s+="    except: redirect(URL('error'))\n"
            s+="    rows=db(query)(db.t_%s.is_active==True).select()\n" % t
            s+="    return dict(rows=rows)\n\n"
        elif items[1]=='search':
            s+="    form, rows=crud.search(db.t_%s,query=db.t_%s.is_active==True)\n" % (t,t)
            s+="    return dict(form=form, rows=rows)\n\n"
        else:
            t=None
    else:
        t=None
    if not t:
        s+="    return dict()\n\n"
    return s

def make_view(page,contents):
    s="{{extend 'layout.html'}}\n\n"
    s+=str(MARKMIN(contents))
    items=page.rsplit('_',1)
    if items[0] in session.app['tables'] and len(items)==2:
        t=items[0]
        if items[1]=='read':
            s+="\n{{=A(T('edit %s'),_href=URL('%s_update',args=request.args(0)))}}\n<br/>\n"%(t,t)
            s+='\n{{=form}}\n'
            s+="{{for t,f in db.t_%s._referenced_by:}}{{if not t[-8:]=='_archive':}}" % t
            s+="[{{=A(t[2:],_href=URL('%s_select'%t[2:],args=(f,form.record.id)))}}]"
            s+='{{pass}}{{pass}}'
        elif items[1]=='create':
            s+="\n{{=A(T('select %s'),_href=URL('%s_select'))}}\n<br/>\n"%(t,t)
            s+='\n{{=form}}\n'
        elif items[1]=='update':
            s+="\n{{=A(T('show %s'),_href=URL('%s_read',args=request.args(0)))}}\n<br/>\n"%(t,t)
            s+='\n{{=form}}\n'
        elif items[1]=='select':
            s+="\n{{if request.args:}}<h3>{{=T('For %s #%s' % (request.args(0)[2:],request.args(1)))}}</h3>{{pass}}\n"
            s+="\n{{=A(T('create new %s'),_href=URL('%s_create'))}}\n<br/>\n"%(t,t)
            s+="\n{{=A(T('search %s'),_href=URL('%s_search'))}}\n<br/>\n"%(t,t)
            s+="\n{{if rows:}}"
            s+="\n  {{headers=dict((str(k),k.label) for k in db.t_%s)}}" % t
            s+="\n  {{=SQLTABLE(rows,headers=headers)}}"
            s+="\n{{else:}}"
            s+="\n  {{=TAG.blockquote(T('No Data'))}}"
            s+="\n{{pass}}\n"
        elif items[1]=='search':
            s+="\n{{=A(T('create new %s'),_href=URL('%s_create'))}}\n<br/>\n"%(t,t)
            s+='\n{{=form}}\n'
            s+="\n{{if rows:}}"
            s+="\n  {{headers=dict((str(k),k.label) for k in db.t_%s)}}" % t
            s+="\n  {{=SQLTABLE(rows,headers=headers)}}"
            s+="\n{{else:}}"
            s+="\n  {{=TAG.blockquote(T('No Data'))}}"
            s+="\n{{pass}}\n"
    return s

def populate(tables):

    s = 'from gluon.contrib.populate import populate\n'
    s+= 'if not db(db.auth_user).count():\n'
    for table in sort_tables(tables):
        t=table=='auth_user' and 'auth_user' or 't_'+table
        s+="     populate(db.%s,10)\n" % t
    return s

def create(options):
    if DEMO_MODE:







|
|
|
|
|
|
|
<

|
|
|
>
|
>
|
|








|
|
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



<

|







383
384
385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415



416
417


















418




419
420
421
422
423
424


































425
426
427

428
429
430
431
432
433
434
435
436
    api_key = settings.login_config.split(':')[-1],
    domain = settings.login_config.split(':')[0],
    url = "http://%s/%s/default/user/login" % (request.env.http_host,request.application))
"""
    write_file(filename, content, 'wb')

def make_menu(pages):
    s=''
    s+='response.title = settings.title\n'
    s+='response.subtitle = settings.subtitle\n'
    s+="response.meta.author = '%(author)s <%(author_email)s>' % settings\n"
    s+='response.meta.keywords = settings.keywords\n'
    s+='response.meta.description = settings.description\n'
    s+='response.menu = [\n'

    for page in pages:
        if not page.startswith('error'):
            if page.endswith('_manage'):
                page_name = page[:-7]
            else:
                page_name = page
            page_name = ' '.join(x.capitalize() for x in page_name.split('_'))
            s+="(T('%s'),URL('default','%s')==URL(),URL('default','%s'),[]),\n" \
                % (page_name,page,page)
    s+=']'
    return s

def make_page(page,contents):
    if 'auth_user' in session.app['tables'] and not page in ('index','error'):
        s="@auth.requires_login()\ndef %s():\n" % page
    else:
        s="def %s():\n" % page
    items = page.rsplit('_',1)
    if items[0] in session.app['tables'] and len(items)==2 and items[1]=='manage':



        s+="    form = SQLFORM.smartgrid(db.t_%s,onupdate=auth.archive)\n" % items[0]
        s+="    return locals()\n\n"


















    else:




        s+="    return dict()\n\n"
    return s

def make_view(page,contents):
    s="{{extend 'layout.html'}}\n\n"
    s+=str(MARKMIN(contents))


































    return s

def populate(tables):

    s = 'from gluon.contrib.populate import populate\n'
    s+= 'if db(db.auth_user).isempty():\n'
    for table in sort_tables(tables):
        t=table=='auth_user' and 'auth_user' or 't_'+table
        s+="     populate(db.%s,10)\n" % t
    return s

def create(options):
    if DEMO_MODE:
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
        controller = os.path.join(request.folder,'..',app,'controllers','default.py')
        file = open(controller,'wb')
        try:
            file.write("""# -*- coding: utf-8 -*-
### required - do no delete
def user(): return dict(form=auth())
def download(): return response.download(request,db)
def call():
    session.forget()
    return service()
### end requires
""")
            for page in session.app['pages']:
                file.write(make_page(page,session.app.get('page_'+page,'')))
        finally:
            file.close()








|
<
<







523
524
525
526
527
528
529
530


531
532
533
534
535
536
537
        controller = os.path.join(request.folder,'..',app,'controllers','default.py')
        file = open(controller,'wb')
        try:
            file.write("""# -*- coding: utf-8 -*-
### required - do no delete
def user(): return dict(form=auth())
def download(): return response.download(request,db)
def call(): return service()


### end requires
""")
            for page in session.app['pages']:
                file.write(make_page(page,session.app.get('page_'+page,'')))
        finally:
            file.close()

Modified applications/admin/languages/af.py from [6394eb18fe] to [bd52361611].
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'These files are served without processing, your images go here': 'Hierdie lêre is sonder veranderinge geserved, jou images gaan hier',
'To create a plugin, name a file/folder plugin_[name]': 'Om ''n plugin te skep, noem ''n lêer/gids plugin_[name]',
'Translation strings for the application': 'Vertaling woorde vir die program',
'Upload & install packed application': 'Oplaai & install gepakte program',
'Upload a package:': 'Oplaai ''n package:',
'Use an url:': 'Gebruik n url:',
'Views': 'Views',
'about': 'oor',
'administrative interface': 'administrative interface',
'and rename it:': 'en verander die naam:',
'change admin password': 'verander admin wagwoord',
'check for upgrades': 'soek vir upgrades',
'clean': 'maak skoon',
'collapse/expand all': 'collapse/expand all',
'compile': 'kompileer',
'controllers': 'beheerders',
'create': 'skep',
'create file with filename:': 'skep lêer met naam:',
'created by': 'geskep deur',
'crontab': 'crontab',
'currently running': 'loop tans',
'database administration': 'database administration',
'deploy': 'deploy',
'direction: ltr': 'direction: ltr',
'download layouts': 'aflaai layouts',
'download plugins': 'aflaai plugins',
'edit': 'wysig',
'errors': 'foute',
'exposes': 'exposes',
'extends': 'extends',
'files': 'lêre',
'filter': 'filter',
'help': 'hulp',
'includes': 'includes',
'install': 'installeer',
'languages': 'tale',
'loading...': 'laai...',
'logout': 'logout',
'models': 'modelle',
'modules': 'modules',
'overwrite installed app': 'skryf oor geinstalleerde program',
'pack all': 'pack alles',
'plugins': 'plugins',
'shell': 'shell',
'site': 'site',
'start wizard': 'start wizard',
'static': 'static',
'test': 'toets',
'uninstall': 'verwyder',
'update all languages': 'update all languages',
'upload': 'oplaai',
'upload file:': 'oplaai lêer:',
'upload plugin file:': 'upload plugin lêer:',
'versioning': 'versioning',
'views': 'views',
'web2py Recent Tweets': 'web2py Onlangse Tweets',







|


|
|
|

|

|





|



|
|




|

|


|


|
|


|
|


|







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'These files are served without processing, your images go here': 'Hierdie lêre is sonder veranderinge geserved, jou images gaan hier',
'To create a plugin, name a file/folder plugin_[name]': 'Om ''n plugin te skep, noem ''n lêer/gids plugin_[name]',
'Translation strings for the application': 'Vertaling woorde vir die program',
'Upload & install packed application': 'Oplaai & install gepakte program',
'Upload a package:': 'Oplaai ''n package:',
'Use an url:': 'Gebruik n url:',
'Views': 'Views',
'About': 'oor',
'administrative interface': 'administrative interface',
'and rename it:': 'en verander die naam:',
'Change admin password': 'verander admin wagwoord',
'Check for upgrades': 'soek vir upgrades',
'Clean': 'maak skoon',
'collapse/expand all': 'collapse/expand all',
'Compile': 'kompileer',
'controllers': 'beheerders',
'Create': 'skep',
'create file with filename:': 'skep lêer met naam:',
'created by': 'geskep deur',
'crontab': 'crontab',
'currently running': 'loop tans',
'database administration': 'database administration',
'Deploy': 'deploy',
'direction: ltr': 'direction: ltr',
'download layouts': 'aflaai layouts',
'download plugins': 'aflaai plugins',
'Edit': 'wysig',
'Errors': 'foute',
'exposes': 'exposes',
'extends': 'extends',
'files': 'lêre',
'filter': 'filter',
'Help': 'hulp',
'includes': 'includes',
'Install': 'installeer',
'languages': 'tale',
'loading...': 'laai...',
'Logout': 'logout',
'models': 'modelle',
'modules': 'modules',
'Overwrite installed app': 'skryf oor geinstalleerde program',
'Pack all': 'pack alles',
'plugins': 'plugins',
'shell': 'shell',
'Site': 'site',
'Start wizard': 'start wizard',
'static': 'static',
'test': 'toets',
'Uninstall': 'verwyder',
'update all languages': 'update all languages',
'upload': 'oplaai',
'upload file:': 'oplaai lêer:',
'upload plugin file:': 'upload plugin lêer:',
'versioning': 'versioning',
'views': 'views',
'web2py Recent Tweets': 'web2py Onlangse Tweets',
Modified applications/admin/languages/bg-bg.py from [7882283c41] to [601bc68396].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
'Upload existing application': 'Upload existing application',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.',
'Use an url:': 'Use an url:',
'Version': 'Version',
'Views': 'Views',
'Welcome to web2py': 'Добре дошъл в web2py',
'YES': 'YES',
'about': 'about',
'additional code for your application': 'additional code for your application',
'admin disabled because no admin password': 'admin disabled because no admin password',
'admin disabled because not supported on google app engine': 'admin disabled because not supported on google apps engine',
'admin disabled because unable to access password file': 'admin disabled because unable to access password file',
'administrative interface': 'administrative interface',
'and rename it (required):': 'and rename it (required):',
'and rename it:': 'and rename it:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'appadmin is disabled because insecure channel',
'application "%s" uninstalled': 'application "%s" uninstalled',
'application compiled': 'application compiled',
'application is compiled and cannot be designed': 'application is compiled and cannot be designed',
'arguments': 'arguments',
'back': 'back',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, errors and sessions cleaned',
'cannot create file': 'cannot create file',
'cannot upload file "%(filename)s"': 'cannot upload file "%(filename)s"',
'change admin password': 'change admin password',
'check all': 'check all',
'check for upgrades': 'check for upgrades',
'clean': 'clean',
'click here for online examples': 'щракни тук за онлайн примери',
'click here for the administrative interface': 'щракни тук за административния интерфейс',
'click to check for upgrades': 'click to check for upgrades',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'compile': 'compile',
'compiled application removed': 'compiled application removed',
'controllers': 'controllers',
'create': 'create',
'create file with filename:': 'create file with filename:',
'create new application:': 'create new application:',
'created by': 'created by',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'currently saved or',
'data uploaded': 'данните бяха качени',
'database': 'database',
'database %s select': 'database %s select',
'database administration': 'database administration',
'db': 'дб',
'defines tables': 'defines tables',
'delete': 'delete',
'delete all checked': 'delete all checked',
'delete plugin': 'delete plugin',
'deploy': 'deploy',
'design': 'дизайн',
'direction: ltr': 'direction: ltr',
'done!': 'готово!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'edit': 'edit',
'edit controller': 'edit controller',
'edit views:': 'edit views:',
'errors': 'errors',
'export as csv file': 'export as csv file',
'exposes': 'exposes',
'extends': 'extends',
'failed to reload module': 'failed to reload module',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'file "%(filename)s" created',
'file "%(filename)s" deleted': 'file "%(filename)s" deleted',
'file "%(filename)s" uploaded': 'file "%(filename)s" uploaded',
'file "%(filename)s" was not deleted': 'file "%(filename)s" was not deleted',
'file "%s" of %s restored': 'file "%s" of %s restored',
'file changed on disk': 'file changed on disk',
'file does not exist': 'file does not exist',
'file saved on %(time)s': 'file saved on %(time)s',
'file saved on %s': 'file saved on %s',
'files': 'files',
'filter': 'filter',
'help': 'help',
'htmledit': 'htmledit',
'includes': 'includes',
'insert new': 'insert new',
'insert new %s': 'insert new %s',
'install': 'install',
'internal error': 'internal error',
'invalid password': 'invalid password',
'invalid request': 'невалидна заявка',
'invalid ticket': 'invalid ticket',
'language file "%(filename)s" created/updated': 'language file "%(filename)s" created/updated',
'languages': 'languages',
'languages updated': 'languages updated',
'loading...': 'loading...',
'login': 'login',
'logout': 'logout',
'merge': 'merge',
'models': 'models',
'modules': 'modules',
'new application "%s" created': 'new application "%s" created',
'new plugin installed': 'new plugin installed',
'new record inserted': 'новият запис беше добавен',
'next 100 rows': 'next 100 rows',
'no match': 'no match',
'or import from csv file': 'or import from csv file',
'or provide app url:': 'or provide app url:',
'or provide application url:': 'or provide application url:',
'overwrite installed app': 'overwrite installed app',
'pack all': 'pack all',
'pack compiled': 'pack compiled',
'pack plugin': 'pack plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" deleted',
'plugins': 'plugins',
'previous 100 rows': 'previous 100 rows',
'record': 'record',
'record does not exist': 'записът не съществува',
'record id': 'record id',
'remove compiled': 'remove compiled',
'restore': 'restore',
'revert': 'revert',
'save': 'save',
'selected': 'selected',
'session expired': 'session expired',
'shell': 'shell',
'site': 'site',
'some files could not be removed': 'some files could not be removed',
'start wizard': 'start wizard',
'state': 'състояние',
'static': 'static',
'submit': 'submit',
'table': 'table',
'test': 'test',
'the application logic, each URL path is mapped in one exposed function in the controller': 'the application logic, each URL path is mapped in one exposed function in the controller',
'the data representation, define database tables and sets': 'the data representation, define database tables and sets',
'the presentations layer, views are also known as templates': 'the presentations layer, views are also known as templates',
'these files are served without processing, your images go here': 'these files are served without processing, your images go here',
'to  previous version.': 'to  previous version.',
'translation strings for the application': 'translation strings for the application',
'try': 'try',
'try something like': 'try something like',
'unable to create application "%s"': 'unable to create application "%s"',
'unable to delete file "%(filename)s"': 'unable to delete file "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'unable to delete file plugin "%(plugin)s"',
'unable to parse csv file': 'не е възможна обработката на csv файла',
'unable to uninstall "%s"': 'unable to uninstall "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'uncheck all',
'uninstall': 'uninstall',
'update': 'update',
'update all languages': 'update all languages',
'upgrade web2py now': 'upgrade web2py now',
'upload': 'upload',
'upload application:': 'upload application:',
'upload file:': 'upload file:',
'upload plugin file:': 'upload plugin file:',







|


















|

|
|





|


|















|





|


|
















|




|









|











|
|
|








|






|

|




















|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
'Upload existing application': 'Upload existing application',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.',
'Use an url:': 'Use an url:',
'Version': 'Version',
'Views': 'Views',
'Welcome to web2py': 'Добре дошъл в web2py',
'YES': 'YES',
'About': 'about',
'additional code for your application': 'additional code for your application',
'admin disabled because no admin password': 'admin disabled because no admin password',
'admin disabled because not supported on google app engine': 'admin disabled because not supported on google apps engine',
'admin disabled because unable to access password file': 'admin disabled because unable to access password file',
'administrative interface': 'administrative interface',
'and rename it (required):': 'and rename it (required):',
'and rename it:': 'and rename it:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'appadmin is disabled because insecure channel',
'application "%s" uninstalled': 'application "%s" uninstalled',
'application compiled': 'application compiled',
'application is compiled and cannot be designed': 'application is compiled and cannot be designed',
'arguments': 'arguments',
'back': 'back',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, errors and sessions cleaned',
'cannot create file': 'cannot create file',
'cannot upload file "%(filename)s"': 'cannot upload file "%(filename)s"',
'Change admin password': 'change admin password',
'check all': 'check all',
'Check for upgrades': 'check for upgrades',
'Clean': 'clean',
'click here for online examples': 'щракни тук за онлайн примери',
'click here for the administrative interface': 'щракни тук за административния интерфейс',
'click to check for upgrades': 'click to check for upgrades',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'Compile': 'compile',
'compiled application removed': 'compiled application removed',
'controllers': 'controllers',
'Create': 'create',
'create file with filename:': 'create file with filename:',
'create new application:': 'create new application:',
'created by': 'created by',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'currently saved or',
'data uploaded': 'данните бяха качени',
'database': 'database',
'database %s select': 'database %s select',
'database administration': 'database administration',
'db': 'дб',
'defines tables': 'defines tables',
'delete': 'delete',
'delete all checked': 'delete all checked',
'delete plugin': 'delete plugin',
'Deploy': 'deploy',
'design': 'дизайн',
'direction: ltr': 'direction: ltr',
'done!': 'готово!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'Edit': 'edit',
'edit controller': 'edit controller',
'edit views:': 'edit views:',
'Errors': 'errors',
'export as csv file': 'export as csv file',
'exposes': 'exposes',
'extends': 'extends',
'failed to reload module': 'failed to reload module',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'file "%(filename)s" created',
'file "%(filename)s" deleted': 'file "%(filename)s" deleted',
'file "%(filename)s" uploaded': 'file "%(filename)s" uploaded',
'file "%(filename)s" was not deleted': 'file "%(filename)s" was not deleted',
'file "%s" of %s restored': 'file "%s" of %s restored',
'file changed on disk': 'file changed on disk',
'file does not exist': 'file does not exist',
'file saved on %(time)s': 'file saved on %(time)s',
'file saved on %s': 'file saved on %s',
'files': 'files',
'filter': 'filter',
'Help': 'help',
'htmledit': 'htmledit',
'includes': 'includes',
'insert new': 'insert new',
'insert new %s': 'insert new %s',
'Install': 'install',
'internal error': 'internal error',
'invalid password': 'invalid password',
'invalid request': 'невалидна заявка',
'invalid ticket': 'invalid ticket',
'language file "%(filename)s" created/updated': 'language file "%(filename)s" created/updated',
'languages': 'languages',
'languages updated': 'languages updated',
'loading...': 'loading...',
'login': 'login',
'Logout': 'logout',
'merge': 'merge',
'models': 'models',
'modules': 'modules',
'new application "%s" created': 'new application "%s" created',
'new plugin installed': 'new plugin installed',
'new record inserted': 'новият запис беше добавен',
'next 100 rows': 'next 100 rows',
'no match': 'no match',
'or import from csv file': 'or import from csv file',
'or provide app url:': 'or provide app url:',
'or provide application url:': 'or provide application url:',
'Overwrite installed app': 'overwrite installed app',
'Pack all': 'pack all',
'Pack compiled': 'pack compiled',
'pack plugin': 'pack plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" deleted',
'plugins': 'plugins',
'previous 100 rows': 'previous 100 rows',
'record': 'record',
'record does not exist': 'записът не съществува',
'record id': 'record id',
'Remove compiled': 'remove compiled',
'restore': 'restore',
'revert': 'revert',
'save': 'save',
'selected': 'selected',
'session expired': 'session expired',
'shell': 'shell',
'Site': 'site',
'some files could not be removed': 'some files could not be removed',
'Start wizard': 'start wizard',
'state': 'състояние',
'static': 'static',
'submit': 'submit',
'table': 'table',
'test': 'test',
'the application logic, each URL path is mapped in one exposed function in the controller': 'the application logic, each URL path is mapped in one exposed function in the controller',
'the data representation, define database tables and sets': 'the data representation, define database tables and sets',
'the presentations layer, views are also known as templates': 'the presentations layer, views are also known as templates',
'these files are served without processing, your images go here': 'these files are served without processing, your images go here',
'to  previous version.': 'to  previous version.',
'translation strings for the application': 'translation strings for the application',
'try': 'try',
'try something like': 'try something like',
'unable to create application "%s"': 'unable to create application "%s"',
'unable to delete file "%(filename)s"': 'unable to delete file "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'unable to delete file plugin "%(plugin)s"',
'unable to parse csv file': 'не е възможна обработката на csv файла',
'unable to uninstall "%s"': 'unable to uninstall "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'uncheck all',
'Uninstall': 'uninstall',
'update': 'update',
'update all languages': 'update all languages',
'upgrade web2py now': 'upgrade web2py now',
'upload': 'upload',
'upload application:': 'upload application:',
'upload file:': 'upload file:',
'upload plugin file:': 'upload plugin file:',
Modified applications/admin/languages/de-de.py from [d326e7c06f] to [bf622518f4].
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
'Welcome to web2py': 'Willkommen zu web2py',
'Which called the function': 'Which called the function',
'Wrap with Abbreviation': 'mit Kürzel einhüllen',
'YES': 'JA',
'You are successfully running web2py': 'web2by wird erfolgreich ausgeführt',
'You can modify this application and adapt it to your needs': 'Sie können diese Anwendung verändern und Ihren Bedürfnissen anpassen',
'You visited the url': 'Sie besuchten die URL',
'about': 'Über',
'additional code for your application': 'zusätzlicher Code für Ihre Anwendung',
'admin disabled because no admin password': ' admin ist deaktiviert, weil kein Admin-Passwort gesetzt ist',
'admin disabled because not supported on google apps engine': 'admin ist deaktiviert, es existiert dafür keine Unterstützung auf der google apps engine',
'admin disabled because unable to access password file': 'admin ist deaktiviert, weil kein Zugriff auf die Passwortdatei besteht',
'administrative interface': 'administrative interface',
'and rename it (required):': 'und benenne sie um (erforderlich):',
'and rename it:': ' und benenne sie um:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'Appadmin ist deaktiviert, wegen der Benutzung eines unsicheren Kanals',
'application "%s" uninstalled': 'Anwendung "%s" deinstalliert',
'application compiled': 'Anwendung kompiliert',
'application is compiled and cannot be designed': 'Die Anwendung ist kompiliert kann deswegen nicht mehr geändert werden',
'arguments': 'arguments',
'back': 'zurück',
'beautify': 'beautify',
'cache': 'Cache',
'cache, errors and sessions cleaned': 'Zwischenspeicher (cache), Fehler und Sitzungen (sessions) gelöscht',
'call': 'call',
'cannot create file': 'Kann Datei nicht erstellen',
'cannot upload file "%(filename)s"': 'Kann Datei nicht Hochladen "%(filename)s"',
'change admin password': 'Administrator-Passwort ändern',
'change password': 'Passwort ändern',
'check all': 'alles auswählen',
'check for upgrades': 'check for upgrades',
'clean': 'löschen',
'click here for online examples': 'hier klicken für online Beispiele',
'click here for the administrative interface': 'hier klicken für die Administrationsoberfläche ',
'click to check for upgrades': 'hier klicken um nach Upgrades zu suchen',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'compile': 'kompilieren',
'compiled application removed': 'kompilierte Anwendung gelöscht',
'controllers': 'Controllers',
'create': 'erstellen',
'create file with filename:': 'erzeuge Datei mit Dateinamen:',
'create new application:': 'erzeuge neue Anwendung:',
'created by': 'created by',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'des derzeit gespeicherten oder',
'customize me!': 'pass mich an!',
'data uploaded': 'Daten hochgeladen',
'database': 'Datenbank',
'database %s select': 'Datenbank %s ausgewählt',
'database administration': 'Datenbankadministration',
'db': 'db',
'defines tables': 'definiere Tabellen',
'delete': 'löschen',
'delete all checked': 'lösche alle markierten',
'delete plugin': 'Plugin löschen',
'deploy': 'deploy',
'design': 'design',
'direction: ltr': 'direction: ltr',
'documentation': 'Dokumentation',
'done!': 'fertig!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'edit': 'bearbeiten',
'edit controller': 'Bearbeite Controller',
'edit profile': 'bearbeite Profil',
'edit views:': 'Views bearbeiten:',
'errors': 'Fehler',
'escape': 'escape',
'export as csv file': 'Exportieren als CSV-Datei',
'exposes': 'stellt zur Verfügung',
'extends': 'erweitert',
'failed to reload module': 'neu laden des Moduls fehlgeschlagen',
'file "%(filename)s" created': 'Datei "%(filename)s" erstellt',
'file "%(filename)s" deleted': 'Datei "%(filename)s" gelöscht',
'file "%(filename)s" uploaded': 'Datei "%(filename)s" hochgeladen',
'file "%(filename)s" was not deleted': 'Datei "%(filename)s" wurde nicht gelöscht',
'file "%s" of %s restored': 'Datei "%s" von %s wiederhergestellt',
'file changed on disk': 'Datei auf Festplatte geändert',
'file does not exist': 'Datei existiert nicht',
'file saved on %(time)s': 'Datei gespeichert am %(time)s',
'file saved on %s': 'Datei gespeichert auf %s',
'files': 'files',
'filter': 'filter',
'help': 'Hilfe',
'htmledit': 'htmledit',
'includes': 'Einfügen',
'index': 'index',
'insert new': 'neu einfügen',
'insert new %s': 'neu einfügen %s',
'install': 'installieren',
'internal error': 'interner Fehler',
'invalid password': 'Ungültiges Passwort',
'invalid request': 'ungültige Anfrage',
'invalid ticket': 'ungültiges Ticket',
'language file "%(filename)s" created/updated': 'Sprachdatei "%(filename)s" erstellt/aktualisiert',
'languages': 'Sprachen',
'languages updated': 'Sprachen aktualisiert',
'loading...': 'lade...',
'located in the file': 'located in Datei',
'login': 'anmelden',
'logout': 'abmelden',
'lost password?': 'Passwort vergessen?',
'merge': 'verbinden',
'models': 'Modelle',
'modules': 'Module',
'new application "%s" created': 'neue Anwendung "%s" erzeugt',
'new record inserted': 'neuer Datensatz eingefügt',
'next 100 rows': 'nächsten 100 Zeilen',
'or import from csv file': 'oder importieren von cvs Datei',
'or provide app url:': 'oder geben Sie eine Anwendungs-URL an:',
'or provide application url:': 'oder geben Sie eine Anwendungs-URL an:',
'overwrite installed app': 'installierte Anwendungen überschreiben',
'pack all': 'verpacke alles',
'pack compiled': 'Verpacke kompiliert',
'pack plugin': 'Plugin verpacken',
'please wait!': 'bitte warten!',
'plugins': 'plugins',
'previous 100 rows': 'vorherige 100 zeilen',
'record': 'Datensatz',
'record does not exist': 'Datensatz existiert nicht',
'record id': 'Datensatz id',
'register': 'Registrierung',
'remove compiled': 'kompilat gelöscht',
'restore': 'wiederherstellen',
'revert': 'zurückkehren',
'save': 'sichern',
'selected': 'ausgewählt(e)',
'session expired': 'Sitzung Abgelaufen',
'shell': 'shell',
'site': 'Seite',
'some files could not be removed': 'einige Dateien konnten nicht gelöscht werden',
'start wizard': 'start wizard',
'state': 'Status',
'static': 'statische Dateien',
'submit': 'Absenden',
'table': 'Tabelle',
'test': 'Test',
'test_def': 'test_def',
'test_for': 'test_for',







|




















|


|
|





|


|
















|






|



|
















|





|










|










|
|
|








|






|

|







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
'Welcome to web2py': 'Willkommen zu web2py',
'Which called the function': 'Which called the function',
'Wrap with Abbreviation': 'mit Kürzel einhüllen',
'YES': 'JA',
'You are successfully running web2py': 'web2by wird erfolgreich ausgeführt',
'You can modify this application and adapt it to your needs': 'Sie können diese Anwendung verändern und Ihren Bedürfnissen anpassen',
'You visited the url': 'Sie besuchten die URL',
'About': 'Über',
'additional code for your application': 'zusätzlicher Code für Ihre Anwendung',
'admin disabled because no admin password': ' admin ist deaktiviert, weil kein Admin-Passwort gesetzt ist',
'admin disabled because not supported on google apps engine': 'admin ist deaktiviert, es existiert dafür keine Unterstützung auf der google apps engine',
'admin disabled because unable to access password file': 'admin ist deaktiviert, weil kein Zugriff auf die Passwortdatei besteht',
'administrative interface': 'administrative interface',
'and rename it (required):': 'und benenne sie um (erforderlich):',
'and rename it:': ' und benenne sie um:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'Appadmin ist deaktiviert, wegen der Benutzung eines unsicheren Kanals',
'application "%s" uninstalled': 'Anwendung "%s" deinstalliert',
'application compiled': 'Anwendung kompiliert',
'application is compiled and cannot be designed': 'Die Anwendung ist kompiliert kann deswegen nicht mehr geändert werden',
'arguments': 'arguments',
'back': 'zurück',
'beautify': 'beautify',
'cache': 'Cache',
'cache, errors and sessions cleaned': 'Zwischenspeicher (cache), Fehler und Sitzungen (sessions) gelöscht',
'call': 'call',
'cannot create file': 'Kann Datei nicht erstellen',
'cannot upload file "%(filename)s"': 'Kann Datei nicht Hochladen "%(filename)s"',
'Change admin password': 'Administrator-Passwort ändern',
'change password': 'Passwort ändern',
'check all': 'alles auswählen',
'Check for upgrades': 'check for upgrades',
'Clean': 'löschen',
'click here for online examples': 'hier klicken für online Beispiele',
'click here for the administrative interface': 'hier klicken für die Administrationsoberfläche ',
'click to check for upgrades': 'hier klicken um nach Upgrades zu suchen',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'Compile': 'kompilieren',
'compiled application removed': 'kompilierte Anwendung gelöscht',
'controllers': 'Controllers',
'Create': 'erstellen',
'create file with filename:': 'erzeuge Datei mit Dateinamen:',
'create new application:': 'erzeuge neue Anwendung:',
'created by': 'created by',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'des derzeit gespeicherten oder',
'customize me!': 'pass mich an!',
'data uploaded': 'Daten hochgeladen',
'database': 'Datenbank',
'database %s select': 'Datenbank %s ausgewählt',
'database administration': 'Datenbankadministration',
'db': 'db',
'defines tables': 'definiere Tabellen',
'delete': 'löschen',
'delete all checked': 'lösche alle markierten',
'delete plugin': 'Plugin löschen',
'Deploy': 'deploy',
'design': 'design',
'direction: ltr': 'direction: ltr',
'documentation': 'Dokumentation',
'done!': 'fertig!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'Edit': 'bearbeiten',
'edit controller': 'Bearbeite Controller',
'edit profile': 'bearbeite Profil',
'edit views:': 'Views bearbeiten:',
'Errors': 'Fehler',
'escape': 'escape',
'export as csv file': 'Exportieren als CSV-Datei',
'exposes': 'stellt zur Verfügung',
'extends': 'erweitert',
'failed to reload module': 'neu laden des Moduls fehlgeschlagen',
'file "%(filename)s" created': 'Datei "%(filename)s" erstellt',
'file "%(filename)s" deleted': 'Datei "%(filename)s" gelöscht',
'file "%(filename)s" uploaded': 'Datei "%(filename)s" hochgeladen',
'file "%(filename)s" was not deleted': 'Datei "%(filename)s" wurde nicht gelöscht',
'file "%s" of %s restored': 'Datei "%s" von %s wiederhergestellt',
'file changed on disk': 'Datei auf Festplatte geändert',
'file does not exist': 'Datei existiert nicht',
'file saved on %(time)s': 'Datei gespeichert am %(time)s',
'file saved on %s': 'Datei gespeichert auf %s',
'files': 'files',
'filter': 'filter',
'Help': 'Hilfe',
'htmledit': 'htmledit',
'includes': 'Einfügen',
'index': 'index',
'insert new': 'neu einfügen',
'insert new %s': 'neu einfügen %s',
'Install': 'installieren',
'internal error': 'interner Fehler',
'invalid password': 'Ungültiges Passwort',
'invalid request': 'ungültige Anfrage',
'invalid ticket': 'ungültiges Ticket',
'language file "%(filename)s" created/updated': 'Sprachdatei "%(filename)s" erstellt/aktualisiert',
'languages': 'Sprachen',
'languages updated': 'Sprachen aktualisiert',
'loading...': 'lade...',
'located in the file': 'located in Datei',
'login': 'anmelden',
'Logout': 'abmelden',
'lost password?': 'Passwort vergessen?',
'merge': 'verbinden',
'models': 'Modelle',
'modules': 'Module',
'new application "%s" created': 'neue Anwendung "%s" erzeugt',
'new record inserted': 'neuer Datensatz eingefügt',
'next 100 rows': 'nächsten 100 Zeilen',
'or import from csv file': 'oder importieren von cvs Datei',
'or provide app url:': 'oder geben Sie eine Anwendungs-URL an:',
'or provide application url:': 'oder geben Sie eine Anwendungs-URL an:',
'Overwrite installed app': 'installierte Anwendungen überschreiben',
'Pack all': 'verpacke alles',
'Pack compiled': 'Verpacke kompiliert',
'pack plugin': 'Plugin verpacken',
'please wait!': 'bitte warten!',
'plugins': 'plugins',
'previous 100 rows': 'vorherige 100 zeilen',
'record': 'Datensatz',
'record does not exist': 'Datensatz existiert nicht',
'record id': 'Datensatz id',
'register': 'Registrierung',
'Remove compiled': 'kompilat gelöscht',
'restore': 'wiederherstellen',
'revert': 'zurückkehren',
'save': 'sichern',
'selected': 'ausgewählt(e)',
'session expired': 'Sitzung Abgelaufen',
'shell': 'shell',
'Site': 'Seite',
'some files could not be removed': 'einige Dateien konnten nicht gelöscht werden',
'Start wizard': 'start wizard',
'state': 'Status',
'static': 'statische Dateien',
'submit': 'Absenden',
'table': 'Tabelle',
'test': 'Test',
'test_def': 'test_def',
'test_for': 'test_for',
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
'try': 'versuche',
'try something like': 'versuche so etwas wie',
'unable to create application "%s"': 'erzeugen von Anwendung "%s" nicht möglich',
'unable to delete file "%(filename)s"': 'löschen von Datein "%(filename)s" nicht möglich',
'unable to parse csv file': 'analysieren der cvs Datei nicht möglich',
'unable to uninstall "%s"': 'deinstallieren von "%s" nicht möglich',
'uncheck all': 'alles demarkieren',
'uninstall': 'deinstallieren',
'update': 'aktualisieren',
'update all languages': 'aktualisiere alle Sprachen',
'upgrade web2py now': 'jetzt web2py upgraden',
'upload': 'upload',
'upload application:': 'lade Anwendung hoch:',
'upload file:': 'lade Datei hoch:',
'upload plugin file:': 'Plugin-Datei hochladen:',







|







317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
'try': 'versuche',
'try something like': 'versuche so etwas wie',
'unable to create application "%s"': 'erzeugen von Anwendung "%s" nicht möglich',
'unable to delete file "%(filename)s"': 'löschen von Datein "%(filename)s" nicht möglich',
'unable to parse csv file': 'analysieren der cvs Datei nicht möglich',
'unable to uninstall "%s"': 'deinstallieren von "%s" nicht möglich',
'uncheck all': 'alles demarkieren',
'Uninstall': 'deinstallieren',
'update': 'aktualisieren',
'update all languages': 'aktualisiere alle Sprachen',
'upgrade web2py now': 'jetzt web2py upgraden',
'upload': 'upload',
'upload application:': 'lade Anwendung hoch:',
'upload file:': 'lade Datei hoch:',
'upload plugin file:': 'Plugin-Datei hochladen:',
Modified applications/admin/languages/es-es.py from [677aa3fba3] to [d1dd79cd61].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
'Upload existing application': 'Suba esta aplicación',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Use (...)&(...) para AND, (...)|(...) para OR, y ~(...) para NOT, para crear consultas más complejas.',
'User ID': 'ID de Usuario',
'Version': 'Versión',
'Views': 'Vistas',
'Welcome to web2py': 'Bienvenido a web2py',
'YES': 'SI',
'about': 'acerca de',
'additional code for your application': 'código adicional para su aplicación',
'admin disabled because no admin password': ' por falta de contraseña',
'admin disabled because not supported on google app engine': 'admin deshabilitado, no es soportado en GAE',
'admin disabled because unable to access password file': 'admin deshabilitado, imposible acceder al archivo con la contraseña',
'and rename it (required):': 'y renombrela (requerido):',
'and rename it:': ' y renombrelo:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'admin deshabilitado, el canal no es seguro',
'application "%s" uninstalled': 'aplicación "%s" desinstalada',
'application compiled': 'aplicación compilada',
'application is compiled and cannot be designed': 'la aplicación está compilada y no puede ser modificada',
'arguments': 'argumentos',
'back': 'atrás',
'browse': 'buscar',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, errores y sesiones eliminados',
'cannot create file': 'no es posible crear archivo',
'cannot upload file "%(filename)s"': 'no es posible subir archivo "%(filename)s"',
'change admin password': 'cambie contraseña admin',
'check all': 'marcar todos',
'clean': 'limpiar',
'click here for online examples': 'haga clic aquí para ver ejemplos en línea',
'click here for the administrative interface': 'haga clic aquí para usar la interfaz administrativa',
'click to check for upgrades': 'haga clic para buscar actualizaciones',
'click to open': 'click to open',
'code': 'código',
'commit (mercurial)': 'commit (mercurial)',
'compile': 'compilar',
'compiled application removed': 'aplicación compilada removida',
'controllers': 'controladores',
'create': 'crear',
'create file with filename:': 'cree archivo con nombre:',
'create new application:': 'nombre de la nueva aplicación:',
'created by': 'creado por',
'crontab': 'crontab',
'currently saved or': 'actualmente guardado o',
'customize me!': 'Adaptame!',
'data uploaded': 'datos subidos',
'database': 'base de datos',
'database %s select': 'selección en base de datos %s',
'database administration': 'administración base de datos',
'db': 'db',
'defines tables': 'define tablas',
'delete': 'eliminar',
'delete all checked': 'eliminar marcados',
'delete plugin': 'eliminar plugin',
'design': 'modificar',
'direction: ltr': 'direction: ltr',
'done!': 'listo!',
'edit': 'editar',
'edit controller': 'editar controlador',
'edit views:': 'editar vistas:',
'errors': 'errores',
'export as csv file': 'exportar como archivo CSV',
'exposes': 'expone',
'extends': 'extiende',
'failed to reload module': 'recarga del módulo ha fallado',
'failed to reload module because:': 'no es posible recargar el módulo por:',
'file "%(filename)s" created': 'archivo "%(filename)s" creado',
'file "%(filename)s" deleted': 'archivo "%(filename)s" eliminado',
'file "%(filename)s" uploaded': 'archivo "%(filename)s" subido',
'file "%(filename)s" was not deleted': 'archivo "%(filename)s" no fué eliminado',
'file "%s" of %s restored': 'archivo "%s" de %s restaurado',
'file changed on disk': 'archivo modificado en el disco',
'file does not exist': 'archivo no existe',
'file saved on %(time)s': 'archivo guardado %(time)s',
'file saved on %s': 'archivo guardado %s',
'help': 'ayuda',
'htmledit': 'htmledit',
'includes': 'incluye',
'insert new': 'inserte nuevo',
'insert new %s': 'inserte nuevo %s',
'install': 'instalar',
'internal error': 'error interno',
'invalid password': 'contraseña inválida',
'invalid request': 'solicitud inválida',
'invalid ticket': 'tiquete inválido',
'language file "%(filename)s" created/updated': 'archivo de lenguaje "%(filename)s" creado/actualizado',
'languages': 'lenguajes',
'languages updated': 'lenguajes actualizados',
'loading...': 'cargando...',
'login': 'inicio de sesión',
'logout': 'fin de sesión',
'manage': 'manage',
'merge': 'combinar',
'models': 'modelos',
'modules': 'módulos',
'new application "%s" created': 'nueva aplicación "%s" creada',
'new plugin installed': 'nuevo plugin instalado',
'new record inserted': 'nuevo registro insertado',
'next 100 rows': '100 filas siguientes',
'no match': 'no encontrado',
'or import from csv file': 'o importar desde archivo CSV',
'or provide app url:': 'o provea URL de la aplicación:',
'or provide application url:': 'o provea URL de la aplicación:',
'overwrite installed app': 'sobreescriba aplicación instalada',
'pack all': 'empaquetar todo',
'pack compiled': 'empaquete compiladas',
'pack plugin': 'empaquetar plugin',
'password changed': 'contraseña cambiada',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" eliminado',
'previous 100 rows': '100 filas anteriores',
'record': 'registro',
'record does not exist': 'el registro no existe',
'record id': 'id de registro',
'remove compiled': 'eliminar compiladas',
'restore': 'restaurar',
'revert': 'revertir',
'save': 'guardar',
'selected': 'seleccionado(s)',
'session expired': 'sesión expirada',
'shell': 'shell',
'site': 'sitio',
'some files could not be removed': 'algunos archivos no pudieron ser removidos',
'state': 'estado',
'static': 'estáticos',
'submit': 'enviar',
'table': 'tabla',
'test': 'probar',
'the application logic, each URL path is mapped in one exposed function in the controller': 'la lógica de la aplicación, cada ruta URL se mapea en una función expuesta en el controlador',







|


















|

|






|


|


















|


|














|




|









|












|
|
|







|






|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
'Upload existing application': 'Suba esta aplicación',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Use (...)&(...) para AND, (...)|(...) para OR, y ~(...) para NOT, para crear consultas más complejas.',
'User ID': 'ID de Usuario',
'Version': 'Versión',
'Views': 'Vistas',
'Welcome to web2py': 'Bienvenido a web2py',
'YES': 'SI',
'About': 'acerca de',
'additional code for your application': 'código adicional para su aplicación',
'admin disabled because no admin password': ' por falta de contraseña',
'admin disabled because not supported on google app engine': 'admin deshabilitado, no es soportado en GAE',
'admin disabled because unable to access password file': 'admin deshabilitado, imposible acceder al archivo con la contraseña',
'and rename it (required):': 'y renombrela (requerido):',
'and rename it:': ' y renombrelo:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'admin deshabilitado, el canal no es seguro',
'application "%s" uninstalled': 'aplicación "%s" desinstalada',
'application compiled': 'aplicación compilada',
'application is compiled and cannot be designed': 'la aplicación está compilada y no puede ser modificada',
'arguments': 'argumentos',
'back': 'atrás',
'browse': 'buscar',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, errores y sesiones eliminados',
'cannot create file': 'no es posible crear archivo',
'cannot upload file "%(filename)s"': 'no es posible subir archivo "%(filename)s"',
'Change admin password': 'cambie contraseña admin',
'check all': 'marcar todos',
'Clean': 'limpiar',
'click here for online examples': 'haga clic aquí para ver ejemplos en línea',
'click here for the administrative interface': 'haga clic aquí para usar la interfaz administrativa',
'click to check for upgrades': 'haga clic para buscar actualizaciones',
'click to open': 'click to open',
'code': 'código',
'commit (mercurial)': 'commit (mercurial)',
'Compile': 'compilar',
'compiled application removed': 'aplicación compilada removida',
'controllers': 'controladores',
'Create': 'crear',
'create file with filename:': 'cree archivo con nombre:',
'create new application:': 'nombre de la nueva aplicación:',
'created by': 'creado por',
'crontab': 'crontab',
'currently saved or': 'actualmente guardado o',
'customize me!': 'Adaptame!',
'data uploaded': 'datos subidos',
'database': 'base de datos',
'database %s select': 'selección en base de datos %s',
'database administration': 'administración base de datos',
'db': 'db',
'defines tables': 'define tablas',
'delete': 'eliminar',
'delete all checked': 'eliminar marcados',
'delete plugin': 'eliminar plugin',
'design': 'modificar',
'direction: ltr': 'direction: ltr',
'done!': 'listo!',
'Edit': 'editar',
'edit controller': 'editar controlador',
'edit views:': 'editar vistas:',
'Errors': 'errores',
'export as csv file': 'exportar como archivo CSV',
'exposes': 'expone',
'extends': 'extiende',
'failed to reload module': 'recarga del módulo ha fallado',
'failed to reload module because:': 'no es posible recargar el módulo por:',
'file "%(filename)s" created': 'archivo "%(filename)s" creado',
'file "%(filename)s" deleted': 'archivo "%(filename)s" eliminado',
'file "%(filename)s" uploaded': 'archivo "%(filename)s" subido',
'file "%(filename)s" was not deleted': 'archivo "%(filename)s" no fué eliminado',
'file "%s" of %s restored': 'archivo "%s" de %s restaurado',
'file changed on disk': 'archivo modificado en el disco',
'file does not exist': 'archivo no existe',
'file saved on %(time)s': 'archivo guardado %(time)s',
'file saved on %s': 'archivo guardado %s',
'Help': 'ayuda',
'htmledit': 'htmledit',
'includes': 'incluye',
'insert new': 'inserte nuevo',
'insert new %s': 'inserte nuevo %s',
'Install': 'instalar',
'internal error': 'error interno',
'invalid password': 'contraseña inválida',
'invalid request': 'solicitud inválida',
'invalid ticket': 'tiquete inválido',
'language file "%(filename)s" created/updated': 'archivo de lenguaje "%(filename)s" creado/actualizado',
'languages': 'lenguajes',
'languages updated': 'lenguajes actualizados',
'loading...': 'cargando...',
'login': 'inicio de sesión',
'Logout': 'fin de sesión',
'manage': 'manage',
'merge': 'combinar',
'models': 'modelos',
'modules': 'módulos',
'new application "%s" created': 'nueva aplicación "%s" creada',
'new plugin installed': 'nuevo plugin instalado',
'new record inserted': 'nuevo registro insertado',
'next 100 rows': '100 filas siguientes',
'no match': 'no encontrado',
'or import from csv file': 'o importar desde archivo CSV',
'or provide app url:': 'o provea URL de la aplicación:',
'or provide application url:': 'o provea URL de la aplicación:',
'Overwrite installed app': 'sobreescriba aplicación instalada',
'Pack all': 'empaquetar todo',
'Pack compiled': 'empaquete compiladas',
'pack plugin': 'empaquetar plugin',
'password changed': 'contraseña cambiada',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" eliminado',
'previous 100 rows': '100 filas anteriores',
'record': 'registro',
'record does not exist': 'el registro no existe',
'record id': 'id de registro',
'Remove compiled': 'eliminar compiladas',
'restore': 'restaurar',
'revert': 'revertir',
'save': 'guardar',
'selected': 'seleccionado(s)',
'session expired': 'sesión expirada',
'shell': 'shell',
'Site': 'sitio',
'some files could not be removed': 'algunos archivos no pudieron ser removidos',
'state': 'estado',
'static': 'estáticos',
'submit': 'enviar',
'table': 'tabla',
'test': 'probar',
'the application logic, each URL path is mapped in one exposed function in the controller': 'la lógica de la aplicación, cada ruta URL se mapea en una función expuesta en el controlador',
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
'unable to create application "%s"': 'no es posible crear la aplicación "%s"',
'unable to delete file "%(filename)s"': 'no es posible eliminar el archivo "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'no es posible eliminar plugin "%(plugin)s"',
'unable to parse csv file': 'no es posible analizar el archivo CSV',
'unable to uninstall "%s"': 'no es posible instalar "%s"',
'unable to upgrade because "%s"': 'no es posible actualizar porque "%s"',
'uncheck all': 'desmarcar todos',
'uninstall': 'desinstalar',
'update': 'actualizar',
'update all languages': 'actualizar todos los lenguajes',
'upgrade web2py now': 'actualize web2py ahora',
'upload application:': 'subir aplicación:',
'upload file:': 'suba archivo:',
'upload plugin file:': 'suba archivo de plugin:',
'variables': 'variables',







|







261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
'unable to create application "%s"': 'no es posible crear la aplicación "%s"',
'unable to delete file "%(filename)s"': 'no es posible eliminar el archivo "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'no es posible eliminar plugin "%(plugin)s"',
'unable to parse csv file': 'no es posible analizar el archivo CSV',
'unable to uninstall "%s"': 'no es posible instalar "%s"',
'unable to upgrade because "%s"': 'no es posible actualizar porque "%s"',
'uncheck all': 'desmarcar todos',
'Uninstall': 'desinstalar',
'update': 'actualizar',
'update all languages': 'actualizar todos los lenguajes',
'upgrade web2py now': 'actualize web2py ahora',
'upload application:': 'subir aplicación:',
'upload file:': 'suba archivo:',
'upload plugin file:': 'suba archivo de plugin:',
'variables': 'variables',
Modified applications/admin/languages/fr-fr.py from [ed6f3ea1be] to [d60ffd84cf].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
'Upload existing application': 'charger une application existante',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Utilisez (...)&(...) pour AND, (...)|(...) pour OR, et ~(...) pour NOT et construire des requêtes plus complexes. ',
'Use an url:': 'Use an url:',
'Version': 'Version',
'Views': 'Vues',
'Web Framework': 'Web Framework',
'YES': 'OUI',
'about': 'à propos',
'additional code for your application': 'code supplémentaire pour votre application',
'admin disabled because no admin password': 'admin désactivé car aucun mot de passe admin',
'admin disabled because not supported on google app engine': 'admin désactivé car non pris en charge sur Google Apps engine',
'admin disabled because unable to access password file': "admin désactivé car incapable d'accéder au fichier mot de passe",
'administrative interface': 'administrative interface',
'and rename it (required):': 'et renommez-la (obligatoire):',
'and rename it:': 'et renommez-le:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'appadmin est désactivé parce que canal non sécurisé',
'application "%s" uninstalled': 'application "%s" désinstallé',
'application %(appname)s installed with md5sum: %(digest)s': 'application %(appname)s installed with md5sum: %(digest)s',
'application compiled': 'application compilée',
'application is compiled and cannot be designed': "l'application est compilée et ne peut être désigné",
'arguments': 'arguments',
'back': 'retour',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, erreurs et sessions nettoyé',
'cannot create file': 'ne peu pas créer de fichier',
'cannot upload file "%(filename)s"': 'ne peu pas charger le fichier "%(filename)s"',
'change admin password': 'change admin password',
'check all': 'tous vérifier ',
'check for upgrades': 'check for upgrades',
'clean': 'nettoyer',
'click to check for upgrades': 'Cliquez pour vérifier les mises à niveau',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'compile': 'compiler',
'compiled application removed': 'application compilée enlevé',
'controllers': 'contrôleurs',
'create': 'create',
'create file with filename:': 'créer un fichier avec nom de fichier:',
'create new application:': 'créer une nouvelle application:',
'created by': 'créé par',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'actuellement enregistrés ou',
'data uploaded': 'données chargées',
'database': 'base de données',
'database %s select': 'base de données  %s sélectionner',
'database administration': 'administration base de données',
'db': 'db',
'defines tables': 'définit les tables',
'delete': 'supprimer',
'delete all checked': 'supprimer tout ce qui est cocher',
'delete plugin': ' supprimer plugin',
'deploy': 'deploy',
'design': 'conception',
'direction: ltr': 'direction: ltr',
'docs': 'docs',
'done!': 'fait!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'edit': 'modifier',
'edit controller': 'modifier contrôleur',
'edit views:': 'edit views:',
'errors': 'erreurs',
'export as csv file': 'exportation au format CSV',
'exposes': 'expose',
'exposes:': 'exposes:',
'extends': 'étend',
'failed to reload module': 'impossible de recharger le module',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'fichier "%(filename)s" créé',
'file "%(filename)s" deleted': 'fichier "%(filename)s" supprimé',
'file "%(filename)s" uploaded': 'fichier "%(filename)s" chargé',
'file "%s" of %s restored': 'fichier "%s" de %s restauré',
'file changed on disk': 'fichier modifié sur le disque',
'file does not exist': "fichier n'existe pas",
'file saved on %(time)s': 'fichier enregistré le %(time)s',
'file saved on %s': 'fichier enregistré le %s',
'files': 'files',
'filter': 'filter',
'help': 'aide',
'htmledit': 'edition html',
'includes': 'inclus',
'index': 'index',
'insert new': 'insérer nouveau',
'insert new %s': 'insérer nouveau %s',
'install': 'install',
'internal error': 'erreur interne',
'invalid password': 'mot de passe invalide',
'invalid request': 'Demande incorrecte',
'invalid ticket': 'ticket non valide',
'language file "%(filename)s" created/updated': 'fichier de langue "%(filename)s" créé/mis à jour',
'languages': 'langues',
'loading...': 'Chargement ...',
'login': 'connexion',
'logout': 'déconnexion',
'merge': 'fusionner',
'models': 'modèles',
'modules': 'modules',
'new application "%s" created': 'nouvelle application "%s" créée',
'new plugin installed': 'nouveau plugin installé',
'new record inserted': 'nouvelle entrée inséré',
'next 100 rows': '100 lignes suivantes',
'no match': 'no match',
'or import from csv file': 'ou importer depuis un fichier CSV ',
'or provide app url:': 'or provide app url:',
'or provide application url:': "ou fournir l'URL de l'application:",
'overwrite installed app': 'overwrite installed app',
'pack all': 'tout empaqueter',
'pack compiled': 'paquet compilé',
'pack plugin': 'paquet plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" supprimé',
'plugins': 'plugins',
'previous 100 rows': '100 lignes précédentes',
'record': 'entrée',
'record does not exist': "l'entrée n'existe pas",
'record id': 'id entrée',
'remove compiled': 'retirer compilé',
'restore': 'restaurer',
'revert': 'revenir',
'save': 'sauver',
'selected': 'sélectionnés',
'session expired': 'la session a expiré ',
'shell': 'shell',
'site': 'site',
'some files could not be removed': 'certains fichiers ne peuvent pas être supprimés',
'start wizard': 'start wizard',
'state': 'état',
'static': 'statiques',
'submit': 'envoyer',
'table': 'table',
'test': 'tester',
'the application logic, each URL path is mapped in one exposed function in the controller': "la logique de l'application, chaque route URL est mappé dans une fonction exposée dans le contrôleur",
'the data representation, define database tables and sets': 'la représentation des données, défini les tables de bases de données et sets',
'the presentations layer, views are also known as templates': 'la couche des présentations, les vues sont également connus en tant que modèles',
'these files are served without processing, your images go here': 'ces fichiers sont servis sans transformation, vos images vont ici',
'to  previous version.': 'à la version précédente.',
'translation strings for the application': "chaînes de traduction de l'application",
'try': 'essayer',
'try something like': 'essayez quelque chose comme',
'unable to create application "%s"': 'impossible de créer l\'application  "%s"',
'unable to delete file "%(filename)s"': 'impossible de supprimer le fichier "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'impossible de supprimer le plugin "%(plugin)s"',
'unable to parse csv file': "impossible d'analyser les fichiers CSV",
'unable to uninstall "%s"': 'impossible de désinstaller "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'tout décocher',
'uninstall': 'désinstaller',
'update': 'mettre à jour',
'update all languages': 'mettre à jour toutes les langues',
'upgrade now': 'upgrade now',
'upgrade web2py now': 'upgrade web2py now',
'upload': 'upload',
'upload application:': "charger l'application:",
'upload file:': 'charger le fichier:',







|



















|

|
|



|


|















|






|


|
















|





|








|











|
|
|








|






|

|




















|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
'Upload existing application': 'charger une application existante',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Utilisez (...)&(...) pour AND, (...)|(...) pour OR, et ~(...) pour NOT et construire des requêtes plus complexes. ',
'Use an url:': 'Use an url:',
'Version': 'Version',
'Views': 'Vues',
'Web Framework': 'Web Framework',
'YES': 'OUI',
'About': 'à propos',
'additional code for your application': 'code supplémentaire pour votre application',
'admin disabled because no admin password': 'admin désactivé car aucun mot de passe admin',
'admin disabled because not supported on google app engine': 'admin désactivé car non pris en charge sur Google Apps engine',
'admin disabled because unable to access password file': "admin désactivé car incapable d'accéder au fichier mot de passe",
'administrative interface': 'administrative interface',
'and rename it (required):': 'et renommez-la (obligatoire):',
'and rename it:': 'et renommez-le:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'appadmin est désactivé parce que canal non sécurisé',
'application "%s" uninstalled': 'application "%s" désinstallé',
'application %(appname)s installed with md5sum: %(digest)s': 'application %(appname)s installed with md5sum: %(digest)s',
'application compiled': 'application compilée',
'application is compiled and cannot be designed': "l'application est compilée et ne peut être désigné",
'arguments': 'arguments',
'back': 'retour',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, erreurs et sessions nettoyé',
'cannot create file': 'ne peu pas créer de fichier',
'cannot upload file "%(filename)s"': 'ne peu pas charger le fichier "%(filename)s"',
'Change admin password': 'change admin password',
'check all': 'tous vérifier ',
'Check for upgrades': 'check for upgrades',
'Clean': 'nettoyer',
'click to check for upgrades': 'Cliquez pour vérifier les mises à niveau',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'Compile': 'compiler',
'compiled application removed': 'application compilée enlevé',
'controllers': 'contrôleurs',
'Create': 'create',
'create file with filename:': 'créer un fichier avec nom de fichier:',
'create new application:': 'créer une nouvelle application:',
'created by': 'créé par',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'actuellement enregistrés ou',
'data uploaded': 'données chargées',
'database': 'base de données',
'database %s select': 'base de données  %s sélectionner',
'database administration': 'administration base de données',
'db': 'db',
'defines tables': 'définit les tables',
'delete': 'supprimer',
'delete all checked': 'supprimer tout ce qui est cocher',
'delete plugin': ' supprimer plugin',
'Deploy': 'deploy',
'design': 'conception',
'direction: ltr': 'direction: ltr',
'docs': 'docs',
'done!': 'fait!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'Edit': 'modifier',
'edit controller': 'modifier contrôleur',
'edit views:': 'edit views:',
'Errors': 'erreurs',
'export as csv file': 'exportation au format CSV',
'exposes': 'expose',
'exposes:': 'exposes:',
'extends': 'étend',
'failed to reload module': 'impossible de recharger le module',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'fichier "%(filename)s" créé',
'file "%(filename)s" deleted': 'fichier "%(filename)s" supprimé',
'file "%(filename)s" uploaded': 'fichier "%(filename)s" chargé',
'file "%s" of %s restored': 'fichier "%s" de %s restauré',
'file changed on disk': 'fichier modifié sur le disque',
'file does not exist': "fichier n'existe pas",
'file saved on %(time)s': 'fichier enregistré le %(time)s',
'file saved on %s': 'fichier enregistré le %s',
'files': 'files',
'filter': 'filter',
'Help': 'aide',
'htmledit': 'edition html',
'includes': 'inclus',
'index': 'index',
'insert new': 'insérer nouveau',
'insert new %s': 'insérer nouveau %s',
'Install': 'install',
'internal error': 'erreur interne',
'invalid password': 'mot de passe invalide',
'invalid request': 'Demande incorrecte',
'invalid ticket': 'ticket non valide',
'language file "%(filename)s" created/updated': 'fichier de langue "%(filename)s" créé/mis à jour',
'languages': 'langues',
'loading...': 'Chargement ...',
'login': 'connexion',
'Logout': 'déconnexion',
'merge': 'fusionner',
'models': 'modèles',
'modules': 'modules',
'new application "%s" created': 'nouvelle application "%s" créée',
'new plugin installed': 'nouveau plugin installé',
'new record inserted': 'nouvelle entrée inséré',
'next 100 rows': '100 lignes suivantes',
'no match': 'no match',
'or import from csv file': 'ou importer depuis un fichier CSV ',
'or provide app url:': 'or provide app url:',
'or provide application url:': "ou fournir l'URL de l'application:",
'Overwrite installed app': 'overwrite installed app',
'Pack all': 'tout empaqueter',
'Pack compiled': 'paquet compilé',
'pack plugin': 'paquet plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" supprimé',
'plugins': 'plugins',
'previous 100 rows': '100 lignes précédentes',
'record': 'entrée',
'record does not exist': "l'entrée n'existe pas",
'record id': 'id entrée',
'Remove compiled': 'retirer compilé',
'restore': 'restaurer',
'revert': 'revenir',
'save': 'sauver',
'selected': 'sélectionnés',
'session expired': 'la session a expiré ',
'shell': 'shell',
'Site': 'site',
'some files could not be removed': 'certains fichiers ne peuvent pas être supprimés',
'Start wizard': 'start wizard',
'state': 'état',
'static': 'statiques',
'submit': 'envoyer',
'table': 'table',
'test': 'tester',
'the application logic, each URL path is mapped in one exposed function in the controller': "la logique de l'application, chaque route URL est mappé dans une fonction exposée dans le contrôleur",
'the data representation, define database tables and sets': 'la représentation des données, défini les tables de bases de données et sets',
'the presentations layer, views are also known as templates': 'la couche des présentations, les vues sont également connus en tant que modèles',
'these files are served without processing, your images go here': 'ces fichiers sont servis sans transformation, vos images vont ici',
'to  previous version.': 'à la version précédente.',
'translation strings for the application': "chaînes de traduction de l'application",
'try': 'essayer',
'try something like': 'essayez quelque chose comme',
'unable to create application "%s"': 'impossible de créer l\'application  "%s"',
'unable to delete file "%(filename)s"': 'impossible de supprimer le fichier "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'impossible de supprimer le plugin "%(plugin)s"',
'unable to parse csv file': "impossible d'analyser les fichiers CSV",
'unable to uninstall "%s"': 'impossible de désinstaller "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'tout décocher',
'Uninstall': 'désinstaller',
'update': 'mettre à jour',
'update all languages': 'mettre à jour toutes les langues',
'upgrade now': 'upgrade now',
'upgrade web2py now': 'upgrade web2py now',
'upload': 'upload',
'upload application:': "charger l'application:",
'upload file:': 'charger le fichier:',
Modified applications/admin/languages/he.py from [f3c994794b] to [bd2f6646ae].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'Upload & install packed application': 'העלה והתקן אפליקציה ארוזה',
'Upload a package:': 'Upload a package:',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'השתמש ב (...)&(...) עבור תנאי AND, (...)|(...) עבור תנאי OR ו~(...) עבור תנאי NOT ליצירת שאילתות מורכבות',
'Use an url:': 'Use an url:',
'Version': 'גירסא',
'Views': 'מראה',
'YES': 'כן',
'about': 'אודות',
'additional code for your application': 'קוד נוסף עבור האפליקציה שלך',
'admin disabled because no admin password': 'ממשק המנהל מנוטרל כי לא הוגדרה סיסמת מנהל',
'admin disabled because not supported on google app engine': 'ממשק המנהל נוטרל, כי אין תמיכה בGoogle app engine',
'admin disabled because unable to access password file': 'ממשק מנהל נוטרל, כי לא ניתן לגשת לקובץ הסיסמאות',
'administrative interface': 'administrative interface',
'and rename it (required):': 'ושנה את שמו (חובה):',
'and rename it:': 'ושנה את שמו:',
'appadmin': 'מנהל מסד הנתונים',
'appadmin is disabled because insecure channel': 'מנהל מסד הנתונים נוטרל בשל ערוץ לא מאובטח',
'application "%s" uninstalled': 'אפליקציה "%s" הוסרה',
'application compiled': 'אפליקציה קומפלה',
'application is compiled and cannot be designed': 'לא ניתן לערוך אפליקציה מקומפלת',
'arguments': 'פרמטרים',
'back': 'אחורה',
'cache': 'מטמון',
'cache, errors and sessions cleaned': 'מטמון, שגיאות וסשן נוקו',
'cannot create file': 'לא מצליח ליצור קובץ',
'cannot upload file "%(filename)s"': 'לא הצלחתי להעלות את הקובץ "%(filename)s"',
'change admin password': 'סיסמת מנהל שונתה',
'check all': 'סמן הכל',
'check for upgrades': 'check for upgrades',
'clean': 'נקה',
'click to check for upgrades': 'לחץ כדי לחפש עדכונים',
'code': 'קוד',
'collapse/expand all': 'collapse/expand all',
'compile': 'קמפל',
'compiled application removed': 'אפליקציה מקומפלת הוסרה',
'controllers': 'בקרים',
'create': 'צור',
'create file with filename:': 'צור קובץ בשם:',
'create new application:': 'צור אפליקציה חדשה:',
'created by': 'נוצר ע"י',
'crontab': 'משימות מתוזמנות',
'currently running': 'currently running',
'currently saved or': 'נשמר כעת או',
'data uploaded': 'המידע הועלה',
'database': 'מסד נתונים',
'database %s select': 'מסד הנתונים %s נבחר',
'database administration': 'ניהול מסד נתונים',
'db': 'מסד נתונים',
'defines tables': 'הגדר טבלאות',
'delete': 'מחק',
'delete all checked': 'סמן הכל למחיקה',
'delete plugin': 'מחק תוסף',
'deploy': 'deploy',
'design': 'עיצוב',
'direction: ltr': 'direction: rtl',
'done!': 'הסתיים!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'edit': 'ערוך',
'edit controller': 'ערוך בקר',
'edit views:': 'ערוך קיבצי תצוגה:',
'errors': 'שגיאות',
'export as csv file': 'יצא לקובץ csv',
'exposes': 'חושף את',
'extends': 'הרחבה של',
'failed to reload module because:': 'נכשל בטעינה חוזרת של מודול בגלל:',
'file "%(filename)s" created': 'הקובץ "%(filename)s" נוצר',
'file "%(filename)s" deleted': 'הקובץ "%(filename)s" נמחק',
'file "%(filename)s" uploaded': 'הקובץ "%(filename)s" הועלה',
'file "%s" of %s restored': 'הקובץ "%s" of %s שוחזר',
'file changed on disk': 'קובץ שונה על גבי הדיסק',
'file does not exist': 'קובץ לא נמצא',
'file saved on %(time)s': 'הקובץ נשמר בשעה %(time)s',
'file saved on %s': 'הקובץ נשמר ב%s',
'filter': 'filter',
'help': 'עזרה',
'htmledit': 'עורך ויזואלי',
'includes': 'מכיל',
'insert new': 'הכנס נוסף',
'insert new %s': 'הכנס %s נוסף',
'inspect attributes': 'inspect attributes',
'install': 'התקן',
'internal error': 'שגיאה מובנית',
'invalid password': 'סיסמא שגויה',
'invalid request': 'בקשה לא תקינה',
'invalid ticket': 'דו"ח שגיאה לא קיים',
'language file "%(filename)s" created/updated': 'קובץ השפה "%(filename)s" נוצר\עודכן',
'languages': 'שפות',
'loading...': 'טוען...',
'locals': 'locals',
'login': 'התחבר',
'logout': 'התנתק',
'merge': 'מזג',
'models': 'מבני נתונים',
'modules': 'מודולים',
'new application "%s" created': 'האפליקציה "%s" נוצרה',
'new plugin installed': 'פלאגין חדש הותקן',
'new record inserted': 'הרשומה נוספה',
'next 100 rows': '100 הרשומות הבאות',
'no match': 'לא נמצאה התאמה',
'or import from csv file': 'או יבא מקובץ csv',
'or provide app url:': 'או ספק כתובת url של אפליקציה',
'overwrite installed app': 'התקן על גבי אפלקציה מותקנת',
'pack all': 'ארוז הכל',
'pack compiled': 'ארוז מקומפל',
'pack plugin': 'ארוז תוסף',
'password changed': 'סיסמא שונתה',
'plugin "%(plugin)s" deleted': 'תוסף "%(plugin)s" נמחק',
'plugins': 'plugins',
'previous 100 rows': '100 הרשומות הקודמות',
'record': 'רשומה',
'record does not exist': 'הרשומה אינה קיימת',
'record id': 'מזהה רשומה',
'remove compiled': 'הסר מקומפל',
'request': 'request',
'response': 'response',
'restore': 'שחזר',
'revert': 'חזור לגירסא קודמת',
'selected': 'נבחרו',
'session': 'session',
'session expired': 'תם הסשן',
'shell': 'שורת פקודה',
'site': 'אתר',
'some files could not be removed': 'לא ניתן היה להסיר חלק מהקבצים',
'start wizard': 'start wizard',
'state': 'מצב',
'static': 'קבצים סטאטיים',
'submit': 'שלח',
'table': 'טבלה',
'test': 'בדיקות',
'the application logic, each URL path is mapped in one exposed function in the controller': 'הלוגיקה של האפליקציה, כל url ממופה לפונקציה חשופה בבקר',
'the data representation, define database tables and sets': 'ייצוג המידע, בו מוגדרים טבלאות ומבנים',
'the presentations layer, views are also known as templates': 'שכבת התצוגה, המכונה גם template',
'these files are served without processing, your images go here': 'אלו הם קבצים הנשלחים מהשרת ללא עיבוד. הכנס את התמונות כאן',
'to  previous version.': 'אין גירסא קודמת',
'translation strings for the application': 'מחרוזות תרגום עבור האפליקציה',
'try': 'נסה',
'try something like': 'נסה משהו כמו',
'unable to create application "%s"': 'נכשל ביצירת האפליקציה "%s"',
'unable to delete file "%(filename)s"': 'נכשל במחיקת הקובץ "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'נכשל במחיקת התוסף "%(plugin)s"',
'unable to parse csv file': 'לא הצלחתי לנתח את הקלט של קובץ csv',
'unable to uninstall "%s"': 'לא ניתן להסיר את "%s"',
'unable to upgrade because "%s"': 'לא ניתן היה לשדרג כי "%s"',
'uncheck all': 'הסר סימון מהכל',
'uninstall': 'הסר התקנה',
'update': 'עדכן',
'update all languages': 'עדכן את כלל קיבצי השפה',
'upgrade now': 'upgrade now',
'upgrade web2py now': 'שדרג את web2py עכשיו',
'upload': 'upload',
'upload application:': 'העלה אפליקציה:',
'upload file:': 'העלה קובץ:',







|


















|

|
|



|


|















|





|


|













|





|









|










|
|
|








|








|

|




















|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'Upload & install packed application': 'העלה והתקן אפליקציה ארוזה',
'Upload a package:': 'Upload a package:',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'השתמש ב (...)&(...) עבור תנאי AND, (...)|(...) עבור תנאי OR ו~(...) עבור תנאי NOT ליצירת שאילתות מורכבות',
'Use an url:': 'Use an url:',
'Version': 'גירסא',
'Views': 'מראה',
'YES': 'כן',
'About': 'אודות',
'additional code for your application': 'קוד נוסף עבור האפליקציה שלך',
'admin disabled because no admin password': 'ממשק המנהל מנוטרל כי לא הוגדרה סיסמת מנהל',
'admin disabled because not supported on google app engine': 'ממשק המנהל נוטרל, כי אין תמיכה בGoogle app engine',
'admin disabled because unable to access password file': 'ממשק מנהל נוטרל, כי לא ניתן לגשת לקובץ הסיסמאות',
'administrative interface': 'administrative interface',
'and rename it (required):': 'ושנה את שמו (חובה):',
'and rename it:': 'ושנה את שמו:',
'appadmin': 'מנהל מסד הנתונים',
'appadmin is disabled because insecure channel': 'מנהל מסד הנתונים נוטרל בשל ערוץ לא מאובטח',
'application "%s" uninstalled': 'אפליקציה "%s" הוסרה',
'application compiled': 'אפליקציה קומפלה',
'application is compiled and cannot be designed': 'לא ניתן לערוך אפליקציה מקומפלת',
'arguments': 'פרמטרים',
'back': 'אחורה',
'cache': 'מטמון',
'cache, errors and sessions cleaned': 'מטמון, שגיאות וסשן נוקו',
'cannot create file': 'לא מצליח ליצור קובץ',
'cannot upload file "%(filename)s"': 'לא הצלחתי להעלות את הקובץ "%(filename)s"',
'Change admin password': 'סיסמת מנהל שונתה',
'check all': 'סמן הכל',
'Check for upgrades': 'check for upgrades',
'Clean': 'נקה',
'click to check for upgrades': 'לחץ כדי לחפש עדכונים',
'code': 'קוד',
'collapse/expand all': 'collapse/expand all',
'Compile': 'קמפל',
'compiled application removed': 'אפליקציה מקומפלת הוסרה',
'controllers': 'בקרים',
'Create': 'צור',
'create file with filename:': 'צור קובץ בשם:',
'create new application:': 'צור אפליקציה חדשה:',
'created by': 'נוצר ע"י',
'crontab': 'משימות מתוזמנות',
'currently running': 'currently running',
'currently saved or': 'נשמר כעת או',
'data uploaded': 'המידע הועלה',
'database': 'מסד נתונים',
'database %s select': 'מסד הנתונים %s נבחר',
'database administration': 'ניהול מסד נתונים',
'db': 'מסד נתונים',
'defines tables': 'הגדר טבלאות',
'delete': 'מחק',
'delete all checked': 'סמן הכל למחיקה',
'delete plugin': 'מחק תוסף',
'Deploy': 'deploy',
'design': 'עיצוב',
'direction: ltr': 'direction: rtl',
'done!': 'הסתיים!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'Edit': 'ערוך',
'edit controller': 'ערוך בקר',
'edit views:': 'ערוך קיבצי תצוגה:',
'Errors': 'שגיאות',
'export as csv file': 'יצא לקובץ csv',
'exposes': 'חושף את',
'extends': 'הרחבה של',
'failed to reload module because:': 'נכשל בטעינה חוזרת של מודול בגלל:',
'file "%(filename)s" created': 'הקובץ "%(filename)s" נוצר',
'file "%(filename)s" deleted': 'הקובץ "%(filename)s" נמחק',
'file "%(filename)s" uploaded': 'הקובץ "%(filename)s" הועלה',
'file "%s" of %s restored': 'הקובץ "%s" of %s שוחזר',
'file changed on disk': 'קובץ שונה על גבי הדיסק',
'file does not exist': 'קובץ לא נמצא',
'file saved on %(time)s': 'הקובץ נשמר בשעה %(time)s',
'file saved on %s': 'הקובץ נשמר ב%s',
'filter': 'filter',
'Help': 'עזרה',
'htmledit': 'עורך ויזואלי',
'includes': 'מכיל',
'insert new': 'הכנס נוסף',
'insert new %s': 'הכנס %s נוסף',
'inspect attributes': 'inspect attributes',
'Install': 'התקן',
'internal error': 'שגיאה מובנית',
'invalid password': 'סיסמא שגויה',
'invalid request': 'בקשה לא תקינה',
'invalid ticket': 'דו"ח שגיאה לא קיים',
'language file "%(filename)s" created/updated': 'קובץ השפה "%(filename)s" נוצר\עודכן',
'languages': 'שפות',
'loading...': 'טוען...',
'locals': 'locals',
'login': 'התחבר',
'Logout': 'התנתק',
'merge': 'מזג',
'models': 'מבני נתונים',
'modules': 'מודולים',
'new application "%s" created': 'האפליקציה "%s" נוצרה',
'new plugin installed': 'פלאגין חדש הותקן',
'new record inserted': 'הרשומה נוספה',
'next 100 rows': '100 הרשומות הבאות',
'no match': 'לא נמצאה התאמה',
'or import from csv file': 'או יבא מקובץ csv',
'or provide app url:': 'או ספק כתובת url של אפליקציה',
'Overwrite installed app': 'התקן על גבי אפלקציה מותקנת',
'Pack all': 'ארוז הכל',
'Pack compiled': 'ארוז מקומפל',
'pack plugin': 'ארוז תוסף',
'password changed': 'סיסמא שונתה',
'plugin "%(plugin)s" deleted': 'תוסף "%(plugin)s" נמחק',
'plugins': 'plugins',
'previous 100 rows': '100 הרשומות הקודמות',
'record': 'רשומה',
'record does not exist': 'הרשומה אינה קיימת',
'record id': 'מזהה רשומה',
'Remove compiled': 'הסר מקומפל',
'request': 'request',
'response': 'response',
'restore': 'שחזר',
'revert': 'חזור לגירסא קודמת',
'selected': 'נבחרו',
'session': 'session',
'session expired': 'תם הסשן',
'shell': 'שורת פקודה',
'Site': 'אתר',
'some files could not be removed': 'לא ניתן היה להסיר חלק מהקבצים',
'Start wizard': 'start wizard',
'state': 'מצב',
'static': 'קבצים סטאטיים',
'submit': 'שלח',
'table': 'טבלה',
'test': 'בדיקות',
'the application logic, each URL path is mapped in one exposed function in the controller': 'הלוגיקה של האפליקציה, כל url ממופה לפונקציה חשופה בבקר',
'the data representation, define database tables and sets': 'ייצוג המידע, בו מוגדרים טבלאות ומבנים',
'the presentations layer, views are also known as templates': 'שכבת התצוגה, המכונה גם template',
'these files are served without processing, your images go here': 'אלו הם קבצים הנשלחים מהשרת ללא עיבוד. הכנס את התמונות כאן',
'to  previous version.': 'אין גירסא קודמת',
'translation strings for the application': 'מחרוזות תרגום עבור האפליקציה',
'try': 'נסה',
'try something like': 'נסה משהו כמו',
'unable to create application "%s"': 'נכשל ביצירת האפליקציה "%s"',
'unable to delete file "%(filename)s"': 'נכשל במחיקת הקובץ "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'נכשל במחיקת התוסף "%(plugin)s"',
'unable to parse csv file': 'לא הצלחתי לנתח את הקלט של קובץ csv',
'unable to uninstall "%s"': 'לא ניתן להסיר את "%s"',
'unable to upgrade because "%s"': 'לא ניתן היה לשדרג כי "%s"',
'uncheck all': 'הסר סימון מהכל',
'Uninstall': 'הסר התקנה',
'update': 'עדכן',
'update all languages': 'עדכן את כלל קיבצי השפה',
'upgrade now': 'upgrade now',
'upgrade web2py now': 'שדרג את web2py עכשיו',
'upload': 'upload',
'upload application:': 'העלה אפליקציה:',
'upload file:': 'העלה קובץ:',
Modified applications/admin/languages/it-it.py from [f838859834] to [c3780eb0f5].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
'Use an url:': 'Use an url:',
'Version': 'Versione',
'View': 'Vista',
'Views': 'viste',
'Welcome %s': 'Benvenuto %s',
'Welcome to web2py': 'Benvenuto su web2py',
'YES': 'SI',
'about': 'informazioni',
'additional code for your application': 'righe di codice aggiuntive per la tua applicazione',
'admin disabled because no admin password': 'amministrazione disabilitata per mancanza di password amministrativa',
'admin disabled because not supported on google app engine': 'amministrazione non supportata da Google Apps Engine',
'admin disabled because unable to access password file': 'amministrazione disabilitata per impossibilità di leggere il file delle password',
'administrative interface': 'administrative interface',
'and rename it (required):': 'e rinominala (obbligatorio):',
'and rename it:': 'e rinominala:',
'appadmin': 'appadmin ',
'appadmin is disabled because insecure channel': 'amministrazione app (appadmin) disabilitata: comunicazione non sicura',
'application "%s" uninstalled': 'applicazione "%s" disinstallata',
'application compiled': 'applicazione compilata',
'application is compiled and cannot be designed': "l'applicazione è compilata e non si può modificare",
'arguments': 'arguments',
'back': 'indietro',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pulitura cache, errori and sessioni ',
'cannot create file': 'impossibile creare il file',
'cannot upload file "%(filename)s"': 'impossibile caricare il file "%(filename)s"',
'change admin password': 'change admin password',
'change password': 'cambia password',
'check all': 'controlla tutto',
'check for upgrades': 'check for upgrades',
'clean': 'pulisci',
'click here for online examples': 'clicca per vedere gli esempi',
'click here for the administrative interface': "clicca per l'interfaccia amministrativa",
'click to check for upgrades': 'clicca per controllare presenza di aggiornamenti',
'code': 'code',
'compile': 'compila',
'compiled application removed': "rimosso il codice compilato dell'applicazione",
'controllers': 'controllers',
'create': 'crea',
'create file with filename:': 'crea un file col nome:',
'create new application:': 'create new application:',
'created by': 'creato da',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'attualmente salvato o',
'customize me!': 'Personalizzami!',
'data uploaded': 'dati caricati',
'database': 'database',
'database %s select': 'database %s select',
'database administration': 'amministrazione database',
'db': 'db',
'defines tables': 'defininisce le tabelle',
'delete': 'Cancella',
'delete all checked': 'cancella tutti i selezionati',
'delete plugin': 'cancella plugin',
'deploy': 'deploy',
'design': 'progetta',
'direction: ltr': 'direction: ltr',
'done!': 'fatto!',
'edit': 'modifica',
'edit controller': 'modifica controller',
'edit profile': 'modifica profilo',
'edit views:': 'modifica viste (view):',
'errors': 'errori',
'export as csv file': 'esporta come file CSV',
'exposes': 'espone',
'extends': 'estende',
'failed to reload module because:': 'ricaricamento modulo fallito perché:',
'file "%(filename)s" created': 'creato il file "%(filename)s"',
'file "%(filename)s" deleted': 'cancellato il file "%(filename)s"',
'file "%(filename)s" uploaded': 'caricato il file "%(filename)s"',
'file "%s" of %s restored': 'ripristinato "%(filename)s"',
'file changed on disk': 'il file ha subito una modifica su disco',
'file does not exist': 'file inesistente',
'file saved on %(time)s': "file salvato nell'istante %(time)s",
'file saved on %s': 'file salvato: %s',
'help': 'aiuto',
'htmledit': 'modifica come html',
'includes': 'include',
'insert new': 'inserisci nuovo',
'insert new %s': 'inserisci nuovo %s',
'install': 'installa',
'internal error': 'errore interno',
'invalid password': 'password non valida',
'invalid request': 'richiesta non valida',
'invalid ticket': 'ticket non valido',
'language file "%(filename)s" created/updated': 'file linguaggio "%(filename)s" creato/aggiornato',
'languages': 'linguaggi',
'loading...': 'caricamento...',
'login': 'accesso',
'logout': 'uscita',
'merge': 'unisci',
'models': 'modelli',
'modules': 'moduli',
'new application "%s" created': 'creata la nuova applicazione "%s"',
'new plugin installed': 'installato nuovo plugin',
'new record inserted': 'nuovo record inserito',
'next 100 rows': 'prossime 100 righe',
'no match': 'nessuna corrispondenza',
'or import from csv file': 'oppure importa da file CSV',
'or provide app url:': "oppure fornisci url dell'applicazione:",
'overwrite installed app': 'sovrascrivi applicazione installata',
'pack all': 'crea pacchetto',
'pack compiled': 'crea pacchetto del codice compilato',
'pack plugin': 'crea pacchetto del plugin',
'password changed': 'password modificata',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" cancellato',
'previous 100 rows': '100 righe precedenti',
'record': 'record',
'record does not exist': 'il record non esiste',
'record id': 'ID del record',
'register': 'registrazione',
'remove compiled': 'rimozione codice compilato',
'restore': 'ripristino',
'revert': 'versione precedente',
'selected': 'selezionato',
'session expired': 'sessions scaduta',
'shell': 'shell',
'site': 'sito',
'some files could not be removed': 'non è stato possibile rimuovere alcuni files',
'start wizard': 'start wizard',
'state': 'stato',
'static': 'statico',
'submit': 'invia',
'table': 'tabella',
'test': 'test',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logica dell\'applicazione, ogni percorso "URL" corrisponde ad una funzione esposta da un controller',
'the data representation, define database tables and sets': 'rappresentazione dei dati, definizione di tabelle di database e di "set" ',
'the presentations layer, views are also known as templates': 'Presentazione dell\'applicazione, viste (views, chiamate anche "templates")',
'these files are served without processing, your images go here': 'questi files vengono serviti così come sono, le immagini vanno qui',
'to  previous version.': 'torna a versione precedente',
'translation strings for the application': "stringhe di traduzioni per l'applicazione",
'try': 'prova',
'try something like': 'prova qualcosa come',
'unable to create application "%s"': 'impossibile creare applicazione "%s"',
'unable to delete file "%(filename)s"': 'impossibile rimuovere file "%(plugin)s"',
'unable to delete file plugin "%(plugin)s"': 'impossibile rimuovere file di plugin "%(plugin)s"',
'unable to parse csv file': 'non riesco a decodificare questo file CSV',
'unable to uninstall "%s"': 'impossibile disinstallare "%s"',
'unable to upgrade because "%s"': 'impossibile aggiornare perché "%s"',
'uncheck all': 'smarca tutti',
'uninstall': 'disinstalla',
'update': 'aggiorna',
'update all languages': 'aggiorna tutti i linguaggi',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': 'carica applicazione:',
'upload file:': 'carica file:',
'upload plugin file:': 'carica file di plugin:',
'variables': 'variables',







|


















|


|
|




|


|
















|



|



|












|




|








|










|
|
|








|





|

|




















|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
'Use an url:': 'Use an url:',
'Version': 'Versione',
'View': 'Vista',
'Views': 'viste',
'Welcome %s': 'Benvenuto %s',
'Welcome to web2py': 'Benvenuto su web2py',
'YES': 'SI',
'About': 'informazioni',
'additional code for your application': 'righe di codice aggiuntive per la tua applicazione',
'admin disabled because no admin password': 'amministrazione disabilitata per mancanza di password amministrativa',
'admin disabled because not supported on google app engine': 'amministrazione non supportata da Google Apps Engine',
'admin disabled because unable to access password file': 'amministrazione disabilitata per impossibilità di leggere il file delle password',
'administrative interface': 'administrative interface',
'and rename it (required):': 'e rinominala (obbligatorio):',
'and rename it:': 'e rinominala:',
'appadmin': 'appadmin ',
'appadmin is disabled because insecure channel': 'amministrazione app (appadmin) disabilitata: comunicazione non sicura',
'application "%s" uninstalled': 'applicazione "%s" disinstallata',
'application compiled': 'applicazione compilata',
'application is compiled and cannot be designed': "l'applicazione è compilata e non si può modificare",
'arguments': 'arguments',
'back': 'indietro',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pulitura cache, errori and sessioni ',
'cannot create file': 'impossibile creare il file',
'cannot upload file "%(filename)s"': 'impossibile caricare il file "%(filename)s"',
'Change admin password': 'change admin password',
'change password': 'cambia password',
'check all': 'controlla tutto',
'Check for upgrades': 'check for upgrades',
'Clean': 'pulisci',
'click here for online examples': 'clicca per vedere gli esempi',
'click here for the administrative interface': "clicca per l'interfaccia amministrativa",
'click to check for upgrades': 'clicca per controllare presenza di aggiornamenti',
'code': 'code',
'Compile': 'compila',
'compiled application removed': "rimosso il codice compilato dell'applicazione",
'controllers': 'controllers',
'Create': 'crea',
'create file with filename:': 'crea un file col nome:',
'create new application:': 'create new application:',
'created by': 'creato da',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'attualmente salvato o',
'customize me!': 'Personalizzami!',
'data uploaded': 'dati caricati',
'database': 'database',
'database %s select': 'database %s select',
'database administration': 'amministrazione database',
'db': 'db',
'defines tables': 'defininisce le tabelle',
'delete': 'Cancella',
'delete all checked': 'cancella tutti i selezionati',
'delete plugin': 'cancella plugin',
'Deploy': 'deploy',
'design': 'progetta',
'direction: ltr': 'direction: ltr',
'done!': 'fatto!',
'Edit': 'modifica',
'edit controller': 'modifica controller',
'edit profile': 'modifica profilo',
'edit views:': 'modifica viste (view):',
'Errors': 'errori',
'export as csv file': 'esporta come file CSV',
'exposes': 'espone',
'extends': 'estende',
'failed to reload module because:': 'ricaricamento modulo fallito perché:',
'file "%(filename)s" created': 'creato il file "%(filename)s"',
'file "%(filename)s" deleted': 'cancellato il file "%(filename)s"',
'file "%(filename)s" uploaded': 'caricato il file "%(filename)s"',
'file "%s" of %s restored': 'ripristinato "%(filename)s"',
'file changed on disk': 'il file ha subito una modifica su disco',
'file does not exist': 'file inesistente',
'file saved on %(time)s': "file salvato nell'istante %(time)s",
'file saved on %s': 'file salvato: %s',
'Help': 'aiuto',
'htmledit': 'modifica come html',
'includes': 'include',
'insert new': 'inserisci nuovo',
'insert new %s': 'inserisci nuovo %s',
'Install': 'installa',
'internal error': 'errore interno',
'invalid password': 'password non valida',
'invalid request': 'richiesta non valida',
'invalid ticket': 'ticket non valido',
'language file "%(filename)s" created/updated': 'file linguaggio "%(filename)s" creato/aggiornato',
'languages': 'linguaggi',
'loading...': 'caricamento...',
'login': 'accesso',
'Logout': 'uscita',
'merge': 'unisci',
'models': 'modelli',
'modules': 'moduli',
'new application "%s" created': 'creata la nuova applicazione "%s"',
'new plugin installed': 'installato nuovo plugin',
'new record inserted': 'nuovo record inserito',
'next 100 rows': 'prossime 100 righe',
'no match': 'nessuna corrispondenza',
'or import from csv file': 'oppure importa da file CSV',
'or provide app url:': "oppure fornisci url dell'applicazione:",
'Overwrite installed app': 'sovrascrivi applicazione installata',
'Pack all': 'crea pacchetto',
'Pack compiled': 'crea pacchetto del codice compilato',
'pack plugin': 'crea pacchetto del plugin',
'password changed': 'password modificata',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" cancellato',
'previous 100 rows': '100 righe precedenti',
'record': 'record',
'record does not exist': 'il record non esiste',
'record id': 'ID del record',
'register': 'registrazione',
'Remove compiled': 'rimozione codice compilato',
'restore': 'ripristino',
'revert': 'versione precedente',
'selected': 'selezionato',
'session expired': 'sessions scaduta',
'shell': 'shell',
'Site': 'sito',
'some files could not be removed': 'non è stato possibile rimuovere alcuni files',
'Start wizard': 'start wizard',
'state': 'stato',
'static': 'statico',
'submit': 'invia',
'table': 'tabella',
'test': 'test',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logica dell\'applicazione, ogni percorso "URL" corrisponde ad una funzione esposta da un controller',
'the data representation, define database tables and sets': 'rappresentazione dei dati, definizione di tabelle di database e di "set" ',
'the presentations layer, views are also known as templates': 'Presentazione dell\'applicazione, viste (views, chiamate anche "templates")',
'these files are served without processing, your images go here': 'questi files vengono serviti così come sono, le immagini vanno qui',
'to  previous version.': 'torna a versione precedente',
'translation strings for the application': "stringhe di traduzioni per l'applicazione",
'try': 'prova',
'try something like': 'prova qualcosa come',
'unable to create application "%s"': 'impossibile creare applicazione "%s"',
'unable to delete file "%(filename)s"': 'impossibile rimuovere file "%(plugin)s"',
'unable to delete file plugin "%(plugin)s"': 'impossibile rimuovere file di plugin "%(plugin)s"',
'unable to parse csv file': 'non riesco a decodificare questo file CSV',
'unable to uninstall "%s"': 'impossibile disinstallare "%s"',
'unable to upgrade because "%s"': 'impossibile aggiornare perché "%s"',
'uncheck all': 'smarca tutti',
'Uninstall': 'disinstalla',
'update': 'aggiorna',
'update all languages': 'aggiorna tutti i linguaggi',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': 'carica applicazione:',
'upload file:': 'carica file:',
'upload plugin file:': 'carica file di plugin:',
'variables': 'variables',
Modified applications/admin/languages/it.py from [bef6439651] to [22dede2011].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
'Use an url:': 'Use an url:',
'Version': 'Versione',
'View': 'Vista',
'Views': 'viste',
'Welcome %s': 'Benvenuto %s',
'Welcome to web2py': 'Benvenuto su web2py',
'YES': 'SI',
'about': 'informazioni',
'additional code for your application': 'righe di codice aggiuntive per la tua applicazione',
'admin disabled because no admin password': 'amministrazione disabilitata per mancanza di password amministrativa',
'admin disabled because not supported on google app engine': 'amministrazione non supportata da Google Apps Engine',
'admin disabled because unable to access password file': 'amministrazione disabilitata per impossibilità di leggere il file delle password',
'administrative interface': 'administrative interface',
'and rename it (required):': 'e rinominala (obbligatorio):',
'and rename it:': 'e rinominala:',
'appadmin': 'appadmin ',
'appadmin is disabled because insecure channel': 'amministrazione app (appadmin) disabilitata: comunicazione non sicura',
'application "%s" uninstalled': 'applicazione "%s" disinstallata',
'application compiled': 'applicazione compilata',
'application is compiled and cannot be designed': "l'applicazione è compilata e non si può modificare",
'arguments': 'arguments',
'back': 'indietro',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pulitura cache, errori and sessioni ',
'cannot create file': 'impossibile creare il file',
'cannot upload file "%(filename)s"': 'impossibile caricare il file "%(filename)s"',
'change admin password': 'change admin password',
'change password': 'cambia password',
'check all': 'controlla tutto',
'check for upgrades': 'check for upgrades',
'clean': 'pulisci',
'click here for online examples': 'clicca per vedere gli esempi',
'click here for the administrative interface': "clicca per l'interfaccia amministrativa",
'click to check for upgrades': 'clicca per controllare presenza di aggiornamenti',
'code': 'code',
'compile': 'compila',
'compiled application removed': "rimosso il codice compilato dell'applicazione",
'controllers': 'controllers',
'create': 'crea',
'create file with filename:': 'crea un file col nome:',
'create new application:': 'create new application:',
'created by': 'creato da',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'attualmente salvato o',
'customize me!': 'Personalizzami!',
'data uploaded': 'dati caricati',
'database': 'database',
'database %s select': 'database %s select',
'database administration': 'amministrazione database',
'db': 'db',
'defines tables': 'defininisce le tabelle',
'delete': 'Cancella',
'delete all checked': 'cancella tutti i selezionati',
'delete plugin': 'cancella plugin',
'deploy': 'deploy',
'design': 'progetta',
'direction: ltr': 'direction: ltr',
'done!': 'fatto!',
'edit': 'modifica',
'edit controller': 'modifica controller',
'edit profile': 'modifica profilo',
'edit views:': 'modifica viste (view):',
'errors': 'errori',
'export as csv file': 'esporta come file CSV',
'exposes': 'espone',
'extends': 'estende',
'failed to reload module because:': 'ricaricamento modulo fallito perché:',
'file "%(filename)s" created': 'creato il file "%(filename)s"',
'file "%(filename)s" deleted': 'cancellato il file "%(filename)s"',
'file "%(filename)s" uploaded': 'caricato il file "%(filename)s"',
'file "%s" of %s restored': 'ripristinato "%(filename)s"',
'file changed on disk': 'il file ha subito una modifica su disco',
'file does not exist': 'file inesistente',
'file saved on %(time)s': "file salvato nell'istante %(time)s",
'file saved on %s': 'file salvato: %s',
'help': 'aiuto',
'htmledit': 'modifica come html',
'includes': 'include',
'insert new': 'inserisci nuovo',
'insert new %s': 'inserisci nuovo %s',
'install': 'installa',
'internal error': 'errore interno',
'invalid password': 'password non valida',
'invalid request': 'richiesta non valida',
'invalid ticket': 'ticket non valido',
'language file "%(filename)s" created/updated': 'file linguaggio "%(filename)s" creato/aggiornato',
'languages': 'linguaggi',
'loading...': 'caricamento...',
'login': 'accesso',
'logout': 'uscita',
'merge': 'unisci',
'models': 'modelli',
'modules': 'moduli',
'new application "%s" created': 'creata la nuova applicazione "%s"',
'new plugin installed': 'installato nuovo plugin',
'new record inserted': 'nuovo record inserito',
'next 100 rows': 'prossime 100 righe',
'no match': 'nessuna corrispondenza',
'or import from csv file': 'oppure importa da file CSV',
'or provide app url:': "oppure fornisci url dell'applicazione:",
'overwrite installed app': 'sovrascrivi applicazione installata',
'pack all': 'crea pacchetto',
'pack compiled': 'crea pacchetto del codice compilato',
'pack plugin': 'crea pacchetto del plugin',
'password changed': 'password modificata',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" cancellato',
'previous 100 rows': '100 righe precedenti',
'record': 'record',
'record does not exist': 'il record non esiste',
'record id': 'ID del record',
'register': 'registrazione',
'remove compiled': 'rimozione codice compilato',
'restore': 'ripristino',
'revert': 'versione precedente',
'selected': 'selezionato',
'session expired': 'sessions scaduta',
'shell': 'shell',
'site': 'sito',
'some files could not be removed': 'non è stato possibile rimuovere alcuni files',
'start wizard': 'start wizard',
'state': 'stato',
'static': 'statico',
'submit': 'invia',
'table': 'tabella',
'test': 'test',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logica dell\'applicazione, ogni percorso "URL" corrisponde ad una funzione esposta da un controller',
'the data representation, define database tables and sets': 'rappresentazione dei dati, definizione di tabelle di database e di "set" ',
'the presentations layer, views are also known as templates': 'Presentazione dell\'applicazione, viste (views, chiamate anche "templates")',
'these files are served without processing, your images go here': 'questi files vengono serviti così come sono, le immagini vanno qui',
'to  previous version.': 'torna a versione precedente',
'translation strings for the application': "stringhe di traduzioni per l'applicazione",
'try': 'prova',
'try something like': 'prova qualcosa come',
'unable to create application "%s"': 'impossibile creare applicazione "%s"',
'unable to delete file "%(filename)s"': 'impossibile rimuovere file "%(plugin)s"',
'unable to delete file plugin "%(plugin)s"': 'impossibile rimuovere file di plugin "%(plugin)s"',
'unable to parse csv file': 'non riesco a decodificare questo file CSV',
'unable to uninstall "%s"': 'impossibile disinstallare "%s"',
'unable to upgrade because "%s"': 'impossibile aggiornare perché "%s"',
'uncheck all': 'smarca tutti',
'uninstall': 'disinstalla',
'update': 'aggiorna',
'update all languages': 'aggiorna tutti i linguaggi',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': 'carica applicazione:',
'upload file:': 'carica file:',
'upload plugin file:': 'carica file di plugin:',
'variables': 'variables',







|


















|


|
|




|


|
















|



|



|












|




|








|










|
|
|








|





|

|




















|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
'Use an url:': 'Use an url:',
'Version': 'Versione',
'View': 'Vista',
'Views': 'viste',
'Welcome %s': 'Benvenuto %s',
'Welcome to web2py': 'Benvenuto su web2py',
'YES': 'SI',
'About': 'informazioni',
'additional code for your application': 'righe di codice aggiuntive per la tua applicazione',
'admin disabled because no admin password': 'amministrazione disabilitata per mancanza di password amministrativa',
'admin disabled because not supported on google app engine': 'amministrazione non supportata da Google Apps Engine',
'admin disabled because unable to access password file': 'amministrazione disabilitata per impossibilità di leggere il file delle password',
'administrative interface': 'administrative interface',
'and rename it (required):': 'e rinominala (obbligatorio):',
'and rename it:': 'e rinominala:',
'appadmin': 'appadmin ',
'appadmin is disabled because insecure channel': 'amministrazione app (appadmin) disabilitata: comunicazione non sicura',
'application "%s" uninstalled': 'applicazione "%s" disinstallata',
'application compiled': 'applicazione compilata',
'application is compiled and cannot be designed': "l'applicazione è compilata e non si può modificare",
'arguments': 'arguments',
'back': 'indietro',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pulitura cache, errori and sessioni ',
'cannot create file': 'impossibile creare il file',
'cannot upload file "%(filename)s"': 'impossibile caricare il file "%(filename)s"',
'Change admin password': 'change admin password',
'change password': 'cambia password',
'check all': 'controlla tutto',
'Check for upgrades': 'check for upgrades',
'Clean': 'pulisci',
'click here for online examples': 'clicca per vedere gli esempi',
'click here for the administrative interface': "clicca per l'interfaccia amministrativa",
'click to check for upgrades': 'clicca per controllare presenza di aggiornamenti',
'code': 'code',
'Compile': 'compila',
'compiled application removed': "rimosso il codice compilato dell'applicazione",
'controllers': 'controllers',
'Create': 'crea',
'create file with filename:': 'crea un file col nome:',
'create new application:': 'create new application:',
'created by': 'creato da',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'attualmente salvato o',
'customize me!': 'Personalizzami!',
'data uploaded': 'dati caricati',
'database': 'database',
'database %s select': 'database %s select',
'database administration': 'amministrazione database',
'db': 'db',
'defines tables': 'defininisce le tabelle',
'delete': 'Cancella',
'delete all checked': 'cancella tutti i selezionati',
'delete plugin': 'cancella plugin',
'Deploy': 'deploy',
'design': 'progetta',
'direction: ltr': 'direction: ltr',
'done!': 'fatto!',
'Edit': 'modifica',
'edit controller': 'modifica controller',
'edit profile': 'modifica profilo',
'edit views:': 'modifica viste (view):',
'Errors': 'errori',
'export as csv file': 'esporta come file CSV',
'exposes': 'espone',
'extends': 'estende',
'failed to reload module because:': 'ricaricamento modulo fallito perché:',
'file "%(filename)s" created': 'creato il file "%(filename)s"',
'file "%(filename)s" deleted': 'cancellato il file "%(filename)s"',
'file "%(filename)s" uploaded': 'caricato il file "%(filename)s"',
'file "%s" of %s restored': 'ripristinato "%(filename)s"',
'file changed on disk': 'il file ha subito una modifica su disco',
'file does not exist': 'file inesistente',
'file saved on %(time)s': "file salvato nell'istante %(time)s",
'file saved on %s': 'file salvato: %s',
'Help': 'aiuto',
'htmledit': 'modifica come html',
'includes': 'include',
'insert new': 'inserisci nuovo',
'insert new %s': 'inserisci nuovo %s',
'Install': 'installa',
'internal error': 'errore interno',
'invalid password': 'password non valida',
'invalid request': 'richiesta non valida',
'invalid ticket': 'ticket non valido',
'language file "%(filename)s" created/updated': 'file linguaggio "%(filename)s" creato/aggiornato',
'languages': 'linguaggi',
'loading...': 'caricamento...',
'login': 'accesso',
'Logout': 'uscita',
'merge': 'unisci',
'models': 'modelli',
'modules': 'moduli',
'new application "%s" created': 'creata la nuova applicazione "%s"',
'new plugin installed': 'installato nuovo plugin',
'new record inserted': 'nuovo record inserito',
'next 100 rows': 'prossime 100 righe',
'no match': 'nessuna corrispondenza',
'or import from csv file': 'oppure importa da file CSV',
'or provide app url:': "oppure fornisci url dell'applicazione:",
'Overwrite installed app': 'sovrascrivi applicazione installata',
'Pack all': 'crea pacchetto',
'Pack compiled': 'crea pacchetto del codice compilato',
'pack plugin': 'crea pacchetto del plugin',
'password changed': 'password modificata',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" cancellato',
'previous 100 rows': '100 righe precedenti',
'record': 'record',
'record does not exist': 'il record non esiste',
'record id': 'ID del record',
'register': 'registrazione',
'Remove compiled': 'rimozione codice compilato',
'restore': 'ripristino',
'revert': 'versione precedente',
'selected': 'selezionato',
'session expired': 'sessions scaduta',
'shell': 'shell',
'Site': 'sito',
'some files could not be removed': 'non è stato possibile rimuovere alcuni files',
'Start wizard': 'start wizard',
'state': 'stato',
'static': 'statico',
'submit': 'invia',
'table': 'tabella',
'test': 'test',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logica dell\'applicazione, ogni percorso "URL" corrisponde ad una funzione esposta da un controller',
'the data representation, define database tables and sets': 'rappresentazione dei dati, definizione di tabelle di database e di "set" ',
'the presentations layer, views are also known as templates': 'Presentazione dell\'applicazione, viste (views, chiamate anche "templates")',
'these files are served without processing, your images go here': 'questi files vengono serviti così come sono, le immagini vanno qui',
'to  previous version.': 'torna a versione precedente',
'translation strings for the application': "stringhe di traduzioni per l'applicazione",
'try': 'prova',
'try something like': 'prova qualcosa come',
'unable to create application "%s"': 'impossibile creare applicazione "%s"',
'unable to delete file "%(filename)s"': 'impossibile rimuovere file "%(plugin)s"',
'unable to delete file plugin "%(plugin)s"': 'impossibile rimuovere file di plugin "%(plugin)s"',
'unable to parse csv file': 'non riesco a decodificare questo file CSV',
'unable to uninstall "%s"': 'impossibile disinstallare "%s"',
'unable to upgrade because "%s"': 'impossibile aggiornare perché "%s"',
'uncheck all': 'smarca tutti',
'Uninstall': 'disinstalla',
'update': 'aggiorna',
'update all languages': 'aggiorna tutti i linguaggi',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': 'carica applicazione:',
'upload file:': 'carica file:',
'upload plugin file:': 'carica file di plugin:',
'variables': 'variables',
Modified applications/admin/languages/pl-pl.py from [4ff0dcf09e] to [976920b9f2].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
'Upload existing application': 'Wyślij istniejącą aplikację',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Użyj (...)&(...) jako AND, (...)|(...) jako OR oraz ~(...)  jako NOT do tworzenia bardziej skomplikowanych zapytań.',
'Use an url:': 'Use an url:',
'Version': 'Version',
'Views': 'Widoki',
'Welcome to web2py': 'Witaj w web2py',
'YES': 'TAK',
'about': 'informacje',
'additional code for your application': 'dodatkowy kod Twojej aplikacji',
'admin disabled because no admin password': 'panel administracyjny wyłączony z powodu braku hasła administracyjnego',
'admin disabled because not supported on google app engine': 'admin disabled because not supported on google apps engine',
'admin disabled because unable to access password file': 'panel administracyjny wyłączony z powodu braku dostępu do pliku z hasłem',
'administrative interface': 'administrative interface',
'and rename it (required):': 'i nadaj jej nową nazwę (wymagane):',
'and rename it:': 'i nadaj mu nową nazwę:',
'appadmin': 'administracja aplikacji',
'appadmin is disabled because insecure channel': 'appadmin is disabled because insecure channel',
'application "%s" uninstalled': 'aplikacja "%s" została odinstalowana',
'application compiled': 'aplikacja została skompilowana',
'application is compiled and cannot be designed': 'aplikacja jest skompilowana i nie może być projektowana',
'arguments': 'arguments',
'back': 'back',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pamięć podręczna, bilety błędów oraz pliki sesji zostały wyczyszczone',
'cannot create file': 'nie można utworzyć pliku',
'cannot upload file "%(filename)s"': 'nie można wysłać pliku "%(filename)s"',
'change admin password': 'change admin password',
'check all': 'zaznacz wszystko',
'check for upgrades': 'check for upgrades',
'clean': 'oczyść',
'click here for online examples': 'kliknij aby przejść do interaktywnych przykładów',
'click here for the administrative interface': 'kliknij aby przejść do panelu administracyjnego',
'click to check for upgrades': 'kliknij aby sprawdzić aktualizacje',
'code': 'code',
'compile': 'skompiluj',
'compiled application removed': 'skompilowana aplikacja została usunięta',
'controllers': 'kontrolery',
'create': 'create',
'create file with filename:': 'utwórz plik o nazwie:',
'create new application:': 'utwórz nową aplikację:',
'created by': 'created by',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'aktualnie zapisany lub',
'data uploaded': 'dane wysłane',
'database': 'baza danych',
'database %s select': 'wybór z bazy danych %s',
'database administration': 'administracja bazy danych',
'db': 'baza danych',
'defines tables': 'zdefiniuj tabele',
'delete': 'usuń',
'delete all checked': 'usuń wszystkie zaznaczone',
'delete plugin': 'delete plugin',
'deploy': 'deploy',
'design': 'projektuj',
'direction: ltr': 'direction: ltr',
'done!': 'zrobione!',
'edit': 'edytuj',
'edit controller': 'edytuj kontroler',
'edit views:': 'edit views:',
'errors': 'błędy',
'export as csv file': 'eksportuj jako plik csv',
'exposes': 'eksponuje',
'extends': 'rozszerza',
'failed to reload module': 'nie udało się przeładować modułu',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'plik "%(filename)s" został utworzony',
'file "%(filename)s" deleted': 'plik "%(filename)s" został usunięty',
'file "%(filename)s" uploaded': 'plik "%(filename)s" został wysłany',
'file "%(filename)s" was not deleted': 'plik "%(filename)s" nie został usunięty',
'file "%s" of %s restored': 'plik "%s" z %s został odtworzony',
'file changed on disk': 'plik na dysku został zmieniony',
'file does not exist': 'plik nie istnieje',
'file saved on %(time)s': 'plik zapisany o %(time)s',
'file saved on %s': 'plik zapisany o %s',
'help': 'pomoc',
'htmledit': 'edytuj HTML',
'includes': 'zawiera',
'insert new': 'wstaw nowy rekord tabeli',
'insert new %s': 'wstaw nowy rekord do tabeli %s',
'install': 'install',
'internal error': 'wewnętrzny błąd',
'invalid password': 'błędne hasło',
'invalid request': 'błędne zapytanie',
'invalid ticket': 'błędny bilet',
'language file "%(filename)s" created/updated': 'plik tłumaczeń "%(filename)s" został utworzony/uaktualniony',
'languages': 'pliki tłumaczeń',
'languages updated': 'pliki tłumaczeń zostały uaktualnione',
'loading...': 'wczytywanie...',
'login': 'zaloguj',
'logout': 'wyloguj',
'merge': 'merge',
'models': 'modele',
'modules': 'moduły',
'new application "%s" created': 'nowa aplikacja "%s" została utworzona',
'new plugin installed': 'new plugin installed',
'new record inserted': 'nowy rekord został wstawiony',
'next 100 rows': 'następne 100 wierszy',
'no match': 'no match',
'or import from csv file': 'lub zaimportuj z pliku csv',
'or provide app url:': 'or provide app url:',
'or provide application url:': 'lub podaj url aplikacji:',
'overwrite installed app': 'overwrite installed app',
'pack all': 'spakuj wszystko',
'pack compiled': 'spakuj skompilowane',
'pack plugin': 'pack plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" deleted',
'previous 100 rows': 'poprzednie 100 wierszy',
'record': 'record',
'record does not exist': 'rekord nie istnieje',
'record id': 'id rekordu',
'remove compiled': 'usuń skompilowane',
'restore': 'odtwórz',
'revert': 'przywróć',
'save': 'zapisz',
'selected': 'zaznaczone',
'session expired': 'sesja wygasła',
'shell': 'powłoka',
'site': 'strona główna',
'some files could not be removed': 'niektóre pliki nie mogły zostać usunięte',
'start wizard': 'start wizard',
'state': 'stan',
'static': 'pliki statyczne',
'submit': 'submit',
'table': 'tabela',
'test': 'testuj',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logika aplikacji, każda ścieżka URL jest mapowana na jedną z funkcji eksponowanych w kontrolerze',
'the data representation, define database tables and sets': 'reprezentacja danych, definicje zbiorów i tabel bazy danych',
'the presentations layer, views are also known as templates': 'warstwa prezentacji, widoki zwane są również szablonami',
'these files are served without processing, your images go here': 'pliki obsługiwane bez interpretacji, to jest miejsce na Twoje obrazy',
'to  previous version.': 'do  poprzedniej wersji.',
'translation strings for the application': 'ciągi tłumaczeń dla aplikacji',
'try': 'spróbój',
'try something like': 'spróbój czegos takiego jak',
'unable to create application "%s"': 'nie można utworzyć aplikacji "%s"',
'unable to delete file "%(filename)s"': 'nie można usunąć pliku "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'unable to delete file plugin "%(plugin)s"',
'unable to parse csv file': 'nie można sparsować pliku csv',
'unable to uninstall "%s"': 'nie można odinstalować "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'odznacz wszystko',
'uninstall': 'odinstaluj',
'update': 'uaktualnij',
'update all languages': 'uaktualnij wszystkie pliki tłumaczeń',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': 'wyślij plik aplikacji:',
'upload file:': 'wyślij plik:',
'upload plugin file:': 'upload plugin file:',
'variables': 'variables',







|


















|

|
|




|


|















|



|


|














|




|









|











|
|
|







|






|

|




















|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
'Upload existing application': 'Wyślij istniejącą aplikację',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Użyj (...)&(...) jako AND, (...)|(...) jako OR oraz ~(...)  jako NOT do tworzenia bardziej skomplikowanych zapytań.',
'Use an url:': 'Use an url:',
'Version': 'Version',
'Views': 'Widoki',
'Welcome to web2py': 'Witaj w web2py',
'YES': 'TAK',
'About': 'informacje',
'additional code for your application': 'dodatkowy kod Twojej aplikacji',
'admin disabled because no admin password': 'panel administracyjny wyłączony z powodu braku hasła administracyjnego',
'admin disabled because not supported on google app engine': 'admin disabled because not supported on google apps engine',
'admin disabled because unable to access password file': 'panel administracyjny wyłączony z powodu braku dostępu do pliku z hasłem',
'administrative interface': 'administrative interface',
'and rename it (required):': 'i nadaj jej nową nazwę (wymagane):',
'and rename it:': 'i nadaj mu nową nazwę:',
'appadmin': 'administracja aplikacji',
'appadmin is disabled because insecure channel': 'appadmin is disabled because insecure channel',
'application "%s" uninstalled': 'aplikacja "%s" została odinstalowana',
'application compiled': 'aplikacja została skompilowana',
'application is compiled and cannot be designed': 'aplikacja jest skompilowana i nie może być projektowana',
'arguments': 'arguments',
'back': 'back',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pamięć podręczna, bilety błędów oraz pliki sesji zostały wyczyszczone',
'cannot create file': 'nie można utworzyć pliku',
'cannot upload file "%(filename)s"': 'nie można wysłać pliku "%(filename)s"',
'Change admin password': 'change admin password',
'check all': 'zaznacz wszystko',
'Check for upgrades': 'check for upgrades',
'Clean': 'oczyść',
'click here for online examples': 'kliknij aby przejść do interaktywnych przykładów',
'click here for the administrative interface': 'kliknij aby przejść do panelu administracyjnego',
'click to check for upgrades': 'kliknij aby sprawdzić aktualizacje',
'code': 'code',
'Compile': 'skompiluj',
'compiled application removed': 'skompilowana aplikacja została usunięta',
'controllers': 'kontrolery',
'Create': 'create',
'create file with filename:': 'utwórz plik o nazwie:',
'create new application:': 'utwórz nową aplikację:',
'created by': 'created by',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'aktualnie zapisany lub',
'data uploaded': 'dane wysłane',
'database': 'baza danych',
'database %s select': 'wybór z bazy danych %s',
'database administration': 'administracja bazy danych',
'db': 'baza danych',
'defines tables': 'zdefiniuj tabele',
'delete': 'usuń',
'delete all checked': 'usuń wszystkie zaznaczone',
'delete plugin': 'delete plugin',
'Deploy': 'deploy',
'design': 'projektuj',
'direction: ltr': 'direction: ltr',
'done!': 'zrobione!',
'Edit': 'edytuj',
'edit controller': 'edytuj kontroler',
'edit views:': 'edit views:',
'Errors': 'błędy',
'export as csv file': 'eksportuj jako plik csv',
'exposes': 'eksponuje',
'extends': 'rozszerza',
'failed to reload module': 'nie udało się przeładować modułu',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'plik "%(filename)s" został utworzony',
'file "%(filename)s" deleted': 'plik "%(filename)s" został usunięty',
'file "%(filename)s" uploaded': 'plik "%(filename)s" został wysłany',
'file "%(filename)s" was not deleted': 'plik "%(filename)s" nie został usunięty',
'file "%s" of %s restored': 'plik "%s" z %s został odtworzony',
'file changed on disk': 'plik na dysku został zmieniony',
'file does not exist': 'plik nie istnieje',
'file saved on %(time)s': 'plik zapisany o %(time)s',
'file saved on %s': 'plik zapisany o %s',
'Help': 'pomoc',
'htmledit': 'edytuj HTML',
'includes': 'zawiera',
'insert new': 'wstaw nowy rekord tabeli',
'insert new %s': 'wstaw nowy rekord do tabeli %s',
'Install': 'install',
'internal error': 'wewnętrzny błąd',
'invalid password': 'błędne hasło',
'invalid request': 'błędne zapytanie',
'invalid ticket': 'błędny bilet',
'language file "%(filename)s" created/updated': 'plik tłumaczeń "%(filename)s" został utworzony/uaktualniony',
'languages': 'pliki tłumaczeń',
'languages updated': 'pliki tłumaczeń zostały uaktualnione',
'loading...': 'wczytywanie...',
'login': 'zaloguj',
'Logout': 'wyloguj',
'merge': 'merge',
'models': 'modele',
'modules': 'moduły',
'new application "%s" created': 'nowa aplikacja "%s" została utworzona',
'new plugin installed': 'new plugin installed',
'new record inserted': 'nowy rekord został wstawiony',
'next 100 rows': 'następne 100 wierszy',
'no match': 'no match',
'or import from csv file': 'lub zaimportuj z pliku csv',
'or provide app url:': 'or provide app url:',
'or provide application url:': 'lub podaj url aplikacji:',
'Overwrite installed app': 'overwrite installed app',
'Pack all': 'spakuj wszystko',
'Pack compiled': 'spakuj skompilowane',
'pack plugin': 'pack plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" deleted',
'previous 100 rows': 'poprzednie 100 wierszy',
'record': 'record',
'record does not exist': 'rekord nie istnieje',
'record id': 'id rekordu',
'Remove compiled': 'usuń skompilowane',
'restore': 'odtwórz',
'revert': 'przywróć',
'save': 'zapisz',
'selected': 'zaznaczone',
'session expired': 'sesja wygasła',
'shell': 'powłoka',
'Site': 'strona główna',
'some files could not be removed': 'niektóre pliki nie mogły zostać usunięte',
'Start wizard': 'start wizard',
'state': 'stan',
'static': 'pliki statyczne',
'submit': 'submit',
'table': 'tabela',
'test': 'testuj',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logika aplikacji, każda ścieżka URL jest mapowana na jedną z funkcji eksponowanych w kontrolerze',
'the data representation, define database tables and sets': 'reprezentacja danych, definicje zbiorów i tabel bazy danych',
'the presentations layer, views are also known as templates': 'warstwa prezentacji, widoki zwane są również szablonami',
'these files are served without processing, your images go here': 'pliki obsługiwane bez interpretacji, to jest miejsce na Twoje obrazy',
'to  previous version.': 'do  poprzedniej wersji.',
'translation strings for the application': 'ciągi tłumaczeń dla aplikacji',
'try': 'spróbój',
'try something like': 'spróbój czegos takiego jak',
'unable to create application "%s"': 'nie można utworzyć aplikacji "%s"',
'unable to delete file "%(filename)s"': 'nie można usunąć pliku "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'unable to delete file plugin "%(plugin)s"',
'unable to parse csv file': 'nie można sparsować pliku csv',
'unable to uninstall "%s"': 'nie można odinstalować "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'odznacz wszystko',
'Uninstall': 'odinstaluj',
'update': 'uaktualnij',
'update all languages': 'uaktualnij wszystkie pliki tłumaczeń',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': 'wyślij plik aplikacji:',
'upload file:': 'wyślij plik:',
'upload plugin file:': 'upload plugin file:',
'variables': 'variables',
Modified applications/admin/languages/pl.py from [83ac10247b] to [e76386ce5d].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
'Upload existing application': 'Wyślij istniejącą aplikację',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Użyj (...)&(...) jako AND, (...)|(...) jako OR oraz ~(...)  jako NOT do tworzenia bardziej skomplikowanych zapytań.',
'Use an url:': 'Use an url:',
'Version': 'Wersja',
'Views': 'Widoki',
'Welcome to web2py': 'Witaj w web2py',
'YES': 'TAK',
'about': 'informacje',
'additional code for your application': 'dodatkowy kod Twojej aplikacji',
'admin disabled because no admin password': 'panel administracyjny wyłączony z powodu braku hasła administracyjnego',
'admin disabled because not supported on google app engine': 'panel administracyjny wyłączony z powodu braku wsparcia na google apps engine',
'admin disabled because unable to access password file': 'panel administracyjny wyłączony z powodu braku dostępu do pliku z hasłem',
'administrative interface': 'administrative interface',
'and rename it (required):': 'i nadaj jej nową nazwę (wymagane):',
'and rename it:': 'i nadaj mu nową nazwę:',
'appadmin': 'administracja aplikacji',
'appadmin is disabled because insecure channel': 'administracja aplikacji wyłączona z powodu braku bezpiecznego połączenia',
'application "%s" uninstalled': 'aplikacja "%s" została odinstalowana',
'application compiled': 'aplikacja została skompilowana',
'application is compiled and cannot be designed': 'aplikacja jest skompilowana i nie może być projektowana',
'arguments': 'arguments',
'back': 'wstecz',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pamięć podręczna, bilety błędów oraz pliki sesji zostały wyczyszczone',
'cannot create file': 'nie można utworzyć pliku',
'cannot upload file "%(filename)s"': 'nie można wysłać pliku "%(filename)s"',
'change admin password': 'change admin password',
'check all': 'zaznacz wszystko',
'check for upgrades': 'check for upgrades',
'clean': 'oczyść',
'click here for online examples': 'kliknij aby przejść do interaktywnych przykładów',
'click here for the administrative interface': 'kliknij aby przejść do panelu administracyjnego',
'click to check for upgrades': 'kliknij aby sprawdzić aktualizacje',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'compile': 'skompiluj',
'compiled application removed': 'skompilowana aplikacja została usunięta',
'controllers': 'kontrolery',
'create': 'create',
'create file with filename:': 'utwórz plik o nazwie:',
'create new application:': 'utwórz nową aplikację:',
'created by': 'utworzone przez',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'aktualnie zapisany lub',
'data uploaded': 'dane wysłane',
'database': 'baza danych',
'database %s select': 'wybór z bazy danych %s',
'database administration': 'administracja bazy danych',
'db': 'baza danych',
'defines tables': 'zdefiniuj tabele',
'delete': 'usuń',
'delete all checked': 'usuń wszystkie zaznaczone',
'delete plugin': 'usuń wtyczkę',
'deploy': 'deploy',
'design': 'projektuj',
'direction: ltr': 'direction: ltr',
'done!': 'zrobione!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'edit': 'edytuj',
'edit controller': 'edytuj kontroler',
'edit views:': 'edit views:',
'errors': 'błędy',
'export as csv file': 'eksportuj jako plik csv',
'exposes': 'eksponuje',
'extends': 'rozszerza',
'failed to reload module': 'nie udało się przeładować modułu',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'plik "%(filename)s" został utworzony',
'file "%(filename)s" deleted': 'plik "%(filename)s" został usunięty',
'file "%(filename)s" uploaded': 'plik "%(filename)s" został wysłany',
'file "%(filename)s" was not deleted': 'plik "%(filename)s" nie został usunięty',
'file "%s" of %s restored': 'plik "%s" z %s został odtworzony',
'file changed on disk': 'plik na dysku został zmieniony',
'file does not exist': 'plik nie istnieje',
'file saved on %(time)s': 'plik zapisany o %(time)s',
'file saved on %s': 'plik zapisany o %s',
'files': 'files',
'filter': 'filter',
'help': 'pomoc',
'htmledit': 'edytuj HTML',
'includes': 'zawiera',
'insert new': 'wstaw nowy rekord tabeli',
'insert new %s': 'wstaw nowy rekord do tabeli %s',
'install': 'install',
'internal error': 'wewnętrzny błąd',
'invalid password': 'błędne hasło',
'invalid request': 'błędne zapytanie',
'invalid ticket': 'błędny bilet',
'language file "%(filename)s" created/updated': 'plik tłumaczeń "%(filename)s" został utworzony/uaktualniony',
'languages': 'pliki tłumaczeń',
'languages updated': 'pliki tłumaczeń zostały uaktualnione',
'loading...': 'wczytywanie...',
'login': 'zaloguj',
'logout': 'wyloguj',
'merge': 'zespól',
'models': 'modele',
'modules': 'moduły',
'new application "%s" created': 'nowa aplikacja "%s" została utworzona',
'new plugin installed': 'nowa wtyczka została zainstalowana',
'new record inserted': 'nowy rekord został wstawiony',
'next 100 rows': 'następne 100 wierszy',
'no match': 'no match',
'or import from csv file': 'lub zaimportuj z pliku csv',
'or provide app url:': 'or provide app url:',
'or provide application url:': 'lub podaj url aplikacji:',
'overwrite installed app': 'overwrite installed app',
'pack all': 'spakuj wszystko',
'pack compiled': 'spakuj skompilowane',
'pack plugin': 'spakuj wtyczkę',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'wtyczka "%(plugin)s" została usunięta',
'plugins': 'plugins',
'previous 100 rows': 'poprzednie 100 wierszy',
'record': 'rekord',
'record does not exist': 'rekord nie istnieje',
'record id': 'ID rekordu',
'remove compiled': 'usuń skompilowane',
'restore': 'odtwórz',
'revert': 'przywróć',
'save': 'zapisz',
'selected': 'zaznaczone',
'session expired': 'sesja wygasła',
'shell': 'powłoka',
'site': 'strona główna',
'some files could not be removed': 'niektóre pliki nie mogły zostać usunięte',
'start wizard': 'start wizard',
'state': 'stan',
'static': 'pliki statyczne',
'submit': 'wyślij',
'table': 'tabela',
'test': 'testuj',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logika aplikacji, każda ścieżka URL jest mapowana na jedną z funkcji eksponowanych w kontrolerze',
'the data representation, define database tables and sets': 'reprezentacja danych, definicje zbiorów i tabel bazy danych',
'the presentations layer, views are also known as templates': 'warstwa prezentacji, widoki zwane są również szablonami',
'these files are served without processing, your images go here': 'pliki obsługiwane bez interpretacji, to jest miejsce na Twoje obrazy',
'to  previous version.': 'do  poprzedniej wersji.',
'translation strings for the application': 'ciągi tłumaczeń dla aplikacji',
'try': 'spróbój',
'try something like': 'spróbój czegos takiego jak',
'unable to create application "%s"': 'nie można utworzyć aplikacji "%s"',
'unable to delete file "%(filename)s"': 'nie można usunąć pliku "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'nie można usunąc pliku wtyczki "%(plugin)s"',
'unable to parse csv file': 'nie można sparsować pliku csv',
'unable to uninstall "%s"': 'nie można odinstalować "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'odznacz wszystko',
'uninstall': 'odinstaluj',
'update': 'uaktualnij',
'update all languages': 'uaktualnij wszystkie pliki tłumaczeń',
'upgrade web2py now': 'upgrade web2py now',
'upload': 'upload',
'upload application:': 'wyślij plik aplikacji:',
'upload file:': 'wyślij plik:',
'upload plugin file:': 'wyślij plik wtyczki:',







|


















|

|
|





|


|















|





|


|
















|




|









|











|
|
|








|






|

|




















|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
'Upload existing application': 'Wyślij istniejącą aplikację',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Użyj (...)&(...) jako AND, (...)|(...) jako OR oraz ~(...)  jako NOT do tworzenia bardziej skomplikowanych zapytań.',
'Use an url:': 'Use an url:',
'Version': 'Wersja',
'Views': 'Widoki',
'Welcome to web2py': 'Witaj w web2py',
'YES': 'TAK',
'About': 'informacje',
'additional code for your application': 'dodatkowy kod Twojej aplikacji',
'admin disabled because no admin password': 'panel administracyjny wyłączony z powodu braku hasła administracyjnego',
'admin disabled because not supported on google app engine': 'panel administracyjny wyłączony z powodu braku wsparcia na google apps engine',
'admin disabled because unable to access password file': 'panel administracyjny wyłączony z powodu braku dostępu do pliku z hasłem',
'administrative interface': 'administrative interface',
'and rename it (required):': 'i nadaj jej nową nazwę (wymagane):',
'and rename it:': 'i nadaj mu nową nazwę:',
'appadmin': 'administracja aplikacji',
'appadmin is disabled because insecure channel': 'administracja aplikacji wyłączona z powodu braku bezpiecznego połączenia',
'application "%s" uninstalled': 'aplikacja "%s" została odinstalowana',
'application compiled': 'aplikacja została skompilowana',
'application is compiled and cannot be designed': 'aplikacja jest skompilowana i nie może być projektowana',
'arguments': 'arguments',
'back': 'wstecz',
'cache': 'cache',
'cache, errors and sessions cleaned': 'pamięć podręczna, bilety błędów oraz pliki sesji zostały wyczyszczone',
'cannot create file': 'nie można utworzyć pliku',
'cannot upload file "%(filename)s"': 'nie można wysłać pliku "%(filename)s"',
'Change admin password': 'change admin password',
'check all': 'zaznacz wszystko',
'Check for upgrades': 'check for upgrades',
'Clean': 'oczyść',
'click here for online examples': 'kliknij aby przejść do interaktywnych przykładów',
'click here for the administrative interface': 'kliknij aby przejść do panelu administracyjnego',
'click to check for upgrades': 'kliknij aby sprawdzić aktualizacje',
'code': 'code',
'collapse/expand all': 'collapse/expand all',
'Compile': 'skompiluj',
'compiled application removed': 'skompilowana aplikacja została usunięta',
'controllers': 'kontrolery',
'Create': 'create',
'create file with filename:': 'utwórz plik o nazwie:',
'create new application:': 'utwórz nową aplikację:',
'created by': 'utworzone przez',
'crontab': 'crontab',
'currently running': 'currently running',
'currently saved or': 'aktualnie zapisany lub',
'data uploaded': 'dane wysłane',
'database': 'baza danych',
'database %s select': 'wybór z bazy danych %s',
'database administration': 'administracja bazy danych',
'db': 'baza danych',
'defines tables': 'zdefiniuj tabele',
'delete': 'usuń',
'delete all checked': 'usuń wszystkie zaznaczone',
'delete plugin': 'usuń wtyczkę',
'Deploy': 'deploy',
'design': 'projektuj',
'direction: ltr': 'direction: ltr',
'done!': 'zrobione!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'Edit': 'edytuj',
'edit controller': 'edytuj kontroler',
'edit views:': 'edit views:',
'Errors': 'błędy',
'export as csv file': 'eksportuj jako plik csv',
'exposes': 'eksponuje',
'extends': 'rozszerza',
'failed to reload module': 'nie udało się przeładować modułu',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': 'plik "%(filename)s" został utworzony',
'file "%(filename)s" deleted': 'plik "%(filename)s" został usunięty',
'file "%(filename)s" uploaded': 'plik "%(filename)s" został wysłany',
'file "%(filename)s" was not deleted': 'plik "%(filename)s" nie został usunięty',
'file "%s" of %s restored': 'plik "%s" z %s został odtworzony',
'file changed on disk': 'plik na dysku został zmieniony',
'file does not exist': 'plik nie istnieje',
'file saved on %(time)s': 'plik zapisany o %(time)s',
'file saved on %s': 'plik zapisany o %s',
'files': 'files',
'filter': 'filter',
'Help': 'pomoc',
'htmledit': 'edytuj HTML',
'includes': 'zawiera',
'insert new': 'wstaw nowy rekord tabeli',
'insert new %s': 'wstaw nowy rekord do tabeli %s',
'Install': 'install',
'internal error': 'wewnętrzny błąd',
'invalid password': 'błędne hasło',
'invalid request': 'błędne zapytanie',
'invalid ticket': 'błędny bilet',
'language file "%(filename)s" created/updated': 'plik tłumaczeń "%(filename)s" został utworzony/uaktualniony',
'languages': 'pliki tłumaczeń',
'languages updated': 'pliki tłumaczeń zostały uaktualnione',
'loading...': 'wczytywanie...',
'login': 'zaloguj',
'Logout': 'wyloguj',
'merge': 'zespól',
'models': 'modele',
'modules': 'moduły',
'new application "%s" created': 'nowa aplikacja "%s" została utworzona',
'new plugin installed': 'nowa wtyczka została zainstalowana',
'new record inserted': 'nowy rekord został wstawiony',
'next 100 rows': 'następne 100 wierszy',
'no match': 'no match',
'or import from csv file': 'lub zaimportuj z pliku csv',
'or provide app url:': 'or provide app url:',
'or provide application url:': 'lub podaj url aplikacji:',
'Overwrite installed app': 'overwrite installed app',
'Pack all': 'spakuj wszystko',
'Pack compiled': 'spakuj skompilowane',
'pack plugin': 'spakuj wtyczkę',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'wtyczka "%(plugin)s" została usunięta',
'plugins': 'plugins',
'previous 100 rows': 'poprzednie 100 wierszy',
'record': 'rekord',
'record does not exist': 'rekord nie istnieje',
'record id': 'ID rekordu',
'Remove compiled': 'usuń skompilowane',
'restore': 'odtwórz',
'revert': 'przywróć',
'save': 'zapisz',
'selected': 'zaznaczone',
'session expired': 'sesja wygasła',
'shell': 'powłoka',
'Site': 'strona główna',
'some files could not be removed': 'niektóre pliki nie mogły zostać usunięte',
'Start wizard': 'start wizard',
'state': 'stan',
'static': 'pliki statyczne',
'submit': 'wyślij',
'table': 'tabela',
'test': 'testuj',
'the application logic, each URL path is mapped in one exposed function in the controller': 'logika aplikacji, każda ścieżka URL jest mapowana na jedną z funkcji eksponowanych w kontrolerze',
'the data representation, define database tables and sets': 'reprezentacja danych, definicje zbiorów i tabel bazy danych',
'the presentations layer, views are also known as templates': 'warstwa prezentacji, widoki zwane są również szablonami',
'these files are served without processing, your images go here': 'pliki obsługiwane bez interpretacji, to jest miejsce na Twoje obrazy',
'to  previous version.': 'do  poprzedniej wersji.',
'translation strings for the application': 'ciągi tłumaczeń dla aplikacji',
'try': 'spróbój',
'try something like': 'spróbój czegos takiego jak',
'unable to create application "%s"': 'nie można utworzyć aplikacji "%s"',
'unable to delete file "%(filename)s"': 'nie można usunąć pliku "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'nie można usunąc pliku wtyczki "%(plugin)s"',
'unable to parse csv file': 'nie można sparsować pliku csv',
'unable to uninstall "%s"': 'nie można odinstalować "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': 'odznacz wszystko',
'Uninstall': 'odinstaluj',
'update': 'uaktualnij',
'update all languages': 'uaktualnij wszystkie pliki tłumaczeń',
'upgrade web2py now': 'upgrade web2py now',
'upload': 'upload',
'upload application:': 'wyślij plik aplikacji:',
'upload file:': 'wyślij plik:',
'upload plugin file:': 'wyślij plik wtyczki:',
Modified applications/admin/languages/pt-br.py from [33973b63ad] to [e7d40b797d].
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Use (...)&(...) para AND, (...)|(...) para OR, y ~(...) para NOT, para criar consultas mais complexas.',
'Use an url:': 'Use uma url:',
'User ID': 'ID do Usuario',
'Version': 'Versão',
'Views': 'Visões',
'Welcome to web2py': 'Bem-vindo ao web2py',
'YES': 'SIM',
'about': 'sobre',
'additional code for your application': 'código adicional para sua aplicação',
'admin disabled because no admin password': ' admin desabilitado por falta de senha definida',
'admin disabled because not supported on google app engine': 'admin dehabilitado, não é soportado no GAE',
'admin disabled because unable to access password file': 'admin desabilitado, não foi possível ler o arquivo de senha',
'administrative interface': 'interface administrativa',
'and rename it (required):': 'e renomeie (requerido):',
'and rename it:': ' e renomeie:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'admin desabilitado, canal inseguro',
'application "%s" uninstalled': 'aplicação "%s" desinstalada',
'application compiled': 'aplicação compilada',
'application is compiled and cannot be designed': 'A aplicação está compilada e não pode ser modificada',
'arguments': 'argumentos',
'back': 'voltar',
'browse': 'buscar',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, erros e sessões eliminadas',
'cannot create file': 'Não é possível criar o arquivo',
'cannot upload file "%(filename)s"': 'não é possível fazer upload do arquivo "%(filename)s"',
'change admin password': 'mudar senha de administrador',
'check all': 'marcar todos',
'check for upgrades': 'checar por atualizações',
'clean': 'limpar',
'click here for online examples': 'clique para ver exemplos online',
'click here for the administrative interface': 'Clique aqui para acessar a interface administrativa',
'click to check for upgrades': 'clique aqui para checar por atualizações',
'click to open': 'clique para abrir',
'code': 'código',
'collapse/expand all': 'collapse/expand all',
'commit (mercurial)': 'commit (mercurial)',
'compile': 'compilar',
'compiled application removed': 'aplicação compilada removida',
'controllers': 'controladores',
'create': 'criar',
'create file with filename:': 'criar um arquivo com o nome:',
'create new application:': 'nome da nova aplicação:',
'created by': 'criado por',
'crontab': 'crontab',
'currently running': 'Executando',
'currently saved or': 'Atualmente salvo ou',
'customize me!': 'Modifique-me',
'data uploaded': 'Dados enviados',
'database': 'banco de dados',
'database %s select': 'Seleção no banco de dados %s',
'database administration': 'administração de banco de dados',
'db': 'db',
'defines tables': 'define as tabelas',
'delete': 'apagar',
'delete all checked': 'apagar marcados',
'delete plugin': 'apagar plugin',
'deploy': 'publicar',
'design': 'modificar',
'direction: ltr': 'direção: ltr',
'done!': 'feito!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'edit': 'editar',
'edit controller': 'editar controlador',
'edit views:': 'editar visões:',
'errors': 'erros',
'export as csv file': 'exportar como arquivo CSV',
'exposes': 'expõe',
'extends': 'estende',
'failed to reload module': 'Falha ao recarregar o módulo',
'failed to reload module because:': 'falha ao recarregar o módulo por:',
'file "%(filename)s" created': 'arquivo "%(filename)s" criado',
'file "%(filename)s" deleted': 'arquivo "%(filename)s" apagado',
'file "%(filename)s" uploaded': 'arquivo "%(filename)s" enviado',
'file "%(filename)s" was not deleted': 'arquivo "%(filename)s" não foi apagado',
'file "%s" of %s restored': 'arquivo "%s" de %s restaurado',
'file changed on disk': 'arquivo modificado no disco',
'file does not exist': 'arquivo não existe',
'file saved on %(time)s': 'arquivo salvo em %(time)s',
'file saved on %s': 'arquivo salvo em %s',
'files': 'files',
'filter': 'filter',
'help': 'ajuda',
'htmledit': 'htmledit',
'includes': 'inclui',
'insert new': 'inserir novo',
'insert new %s': 'inserir novo %s',
'inspect attributes': 'inspect attributes',
'install': 'instalar',
'internal error': 'erro interno',
'invalid password': 'senha inválida',
'invalid request': 'solicitação inválida',
'invalid ticket': 'ticket inválido',
'language file "%(filename)s" created/updated': 'arquivo de linguagem "%(filename)s" criado/atualizado',
'languages': 'linguagens',
'languages updated': 'linguagens atualizadas',
'loading...': 'carregando...',
'locals': 'locals',
'login': 'inicio de sessão',
'logout': 'finalizar sessão',
'manage': 'gerenciar',
'merge': 'juntar',
'models': 'modelos',
'modules': 'módulos',
'new application "%s" created': 'nova aplicação "%s" criada',
'new plugin installed': 'novo plugin instalado',
'new record inserted': 'novo registro inserido',
'next 100 rows': 'próximos 100 registros',
'no match': 'não encontrado',
'or import from csv file': 'ou importar de um arquivo CSV',
'or provide app url:': 'ou forneça a url de uma aplicação:',
'or provide application url:': 'ou forneça a url de uma aplicação:',
'overwrite installed app': 'sobrescrever aplicação instalada',
'pack all': 'criar pacote',
'pack compiled': 'criar pacote compilado',
'pack plugin': 'empacotar plugin',
'password changed': 'senha alterada',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" eliminado',
'plugins': 'plugins',
'previous 100 rows': '100 registros anteriores',
'record': 'registro',
'record does not exist': 'o registro não existe',
'record id': 'id do registro',
'remove compiled': 'eliminar compilados',
'request': 'request',
'response': 'response',
'restore': 'restaurar',
'revert': 'reverter',
'save': 'salvar',
'selected': 'selecionado(s)',
'session': 'session',
'session expired': 'sessão expirada',
'shell': 'Terminal',
'site': 'site',
'some files could not be removed': 'alguns arquicos não puderam ser removidos',
'start wizard': 'iniciar assistente',
'state': 'estado',
'static': 'estáticos',
'submit': 'enviar',
'table': 'tabela',
'test': 'testar',
'the application logic, each URL path is mapped in one exposed function in the controller': 'A lógica da aplicação, cada URL é mapeada para uma função exposta pelo controlador',
'the data representation, define database tables and sets': 'A representação dos dadps, define tabelas e estruturas de dados',
'the presentations layer, views are also known as templates': 'A camada de apresentação, As visões também são chamadas de templates',
'these files are served without processing, your images go here': 'Estes arquivos são servidos sem processamento, suas imagens ficam aqui',
'to  previous version.': 'para a versão anterior.',
'translation strings for the application': 'textos traduzidos para a aplicação',
'try': 'tente',
'try something like': 'tente algo como',
'unable to create application "%s"': 'não é possível criar a aplicação "%s"',
'unable to delete file "%(filename)s"': 'não é possível criar o arquico "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'não é possível criar o plugin "%(plugin)s"',
'unable to parse csv file': 'não é possível analisar o arquivo CSV',
'unable to uninstall "%s"': 'não é possível instalar "%s"',
'unable to upgrade because "%s"': 'não é possível atualizar porque "%s"',
'uncheck all': 'desmarcar todos',
'uninstall': 'desinstalar',
'update': 'atualizar',
'update all languages': 'atualizar todas as linguagens',
'upgrade web2py now': 'atualize o web2py agora',
'upload': 'upload',
'upload application:': 'Fazer upload de uma aplicação:',
'upload file:': 'Enviar arquivo:',
'upload plugin file:': 'Enviar arquivo de plugin:',







|



















|

|
|







|


|
















|





|


|
















|





|










|












|
|
|








|









|

|




















|







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': 'Use (...)&(...) para AND, (...)|(...) para OR, y ~(...) para NOT, para criar consultas mais complexas.',
'Use an url:': 'Use uma url:',
'User ID': 'ID do Usuario',
'Version': 'Versão',
'Views': 'Visões',
'Welcome to web2py': 'Bem-vindo ao web2py',
'YES': 'SIM',
'About': 'sobre',
'additional code for your application': 'código adicional para sua aplicação',
'admin disabled because no admin password': ' admin desabilitado por falta de senha definida',
'admin disabled because not supported on google app engine': 'admin dehabilitado, não é soportado no GAE',
'admin disabled because unable to access password file': 'admin desabilitado, não foi possível ler o arquivo de senha',
'administrative interface': 'interface administrativa',
'and rename it (required):': 'e renomeie (requerido):',
'and rename it:': ' e renomeie:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'admin desabilitado, canal inseguro',
'application "%s" uninstalled': 'aplicação "%s" desinstalada',
'application compiled': 'aplicação compilada',
'application is compiled and cannot be designed': 'A aplicação está compilada e não pode ser modificada',
'arguments': 'argumentos',
'back': 'voltar',
'browse': 'buscar',
'cache': 'cache',
'cache, errors and sessions cleaned': 'cache, erros e sessões eliminadas',
'cannot create file': 'Não é possível criar o arquivo',
'cannot upload file "%(filename)s"': 'não é possível fazer upload do arquivo "%(filename)s"',
'Change admin password': 'mudar senha de administrador',
'check all': 'marcar todos',
'Check for upgrades': 'checar por atualizações',
'Clean': 'limpar',
'click here for online examples': 'clique para ver exemplos online',
'click here for the administrative interface': 'Clique aqui para acessar a interface administrativa',
'click to check for upgrades': 'clique aqui para checar por atualizações',
'click to open': 'clique para abrir',
'code': 'código',
'collapse/expand all': 'collapse/expand all',
'commit (mercurial)': 'commit (mercurial)',
'Compile': 'compilar',
'compiled application removed': 'aplicação compilada removida',
'controllers': 'controladores',
'Create': 'criar',
'create file with filename:': 'criar um arquivo com o nome:',
'create new application:': 'nome da nova aplicação:',
'created by': 'criado por',
'crontab': 'crontab',
'currently running': 'Executando',
'currently saved or': 'Atualmente salvo ou',
'customize me!': 'Modifique-me',
'data uploaded': 'Dados enviados',
'database': 'banco de dados',
'database %s select': 'Seleção no banco de dados %s',
'database administration': 'administração de banco de dados',
'db': 'db',
'defines tables': 'define as tabelas',
'delete': 'apagar',
'delete all checked': 'apagar marcados',
'delete plugin': 'apagar plugin',
'Deploy': 'publicar',
'design': 'modificar',
'direction: ltr': 'direção: ltr',
'done!': 'feito!',
'download layouts': 'download layouts',
'download plugins': 'download plugins',
'Edit': 'editar',
'edit controller': 'editar controlador',
'edit views:': 'editar visões:',
'Errors': 'erros',
'export as csv file': 'exportar como arquivo CSV',
'exposes': 'expõe',
'extends': 'estende',
'failed to reload module': 'Falha ao recarregar o módulo',
'failed to reload module because:': 'falha ao recarregar o módulo por:',
'file "%(filename)s" created': 'arquivo "%(filename)s" criado',
'file "%(filename)s" deleted': 'arquivo "%(filename)s" apagado',
'file "%(filename)s" uploaded': 'arquivo "%(filename)s" enviado',
'file "%(filename)s" was not deleted': 'arquivo "%(filename)s" não foi apagado',
'file "%s" of %s restored': 'arquivo "%s" de %s restaurado',
'file changed on disk': 'arquivo modificado no disco',
'file does not exist': 'arquivo não existe',
'file saved on %(time)s': 'arquivo salvo em %(time)s',
'file saved on %s': 'arquivo salvo em %s',
'files': 'files',
'filter': 'filter',
'Help': 'ajuda',
'htmledit': 'htmledit',
'includes': 'inclui',
'insert new': 'inserir novo',
'insert new %s': 'inserir novo %s',
'inspect attributes': 'inspect attributes',
'Install': 'instalar',
'internal error': 'erro interno',
'invalid password': 'senha inválida',
'invalid request': 'solicitação inválida',
'invalid ticket': 'ticket inválido',
'language file "%(filename)s" created/updated': 'arquivo de linguagem "%(filename)s" criado/atualizado',
'languages': 'linguagens',
'languages updated': 'linguagens atualizadas',
'loading...': 'carregando...',
'locals': 'locals',
'login': 'inicio de sessão',
'Logout': 'finalizar sessão',
'manage': 'gerenciar',
'merge': 'juntar',
'models': 'modelos',
'modules': 'módulos',
'new application "%s" created': 'nova aplicação "%s" criada',
'new plugin installed': 'novo plugin instalado',
'new record inserted': 'novo registro inserido',
'next 100 rows': 'próximos 100 registros',
'no match': 'não encontrado',
'or import from csv file': 'ou importar de um arquivo CSV',
'or provide app url:': 'ou forneça a url de uma aplicação:',
'or provide application url:': 'ou forneça a url de uma aplicação:',
'Overwrite installed app': 'sobrescrever aplicação instalada',
'Pack all': 'criar pacote',
'Pack compiled': 'criar pacote compilado',
'pack plugin': 'empacotar plugin',
'password changed': 'senha alterada',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" eliminado',
'plugins': 'plugins',
'previous 100 rows': '100 registros anteriores',
'record': 'registro',
'record does not exist': 'o registro não existe',
'record id': 'id do registro',
'Remove compiled': 'eliminar compilados',
'request': 'request',
'response': 'response',
'restore': 'restaurar',
'revert': 'reverter',
'save': 'salvar',
'selected': 'selecionado(s)',
'session': 'session',
'session expired': 'sessão expirada',
'shell': 'Terminal',
'Site': 'site',
'some files could not be removed': 'alguns arquicos não puderam ser removidos',
'Start wizard': 'iniciar assistente',
'state': 'estado',
'static': 'estáticos',
'submit': 'enviar',
'table': 'tabela',
'test': 'testar',
'the application logic, each URL path is mapped in one exposed function in the controller': 'A lógica da aplicação, cada URL é mapeada para uma função exposta pelo controlador',
'the data representation, define database tables and sets': 'A representação dos dadps, define tabelas e estruturas de dados',
'the presentations layer, views are also known as templates': 'A camada de apresentação, As visões também são chamadas de templates',
'these files are served without processing, your images go here': 'Estes arquivos são servidos sem processamento, suas imagens ficam aqui',
'to  previous version.': 'para a versão anterior.',
'translation strings for the application': 'textos traduzidos para a aplicação',
'try': 'tente',
'try something like': 'tente algo como',
'unable to create application "%s"': 'não é possível criar a aplicação "%s"',
'unable to delete file "%(filename)s"': 'não é possível criar o arquico "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'não é possível criar o plugin "%(plugin)s"',
'unable to parse csv file': 'não é possível analisar o arquivo CSV',
'unable to uninstall "%s"': 'não é possível instalar "%s"',
'unable to upgrade because "%s"': 'não é possível atualizar porque "%s"',
'uncheck all': 'desmarcar todos',
'Uninstall': 'desinstalar',
'update': 'atualizar',
'update all languages': 'atualizar todas as linguagens',
'upgrade web2py now': 'atualize o web2py agora',
'upload': 'upload',
'upload application:': 'Fazer upload de uma aplicação:',
'upload file:': 'Enviar arquivo:',
'upload plugin file:': 'Enviar arquivo de plugin:',
Modified applications/admin/languages/zh-cn.py from [d9ae1038f2] to [f5e338d3a7].
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': '',
'Use an url:': 'Use an url:',
'User ID': '用户ID',
'Version': '版本',
'Views': '视图',
'Welcome to web2py': '欢迎使用web2py',
'YES': '是',
'about': '关于',
'additional code for your application': '给你的应用附加代码',
'admin disabled because no admin password': '管理员需要设定密码,否则无法管理',
'admin disabled because not supported on google app engine': '未支持GAE,无法管理',
'admin disabled because unable to access password file': '需要可以操作密码文件,否则无法进行管理',
'administrative interface': 'administrative interface',
'and rename it (required):': '重命名为 (必须):',
'and rename it:': ' 重命名为:',
'appadmin': '应用管理',
'appadmin is disabled because insecure channel': '应用管理因非法通道失效',
'application "%s" uninstalled': '应用"%s" 已被卸载',
'application compiled': '应用已编译完',
'application is compiled and cannot be designed': '应用已编译完无法设计',
'arguments': 'arguments',
'back': 'back',
'cache': 'cache',
'cache, errors and sessions cleaned': '缓存、错误、sesiones已被清空',
'cannot create file': '无法创建文件',
'cannot upload file "%(filename)s"': '无法上传文件 "%(filename)s"',
'change admin password': 'change admin password',
'check all': '检查所有',
'check for upgrades': 'check for upgrades',
'clean': '清除',
'click here for online examples': '猛击此处,查看在线实例',
'click here for the administrative interface': '猛击此处,进入管理界面',
'click to check for upgrades': '猛击查看是否有升级版本',
'code': 'code',
'compile': '编译',
'compiled application removed': '已编译应用已移走',
'controllers': '控制器',
'create': 'create',
'create file with filename:': '创建文件用这名:',
'create new application:': '创建新应用:',
'created by': '创建自',
'crontab': '定期事务',
'currently running': 'currently running',
'currently saved or': '保存当前的或',
'customize me!': '定制俺!',
'data uploaded': '数据已上传',
'database': '数据库',
'database %s select': '数据库 %s 选择',
'database administration': '数据库管理',
'db': '',
'defines tables': '已定义表',
'delete': '删除',
'delete all checked': '删除所有选择的',
'delete plugin': 'delete plugin',
'deploy': 'deploy',
'design': '设计',
'direction: ltr': 'direction: ltr',
'done!': '搞定!',
'edit': '修改',
'edit controller': '修订控制器',
'edit views:': 'edit views:',
'errors': '错误',
'export as csv file': '导出为CSV文件',
'exposes': '暴露',
'extends': '扩展',
'failed to reload module': '重新加载模块失败',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': '文件 "%(filename)s" 已创建',
'file "%(filename)s" deleted': '文件 "%(filename)s" 已删除',
'file "%(filename)s" uploaded': '文件 "%(filename)s" 已上传',
'file "%(filename)s" was not deleted': '文件 "%(filename)s" 没删除',
'file "%s" of %s restored': '文件"%s" 有关 %s 已重存',
'file changed on disk': '硬盘上的文件已经修改',
'file does not exist': '文件并不存在',
'file saved on %(time)s': '文件保存于 %(time)s',
'file saved on %s': '文件保存在 %s',
'help': '帮助',
'htmledit': 'html编辑',
'includes': '包含',
'insert new': '新插入',
'insert new %s': '新插入 %s',
'install': 'install',
'internal error': '内部错误',
'invalid password': '无效密码',
'invalid request': '无效请求',
'invalid ticket': '无效传票',
'language file "%(filename)s" created/updated': '语言文件 "%(filename)s"被创建/更新',
'languages': '语言',
'languages updated': '语言已被刷新',
'loading...': '载入中...',
'login': '登录',
'logout': '注销',
'merge': '合并',
'models': '模型s',
'modules': '模块s',
'new application "%s" created': '新应用 "%s"已被创建',
'new plugin installed': 'new plugin installed',
'new record inserted': '新记录被插入',
'next 100 rows': '后100行',
'no match': 'no match',
'or import from csv file': '或者,从csv文件导入',
'or provide app url:': 'or provide app url:',
'or provide application url:': '或者,提供应用所在地址链接:',
'overwrite installed app': 'overwrite installed app',
'pack all': '全部打包',
'pack compiled': '包编译完',
'pack plugin': 'pack plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" deleted',
'previous 100 rows': '前100行',
'record': 'record',
'record does not exist': '记录并不存在',
'record id': '记录ID',
'remove compiled': '已移除',
'restore': '重存',
'revert': '恢复',
'save': '保存',
'selected': '已选',
'session expired': '会话过期',
'shell': '',
'site': '总站',
'some files could not be removed': '有些文件无法被移除',
'start wizard': 'start wizard',
'state': '状态',
'static': '静态文件',
'submit': '提交',
'table': '表',
'test': '测试',
'the application logic, each URL path is mapped in one exposed function in the controller': '应用逻辑:每个URL由控制器暴露的函式完成映射',
'the data representation, define database tables and sets': '数据表达式,定义数据库/表',







|


















|

|
|




|


|
















|



|


|














|




|









|











|
|
|







|






|

|







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...)  for NOT to build more complex queries.': '',
'Use an url:': 'Use an url:',
'User ID': '用户ID',
'Version': '版本',
'Views': '视图',
'Welcome to web2py': '欢迎使用web2py',
'YES': '是',
'About': '关于',
'additional code for your application': '给你的应用附加代码',
'admin disabled because no admin password': '管理员需要设定密码,否则无法管理',
'admin disabled because not supported on google app engine': '未支持GAE,无法管理',
'admin disabled because unable to access password file': '需要可以操作密码文件,否则无法进行管理',
'administrative interface': 'administrative interface',
'and rename it (required):': '重命名为 (必须):',
'and rename it:': ' 重命名为:',
'appadmin': '应用管理',
'appadmin is disabled because insecure channel': '应用管理因非法通道失效',
'application "%s" uninstalled': '应用"%s" 已被卸载',
'application compiled': '应用已编译完',
'application is compiled and cannot be designed': '应用已编译完无法设计',
'arguments': 'arguments',
'back': 'back',
'cache': 'cache',
'cache, errors and sessions cleaned': '缓存、错误、sesiones已被清空',
'cannot create file': '无法创建文件',
'cannot upload file "%(filename)s"': '无法上传文件 "%(filename)s"',
'Change admin password': 'change admin password',
'check all': '检查所有',
'Check for upgrades': 'check for upgrades',
'Clean': '清除',
'click here for online examples': '猛击此处,查看在线实例',
'click here for the administrative interface': '猛击此处,进入管理界面',
'click to check for upgrades': '猛击查看是否有升级版本',
'code': 'code',
'Compile': '编译',
'compiled application removed': '已编译应用已移走',
'controllers': '控制器',
'Create': 'create',
'create file with filename:': '创建文件用这名:',
'create new application:': '创建新应用:',
'created by': '创建自',
'crontab': '定期事务',
'currently running': 'currently running',
'currently saved or': '保存当前的或',
'customize me!': '定制俺!',
'data uploaded': '数据已上传',
'database': '数据库',
'database %s select': '数据库 %s 选择',
'database administration': '数据库管理',
'db': '',
'defines tables': '已定义表',
'delete': '删除',
'delete all checked': '删除所有选择的',
'delete plugin': 'delete plugin',
'Deploy': 'deploy',
'design': '设计',
'direction: ltr': 'direction: ltr',
'done!': '搞定!',
'Edit': '修改',
'edit controller': '修订控制器',
'edit views:': 'edit views:',
'Errors': '错误',
'export as csv file': '导出为CSV文件',
'exposes': '暴露',
'extends': '扩展',
'failed to reload module': '重新加载模块失败',
'failed to reload module because:': 'failed to reload module because:',
'file "%(filename)s" created': '文件 "%(filename)s" 已创建',
'file "%(filename)s" deleted': '文件 "%(filename)s" 已删除',
'file "%(filename)s" uploaded': '文件 "%(filename)s" 已上传',
'file "%(filename)s" was not deleted': '文件 "%(filename)s" 没删除',
'file "%s" of %s restored': '文件"%s" 有关 %s 已重存',
'file changed on disk': '硬盘上的文件已经修改',
'file does not exist': '文件并不存在',
'file saved on %(time)s': '文件保存于 %(time)s',
'file saved on %s': '文件保存在 %s',
'Help': '帮助',
'htmledit': 'html编辑',
'includes': '包含',
'insert new': '新插入',
'insert new %s': '新插入 %s',
'Install': 'install',
'internal error': '内部错误',
'invalid password': '无效密码',
'invalid request': '无效请求',
'invalid ticket': '无效传票',
'language file "%(filename)s" created/updated': '语言文件 "%(filename)s"被创建/更新',
'languages': '语言',
'languages updated': '语言已被刷新',
'loading...': '载入中...',
'login': '登录',
'Logout': '注销',
'merge': '合并',
'models': '模型s',
'modules': '模块s',
'new application "%s" created': '新应用 "%s"已被创建',
'new plugin installed': 'new plugin installed',
'new record inserted': '新记录被插入',
'next 100 rows': '后100行',
'no match': 'no match',
'or import from csv file': '或者,从csv文件导入',
'or provide app url:': 'or provide app url:',
'or provide application url:': '或者,提供应用所在地址链接:',
'Overwrite installed app': 'overwrite installed app',
'Pack all': '全部打包',
'Pack compiled': '包编译完',
'pack plugin': 'pack plugin',
'password changed': 'password changed',
'plugin "%(plugin)s" deleted': 'plugin "%(plugin)s" deleted',
'previous 100 rows': '前100行',
'record': 'record',
'record does not exist': '记录并不存在',
'record id': '记录ID',
'Remove compiled': '已移除',
'restore': '重存',
'revert': '恢复',
'save': '保存',
'selected': '已选',
'session expired': '会话过期',
'shell': '',
'Site': '总站',
'some files could not be removed': '有些文件无法被移除',
'Start wizard': 'start wizard',
'state': '状态',
'static': '静态文件',
'submit': '提交',
'table': '表',
'test': '测试',
'the application logic, each URL path is mapped in one exposed function in the controller': '应用逻辑:每个URL由控制器暴露的函式完成映射',
'the data representation, define database tables and sets': '数据表达式,定义数据库/表',
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
'unable to create application "%s"': '无法创建应用 "%s"',
'unable to delete file "%(filename)s"': '无法删除文件 "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'unable to delete file plugin "%(plugin)s"',
'unable to parse csv file': '无法生成 cvs',
'unable to uninstall "%s"': '无法卸载 "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': '反选全部',
'uninstall': '卸载',
'update': '更新',
'update all languages': '更新所有语言',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': '提交已有的应用:',
'upload file:': '提交文件:',
'upload plugin file:': 'upload plugin file:',
'variables': 'variables',







|







269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
'unable to create application "%s"': '无法创建应用 "%s"',
'unable to delete file "%(filename)s"': '无法删除文件 "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': 'unable to delete file plugin "%(plugin)s"',
'unable to parse csv file': '无法生成 cvs',
'unable to uninstall "%s"': '无法卸载 "%s"',
'unable to upgrade because "%s"': 'unable to upgrade because "%s"',
'uncheck all': '反选全部',
'Uninstall': '卸载',
'update': '更新',
'update all languages': '更新所有语言',
'upgrade web2py now': 'upgrade web2py now',
'upload application:': '提交已有的应用:',
'upload file:': '提交文件:',
'upload plugin file:': 'upload plugin file:',
'variables': 'variables',
Modified applications/admin/languages/zh-tw.py from [599934d534] to [fc47a55de9].
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
'Verify Password': '驗證密碼',
'Version': '版本',
'View': '視圖',
'Views': '視圖',
'Welcome %s': '歡迎 %s',
'Welcome to web2py': '歡迎使用 web2py',
'YES': '是',
'about': '關於',
'additional code for your application': '應用程式額外的程式碼',
'admin disabled because no admin password': '管理介面關閉原因是沒有設定管理員密碼 ',
'admin disabled because not supported on google app engine': '管理介面關閉原因是不支援在google apps engine環境下運作',
'admin disabled because unable to access password file': '管理介面關閉原因是無法存取密碼檔',
'amy_ajax': 'amy_ajax',
'and rename it (required):': '同時更名為(必要的):',
'and rename it:': '同時更名為:',
'appadmin': '應用程式管理員',
'appadmin is disabled because insecure channel': '管理介面關閉理由是連線方式不安全',
'application "%s" uninstalled': '已移除應用程式 "%s"',
'application compiled': '已編譯應用程式',
'application is compiled and cannot be designed': '應用程式已經編譯無法重新設計',
'arguments': 'arguments',
'back': '回復(back)',
'cache': '快取記憶體',
'cache, errors and sessions cleaned': '快取記憶體,錯誤紀錄,連線紀錄已清除',
'cannot create file': '無法創建檔案',
'cannot upload file "%(filename)s"': '無法上傳檔案 "%(filename)s"',
'change admin password': 'change admin password',
'change_password': '變更密碼',
'check all': '全選',
'clean': '清除',
'click here for online examples': '點此處進入線上範例',
'click here for the administrative interface': '點此處進入管理介面',
'click to check for upgrades': '點擊打勾以便升級',
'code': 'code',
'compile': '編譯',
'compiled application removed': '已移除已編譯的應用程式',
'controllers': '控件',
'create': '創建',
'create file with filename:': '創建檔案:',
'create new application:': '創建新應用程式:',
'created by': '創建自',
'crontab': '定時執行表',
'currently saved or': '現在存檔或',
'customize me!': '請調整我!',
'data uploaded': '資料已上傳',
'database': '資料庫',
'database %s select': '已選擇 %s 資料庫',
'database administration': '資料庫管理',
'db': 'db',
'defines tables': '定義資料表',
'delete': '刪除',
'delete all checked': '刪除所有已選擇項目',
'delete plugin': '刪除插件',
'delete_plugin': '刪除插件',
'design': '設計',
'direction: ltr': 'direction: ltr',
'done!': '完成!',
'edit': '編輯',
'edit controller': '編輯控件',
'edit views:': '編輯視圖',
'edit_language': '編輯語言檔',
'errors': '錯誤紀錄',
'export as csv file': '以逗號分隔檔(csv)格式匯出',
'exposes': '外顯',
'extends': '擴展',
'failed to reload module because:': '因為下列原因無法重新載入程式模組:',
'file "%(filename)s" created': '檔案 "%(filename)s" 已創建',
'file "%(filename)s" deleted': '檔案 "%(filename)s" 已刪除',
'file "%(filename)s" uploaded': '檔案 "%(filename)s" 已上傳',
'file "%s" of %s restored': '檔案 %s 的 "%s" 已回存',
'file changed on disk': '在磁碟上檔案已改變',
'file does not exist': '檔案不存在',
'file saved on %(time)s': '檔案已於 %(time)s 儲存',
'file saved on %s': '檔案在 %s 已儲存',
'help': '說明檔',
'htmledit': 'html編輯',
'includes': '包含',
'index': '索引',
'insert new': '插入新資料',
'insert new %s': '插入新資料 %s',
'install': '安裝',
'internal error': '內部錯誤',
'invalid password': '密碼錯誤',
'invalid request': '不合法的網路要求(request)',
'invalid ticket': '不合法的問題單號',
'language file "%(filename)s" created/updated': '語言檔"%(filename)s"已創建或更新',
'languages': '語言檔',
'loading...': '載入中...',
'login': '登入',
'logout': '登出',
'merge': '合併',
'models': '資料庫模組',
'modules': '程式模組',
'new application "%s" created': '已創建新的應用程式 "%s"',
'new plugin installed': '已安裝新插件',
'new record inserted': '已新增新紀錄',
'next 100 rows': '往後 100 筆',
'no match': '無法匹配',
'or import from csv file': '或是從逗號分隔檔(CSV)匯入',
'or provide app url:': '或是提供應用程式的安裝網址:',
'overwrite installed app': '覆蓋已安裝的應用程式',
'pack all': '全部打包',
'pack compiled': '打包已編譯資料',
'pack plugin': '打包插件',
'password changed': '密碼已變更',
'peek': '選取',
'plugin': '插件',
'plugin "%(plugin)s" deleted': '已刪除插件"%(plugin)s"',
'previous 100 rows': '往前 100 筆',
'record': '紀錄',
'record does not exist': '紀錄不存在',
'record id': '紀錄編號',
'register': '註冊',
'remove compiled': '編譯檔案已移除',
'resolve': '解決',
'restore': '回存',
'revert': '反向恢復',
'save': '儲存',
'selected': '已選擇',
'session expired': '連線(session)已過時',
'shell': '命令列操作介面',
'site': '網站',
'some files could not be removed': '部份檔案無法移除',
'state': '狀態',
'static': '靜態檔案',
'submit': '傳送',
'table': '資料表',
'test': '測試',
'the application logic, each URL path is mapped in one exposed function in the controller': '應用程式邏輯 - 每個網址路徑對應到一個控件的函式',







|


















|


|




|


|



















|



|












|





|








|










|
|
|










|







|







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
'Verify Password': '驗證密碼',
'Version': '版本',
'View': '視圖',
'Views': '視圖',
'Welcome %s': '歡迎 %s',
'Welcome to web2py': '歡迎使用 web2py',
'YES': '是',
'About': '關於',
'additional code for your application': '應用程式額外的程式碼',
'admin disabled because no admin password': '管理介面關閉原因是沒有設定管理員密碼 ',
'admin disabled because not supported on google app engine': '管理介面關閉原因是不支援在google apps engine環境下運作',
'admin disabled because unable to access password file': '管理介面關閉原因是無法存取密碼檔',
'amy_ajax': 'amy_ajax',
'and rename it (required):': '同時更名為(必要的):',
'and rename it:': '同時更名為:',
'appadmin': '應用程式管理員',
'appadmin is disabled because insecure channel': '管理介面關閉理由是連線方式不安全',
'application "%s" uninstalled': '已移除應用程式 "%s"',
'application compiled': '已編譯應用程式',
'application is compiled and cannot be designed': '應用程式已經編譯無法重新設計',
'arguments': 'arguments',
'back': '回復(back)',
'cache': '快取記憶體',
'cache, errors and sessions cleaned': '快取記憶體,錯誤紀錄,連線紀錄已清除',
'cannot create file': '無法創建檔案',
'cannot upload file "%(filename)s"': '無法上傳檔案 "%(filename)s"',
'Change admin password': 'change admin password',
'change_password': '變更密碼',
'check all': '全選',
'Clean': '清除',
'click here for online examples': '點此處進入線上範例',
'click here for the administrative interface': '點此處進入管理介面',
'click to check for upgrades': '點擊打勾以便升級',
'code': 'code',
'Compile': '編譯',
'compiled application removed': '已移除已編譯的應用程式',
'controllers': '控件',
'Create': '創建',
'create file with filename:': '創建檔案:',
'create new application:': '創建新應用程式:',
'created by': '創建自',
'crontab': '定時執行表',
'currently saved or': '現在存檔或',
'customize me!': '請調整我!',
'data uploaded': '資料已上傳',
'database': '資料庫',
'database %s select': '已選擇 %s 資料庫',
'database administration': '資料庫管理',
'db': 'db',
'defines tables': '定義資料表',
'delete': '刪除',
'delete all checked': '刪除所有已選擇項目',
'delete plugin': '刪除插件',
'delete_plugin': '刪除插件',
'design': '設計',
'direction: ltr': 'direction: ltr',
'done!': '完成!',
'Edit': '編輯',
'edit controller': '編輯控件',
'edit views:': '編輯視圖',
'edit_language': '編輯語言檔',
'Errors': '錯誤紀錄',
'export as csv file': '以逗號分隔檔(csv)格式匯出',
'exposes': '外顯',
'extends': '擴展',
'failed to reload module because:': '因為下列原因無法重新載入程式模組:',
'file "%(filename)s" created': '檔案 "%(filename)s" 已創建',
'file "%(filename)s" deleted': '檔案 "%(filename)s" 已刪除',
'file "%(filename)s" uploaded': '檔案 "%(filename)s" 已上傳',
'file "%s" of %s restored': '檔案 %s 的 "%s" 已回存',
'file changed on disk': '在磁碟上檔案已改變',
'file does not exist': '檔案不存在',
'file saved on %(time)s': '檔案已於 %(time)s 儲存',
'file saved on %s': '檔案在 %s 已儲存',
'Help': '說明檔',
'htmledit': 'html編輯',
'includes': '包含',
'index': '索引',
'insert new': '插入新資料',
'insert new %s': '插入新資料 %s',
'Install': '安裝',
'internal error': '內部錯誤',
'invalid password': '密碼錯誤',
'invalid request': '不合法的網路要求(request)',
'invalid ticket': '不合法的問題單號',
'language file "%(filename)s" created/updated': '語言檔"%(filename)s"已創建或更新',
'languages': '語言檔',
'loading...': '載入中...',
'login': '登入',
'Logout': '登出',
'merge': '合併',
'models': '資料庫模組',
'modules': '程式模組',
'new application "%s" created': '已創建新的應用程式 "%s"',
'new plugin installed': '已安裝新插件',
'new record inserted': '已新增新紀錄',
'next 100 rows': '往後 100 筆',
'no match': '無法匹配',
'or import from csv file': '或是從逗號分隔檔(CSV)匯入',
'or provide app url:': '或是提供應用程式的安裝網址:',
'Overwrite installed app': '覆蓋已安裝的應用程式',
'Pack all': '全部打包',
'Pack compiled': '打包已編譯資料',
'pack plugin': '打包插件',
'password changed': '密碼已變更',
'peek': '選取',
'plugin': '插件',
'plugin "%(plugin)s" deleted': '已刪除插件"%(plugin)s"',
'previous 100 rows': '往前 100 筆',
'record': '紀錄',
'record does not exist': '紀錄不存在',
'record id': '紀錄編號',
'register': '註冊',
'Remove compiled': '編譯檔案已移除',
'resolve': '解決',
'restore': '回存',
'revert': '反向恢復',
'save': '儲存',
'selected': '已選擇',
'session expired': '連線(session)已過時',
'shell': '命令列操作介面',
'Site': '網站',
'some files could not be removed': '部份檔案無法移除',
'state': '狀態',
'static': '靜態檔案',
'submit': '傳送',
'table': '資料表',
'test': '測試',
'the application logic, each URL path is mapped in one exposed function in the controller': '應用程式邏輯 - 每個網址路徑對應到一個控件的函式',
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
'unable to create application "%s"': '無法創建應用程式 "%s"',
'unable to delete file "%(filename)s"': '無法刪除檔案 "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': '無法刪查插件檔 "%(plugin)s"',
'unable to parse csv file': '無法解析逗號分隔檔(csv)',
'unable to uninstall "%s"': '無法移除安裝 "%s"',
'unable to upgrade because "%s"': '無法升級因為 "%s"',
'uncheck all': '全不選',
'uninstall': '解除安裝',
'update': '更新',
'update all languages': '將程式中待翻譯語句更新到所有的語言檔',
'upgrade web2py now': 'upgrade web2py now',
'upgrade_web2py': '升級 web2py',
'upload application:': '上傳應用程式:',
'upload file:': '上傳檔案:',
'upload plugin file:': '上傳插件檔:',







|







280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
'unable to create application "%s"': '無法創建應用程式 "%s"',
'unable to delete file "%(filename)s"': '無法刪除檔案 "%(filename)s"',
'unable to delete file plugin "%(plugin)s"': '無法刪查插件檔 "%(plugin)s"',
'unable to parse csv file': '無法解析逗號分隔檔(csv)',
'unable to uninstall "%s"': '無法移除安裝 "%s"',
'unable to upgrade because "%s"': '無法升級因為 "%s"',
'uncheck all': '全不選',
'Uninstall': '解除安裝',
'update': '更新',
'update all languages': '將程式中待翻譯語句更新到所有的語言檔',
'upgrade web2py now': 'upgrade web2py now',
'upgrade_web2py': '升級 web2py',
'upload application:': '上傳應用程式:',
'upload file:': '上傳檔案:',
'upload plugin file:': '上傳插件檔:',
Modified applications/admin/models/menu.py from [cbe8ab5af6] to [3ef86ec614].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32

# ###########################################################
# ## generate menu
# ###########################################################

_a = request.application
_c = request.controller
_f = request.function
response.title = '%s %s' % (_f, '/'.join(request.args))
response.subtitle = 'admin'
response.menu = [(T('site'), _f == 'site', URL(_a,'default','site'))]

if request.args:
    _t = request.args[0]
    response.menu.append((T('edit'), _c == 'default' and _f == 'design',
                         URL(_a,'default','design',args=_t)))
    response.menu.append((T('about'), _c == 'default' and _f == 'about',
                         URL(_a,'default','about',args=_t)))
    response.menu.append((T('errors'), _c == 'default' and _f == 'errors',
                         URL(_a,'default','errors',args=_t)))

    response.menu.append((T('versioning'),
                          _c == 'mercurial' and _f == 'commit',
                          URL(_a,'mercurial','commit',args=_t)))

if not session.authorized:
    response.menu = [(T('login'), True, '')]
else:
    response.menu.append((T('logout'), False,
                          URL(_a,'default',f='logout')))


response.menu.append((T('help'), False, URL('examples','default','index')))











|



|

|

|

<
|




|

|


>
|
|
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
# ###########################################################
# ## generate menu
# ###########################################################

_a = request.application
_c = request.controller
_f = request.function
response.title = '%s %s' % (_f, '/'.join(request.args))
response.subtitle = 'admin'
response.menu = [(T('Site'), _f == 'site', URL(_a,'default','site'))]

if request.args:
    _t = request.args[0]
    response.menu.append((T('Edit'), _c == 'default' and _f == 'design',
                         URL(_a,'default','design',args=_t)))
    response.menu.append((T('About'), _c == 'default' and _f == 'about',
                         URL(_a,'default','about',args=_t)))
    response.menu.append((T('Errors'), _c == 'default' and _f == 'errors',
                         URL(_a,'default','errors',args=_t)))

    response.menu.append((T('Versioning'),
                          _c == 'mercurial' and _f == 'commit',
                          URL(_a,'mercurial','commit',args=_t)))

if not session.authorized:
    response.menu = [(T('Login'), True, '')]
else:
    response.menu.append((T('Logout'), False,
                          URL(_a,'default',f='logout')))

if os.path.exists('applications/examples'):
    response.menu.append((T('Help'), False, URL('examples','default','index')))
else:
    response.menu.append((T('Help'), False, 'http://web2py.com/examples'))
Modified applications/admin/static/js/jquery.js from [7622c9ac23] to [0cf62d1dd0].

cannot compute difference between binary files

Modified applications/admin/static/js/web2py_ajax.js from [7f2851f561] to [afc700bdca].
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) { if(t) { if(t==':eval') eval(msg); else jQuery("#" + t).html(msg); } } }); 
}

String.prototype.reverse = function () { return this.split('').reverse().join('');};
function web2py_ajax_init() {
  jQuery('.hidden').hide();
  jQuery('.error').hide().slideDown('slow');
  jQuery('.flash').click(function() { jQuery(this).fadeOut('slow'); return false; });
  // jQuery('input[type=submit]').click(function(){var t=jQuery(this);t.hide();t.after('<input class="submit_disabled" disabled="disabled" type="submit" name="'+t.attr("name")+'_dummy" value="'+t.val()+'">')});
  jQuery('input.integer').live('keyup', function(){this.value=this.value.reverse().replace(/[^0-9\-]|\-(?=.)/g,'').reverse();});
  jQuery('input.double,input.decimal').live('keyup', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();});
  var confirm_message = (typeof w2p_ajax_confirm_message != 'undefined') ? w2p_ajax_confirm_message : "Are you sure you want to delete this object?";
  jQuery("input[type='checkbox'].delete").live('click', function(){ if(this.checked) if(!confirm(confirm_message)) this.checked=false; });
  var date_format = (typeof w2p_ajax_date_format != 'undefined') ? w2p_ajax_date_format : "%Y-%m-%d";
  try {jQuery("input.date").live('focus',function() {Calendar.setup({







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) { if(t) { if(t==':eval') eval(msg); else jQuery("#" + t).html(msg); } } }); 
}

String.prototype.reverse = function () { return this.split('').reverse().join('');};
function web2py_ajax_init() {
  jQuery('.hidden').hide();
  jQuery('.error').hide().slideDown('slow');
  jQuery('.flash').click(function(e) { jQuery(this).fadeOut('slow'); e.preventDefault(); });
  // jQuery('input[type=submit]').click(function(){var t=jQuery(this);t.hide();t.after('<input class="submit_disabled" disabled="disabled" type="submit" name="'+t.attr("name")+'_dummy" value="'+t.val()+'">')});
  jQuery('input.integer').live('keyup', function(){this.value=this.value.reverse().replace(/[^0-9\-]|\-(?=.)/g,'').reverse();});
  jQuery('input.double,input.decimal').live('keyup', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();});
  var confirm_message = (typeof w2p_ajax_confirm_message != 'undefined') ? w2p_ajax_confirm_message : "Are you sure you want to delete this object?";
  jQuery("input[type='checkbox'].delete").live('click', function(){ if(this.checked) if(!confirm(confirm_message)) this.checked=false; });
  var date_format = (typeof w2p_ajax_date_format != 'undefined') ? w2p_ajax_date_format : "%Y-%m-%d";
  try {jQuery("input.date").live('focus',function() {Calendar.setup({
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
   if(flash.html()) flash.slideDown();
   web2py_ajax_init();
});
function web2py_trap_form(action,target) {
   jQuery('#'+target+' form').each(function(i){
      var form=jQuery(this);
      if(!form.hasClass('no_trap'))
        form.submit(function(obj){
         jQuery('.flash').hide().html('');
         web2py_ajax_page('post',action,form.serialize(),target);
         return false;
      });
   });
}
function web2py_ajax_page(method,action,data,target) {
  jQuery.ajax({'type':method,'url':action,'data':data,
    'beforeSend':function(xhr) {
      xhr.setRequestHeader('web2py-component-location',document.location);







|


|







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
   if(flash.html()) flash.slideDown();
   web2py_ajax_init();
});
function web2py_trap_form(action,target) {
   jQuery('#'+target+' form').each(function(i){
      var form=jQuery(this);
      if(!form.hasClass('no_trap'))
        form.submit(function(e){
         jQuery('.flash').hide().html('');
         web2py_ajax_page('post',action,form.serialize(),target);
	 e.preventDefault();
      });
   });
}
function web2py_ajax_page(method,action,data,target) {
  jQuery.ajax({'type':method,'url':action,'data':data,
    'beforeSend':function(xhr) {
      xhr.setRequestHeader('web2py-component-location',document.location);
Modified applications/admin/views/default/about.html from [f977b1a453] to [b342dc744a].
1
2
3
4
5
6
7
8
9
10
11
12
{{extend 'layout.html'}}

{{block sectionclass}}about{{end}}

<h2>{{=T("About application")}} "{{=app}}"</h2>
<h3>{{=T("About")}} {{=app}}</h3>
<p class="controls">{{=button(URL('edit/%s/ABOUT' % (app)), T('edit'))}}</p>
<div class="about_text legalese">{{=about}}</div>
<h3>{{=T('License for')}} {{=app}}</h3>
<p class="controls">{{=button(URL('edit/%s/LICENSE' % (app)), T('edit'))}}</p>
<div class="license_text legalese">{{=license}}</div>
</ul>






|


|


1
2
3
4
5
6
7
8
9
10
11
12
{{extend 'layout.html'}}

{{block sectionclass}}about{{end}}

<h2>{{=T("About application")}} "{{=app}}"</h2>
<h3>{{=T("About")}} {{=app}}</h3>
<p class="controls">{{=button(URL('edit/%s/ABOUT' % (app)), T('Edit'))}}</p>
<div class="about_text legalese">{{=about}}</div>
<h3>{{=T('License for')}} {{=app}}</h3>
<p class="controls">{{=button(URL('edit/%s/LICENSE' % (app)), T('Edit'))}}</p>
<div class="license_text legalese">{{=license}}</div>
</ul>
Modified applications/admin/views/default/design.html from [f9b44e4321] to [bb614a9671].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{{extend 'layout.html'}}
{{
def all(items):
    return reduce(lambda a,b:a and b,items,True)
def peekfile(path,file):
    return A(file.replace('\\\\','/'),_href=URL('peek', args=(app, path, file)))  
def editfile(path,file):
    return A(SPAN(T('edit')),_class='button editbutton',_href=URL('edit', args=(app, path, file)))  
def testfile(path,file):
    return A(TAG[''](IMG(_src=URL('static', 'images/test_icon.png'), _alt=T('test')), SPAN(T("Run tests in this file (to run all files, you may also use the button labelled 'test')"))), _class='icon test tooltip',_href=URL('test', args=(app, file))) 
def editlanguagefile(path,file):
    return A(SPAN(T('edit')),_class='button editbutton',_href=URL('edit_language', args=(app, path, file))) 
def file_upload_form(location):
    form=FORM(T("upload file:")," ",
              INPUT(_type="file",_name="file")," ",T("and rename it:")," ",
              INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
              INPUT(_type="hidden",_name="location",_value=location),
              INPUT(_type="hidden",_name="sender",_value=URL('design',args=app)),
              INPUT(_type="submit",_value=T("upload")),_action=URL('upload_file'))
    return form  
def file_create_form(location):
    form=FORM(T("create file with filename:")," ",
              INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
              INPUT(_type="hidden",_name="location",_value=location),
              INPUT(_type="hidden",_name="sender",_value=URL('design',args=app)),
              INPUT(_type="submit",_value=T("create")),_action=URL('create_file'))
    return form
def upload_plugin_form(app):
    form=FORM(T("upload plugin file:")," ",
              INPUT(_type="file",_name="pluginfile"),
              INPUT(_type="submit",_value=T("upload")))
    return form
def deletefile(arglist):







|



|













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{{extend 'layout.html'}}
{{
def all(items):
    return reduce(lambda a,b:a and b,items,True)
def peekfile(path,file):
    return A(file.replace('\\\\','/'),_href=URL('peek', args=(app, path, file)))  
def editfile(path,file):
    return A(SPAN(T('Edit')),_class='button editbutton',_href=URL('edit', args=(app, path, file)))  
def testfile(path,file):
    return A(TAG[''](IMG(_src=URL('static', 'images/test_icon.png'), _alt=T('test')), SPAN(T("Run tests in this file (to run all files, you may also use the button labelled 'test')"))), _class='icon test tooltip',_href=URL('test', args=(app, file))) 
def editlanguagefile(path,file):
    return A(SPAN(T('Edit')),_class='button editbutton',_href=URL('edit_language', args=(app, path, file))) 
def file_upload_form(location):
    form=FORM(T("upload file:")," ",
              INPUT(_type="file",_name="file")," ",T("and rename it:")," ",
              INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
              INPUT(_type="hidden",_name="location",_value=location),
              INPUT(_type="hidden",_name="sender",_value=URL('design',args=app)),
              INPUT(_type="submit",_value=T("upload")),_action=URL('upload_file'))
    return form  
def file_create_form(location):
    form=FORM(T("create file with filename:")," ",
              INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
              INPUT(_type="hidden",_name="location",_value=location),
              INPUT(_type="hidden",_name="sender",_value=URL('design',args=app)),
              INPUT(_type="submit",_value=T("Create")),_action=URL('create_file'))
    return form
def upload_plugin_form(app):
    form=FORM(T("upload plugin file:")," ",
              INPUT(_type="file",_name="pluginfile"),
              INPUT(_type="submit",_value=T("upload")))
    return form
def deletefile(arglist):
Modified applications/admin/views/default/peek.html from [ac2e58d0d6] to [9463c1f29b].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{{extend 'layout.html'}}

{{block sectionclass}}peek{{end}}

<h2>{{=T("Peeking at file")}} "{{=filename}}"</h2>

<p class="controls">
{{=button(URL('design',args=request.args[0]), T('back'))}}
{{=button(URL('edit',args=request.args), T('edit'))}}
</p>

{{
if filename[-3:]=='.py': language='python'
else: language='html'
}}
{{=CODE(data,language=language,link='/examples/global/vars/')}}








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{{extend 'layout.html'}}

{{block sectionclass}}peek{{end}}

<h2>{{=T("Peeking at file")}} "{{=filename}}"</h2>

<p class="controls">
{{=button(URL('design',args=request.args[0]), T('back'))}}
{{=button(URL('edit',args=request.args), T('Edit'))}}
</p>

{{
if filename[-3:]=='.py': language='python'
else: language='html'
}}
{{=CODE(data,language=language,link='/examples/global/vars/')}}
Modified applications/admin/views/default/plugin.html from [084d2364cc] to [695b8c8c14].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{{extend 'layout.html'}}
{{
import os
def all(items):
    return reduce(lambda a,b:a and b,items,True)
def peekfile(path,file):
    return A(file.replace('\\\\','/'),_href=URL('peek', args=(app, path, file)))
def editfile(path,file):
    return A(SPAN(T('edit')),_class='button editbutton',_href=URL('edit', args=(app, path, file)))
def testfile(path,file):
    return A(TAG[''](IMG(_src=URL('static', 'images/test_icon.png'), _alt=T('test')), SPAN(T("Run tests in this file"))), _class='icon test tooltip',_href=URL('test', args=(app, file)))
def editlanguagefile(path,file):
    return A(SPAN(T('edit')),_class='button editbutton',_href=URL('edit_language', args=(app, path, file))) 
def file_upload_form(location):
    form=FORM(T("upload file:")," ",
              INPUT(_type="file",_name="file")," ",T("and rename it:")," ",
              INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
              INPUT(_type="hidden",_name="location",_value=location),
              INPUT(_type="hidden",_name="sender",_value=URL('design/'+app)),
              INPUT(_type="submit",_value=T("submit")),_action=URL('upload_file'))








|



|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{{extend 'layout.html'}}
{{
import os
def all(items):
    return reduce(lambda a,b:a and b,items,True)
def peekfile(path,file):
    return A(file.replace('\\\\','/'),_href=URL('peek', args=(app, path, file)))
def editfile(path,file):
    return A(SPAN(T('Edit')),_class='button editbutton',_href=URL('edit', args=(app, path, file)))
def testfile(path,file):
    return A(TAG[''](IMG(_src=URL('static', 'images/test_icon.png'), _alt=T('test')), SPAN(T("Run tests in this file"))), _class='icon test tooltip',_href=URL('test', args=(app, file)))
def editlanguagefile(path,file):
    return A(SPAN(T('Edit')),_class='button editbutton',_href=URL('edit_language', args=(app, path, file))) 
def file_upload_form(location):
    form=FORM(T("upload file:")," ",
              INPUT(_type="file",_name="file")," ",T("and rename it:")," ",
              INPUT(_type="text",_name="filename",requires=IS_NOT_EMPTY),
              INPUT(_type="hidden",_name="location",_value=location),
              INPUT(_type="hidden",_name="sender",_value=URL('design/'+app)),
              INPUT(_type="submit",_value=T("submit")),_action=URL('upload_file'))
Modified applications/admin/views/default/site.html from [f3096ca1c3] to [296a772366].
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        <h3 class="currentapp">{{=a}} ({{=T('currently running')}})</h3>  
        <p class="controls">
        {{else:}}
        <h3 class="editableapp">{{=A(a,_href=URL(a,'default','index'))}}</h3> 
	{{if MULTI_USER_MODE and db.app(name=a):}}(created by {{="%(first_name)s %(last_name)s" % db.auth_user[db.app(name=a).owner]}}){{pass}}
        <p class="controls">
        {{if not os.path.exists('applications/%s/compiled' % a):}}
        {{=sp_button(URL('design',args=a), T("edit"))}}
        {{else:}}
        {{=button(URL(a,'appadmin','index'), T("appadmin"))}}
        {{pass}}
        {{=button(URL('about',args=a), T("about"))}}
        {{pass}}
        {{=button(URL('errors',args=a), T("errors"))}}
        {{=button(URL('cleanup',args=a), T("clean"))}}
        {{=button(URL('pack',args=a), T("pack all"))}}
        {{if not os.path.exists('applications/%s/compiled' % a):}}
        {{=button(URL('compile_app',args=a), T("compile"))}}
        {{else:}}
        {{=button(URL('pack',args=(a, 'compiled')), T("pack compiled"))}}
        {{if glob.glob('applications/%s/controllers/*.py' % a):}}
        {{=button(URL('remove_compiled_app',args=a), T("remove compiled"))}}
        {{pass}}
        {{pass}}
        {{if a!=request.application:}}
        {{=button(URL('uninstall',args=a), T("uninstall"))}}
        {{pass}}
        </p>
      </li>
      {{pass}}
    </ul>
  </div>
</div>

<div class="sidebar fl60">
  <div class="sidebar_inner controls">
    <div class="pwdchange">
      <!-- CHANGE ADMIN PWD -->
      {{if MULTI_USER_MODE:}}
      {{=auth.navbar()}}
      {{else:}}
      {{=sp_button(URL('change_password'), T('change admin password'))}}
      {{pass}}
    </div>
    <!-- VERSION -->
    {{if is_manager():}}
    <div class="box">
      <h3>{{=myversion}}</h3>      
      {{if session.check_version:}}
      <p id="check_version">
        {{=T('Checking for upgrades...')}}
      <script>ajax('{{=URL('check_version')}}',[],'check_version');</script>{{session.check_version=False}}
      {{else:}}
      <p id="check_version">
        {{=button("javascript:ajax('"+URL('check_version')+"',[],'check_version')", T('check for upgrades'))}}
      {{pass}}
      </p>
      <div class="formfield">
	Running on {{=request.env.server_software}}
      </div>

    </div>
    {{pass}}
    <!-- APP WIZARD -->
    <div class="box">
      <h3>{{=T("New application wizard")}}</h3>
      <p>{{=button(URL('wizard','index'), T('start wizard'))}}
      {{=T("(requires internet access)")}}</p>
    </div>
    <!-- SCAFFOLD APP -->
    <div class="box">
      <h3>{{=T("New simple application")}}</h3>
      <form action="" enctype="multipart/form-data" method="post">
        <div class="formfield">
          {{=LABEL(T("Application name:"), _for="scaffold_filename")}} 
          <input name="filename" type="text" id="scaffold_filename" /> 
          <button type="submit" class="button">{{=T('create')}}</button>
        </div>
        <div class="hidden"></div>
      </form>
    </div>
    <!-- UPLOAD PACKAGE -->
    <div class="box">
      <h3>{{=T("Upload & install packed application")}}</h3>
      <form action="" enctype="multipart/form-data" method="post">
        <div class="formfield">
	  <table>
            <tr>
	      <td>
		{{=LABEL(T("Application name:"), _form='upload_filename')}}
	      </td>







|



|

|
|
|

|

|

|



|















|





|






|





>





|









|






|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
        <h3 class="currentapp">{{=a}} ({{=T('currently running')}})</h3>  
        <p class="controls">
        {{else:}}
        <h3 class="editableapp">{{=A(a,_href=URL(a,'default','index'))}}</h3> 
	{{if MULTI_USER_MODE and db.app(name=a):}}(created by {{="%(first_name)s %(last_name)s" % db.auth_user[db.app(name=a).owner]}}){{pass}}
        <p class="controls">
        {{if not os.path.exists('applications/%s/compiled' % a):}}
        {{=sp_button(URL('design',args=a), T("Edit"))}}
        {{else:}}
        {{=button(URL(a,'appadmin','index'), T("appadmin"))}}
        {{pass}}
        {{=button(URL('about',args=a), T("About"))}}
        {{pass}}
        {{=button(URL('errors',args=a), T("Errors"))}}
        {{=button(URL('cleanup',args=a), T("Clean"))}}
        {{=button(URL('pack',args=a), T("Pack all"))}}
        {{if not os.path.exists('applications/%s/compiled' % a):}}
        {{=button(URL('compile_app',args=a), T("Compile"))}}
        {{else:}}
        {{=button(URL('pack',args=(a, 'compiled')), T("Pack compiled"))}}
        {{if glob.glob('applications/%s/controllers/*.py' % a):}}
        {{=button(URL('remove_compiled_app',args=a), T("Remove compiled"))}}
        {{pass}}
        {{pass}}
        {{if a!=request.application:}}
        {{=button(URL('uninstall',args=a), T("Uninstall"))}}
        {{pass}}
        </p>
      </li>
      {{pass}}
    </ul>
  </div>
</div>

<div class="sidebar fl60">
  <div class="sidebar_inner controls">
    <div class="pwdchange">
      <!-- CHANGE ADMIN PWD -->
      {{if MULTI_USER_MODE:}}
      {{=auth.navbar()}}
      {{else:}}
      {{=sp_button(URL('change_password'), T('Change admin password'))}}
      {{pass}}
    </div>
    <!-- VERSION -->
    {{if is_manager():}}
    <div class="box">
      <h3>{{="Version %s.%s.%s (%s) %s" % myversion}}</h3>      
      {{if session.check_version:}}
      <p id="check_version">
        {{=T('Checking for upgrades...')}}
      <script>ajax('{{=URL('check_version')}}',[],'check_version');</script>{{session.check_version=False}}
      {{else:}}
      <p id="check_version">
        {{=button("javascript:ajax('"+URL('check_version')+"',[],'check_version')", T('Check for upgrades'))}}
      {{pass}}
      </p>
      <div class="formfield">
	Running on {{=request.env.server_software}}
      </div>
      <p>{{=button(URL('default','reload_routes'), T('Reload routes'))}}</p>
    </div>
    {{pass}}
    <!-- APP WIZARD -->
    <div class="box">
      <h3>{{=T("New application wizard")}}</h3>
      <p>{{=button(URL('wizard','index'), T('Start wizard'))}}
      {{=T("(requires internet access)")}}</p>
    </div>
    <!-- SCAFFOLD APP -->
    <div class="box">
      <h3>{{=T("New simple application")}}</h3>
      <form action="" enctype="multipart/form-data" method="post">
        <div class="formfield">
          {{=LABEL(T("Application name:"), _for="scaffold_filename")}} 
          <input name="filename" type="text" id="scaffold_filename" /> 
          <button type="submit" class="button">{{=T('Create')}}</button>
        </div>
        <div class="hidden"></div>
      </form>
    </div>
    <!-- UPLOAD PACKAGE -->
    <div class="box">
      <h3>{{=T("Upload and install packed application")}}</h3>
      <form action="" enctype="multipart/form-data" method="post">
        <div class="formfield">
	  <table>
            <tr>
	      <td>
		{{=LABEL(T("Application name:"), _form='upload_filename')}}
	      </td>
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
	      <td>
		<input id="file" name="file" type="file" id="upload_file" /> 
		<b>OR</b>
	      </td>
            </tr>
	    <tr>
              <td>
		{{=LABEL(T("Use an url:"), _for='upload_url')}}
	      </td>
	      <td>
		<input id="appurl" name="appurl" type="text" id="upload_url"/>
	      </td>
	    </tr>
	    <tr>
	      <td></td>
              <td>
		<input type="checkbox" name="overwrite_check" id="upload_overwrite" /> 
		{{=LABEL(T("overwrite installed app"), _for='upload_overwrite')}}
	      </td>
	    </tr>
	    <tr>
	      <td></td>
	      <td>
		<button type="submit">{{=T('install')}}</button>
	      </td>
	    </tr>
	  </table>
        </div>
      </form>
    </div>
    <!-- DEPLOY ON GAE -->
    <div class="box">
      <h3>{{=T("Deploy on Google App Engine")}}</h3>
      <p>{{=button(URL('gae','deploy'), T('deploy'))}}</p>
    </div><br/>
    {{if TWITTER_HASH:}}	
    <div class="box">
      <h3>{{=T("%s Recent Tweets"%TWITTER_HASH)}}</h3>
      <div id="tweets">{{=T('loading...')}}</div>
      <script>
        jQuery(document).ready(function(){jQuery('#tweets').load('{{=URL('twitter')}}')});
      </script>
    </div>
    {{pass}}
  </div>
</div>







|









|





|









|












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
	      <td>
		<input id="file" name="file" type="file" id="upload_file" /> 
		<b>OR</b>
	      </td>
            </tr>
	    <tr>
              <td>
		{{=LABEL(T("Get from URL:"), _for='upload_url')}}
	      </td>
	      <td>
		<input id="appurl" name="appurl" type="text" id="upload_url"/>
	      </td>
	    </tr>
	    <tr>
	      <td></td>
              <td>
		<input type="checkbox" name="overwrite_check" id="upload_overwrite" /> 
		{{=LABEL(T("Overwrite installed app"), _for='upload_overwrite')}}
	      </td>
	    </tr>
	    <tr>
	      <td></td>
	      <td>
		<button type="submit">{{=T('Install')}}</button>
	      </td>
	    </tr>
	  </table>
        </div>
      </form>
    </div>
    <!-- DEPLOY ON GAE -->
    <div class="box">
      <h3>{{=T("Deploy on Google App Engine")}}</h3>
      <p>{{=button(URL('gae','deploy'), T('Deploy'))}}</p>
    </div><br/>
    {{if TWITTER_HASH:}}	
    <div class="box">
      <h3>{{=T("%s Recent Tweets"%TWITTER_HASH)}}</h3>
      <div id="tweets">{{=T('loading...')}}</div>
      <script>
        jQuery(document).ready(function(){jQuery('#tweets').load('{{=URL('twitter')}}')});
      </script>
    </div>
    {{pass}}
  </div>
</div>
Modified applications/admin/views/layout.html from [c4facc28a3] to [8713b04ead].
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        <div id="main">
            <div id="main_inner">
                <div class="flash">{{=response.flash or ''}}</div>
                {{include}}
            </div>
        </div>
        <div id="footer" class="fixed">
            {{=T('Powered by')}} {{=A('web2py', _href='http://www.web2py.com')}}&trade; {{=T('created by')}} Massimo Di Pierro &copy;2007-2010 -
	    {{if hasattr(T,'get_possible_languages'):}}
	    <span>
	      {{=T('Admin language')}}
	      <select name="adminlanguage" onchange="var date = new Date();cookieDate=date.setTime(date.getTime()+(100*24*60*60*1000));document.cookie='adminLanguage='+this.options[this.selectedIndex].value+'; expires='+cookieDate+'; path=/';window.location.reload()">
		{{for language in T.get_possible_languages():}}
		<option {{=T.accepted_language==language and 'selected' or ''}} >{{=language}}</option>
		{{pass}}







|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        <div id="main">
            <div id="main_inner">
                <div class="flash">{{=response.flash or ''}}</div>
                {{include}}
            </div>
        </div>
        <div id="footer" class="fixed">
            {{=T('Powered by')}} {{=A('web2py', _href='http://www.web2py.com')}}&trade; {{=T('created by')}} Massimo Di Pierro &copy;2007-2011 -
	    {{if hasattr(T,'get_possible_languages'):}}
	    <span>
	      {{=T('Admin language')}}
	      <select name="adminlanguage" onchange="var date = new Date();cookieDate=date.setTime(date.getTime()+(100*24*60*60*1000));document.cookie='adminLanguage='+this.options[this.selectedIndex].value+'; expires='+cookieDate+'; path=/';window.location.reload()">
		{{for language in T.get_possible_languages():}}
		<option {{=T.accepted_language==language and 'selected' or ''}} >{{=language}}</option>
		{{pass}}
Modified applications/admin/views/wizard/step.html from [0b95247d7c] to [3ab784f285].
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  <div class="box">
    <h3>{{=T('Basics')}}</h3>
    <p>{{=button(URL('index'), T('restart'))}}</p>
    <p><strong>App Name:</strong> {{=session.app['name']}}</p>
  </div>
  <div class="box">
    <h3>Current settings</h3>      
    <p>{{=button(URL('step1'), T('edit'))}}</p>
    <ul id="current_settings">
    	{{for key,value in session.app['params']:}}
    	<li><b>{{=key}}:</b> {{=value}}</li>
    	{{pass}}
    </ul>
  </div>
  <div class="box">
    <h3>Tables</h3>
    <p>{{=button(URL('step2'), T('edit all'))}}</p>
    <ul>
    	{{for i,table in enumerate(session.app['tables']):}}
    	<li>{{=button(URL('step3',args=i), T('edit'))}} <strong>{{=table}}</strong></li>
    	{{pass}}
    </ul>
  </div>
  <div class="box">
    <h3>Pages</h3>
    <p>{{=button(URL('step4'), T('edit all'))}}</p>
    <ul>
      {{for i,page in enumerate(session.app['pages']):}}
      <li>{{=button(URL('step5',args=i), T('edit'))}} <strong>{{=page}}</strong></li>
      {{pass}}
    </ul>
  </div>
  <div class="box">
    <h3>{{=T('Generate')}}</h3>
    <p>{{=button(URL('step6'), T('go!'))}}</p>
  </div>







|











|








|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  <div class="box">
    <h3>{{=T('Basics')}}</h3>
    <p>{{=button(URL('index'), T('restart'))}}</p>
    <p><strong>App Name:</strong> {{=session.app['name']}}</p>
  </div>
  <div class="box">
    <h3>Current settings</h3>      
    <p>{{=button(URL('step1'), T('Edit'))}}</p>
    <ul id="current_settings">
    	{{for key,value in session.app['params']:}}
    	<li><b>{{=key}}:</b> {{=value}}</li>
    	{{pass}}
    </ul>
  </div>
  <div class="box">
    <h3>Tables</h3>
    <p>{{=button(URL('step2'), T('edit all'))}}</p>
    <ul>
    	{{for i,table in enumerate(session.app['tables']):}}
    	<li>{{=button(URL('step3',args=i), T('Edit'))}} <strong>{{=table}}</strong></li>
    	{{pass}}
    </ul>
  </div>
  <div class="box">
    <h3>Pages</h3>
    <p>{{=button(URL('step4'), T('edit all'))}}</p>
    <ul>
      {{for i,page in enumerate(session.app['pages']):}}
      <li>{{=button(URL('step5',args=i), T('Edit'))}} <strong>{{=page}}</strong></li>
      {{pass}}
    </ul>
  </div>
  <div class="box">
    <h3>{{=T('Generate')}}</h3>
    <p>{{=button(URL('step6'), T('go!'))}}</p>
  </div>
Deleted applications/examples/ABOUT version [ea96ed160b].
Deleted applications/examples/LICENSE version [4719a3b620].
Deleted applications/examples/__init__.py version [da39a3ee5e].
Deleted applications/examples/controllers/ajax_examples.py version [c86cb0618f].
Deleted applications/examples/controllers/appadmin.py version [1eb6fe022d].
Deleted applications/examples/controllers/database_examples.py version [d7a27016aa].
Deleted applications/examples/controllers/default.py version [d78f059886].
Deleted applications/examples/controllers/form_examples.py version [89768d6d15].
Deleted applications/examples/controllers/global.py version [7b13545222].
Deleted applications/examples/controllers/layout_examples.py version [7591b93b83].
Deleted applications/examples/controllers/session_examples.py version [83a6e5ca77].
Deleted applications/examples/controllers/simple_examples.py version [4082840564].
Deleted applications/examples/controllers/spreadsheet.py version [9142324704].
Deleted applications/examples/controllers/template_examples.py version [0afc3bbead].
Deleted applications/examples/models/db.py version [04002207a9].
Deleted applications/examples/models/feeds_reader.py version [cd96873e70].
Deleted applications/examples/models/markmin.py version [4d602f756d].
Deleted applications/examples/models/menu.py version [e8143d44af].
Deleted applications/examples/private/content/en/default/documentation/community.markmin version [95b4ce4ac6].
Deleted applications/examples/private/content/en/default/documentation/main.markmin version [cca528997e].
Deleted applications/examples/private/content/en/default/documentation/more.markmin version [07e3a74e83].
Deleted applications/examples/private/content/en/default/documentation/official.markmin version [211d236d62].
Deleted applications/examples/private/content/en/default/index/maincontent.markmin version [a65187fd5d].
Deleted applications/examples/private/content/en/default/index/whyweb2py.markmin version [d28d0c3ed9].
Deleted applications/examples/private/content/en/default/usergroups/grouplist.markmin version [0dc9361e64].
Deleted applications/examples/static/artwork.tar.gz version [29e1ed6f71].
Deleted applications/examples/static/bg.gif version [06957bce5d].
Deleted applications/examples/static/bg.png version [7047b59774].
Deleted applications/examples/static/css/artwork.css version [184a8c1dc1].
Deleted applications/examples/static/css/calendar.css version [be94f02d8c].
Deleted applications/examples/static/css/home.css version [e27ddc442c].
Deleted applications/examples/static/css/menu.css version [796415f51c].
Deleted applications/examples/static/epydoc/api-objects.txt version [07835d23e8].
Deleted applications/examples/static/epydoc/class-tree.html version [ba68f0f97c].
Deleted applications/examples/static/epydoc/crarr.png version [bcc1196f30].
Deleted applications/examples/static/epydoc/datetime.date-class.html version [f4d4483ada].
Deleted applications/examples/static/epydoc/datetime.datetime-class.html version [3fd874a974].
Deleted applications/examples/static/epydoc/datetime.time-class.html version [9e509d7714].
Deleted applications/examples/static/epydoc/epydoc.css version [586d28cf53].
Deleted applications/examples/static/epydoc/epydoc.js version [9f477dc176].
Deleted applications/examples/static/epydoc/exceptions.Exception-class.html version [f379659542].
Deleted applications/examples/static/epydoc/frames.html version [551171ca4e].
Deleted applications/examples/static/epydoc/help.html version [ab544c3828].
Deleted applications/examples/static/epydoc/identifier-index.html version [0a2be90a87].
Deleted applications/examples/static/epydoc/index.html version [551171ca4e].
Deleted applications/examples/static/epydoc/module-tree.html version [c599e47485].
Deleted applications/examples/static/epydoc/psycopg2-module.html version [26fe2ee9c5].
Deleted applications/examples/static/epydoc/psycopg2-pysrc.html version [d3e7cfc9c4].
Deleted applications/examples/static/epydoc/psycopg2.DataError-class.html version [ab191da1ee].
Deleted applications/examples/static/epydoc/psycopg2.DatabaseError-class.html version [7fe80798af].
Deleted applications/examples/static/epydoc/psycopg2.Error-class.html version [98de8f55d1].
Deleted applications/examples/static/epydoc/psycopg2.IntegrityError-class.html version [9ecedfb976].
Deleted applications/examples/static/epydoc/psycopg2.InterfaceError-class.html version [e709319c9c].
Deleted applications/examples/static/epydoc/psycopg2.InternalError-class.html version [c5cf33be98].
Deleted applications/examples/static/epydoc/psycopg2.NotSupportedError-class.html version [1f2478371d].
Deleted applications/examples/static/epydoc/psycopg2.OperationalError-class.html version [608497a402].
Deleted applications/examples/static/epydoc/psycopg2.ProgrammingError-class.html version [6c4dff9c05].
Deleted applications/examples/static/epydoc/psycopg2.Warning-class.html version [be3cdbc9fc].
Deleted applications/examples/static/epydoc/psycopg2.tz-module.html version [5c4671c67e].
Deleted applications/examples/static/epydoc/psycopg2.tz-pysrc.html version [5bfdfb6ac0].
Deleted applications/examples/static/epydoc/psycopg2.tz.FixedOffsetTimezone-class.html version [3eba9aaaca].
Deleted applications/examples/static/epydoc/psycopg2.tz.LocalTimezone-class.html version [654c1e9c12].
Deleted applications/examples/static/epydoc/redirect.html version [56928789d6].
Deleted applications/examples/static/epydoc/sqlite3.dbapi2-module.html version [57e6fdf38d].
Deleted applications/examples/static/epydoc/sqlite3.dbapi2-pysrc.html version [85bf49c164].
Deleted applications/examples/static/epydoc/title.png version [4ed899302f].
Deleted applications/examples/static/epydoc/toc-everything.html version [8a9b5797c5].
Deleted applications/examples/static/epydoc/toc-psycopg2-module.html version [6e8e39f6da].
Deleted applications/examples/static/epydoc/toc-psycopg2.tz-module.html version [b7670e47fa].
Deleted applications/examples/static/epydoc/toc-sqlite3.dbapi2-module.html version [cc3d655c7e].
Deleted applications/examples/static/epydoc/toc-web2py.gluon-module.html version [e5c2599ab2].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.admin-module.html version [a7e715d95c].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.cfs-module.html version [959737b8c7].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.compileapp-module.html version [93e4a8d8be].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.contenttype-module.html version [ee8e7493ad].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.contrib.pymysql-module.html version [dce5967558].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.contrib.pymysql.constants-module.html version [475eb8ccf2].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.contrib.pymysql.constants.FIELD_TYPE-module.html version [c597ca903f].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.contrib.pymysql.converters-module.html version [8395aec7ee].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.custom_import-module.html version [c00690a506].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.dal-module.html version [47ee44525c].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.debug-module.html version [044eae7ecb].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.decoder-module.html version [40d4d7156f].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.fileutils-module.html version [6fd241c0d3].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.globals-module.html version [935714ef40].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.highlight-module.html version [960d2f424a].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.html-module.html version [831543d28e].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.http-module.html version [508663cb02].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.import_all-module.html version [33e2761ec5].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.languages-module.html version [6fcbc298a9].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.main-module.html version [4f3509a60a].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.myregex-module.html version [6a946ca9dd].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.newcron-module.html version [d7b0aecedb].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.portalocker-module.html version [17809e2a47].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.reserved_sql_keywords-module.html version [79280176ff].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.restricted-module.html version [385bc2259a].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.rewrite-module.html version [6df2360817].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.rocket-module.html version [045556ff3d].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.sanitizer-module.html version [5a61ccd126].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.serializers-module.html version [4057bf45c4].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.settings-module.html version [306124ce3e].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.shell-module.html version [519c05b9fe].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.sql-module.html version [c78d181c06].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.sqlhtml-module.html version [a91cf4dccb].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.storage-module.html version [dc89bdea5d].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.streamer-module.html version [d41c4b72b1].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.template-module.html version [d3ae0a8298].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.tools-module.html version [f2cc8960ba].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.utils-module.html version [b0871ad0dd].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.validators-module.html version [43d57f7c44].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.widget-module.html version [02cb1ae712].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.winservice-module.html version [618bdc4f34].
Deleted applications/examples/static/epydoc/toc-web2py.gluon.xmlrpc-module.html version [f7f520eab7].
Deleted applications/examples/static/epydoc/toc.html version [a93743e4d3].
Deleted applications/examples/static/epydoc/web2py.gluon-module.html version [0ef563c871].
Deleted applications/examples/static/epydoc/web2py.gluon-pysrc.html version [4c786500d5].
Deleted applications/examples/static/epydoc/web2py.gluon.admin-module.html version [5cee0b8091].
Deleted applications/examples/static/epydoc/web2py.gluon.admin-pysrc.html version [8300f8ff59].
Deleted applications/examples/static/epydoc/web2py.gluon.cfs-module.html version [d599cce730].
Deleted applications/examples/static/epydoc/web2py.gluon.cfs-pysrc.html version [92e2709656].
Deleted applications/examples/static/epydoc/web2py.gluon.compileapp-module.html version [0dcf560404].
Deleted applications/examples/static/epydoc/web2py.gluon.compileapp-pysrc.html version [fa5f65d8df].
Deleted applications/examples/static/epydoc/web2py.gluon.compileapp.LoadFactory-class.html version [9b8934cb63].
Deleted applications/examples/static/epydoc/web2py.gluon.compileapp.mybuiltin-class.html version [4d85223ce5].
Deleted applications/examples/static/epydoc/web2py.gluon.contenttype-module.html version [04cba23f1a].
Deleted applications/examples/static/epydoc/web2py.gluon.contenttype-pysrc.html version [1f70e68e9f].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql-module.html version [41a3a21ee7].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql-pysrc.html version [18b8580005].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.DBAPISet-class.html version [68bd4d7cc5].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.constants-module.html version [977eeabb05].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.constants-pysrc.html version [b4f0e11b91].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.constants.FIELD_TYPE-module.html version [2bf8b6e0bd].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.constants.FIELD_TYPE-pysrc.html version [9a1c978d8f].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.converters-module.html version [996ec5e093].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.converters-pysrc.html version [fc4479fa6d].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.DataError-class.html version [ce29a6d9ad].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.DatabaseError-class.html version [c1d0dcc6c7].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.Error-class.html version [f786a98fc1].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.IntegrityError-class.html version [0e493dd542].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.InterfaceError-class.html version [1048eca9be].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.InternalError-class.html version [2e6096c089].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.NotSupportedError-class.html version [f170f4c50c].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.OperationalError-class.html version [4c5245a8ef].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.ProgrammingError-class.html version [a8eb2e37c9].
Deleted applications/examples/static/epydoc/web2py.gluon.contrib.pymysql.err.Warning-class.html version [556300840f].
Deleted applications/examples/static/epydoc/web2py.gluon.custom_import-module.html version [c401a77d12].
Deleted applications/examples/static/epydoc/web2py.gluon.custom_import-pysrc.html version [a03ed4d47f].
Deleted applications/examples/static/epydoc/web2py.gluon.custom_import._BaseImporter-class.html version [159e514682].
Deleted applications/examples/static/epydoc/web2py.gluon.custom_import._DateTrackerImporter-class.html version [00b9207621].
Deleted applications/examples/static/epydoc/web2py.gluon.custom_import._Web2pyDateTrackerImporter-class.html version [a2aa0dbfca].
Deleted applications/examples/static/epydoc/web2py.gluon.custom_import._Web2pyImporter-class.html version [7b8cb16291].
Deleted applications/examples/static/epydoc/web2py.gluon.dal-module.html version [ed310cf04e].
Deleted applications/examples/static/epydoc/web2py.gluon.dal-pysrc.html version [db12cff127].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.BaseAdapter-class.html version [a2f1c94717].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.ConnectionPool-class.html version [56bc1749c0].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.CouchDBAdapter-class.html version [478c363b53].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.CubridAdapter-class.html version [12de98219b].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.DAL-class.html version [dbaca854e9].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.DB2Adapter-class.html version [4684febe52].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.DatabaseStoredFile-class.html version [81f5061ea5].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Expression-class.html version [6f4cd3eb71].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Field-class.html version [8b5e77e0e7].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.FireBirdAdapter-class.html version [5dc9fba6a8].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.FireBirdEmbeddedAdapter-class.html version [22e07c62c5].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.GAEDecimalProperty-class.html version [a22ba41e73].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.GAEF-class.html version [65c549cf09].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.GoogleDatastoreAdapter-class.html version [48ef4914fd].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.GoogleSQLAdapter-class.html version [d43853aa04].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.InformixAdapter-class.html version [4f0255356e].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.IngresAdapter-class.html version [03ae703d89].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.IngresUnicodeAdapter-class.html version [be5498a12e].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.JDBCPostgreSQLAdapter-class.html version [c1ba390156].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.JDBCSQLiteAdapter-class.html version [b9fbe073cc].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.MSSQL2Adapter-class.html version [34da5cced1].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.MSSQLAdapter-class.html version [3e0138748b].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.MongoDBAdapter-class.html version [78efdc3075].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.MySQLAdapter-class.html version [4488c60f3a].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.NoSQLAdapter-class.html version [de152a958e].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.OracleAdapter-class.html version [b996aa01cd].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.PostgreSQLAdapter-class.html version [44e96ba098].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Query-class.html version [2e6b55b6e6].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Reference-class.html version [96b4ec80fb].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Row-class.html version [6d743fb6cd].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Rows-class.html version [d00146a602].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.SAPDBAdapter-class.html version [b90afb4928].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.SQLALL-class.html version [b90e82234d].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.SQLCallableList-class.html version [37b88fbccd].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.SQLCustomType-class.html version [0e67e537d3].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.SQLiteAdapter-class.html version [9a6c932756].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Set-class.html version [88937b4961].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.Table-class.html version [314362c35b].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.TeradataAdapter-class.html version [641bf6566e].
Deleted applications/examples/static/epydoc/web2py.gluon.dal.UseDatabaseStoredFile-class.html version [edea0c49ea].
Deleted applications/examples/static/epydoc/web2py.gluon.debug-module.html version [b5a47db524].
Deleted applications/examples/static/epydoc/web2py.gluon.debug-pysrc.html version [ac6d24e938].
Deleted applications/examples/static/epydoc/web2py.gluon.debug.Pipe-class.html version [bb56fead4a].
Deleted applications/examples/static/epydoc/web2py.gluon.decoder-module.html version [57f7996c02].
Deleted applications/examples/static/epydoc/web2py.gluon.decoder-pysrc.html version [e8f304d098].
Deleted applications/examples/static/epydoc/web2py.gluon.fileutils-module.html version [4077d6f0a7].
Deleted applications/examples/static/epydoc/web2py.gluon.fileutils-pysrc.html version [ce901d93fe].
Deleted applications/examples/static/epydoc/web2py.gluon.globals-module.html version [82dd89441e].
Deleted applications/examples/static/epydoc/web2py.gluon.globals-pysrc.html version [d0eae33eb6].
Deleted applications/examples/static/epydoc/web2py.gluon.globals.Request-class.html version [1d61817dd0].
Deleted applications/examples/static/epydoc/web2py.gluon.globals.Response-class.html version [5f39c060b7].
Deleted applications/examples/static/epydoc/web2py.gluon.globals.Session-class.html version [2843b7267c].
Deleted applications/examples/static/epydoc/web2py.gluon.highlight-module.html version [0c8acf3456].
Deleted applications/examples/static/epydoc/web2py.gluon.highlight-pysrc.html version [617e5de201].
Deleted applications/examples/static/epydoc/web2py.gluon.highlight.Highlighter-class.html version [a184022da3].
Deleted applications/examples/static/epydoc/web2py.gluon.html-module.html version [d91a1cb89b].
Deleted applications/examples/static/epydoc/web2py.gluon.html-pysrc.html version [bf0acc8ed2].
Deleted applications/examples/static/epydoc/web2py.gluon.html.A-class.html version [f778d0c1e3].
Deleted applications/examples/static/epydoc/web2py.gluon.html.B-class.html version [76e056e366].
Deleted applications/examples/static/epydoc/web2py.gluon.html.BEAUTIFY-class.html version [29b9d42f7a].
Deleted applications/examples/static/epydoc/web2py.gluon.html.BODY-class.html version [1635add987].
Deleted applications/examples/static/epydoc/web2py.gluon.html.BR-class.html version [9f2c90f163].
Deleted applications/examples/static/epydoc/web2py.gluon.html.BUTTON-class.html version [04b6110bdc].
Deleted applications/examples/static/epydoc/web2py.gluon.html.CAT-class.html version [993a43e91b].
Deleted applications/examples/static/epydoc/web2py.gluon.html.CENTER-class.html version [e3263e1c88].
Deleted applications/examples/static/epydoc/web2py.gluon.html.CODE-class.html version [a87c5b4520].
Deleted applications/examples/static/epydoc/web2py.gluon.html.COL-class.html version [bc360c4958].
Deleted applications/examples/static/epydoc/web2py.gluon.html.COLGROUP-class.html version [9a5f5114cd].
Deleted applications/examples/static/epydoc/web2py.gluon.html.DIV-class.html version [30fd838995].
Deleted applications/examples/static/epydoc/web2py.gluon.html.EM-class.html version [ff7a71b520].
Deleted applications/examples/static/epydoc/web2py.gluon.html.EMBED-class.html version [562b01e136].
Deleted applications/examples/static/epydoc/web2py.gluon.html.FIELDSET-class.html version [3dae8c1431].
Deleted applications/examples/static/epydoc/web2py.gluon.html.FORM-class.html version [98a4f6927b].
Deleted applications/examples/static/epydoc/web2py.gluon.html.H1-class.html version [addbcdaf68].
Deleted applications/examples/static/epydoc/web2py.gluon.html.H2-class.html version [47230b2e8b].
Deleted applications/examples/static/epydoc/web2py.gluon.html.H3-class.html version [ea39d09542].
Deleted applications/examples/static/epydoc/web2py.gluon.html.H4-class.html version [1e5c25a9dd].
Deleted applications/examples/static/epydoc/web2py.gluon.html.H5-class.html version [691497d1b9].
Deleted applications/examples/static/epydoc/web2py.gluon.html.H6-class.html version [5430bc41bf].
Deleted applications/examples/static/epydoc/web2py.gluon.html.HEAD-class.html version [e901afb86d].
Deleted applications/examples/static/epydoc/web2py.gluon.html.HR-class.html version [ebb94d83cd].
Deleted applications/examples/static/epydoc/web2py.gluon.html.HTML-class.html version [5b31ac3ac1].
Deleted applications/examples/static/epydoc/web2py.gluon.html.I-class.html version [7b5c5b12f8].
Deleted applications/examples/static/epydoc/web2py.gluon.html.IFRAME-class.html version [21c33eb3e3].
Deleted applications/examples/static/epydoc/web2py.gluon.html.IMG-class.html version [11843c218a].
Deleted applications/examples/static/epydoc/web2py.gluon.html.INPUT-class.html version [98d72b4044].
Deleted applications/examples/static/epydoc/web2py.gluon.html.LABEL-class.html version [c6c8c8201f].
Deleted applications/examples/static/epydoc/web2py.gluon.html.LEGEND-class.html version [9af1325424].
Deleted applications/examples/static/epydoc/web2py.gluon.html.LI-class.html version [31fe1ad440].
Deleted applications/examples/static/epydoc/web2py.gluon.html.LINK-class.html version [ea3a21fbec].
Deleted applications/examples/static/epydoc/web2py.gluon.html.MARKMIN-class.html version [e8a1d40082].
Deleted applications/examples/static/epydoc/web2py.gluon.html.MENU-class.html version [98e5b2ac14].
Deleted applications/examples/static/epydoc/web2py.gluon.html.META-class.html version [4277516f23].
Deleted applications/examples/static/epydoc/web2py.gluon.html.OBJECT-class.html version [37bc31528c].
Deleted applications/examples/static/epydoc/web2py.gluon.html.OL-class.html version [dfd352c2d7].
Deleted applications/examples/static/epydoc/web2py.gluon.html.OPTGROUP-class.html version [d16b317279].
Deleted applications/examples/static/epydoc/web2py.gluon.html.OPTION-class.html version [ec220c7b19].
Deleted applications/examples/static/epydoc/web2py.gluon.html.P-class.html version [edaf60a08f].
Deleted applications/examples/static/epydoc/web2py.gluon.html.PRE-class.html version [7bc1129656].
Deleted applications/examples/static/epydoc/web2py.gluon.html.SCRIPT-class.html version [b07e17418a].
Deleted applications/examples/static/epydoc/web2py.gluon.html.SELECT-class.html version [240e05e400].
Deleted applications/examples/static/epydoc/web2py.gluon.html.SPAN-class.html version [a566cd3553].
Deleted applications/examples/static/epydoc/web2py.gluon.html.STYLE-class.html version [97c785cce6].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TABLE-class.html version [a37ed87427].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TBODY-class.html version [2d87050f29].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TD-class.html version [d0b7dd5842].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TEXTAREA-class.html version [78dabbe178].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TFOOT-class.html version [bdb5980fdc].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TH-class.html version [867786066c].
Deleted applications/examples/static/epydoc/web2py.gluon.html.THEAD-class.html version [711ceac1ad].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TITLE-class.html version [4713aa96ff].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TR-class.html version [3f28a2fb41].
Deleted applications/examples/static/epydoc/web2py.gluon.html.TT-class.html version [1da78823d0].
Deleted applications/examples/static/epydoc/web2py.gluon.html.UL-class.html version [302744e135].
Deleted applications/examples/static/epydoc/web2py.gluon.html.XHTML-class.html version [18a5234b59].
Deleted applications/examples/static/epydoc/web2py.gluon.html.XML-class.html version [6a4887778e].
Deleted applications/examples/static/epydoc/web2py.gluon.html.XmlComponent-class.html version [a967ed3e51].
Deleted applications/examples/static/epydoc/web2py.gluon.html.__TAG__-class.html version [4becefb1f6].
Deleted applications/examples/static/epydoc/web2py.gluon.html.web2pyHTMLParser-class.html version [e2ecc8b067].
Deleted applications/examples/static/epydoc/web2py.gluon.http-module.html version [6ce42b522a].
Deleted applications/examples/static/epydoc/web2py.gluon.http-pysrc.html version [7b89febbf3].
Deleted applications/examples/static/epydoc/web2py.gluon.http.HTTP-class.html version [b058fe165d].
Deleted applications/examples/static/epydoc/web2py.gluon.import_all-module.html version [ab566a9b0d].
Deleted applications/examples/static/epydoc/web2py.gluon.import_all-pysrc.html version [7b0dd0251d].
Deleted applications/examples/static/epydoc/web2py.gluon.languages-module.html version [b32d97ebcd].
Deleted applications/examples/static/epydoc/web2py.gluon.languages-pysrc.html version [f0d761253d].
Deleted applications/examples/static/epydoc/web2py.gluon.languages.lazyT-class.html version [608a957eab].
Deleted applications/examples/static/epydoc/web2py.gluon.languages.translator-class.html version [13b6665364].
Deleted applications/examples/static/epydoc/web2py.gluon.main-module.html version [e85679a056].
Deleted applications/examples/static/epydoc/web2py.gluon.main-pysrc.html version [68c2220c95].
Deleted applications/examples/static/epydoc/web2py.gluon.main.HttpServer-class.html version [092b33f577].
Deleted applications/examples/static/epydoc/web2py.gluon.myregex-module.html version [27c3fcabeb].
Deleted applications/examples/static/epydoc/web2py.gluon.myregex-pysrc.html version [51b8151960].
Deleted applications/examples/static/epydoc/web2py.gluon.newcron-module.html version [f86e28bd63].
Deleted applications/examples/static/epydoc/web2py.gluon.newcron-pysrc.html version [9bd2024050].
Deleted applications/examples/static/epydoc/web2py.gluon.newcron.Token-class.html version [9ba2119fd9].
Deleted applications/examples/static/epydoc/web2py.gluon.newcron.cronlauncher-class.html version [0f2ad75d98].
Deleted applications/examples/static/epydoc/web2py.gluon.newcron.extcron-class.html version [6f5e36ade8].
Deleted applications/examples/static/epydoc/web2py.gluon.newcron.hardcron-class.html version [9abcc7fc37].
Deleted applications/examples/static/epydoc/web2py.gluon.newcron.softcron-class.html version [0eda98b583].
Deleted applications/examples/static/epydoc/web2py.gluon.portalocker-module.html version [9831377c12].
Deleted applications/examples/static/epydoc/web2py.gluon.portalocker-pysrc.html version [752e06577e].
Deleted applications/examples/static/epydoc/web2py.gluon.reserved_sql_keywords-module.html version [3a8937131a].
Deleted applications/examples/static/epydoc/web2py.gluon.reserved_sql_keywords-pysrc.html version [acfd6e6533].
Deleted applications/examples/static/epydoc/web2py.gluon.restricted-module.html version [06ba297d7b].
Deleted applications/examples/static/epydoc/web2py.gluon.restricted-pysrc.html version [50d9c26e40].
Deleted applications/examples/static/epydoc/web2py.gluon.restricted.RestrictedError-class.html version [8cbd3440b3].
Deleted applications/examples/static/epydoc/web2py.gluon.restricted.TicketStorage-class.html version [d802399b10].
Deleted applications/examples/static/epydoc/web2py.gluon.rewrite-module.html version [4fd757034e].
Deleted applications/examples/static/epydoc/web2py.gluon.rewrite-pysrc.html version [11da0e715c].
Deleted applications/examples/static/epydoc/web2py.gluon.rewrite.MapUrlIn-class.html version [894993d987].
Deleted applications/examples/static/epydoc/web2py.gluon.rewrite.MapUrlOut-class.html version [08c1f2da91].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket-module.html version [f74f937a0f].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket-pysrc.html version [b4481f1ec0].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.BadRequest-class.html version [651b63d531].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.ChunkedReader-class.html version [a3e63b2fa3].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.Connection-class.html version [ad196c58f0].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.FileWrapper-class.html version [8c90c0c649].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.Headers-class.html version [2e33dc67c8].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.Listener-class.html version [7580afb6ae].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.Monitor-class.html version [e0283ec8a4].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.NullHandler-class.html version [7d5333f4d6].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.Rocket-class.html version [33e74898b0].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.SSLError-class.html version [d2b28b62bc].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.SocketClosed-class.html version [726b4508b3].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.SocketTimeout-class.html version [cb588b8631].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.ThreadPool-class.html version [f0c9541be1].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.WSGIWorker-class.html version [e8e022554d].
Deleted applications/examples/static/epydoc/web2py.gluon.rocket.Worker-class.html version [b6709670c1].
Deleted applications/examples/static/epydoc/web2py.gluon.sanitizer-module.html version [23b78e7017].
Deleted applications/examples/static/epydoc/web2py.gluon.sanitizer-pysrc.html version [3639cbca25].
Deleted applications/examples/static/epydoc/web2py.gluon.sanitizer.XssCleaner-class.html version [0c43de2900].
Deleted applications/examples/static/epydoc/web2py.gluon.serializers-module.html version [581c663b6c].
Deleted applications/examples/static/epydoc/web2py.gluon.serializers-pysrc.html version [96244d03e5].
Deleted applications/examples/static/epydoc/web2py.gluon.settings-module.html version [fff7c202aa].
Deleted applications/examples/static/epydoc/web2py.gluon.settings-pysrc.html version [800fd79f7c].
Deleted applications/examples/static/epydoc/web2py.gluon.shell-module.html version [4c84b22959].
Deleted applications/examples/static/epydoc/web2py.gluon.shell-pysrc.html version [b8f1d47055].
Deleted applications/examples/static/epydoc/web2py.gluon.sql-module.html version [8f4ab78faa].
Deleted applications/examples/static/epydoc/web2py.gluon.sql-pysrc.html version [5b6ff9af99].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml-module.html version [85cd1307e2].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml-pysrc.html version [d3355e996d].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.AutocompleteWidget-class.html version [e91a87be60].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.BooleanWidget-class.html version [08938972d4].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.CheckboxesWidget-class.html version [4f090369f9].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.DateWidget-class.html version [72b32f43b6].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.DatetimeWidget-class.html version [c10a4ab6e4].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.DecimalWidget-class.html version [17f96e5e6b].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.DoubleWidget-class.html version [a9be972484].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.FormWidget-class.html version [338a187a3c].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.IntegerWidget-class.html version [a62cbb9a79].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.ListWidget-class.html version [1a94f33f59].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.MultipleOptionsWidget-class.html version [f2a494bd6d].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.OptionsWidget-class.html version [9b11fe669d].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.PasswordWidget-class.html version [f1e8b8d8da].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.RadioWidget-class.html version [ae1acf17b8].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.SQLFORM-class.html version [edc7f7054d].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.SQLTABLE-class.html version [1564b6b370].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.StringWidget-class.html version [0ecfd8d20e].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.TextWidget-class.html version [36972c8e6f].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.TimeWidget-class.html version [d23e90b78a].
Deleted applications/examples/static/epydoc/web2py.gluon.sqlhtml.UploadWidget-class.html version [b0f6dd97bb].
Deleted applications/examples/static/epydoc/web2py.gluon.storage-module.html version [22860bb95b].
Deleted applications/examples/static/epydoc/web2py.gluon.storage-pysrc.html version [7202e1902a].
Deleted applications/examples/static/epydoc/web2py.gluon.storage.List-class.html version [2adef8ff7c].
Deleted applications/examples/static/epydoc/web2py.gluon.storage.Messages-class.html version [6479cfbe5f].
Deleted applications/examples/static/epydoc/web2py.gluon.storage.Settings-class.html version [ea231522f4].
Deleted applications/examples/static/epydoc/web2py.gluon.storage.Storage-class.html version [3ed9ef189a].
Deleted applications/examples/static/epydoc/web2py.gluon.storage.StorageList-class.html version [05265dd36e].
Deleted applications/examples/static/epydoc/web2py.gluon.streamer-module.html version [55c2cca87c].
Deleted applications/examples/static/epydoc/web2py.gluon.streamer-pysrc.html version [ae3e5a2180].
Deleted applications/examples/static/epydoc/web2py.gluon.template-module.html version [506ca3853b].
Deleted applications/examples/static/epydoc/web2py.gluon.template-pysrc.html version [250231be3f].
Deleted applications/examples/static/epydoc/web2py.gluon.template.BlockNode-class.html version [6aecc39ca0].
Deleted applications/examples/static/epydoc/web2py.gluon.template.Content-class.html version [b5705562dd].
Deleted applications/examples/static/epydoc/web2py.gluon.template.Node-class.html version [d501b4ab8c].
Deleted applications/examples/static/epydoc/web2py.gluon.template.SuperNode-class.html version [5767e3e489].
Deleted applications/examples/static/epydoc/web2py.gluon.template.TemplateParser-class.html version [9d42f2d6b0].
Deleted applications/examples/static/epydoc/web2py.gluon.tools-module.html version [74144a5a07].
Deleted applications/examples/static/epydoc/web2py.gluon.tools-pysrc.html version [8335dd38ee].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.Auth-class.html version [0fe1527bc2].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.Crud-class.html version [d056f83bae].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.Mail-class.html version [9399bb8613].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.Mail.Attachment-class.html version [d687f3b0e3].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.PluginManager-class.html version [89ed9f3413].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.Recaptcha-class.html version [5b47346c89].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.Service-class.html version [b8dda85409].
Deleted applications/examples/static/epydoc/web2py.gluon.tools.Service.JsonRpcException-class.html version [9e958ec2fc].
Deleted applications/examples/static/epydoc/web2py.gluon.utils-module.html version [d89a1ae043].
Deleted applications/examples/static/epydoc/web2py.gluon.utils-pysrc.html version [b1d3d5db34].
Deleted applications/examples/static/epydoc/web2py.gluon.validators-module.html version [73d78f5035].
Deleted applications/examples/static/epydoc/web2py.gluon.validators-pysrc.html version [55a281d17d].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.CLEANUP-class.html version [d416dac2c4].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.CRYPT-class.html version [c1b29fea74].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_ALPHANUMERIC-class.html version [2258723eba].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_DATE-class.html version [bc026fbc4d].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_DATETIME-class.html version [731336b4d9].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_DATETIME_IN_RANGE-class.html version [f4950f15af].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_DATE_IN_RANGE-class.html version [463f057d3a].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_DECIMAL_IN_RANGE-class.html version [df2914c3a1].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_EMAIL-class.html version [bba401f554].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_EMPTY_OR-class.html version [29849818be].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_EQUAL_TO-class.html version [c2b68c5868].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_EXPR-class.html version [fa286666d7].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_FLOAT_IN_RANGE-class.html version [5667043e98].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_GENERIC_URL-class.html version [82072b9c87].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_HTTP_URL-class.html version [1faacb2d20].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_IMAGE-class.html version [81c19d5d14].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_INT_IN_RANGE-class.html version [67bc87516f].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_IN_DB-class.html version [f9ee0fb36d].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_IN_SET-class.html version [9aff693eab].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_IN_SUBSET-class.html version [389d421840].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_IPV4-class.html version [cbb515ef29].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_LENGTH-class.html version [c75fdddd52].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_LIST_OF-class.html version [26a870e373].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_LOWER-class.html version [b9a3c963ad].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_MATCH-class.html version [f2f2d3dee0].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_NOT_EMPTY-class.html version [bbf8d9338b].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_NOT_IN_DB-class.html version [fbecc9eaf1].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_SLUG-class.html version [cea5b54853].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_STRONG-class.html version [13727bb29d].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_TIME-class.html version [804c06f151].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_UPLOAD_FILENAME-class.html version [8fe772013c].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_UPPER-class.html version [a47aa53cb4].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.IS_URL-class.html version [36554a2958].
Deleted applications/examples/static/epydoc/web2py.gluon.validators.Validator-class.html version [288c8a8613].
Deleted applications/examples/static/epydoc/web2py.gluon.widget-module.html version [55a9443924].
Deleted applications/examples/static/epydoc/web2py.gluon.widget-pysrc.html version [12134bd7a0].
Deleted applications/examples/static/epydoc/web2py.gluon.widget.IO-class.html version [e1bc460720].
Deleted applications/examples/static/epydoc/web2py.gluon.widget.web2pyDialog-class.html version [e156c1b12b].
Deleted applications/examples/static/epydoc/web2py.gluon.winservice-module.html version [ad44be3833].
Deleted applications/examples/static/epydoc/web2py.gluon.winservice-pysrc.html version [cc36810a51].
Deleted applications/examples/static/epydoc/web2py.gluon.winservice.Service-class.html version [9f5d94f195].
Deleted applications/examples/static/epydoc/web2py.gluon.winservice.Web2pyService-class.html version [c8466002fb].
Deleted applications/examples/static/epydoc/web2py.gluon.xmlrpc-module.html version [2d16f1c210].
Deleted applications/examples/static/epydoc/web2py.gluon.xmlrpc-pysrc.html version [93a1d9e415].
Deleted applications/examples/static/favicon.ico version [8849e0925e].
Deleted applications/examples/static/img/Menu-2.png version [582b8c90b9].
Deleted applications/examples/static/img/Stickers1.png version [1cc869aeae].
Deleted applications/examples/static/img/Stickers2.png version [0baee84b0d].
Deleted applications/examples/static/img/Stickers3.png version [219edabd06].
Deleted applications/examples/static/img/Stickers4.png version [a4569b8a88].
Deleted applications/examples/static/img/Stickers5.png version [ed683e2c0e].
Deleted applications/examples/static/img/Stickers6.png version [fe1b73261d].
Deleted applications/examples/static/img/Stickers7.png version [6916525230].
Deleted applications/examples/static/img/Stickers8.png version [a4569b8a88].
Deleted applications/examples/static/img/back-02.png version [9701d17c04].
Deleted applications/examples/static/img/back-03.png version [6503c7eff4].
Deleted applications/examples/static/img/back-04.png version [5a0138a6a3].
Deleted applications/examples/static/img/back-05.png version [add7d156f9].
Deleted applications/examples/static/img/back-R-02.png version [a171e00107].
Deleted applications/examples/static/img/demo.png version [3b18867ab1].
Deleted applications/examples/static/img/favicon.ico version [8849e0925e].
Deleted applications/examples/static/img/favicon.png version [7b090af72f].
Deleted applications/examples/static/img/gluon.png version [a0e4c56a96].
Deleted applications/examples/static/img/icons/1283521892_my-account.png version [7e09b563ce].
Deleted applications/examples/static/img/icons/1283522082_phone.png version [737f51280e].
Deleted applications/examples/static/img/icons/1283522094_email.png version [fbf1aad3fc].
Deleted applications/examples/static/img/icons/1283522104_sign-up.png version [4bb9e9abaf].
Deleted applications/examples/static/img/icons/1283522131_contact.png version [eb8e575e41].
Deleted applications/examples/static/img/icons/1283522158_login.png version [a852b7e943].
Deleted applications/examples/static/img/icons/1283522183_twitter.png version [e387dafe9a].
Deleted applications/examples/static/img/icons/1283522183_video.png version [9cea6af59e].
Deleted applications/examples/static/img/icons/1283522207_library.png version [fb8d2842de].
Deleted applications/examples/static/img/icons/1283522229_cv.png version [287176c0b4].
Deleted applications/examples/static/img/icons/1283522239_order-2.png version [a483819e8c].
Deleted applications/examples/static/img/icons/1283523038_multi-agents.png version [f0dab5831e].
Deleted applications/examples/static/img/icons/1283523136_chat.png version [46b5eb9831].
Deleted applications/examples/static/img/icons/1283523297_email.png version [741e4535eb].
Deleted applications/examples/static/img/icons/1283523332_calculator.png version [6f1b9c3e25].
Deleted applications/examples/static/img/icons/1283523626_search.png version [57e7773dc0].
Deleted applications/examples/static/img/icons/1283524371_calculator.png version [6f1b9c3e25].
Deleted applications/examples/static/img/icons/1283524386_mobile.png version [c123654af5].
Deleted applications/examples/static/img/icons/1283524452_cloud-filled.png version [c703e5329e].
Deleted applications/examples/static/img/icons/1283524467_home.png version [c39317e9f3].
Deleted applications/examples/static/img/icons/1285713038_video32.png version [cc0174e792].
Deleted applications/examples/static/img/icons/CHAT_32x32-32.png version [f67fac2bbc].
Deleted applications/examples/static/img/icons/FILE_32x32-32.png version [30c8fa7d0d].
Deleted applications/examples/static/img/icons/FOLDER - DOWNLOAD_32x32-32.png version [02f9dd179c].
Deleted applications/examples/static/img/icons/FOLDER - FONTS_32x32-32.png version [8015d19bb7].
Deleted applications/examples/static/img/icons/FOLDER - GAMES_32x32-32.png version [a8fa142c61].
Deleted applications/examples/static/img/icons/FOLDER - INTERNET_32x32-32.png version [21cb12f786].
Deleted applications/examples/static/img/icons/FOLDER - MUSIC_32x32-32.png version [0dc5fed446].
Deleted applications/examples/static/img/icons/FOLDER - PICTURES_32x32-32.png version [30443f2575].
Deleted applications/examples/static/img/icons/FOLDER - PRINTER_32x32-32.png version [d57186a10e].
Deleted applications/examples/static/img/icons/FOLDER_32x32-32.png version [3afaa5d3f9].
Deleted applications/examples/static/img/icons/HELP_32x32-32.png version [61ea918c20].
Deleted applications/examples/static/img/icons/NETWORK - FOLDER OPEN_32x32-32.png version [b902a6e47e].
Deleted applications/examples/static/img/icons/TV_32x32-32.png version [b20a1ebbd9].
Deleted applications/examples/static/img/icons/TWEET DECK_32x32-32.png version [7fb948b811].
Deleted applications/examples/static/img/icons/_README_ecqlipse.2.png.txt version [09350ce7a0].
Deleted applications/examples/static/img/icons/appliances.png version [063b19a7d4].
Deleted applications/examples/static/img/icons/demo.png version [252d60a3a8].
Deleted applications/examples/static/img/icons/examples.png version [8754de2d2c].
Deleted applications/examples/static/img/icons/livechat.png version [5ce0fc3220].
Deleted applications/examples/static/img/icons/plugins.png version [b1c3a150ad].
Deleted applications/examples/static/img/icons/slices.png version [9ebf1550d8].
Deleted applications/examples/static/img/icons/tutorials.png version [c2433dd331].
Deleted applications/examples/static/img/icons/twitter.png version [f5cbfb42b8].
Deleted applications/examples/static/img/icons/usergroups.png version [b7139dde61].
Deleted applications/examples/static/img/icons/uservoice.png version [0d71619532].
Deleted applications/examples/static/img/icons/videos.png version [639320ebef].
Deleted applications/examples/static/img/logo3Tones.png version [64bc8f5bd2].
Deleted applications/examples/static/img/logo_bw.png version [302b12b7b3].
Deleted applications/examples/static/img/logo_db.png version [5d5033eca0].
Deleted applications/examples/static/img/logo_lb.png version [1ce85f083c].
Deleted applications/examples/static/img/netdow1.png version [475141bba7].
Deleted applications/examples/static/img/netdow2.png version [c39b6d2525].
Deleted applications/examples/static/img/netdow3.png version [c703e5329e].
Deleted applications/examples/static/img/online_book_cover.jpg version [bf3c689113].
Deleted applications/examples/static/img/tipDownloads.png version [2ad4b350e0].
Deleted applications/examples/static/img/tipDownloads2.png version [b4becb3823].
Deleted applications/examples/static/img/web2py_logo.png version [2479398bdc].
Deleted applications/examples/static/js/calendar.js version [dabf984f8c].
Deleted applications/examples/static/js/jquery.js version [7622c9ac23].
Deleted applications/examples/static/js/web2py_ajax.js version [7f2851f561].
Deleted applications/examples/static/kpax.png version [df86cf8c7e].
Deleted applications/examples/static/markmin.html version [770a4eca1c].
Deleted applications/examples/static/powered_by/web2py_sticker_3d8799.png version [3410a7393c].
Deleted applications/examples/static/powered_by/web2py_sticker_3d9960.png version [60ea143977].
Deleted applications/examples/static/powered_by/web2py_sticker_463d99.png version [d480bd13ee].
Deleted applications/examples/static/powered_by/web2py_sticker_73993d.png version [f8846c2722].
Deleted applications/examples/static/powered_by/web2py_sticker_993d3d.png version [9b86140ee1].
Deleted applications/examples/static/powered_by/web2py_sticker_993d98.png version [0272dcf2f5].
Deleted applications/examples/static/powered_by/web2py_sticker_996f3d.png version [873403388a].
Deleted applications/examples/static/powered_by/web2py_sticker_99963d.png version [ccc377131a].
Deleted applications/examples/static/robots.txt version [00914a3dbd].
Deleted applications/examples/static/title.png version [4ed899302f].
Deleted applications/examples/static/web2py_contributor_agreement.pdf version [ff68111ffe].
Deleted applications/examples/static/web2py_logo.png version [2479398bdc].
Deleted applications/examples/static/web2py_logo_light.png version [9bb63c121c].
Deleted applications/examples/views/ajax_examples/fade.html version [e7aa5189d8].
Deleted applications/examples/views/ajax_examples/index.html version [2fd6a0649e].
Deleted applications/examples/views/appadmin.html version [3b13f939eb].
Deleted applications/examples/views/database_examples/buy.html version [9c79d70cf8].
Deleted applications/examples/views/database_examples/register_dog.html version [ea088337e6].
Deleted applications/examples/views/database_examples/register_product.html version [a2de7211fd].
Deleted applications/examples/views/database_examples/register_user.html version [6c99ba526d].
Deleted applications/examples/views/default/changelog.html version [51c880bb1f].
Deleted applications/examples/views/default/documentation.html version [8968f7f1ba].
Deleted applications/examples/views/default/download.html version [fcd696b3fd].
Deleted applications/examples/views/default/examples.html version [ed383c3b10].
Deleted applications/examples/views/default/index.html version [500a555007].
Deleted applications/examples/views/default/license.html version [77628486a9].
Deleted applications/examples/views/default/support.html version [b6989e8a95].
Deleted applications/examples/views/default/usergroups.html version [d8a8ea5563].
Deleted applications/examples/views/default/videos.html version [091e89e96a].
Deleted applications/examples/views/default/what.html version [5c10370384].
Deleted applications/examples/views/default/who.html version [7161e119e7].
Deleted applications/examples/views/generic.html version [8c1f46b26e].
Deleted applications/examples/views/generic.json version [25f5fba8a2].
Deleted applications/examples/views/generic.load version [d38b6c52f3].
Deleted applications/examples/views/generic.rss version [f16be9a903].
Deleted applications/examples/views/generic.xml version [8aecf60dfa].
Deleted applications/examples/views/global/vars.html version [8910c2a98c].
Deleted applications/examples/views/images_examples/index.html version [4ef87f3eab].
Deleted applications/examples/views/layout.html version [530cee6691].
Deleted applications/examples/views/layout_examples/basic.html version [503baf211e].
Deleted applications/examples/views/layout_examples/civilized.html version [25695445ff].
Deleted applications/examples/views/layout_examples/layout_civilized.html version [27fc938344].
Deleted applications/examples/views/layout_examples/layout_sleek.html version [42c67a5f4b].
Deleted applications/examples/views/layout_examples/slick.html version [0e1addb63a].
Deleted applications/examples/views/session_examples/counter.html version [209e13c459].
Deleted applications/examples/views/simple_examples/hello3.html version [f5821e98a8].
Deleted applications/examples/views/spreadsheet/index.html version [8d31ea574b].
Deleted applications/examples/views/template_examples/beautify.html version [7fe049ca86].
Deleted applications/examples/views/template_examples/escape.html version [2424b92746].
Deleted applications/examples/views/template_examples/test_def.html version [279b8cba35].
Deleted applications/examples/views/template_examples/test_for.html version [c3bacad07e].
Deleted applications/examples/views/template_examples/test_if.html version [b03b1579a9].
Deleted applications/examples/views/template_examples/test_try.html version [a5abc71db7].
Deleted applications/examples/views/template_examples/variables.html version [f24dbec526].
Deleted applications/examples/views/template_examples/xml.html version [e0927413bf].
Deleted applications/examples/views/web2py_ajax.html version [679a48264c].
Modified applications/mobileblur/controllers/default.py from [f7fe7a35c9] to [b38b4efcae].
1
2
3
4
5
6
7
8
9
10
11
12
13















from pprint import pprint

def index():
    raw_feeds = newsblur.feeds(flat=True)["feeds"]
    feeds = {}
    for feed in raw_feeds.itervalues():
        for i in range(threshold, 2):
            if feed[thresholds[i]] > 0:
                feeds[feed["feed_title"]] = feed
                break

    pprint(feeds)
    return dict(feeds=feeds, threshold=threshold)


























<

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pprint import pprint

def index():
    raw_feeds = newsblur.feeds(flat=True)["feeds"]
    feeds = {}
    for feed in raw_feeds.itervalues():
        for i in range(threshold, 2):
            if feed[thresholds[i]] > 0:
                feeds[feed["feed_title"]] = feed
                break


    return dict(feeds=feeds, threshold=threshold)


def login():
    login_form = SQLFORM.factory(
        Field("username", requires=IS_NOT_EMPTY()),
        Field("password", "password", requires=IS_NOT_EMPTY())
    )
    if login_form.accepts(request):
        results = newsblur.login(login_form.vars["username"], login_form.vars["password"])
        response.cookies["nb_cookie"] = newsblur.cookies
        response.cookies["nb_cookie"]["path"] = "/"
        print "cookie =", newsblur.cookies
        redirect(URL("index"))

    return dict(login_form=login_form)
Modified applications/mobileblur/models/0_helpers.py from [d9e34b5918] to [6363f858c9].
1
2
3
4
5
6
7
8



9
newsblur = local_import("newsblur")

threshold = 0
thresholds = ["nt", "ps", "ng"]  # indices -1, 0, 1 for negative, neutral, and positive intelligence filters

def login(username="spiffytech"):
    user = db(db.users.username==username).select().first()
    if user["cookie"] is None:



        results = newsblur.login(user["username"], user["password"])





|
|
|
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
newsblur = local_import("newsblur")

threshold = 0
thresholds = ["nt", "ps", "ng"]  # indices -1, 0, 1 for negative, neutral, and positive intelligence filters

#import ipdb
#ipdb.set_trace()
if "nb_cookie" not in request.cookies.keys():
    if [request.application, request.controller, request.function] != [request.application, "default", "login"]:
        redirect(URL("default", "login"))
#else:
#    newsblur.cookies = request.cookies["nb_cookie"]
Modified applications/mobileblur/models/db.py from [9c80a3439c] to [34c2cab0a7].
30
31
32
33
34
35
36

37
38
39
40
41
42
43
## - crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Mail, Auth, Crud, Service, PluginManager, prettydate
mail = Mail()                                  # mailer
auth = Auth(db)                                # authentication/authorization

crud = Crud(db)                                # for CRUD helpers using auth
service = Service()                            # for json, xml, jsonrpc, xmlrpc, amfrpc
plugins = PluginManager()                      # for configuring plugins

mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
mail.settings.sender = 'you@gmail.com'         # your email
mail.settings.login = 'username:password'      # your credentials or None







>







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## - crud actions
## (more options discussed in gluon/tools.py)
#########################################################################

from gluon.tools import Mail, Auth, Crud, Service, PluginManager, prettydate
mail = Mail()                                  # mailer
auth = Auth(db)                                # authentication/authorization

crud = Crud(db)                                # for CRUD helpers using auth
service = Service()                            # for json, xml, jsonrpc, xmlrpc, amfrpc
plugins = PluginManager()                      # for configuring plugins

mail.settings.server = 'logging' or 'smtp.gmail.com:587'  # your SMTP server
mail.settings.sender = 'you@gmail.com'         # your email
mail.settings.login = 'username:password'      # your credentials or None
82
83
84
85
86
87
88
89
#########################################################################

db.define_table("users",
    Field("username"),
    Field("password"),
    Field("cookie")
)
login()







<
83
84
85
86
87
88
89

#########################################################################

db.define_table("users",
    Field("username"),
    Field("password"),
    Field("cookie")
)

Added applications/mobileblur/views/default/login.html version [52a0d74dbd].
Deleted applications/welcome/ABOUT version [f4515d4b07].
Deleted applications/welcome/LICENSE version [23c98cb4b6].
Deleted applications/welcome/__init__.py version [da39a3ee5e].
Deleted applications/welcome/controllers/appadmin.py version [1eb6fe022d].
Deleted applications/welcome/controllers/default.py version [2692ae6403].
Deleted applications/welcome/cron/crontab version [2523d8a048].
Deleted applications/welcome/languages/es-es.py version [02c08ffea8].
Deleted applications/welcome/languages/fr-ca.py version [a1c8c80bd7].
Deleted applications/welcome/languages/fr-fr.py version [12b6d60c6d].
Deleted applications/welcome/languages/hi-hi.py version [568b21ea86].
Deleted applications/welcome/languages/hu-hu.py version [cbea9c4c52].
Deleted applications/welcome/languages/hu.py version [cbea9c4c52].
Deleted applications/welcome/languages/it-it.py version [968a746998].
Deleted applications/welcome/languages/it.py version [968a746998].
Deleted applications/welcome/languages/pl-pl.py version [92556d9416].
Deleted applications/welcome/languages/pl.py version [1cc9928895].
Deleted applications/welcome/languages/pt-br.py version [359b67f161].
Deleted applications/welcome/languages/pt-pt.py version [6f522fc1e4].
Deleted applications/welcome/languages/pt.py version [6f522fc1e4].
Deleted applications/welcome/languages/ru-ru.py version [628e206f31].
Deleted applications/welcome/languages/sk-sk.py version [928c03512a].
Deleted applications/welcome/languages/zh-tw.py version [b37aeebf91].
Deleted applications/welcome/models/db.py version [f6575d3cb8].
Deleted applications/welcome/models/menu.py version [2fb70868d5].
Deleted applications/welcome/modules/__init__.py version [da39a3ee5e].
Deleted applications/welcome/static/css/base.css version [0353986da0].
Deleted applications/welcome/static/css/calendar.css version [263a0ae7af].
Deleted applications/welcome/static/css/handheld.css version [721460498f].
Deleted applications/welcome/static/css/superfish-navbar.css version [f80d0fda82].
Deleted applications/welcome/static/css/superfish-vertical.css version [cc09787089].
Deleted applications/welcome/static/css/superfish.css version [e354e3670d].
Deleted applications/welcome/static/favicon.ico version [8849e0925e].
Deleted applications/welcome/static/images/arrows-ffffff.png version [848c456cab].
Deleted applications/welcome/static/images/css3buttons_backgrounds.png version [373872c147].
Deleted applications/welcome/static/images/css3buttons_icons.png version [3d43fcf538].
Deleted applications/welcome/static/images/error.png version [a460cc5cea].
Deleted applications/welcome/static/images/ok.png version [64ef5ff48b].
Deleted applications/welcome/static/images/poweredby.png version [0baee84b0d].
Deleted applications/welcome/static/images/shadow.png version [7ea95cf0e2].
Deleted applications/welcome/static/images/warn.png version [5b675a6959].
Deleted applications/welcome/static/images/warning.png version [9c06299898].
Deleted applications/welcome/static/js/calendar.js version [ee22da85cc].
Deleted applications/welcome/static/js/dd_belatedpng.js version [11ff3e17f1].
Deleted applications/welcome/static/js/jquery.js version [7622c9ac23].
Deleted applications/welcome/static/js/modernizr-1.7.min.js version [96922cbe86].
Deleted applications/welcome/static/js/superfish.js version [b7b4fdd4a0].
Deleted applications/welcome/static/js/web2py_ajax.js version [7f2851f561].
Deleted applications/welcome/static/robots.txt version [32c4950688].
Deleted applications/welcome/views/__init__.py version [da39a3ee5e].
Deleted applications/welcome/views/appadmin.html version [3b13f939eb].
Deleted applications/welcome/views/default/index.html version [58e990f1c8].
Deleted applications/welcome/views/default/user.html version [7cba4a5dbc].
Deleted applications/welcome/views/generic.html version [5ecbd3689c].
Deleted applications/welcome/views/generic.json version [2eb11890a0].
Deleted applications/welcome/views/generic.load version [fa6df36d52].
Deleted applications/welcome/views/generic.pdf version [c404f699b1].
Deleted applications/welcome/views/generic.rss version [ed113b27d9].
Deleted applications/welcome/views/generic.xml version [92f603b5bb].
Deleted applications/welcome/views/layout.html version [78b7d8a5ef].
Deleted applications/welcome/views/web2py_ajax.html version [4a6f603253].
Modified cgihandler.py from [2f1a36bb3b] to [d56b243ab0].
14
15
16
17
18
19
20

path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
sys.path = [path]+[p for p in sys.path if not p==path]

import gluon.main

wsgiref.handlers.CGIHandler().run(gluon.main.wsgibase)








>
14
15
16
17
18
19
20
21
path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
sys.path = [path]+[p for p in sys.path if not p==path]

import gluon.main

wsgiref.handlers.CGIHandler().run(gluon.main.wsgibase)

Modified fcgihandler.py from [381db6b66f] to [196448d2fb].
47
48
49
50
51
52
53

    application = gluon.main.wsgibase

if SOFTCRON:
    from gluon.settings import global_settings
    global_settings.web2py_crontype = 'soft'

fcgi.WSGIServer(application, bindAddress='/tmp/fcgi.sock').run()








>
47
48
49
50
51
52
53
54
    application = gluon.main.wsgibase

if SOFTCRON:
    from gluon.settings import global_settings
    global_settings.web2py_crontype = 'soft'

fcgi.WSGIServer(application, bindAddress='/tmp/fcgi.sock').run()

Modified gaehandler.py from [2e5f959427] to [439fc9680b].
109
110
111
112
113
114
115

    if APPSTATS:
        run_wsgi_app(wsgiapp)
    else:
        wsgiref.handlers.CGIHandler().run(wsgiapp)

if __name__ == '__main__':
    main()








>
109
110
111
112
113
114
115
116
    if APPSTATS:
        run_wsgi_app(wsgiapp)
    else:
        wsgiref.handlers.CGIHandler().run(wsgiapp)

if __name__ == '__main__':
    main()

Modified gluon/__init__.py from [261ab37d87] to [08875d3c07].
14
15
16
17
18
19
20




21

from globals import current
from html import *
from validators import *
from http import redirect, HTTP
from dal import DAL, Field
from sqlhtml import SQLFORM, SQLTABLE












>
>
>
>

14
15
16
17
18
19
20
21
22
23
24
25

from globals import current
from html import *
from validators import *
from http import redirect, HTTP
from dal import DAL, Field
from sqlhtml import SQLFORM, SQLTABLE





Added gluon/__init__.pyc version [4b1dda92da].
Modified gluon/admin.py from [76dc3c9e63] to [d5f62e0e51].
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import traceback
import zipfile
import urllib
from shutil import rmtree
from utils import web2py_uuid
from fileutils import w2p_pack, w2p_unpack, w2p_pack_plugin, w2p_unpack_plugin
from fileutils import up, fix_newlines, abspath, recursive_unlink
from fileutils import read_file, write_file
from restricted import RestrictedError
from settings import global_settings

def apath(path='', r=None):
    """
    Builds a path inside an application folder








|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import traceback
import zipfile
import urllib
from shutil import rmtree
from utils import web2py_uuid
from fileutils import w2p_pack, w2p_unpack, w2p_pack_plugin, w2p_unpack_plugin
from fileutils import up, fix_newlines, abspath, recursive_unlink
from fileutils import read_file, write_file, parse_version
from restricted import RestrictedError
from settings import global_settings

def apath(path='', r=None):
    """
    Builds a path inside an application folder

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
        `True` if upgrade available, `False` if current version if up-to-date,
        -1 on error
    version:
        the most up-to-version available
    """
    try:
        from urllib import urlopen
        version = urlopen(version_URL).read()
    except Exception:
        return -1, myversion

    if version > myversion:
        return True, version
    else:
        return False, version







|







340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
        `True` if upgrade available, `False` if current version if up-to-date,
        -1 on error
    version:
        the most up-to-version available
    """
    try:
        from urllib import urlopen
        version = parse_version(urlopen(version_URL).read())
    except Exception:
        return -1, myversion

    if version > myversion:
        return True, version
    else:
        return False, version
446
447
448
449
450
451
452
453


            for subfolder in ('models', 'views', 'controllers', 'databases',
                              'modules', 'cron', 'errors', 'sessions',
                              'languages', 'static', 'private', 'uploads'):
                path =  os.path.join(request.folder, subfolder)
                if not os.path.exists(path):
                    os.mkdir(path)
            global_settings.app_folders.add(request.folder)











>
>
446
447
448
449
450
451
452
453
454
455
            for subfolder in ('models', 'views', 'controllers', 'databases',
                              'modules', 'cron', 'errors', 'sessions',
                              'languages', 'static', 'private', 'uploads'):
                path =  os.path.join(request.folder, subfolder)
                if not os.path.exists(path):
                    os.mkdir(path)
            global_settings.app_folders.add(request.folder)



Added gluon/admin.pyc version [f384b2f33c].
Added gluon/cache.py version [9258d641dc].
Added gluon/cache.pyc version [4c62f4a468].
Modified gluon/cfs.py from [a70d589858] to [f85d4d8306].
44
45
46
47
48
49
50


51
        data = read_file(filename)
    else:
        data = filter()
    cfs_lock.acquire()
    cfs[key] = (t, data)
    cfs_lock.release()
    return data










>
>

44
45
46
47
48
49
50
51
52
53
        data = read_file(filename)
    else:
        data = filter()
    cfs_lock.acquire()
    cfs[key] = (t, data)
    cfs_lock.release()
    return data



Added gluon/cfs.pyc version [c27431a52a].
Modified gluon/compileapp.py from [77197379d7] to [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()



Added gluon/compileapp.pyc version [fde14323b3].
Modified gluon/contenttype.py from [b7880bfab9] to [7a890ef3d0].
240
241
242
243
244
245
246

247
248
249
250
251
252
253
    '.jpeg': 'image/jpeg',
    '.jpf': 'image/jp2',
    '.jpg': 'image/jpeg',
    '.jpr': 'application/x-jbuilder-project',
    '.jpx': 'image/jp2',
    '.js': 'application/javascript',
    '.json': 'application/json',

    '.k25': 'image/x-kodak-k25',
    '.kar': 'audio/midi',
    '.karbon': 'application/x-karbon',
    '.kdc': 'image/x-kodak-kdc',
    '.kdelnk': 'application/x-desktop',
    '.kexi': 'application/x-kexiproject-sqlite3',
    '.kexic': 'application/x-kexi-connectiondata',







>







240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
    '.jpeg': 'image/jpeg',
    '.jpf': 'image/jp2',
    '.jpg': 'image/jpeg',
    '.jpr': 'application/x-jbuilder-project',
    '.jpx': 'image/jp2',
    '.js': 'application/javascript',
    '.json': 'application/json',
    '.jsonp': 'application/jsonp',
    '.k25': 'image/x-kodak-k25',
    '.kar': 'audio/midi',
    '.karbon': 'application/x-karbon',
    '.kdc': 'image/x-kodak-kdc',
    '.kdelnk': 'application/x-desktop',
    '.kexi': 'application/x-kexiproject-sqlite3',
    '.kexic': 'application/x-kexi-connectiondata',
711
712
713
714
715
716
717
718


        default = CONTENT_TYPE.get(filename[i:].lower(),default)
        j = filename.rfind('.', 0, i)
        if j>=0:
            default = CONTENT_TYPE.get(filename[j:].lower(),default)
    if default.startswith('text/'):
        default += '; charset=utf-8'
    return default











>
>
712
713
714
715
716
717
718
719
720
721
        default = CONTENT_TYPE.get(filename[i:].lower(),default)
        j = filename.rfind('.', 0, i)
        if j>=0:
            default = CONTENT_TYPE.get(filename[j:].lower(),default)
    if default.startswith('text/'):
        default += '; charset=utf-8'
    return default



Added gluon/contenttype.pyc version [e29ed3a249].
Modified gluon/contrib/AuthorizeNet.py from [e1e5a92158] to [d3aed38008].
253
254
255
256
257
258
259

260
        print 'An error occured'
    print 'approved',payment.isApproved()
    print 'declined',payment.isDeclined()
    print 'error',payment.isError()

if __name__=='__main__':
    test()









>

253
254
255
256
257
258
259
260
261
        print 'An error occured'
    print 'approved',payment.isApproved()
    print 'declined',payment.isDeclined()
    print 'error',payment.isError()

if __name__=='__main__':
    test()


Modified gluon/contrib/__init__.py from [71853c6197] to [7c338ed284].

1
2



>


1
2
3



Modified gluon/contrib/comet_messaging.py from [9ef31a1bd5] to [0d35f52c8b].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/python
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

Attention: Requires Chrome or Safari. For IE of Firefox you need https://github.com/gimite/web-socket-js

1) install tornado

   easy_install tornado

2) start this app:

   python gluon/contrib/comet_messaging.py -k mykey -p 8888









|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/python
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

Attention: Requires Chrome or Safari. For IE of Firefox you need https://github.com/gimite/web-socket-js

1) install tornado (requires Tornado 2.1)

   easy_install tornado

2) start this app:

   python gluon/contrib/comet_messaging.py -k mykey -p 8888

184
185
186
187
188
189
190
191

        (r'/', PostHandler),
        (r'/token', TokenHandler),
        (r'/realtime/(.*)', DistributeHandler)]
    application = tornado.web.Application(urls, auto_reload=True)
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(int(options.port), address=options.address)
    tornado.ioloop.IOLoop.instance().start()










>
184
185
186
187
188
189
190
191
192
        (r'/', PostHandler),
        (r'/token', TokenHandler),
        (r'/realtime/(.*)', DistributeHandler)]
    application = tornado.web.Application(urls, auto_reload=True)
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(int(options.port), address=options.address)
    tornado.ioloop.IOLoop.instance().start()


Modified gluon/contrib/feedparser.py from [5437fea58f] to [9e55c095f1].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Universal feed parser

Handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds

Visit http://feedparser.org/ for the latest version
Visit http://feedparser.org/docs/ for the latest documentation

Required: Python 2.1 or later
Recommended: Python 2.3 or later
Recommended: CJKCodecs and iconv_codec <http://cjkpython.i18n.org/>
"""  # + "$Revision: 1.92 $"[11:15] + "-cvs"

__version__ = '4.1'
__license__ = \
    """Copyright (c) 2002-2006, Mark Pilgrim, All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,

<
<







|
<

|

|
<
|







1


2
3
4
5
6
7
8
9

10
11
12
13

14
15
16
17
18
19
20
21
#!/usr/bin/env python


"""Universal feed parser

Handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds

Visit http://feedparser.org/ for the latest version
Visit http://feedparser.org/docs/ for the latest documentation

Required: Python 2.4 or later

Recommended: CJKCodecs and iconv_codec <http://cjkpython.i18n.org/>
"""

__version__ = "5.0.1"

__license__ = """Copyright (c) 2002-2008, Mark Pilgrim, All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
33
34
35
36
37
38
39
40
41
42
43
44
45
46



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

75



76



77
78




79





80




81











































82
83

84
85
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

251









252
253
254
255
256
257
258
259
260
261
262
263
264

265
266

267

268
269
270
271
272
273

274
275
276






277
278
279
280
281
282
283
284
285
286
287
288
289


290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589




























590
591
592
593
594
595

596
597





598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637


638
639
640
641
642
643
644
645
646
647
648
649
650
651

652
653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738


739
740
741
742







743
744


745

746
747
748
749
750
751
752
753
754
755




756


757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796



797
798
799
800
801
802
803
804
805

806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841




842




843
844
845
846
847
848
849
850
851
852
853
854
855
856


857
858
859
860
861


862
863
864
865
866
867
868
869
870
871
872
873
874

875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987

988

989
990
991
992

993



994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033



1034
1035
1036
1037
1038
1039
1040
1041
1042
1043



























1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058




1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069




1070
1071

1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087















1088
1089
1090
1091
1092
1093
1094
1095
1096





1097
1098
1099
1100
1101




1102


1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115





1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134



1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149


1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162





















1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203



1204
1205
1206
1207
1208
1209
1210
1211
1212



1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244


1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261

1262



1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273


1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285



1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE."""
__author__ = 'Mark Pilgrim <http://diveintomark.org/>'
__contributors__ = ['Jason Diamond <http://injektilo.org/>',
                    'John Beimler <http://john.beimler.org/>',
                    'Fazal Majid <http://www.majid.info/mylos/weblog/>'
                    , 'Aaron Swartz <http://aaronsw.com/>',
                    'Kevin Marks <http://epeus.blogspot.com/>']
_debug = 0




# HTTP "User-Agent" header to send to servers when downloading feeds.
# If you are embedding feedparser in a larger application, you should
# change this to your application name and URL.

USER_AGENT = 'UniversalFeedParser/%s +http://feedparser.org/'\
     % __version__

# HTTP "Accept" header to send to servers when downloading feeds.  If you don't
# want to send an Accept header, set this to None.

ACCEPT_HEADER = \
    'application/atom+xml,application/rdf+xml,application/rss+xml,application/x-netcdf,application/xml;q=0.9,text/xml;q=0.2,*/*;q=0.1'

# List of preferred XML parsers, by SAX driver name.  These will be tried first,
# but if they're not installed, Python will keep searching through its own list
# of pre-installed parsers until it finds one that supports everything we need.

PREFERRED_XML_PARSERS = ['drv_libxml2']

# If you want feedparser to automatically run HTML markup through HTML Tidy, set
# this to 1.  Requires mxTidy <http://www.egenix.com/files/python/mxTidy.html>
# or utidylib <http://utidylib.berlios.de/>.

TIDY_MARKUP = 0

# List of Python interfaces for HTML Tidy, in order of preference.  Only useful
# if TIDY_MARKUP = 1





PREFERRED_TIDY_INTERFACES = ['uTidy', 'mxTidy']




# ---------- required modules (should come with any Python distribution) ----------










import sgmllib




import re











































import sys
import copy

import urlparse
import time
import rfc822
import types
import cgi
import urllib
import urllib2




try:



    from cStringIO import StringIO as _StringIO
except:
    from StringIO import StringIO as _StringIO

# ---------- optional modules (feedparser will work without these, but with reduced functionality) ----------

# gzip is included with most Python distributions, but may not be available if you compiled your own

try:
    import gzip
except:
    gzip = None
try:
    import zlib
except:
    zlib = None

# If a real XML parser is available, feedparser will attempt to use it.  feedparser has
# been tested with the built-in SAX parser, PyXML, and libxml2.  On platforms where the
# Python distribution does not come with an XML parser (such as Mac OS X 10.2 and some
# versions of FreeBSD), feedparser will quietly fall back on regex-based parsing.

try:
    import xml.sax
    xml.sax.make_parser(PREFERRED_XML_PARSERS)  # test for valid parsers
    from xml.sax.saxutils import escape as _xmlescape
    _XML_AVAILABLE = 1
except:
    _XML_AVAILABLE = 0


    def _xmlescape(data):
        data = data.replace('&', '&amp;')
        data = data.replace('>', '&gt;')
        data = data.replace('<', '&lt;')


        return data


# base64 support for Atom feeds that contain embedded binary data









try:
    import base64
    import binascii
except:


    base64 = binascii = None
















































# cjkcodecs and iconv_codec provide support for more character encodings.
# Both are available from http://cjkpython.i18n.org/

try:
    import cjkcodecs.aliases
except:
    pass
try:
    import iconv_codec
except:
    pass

# chardet library auto-detects character encodings
# Download from http://chardet.feedparser.org/

try:
    import chardet
    if _debug:

        import chardet.constants
        chardet.constants._debug = 1







except:
    chardet = None

# ---------- don't touch these ----------


class ThingsNobodyCaresAboutButMe(Exception):

    pass


class CharacterEncodingOverride(ThingsNobodyCaresAboutButMe):

    pass


class CharacterEncodingUnknown(ThingsNobodyCaresAboutButMe):

    pass


class NonXMLContentType(ThingsNobodyCaresAboutButMe):

    pass


class UndeclaredNamespace(Exception):

    pass


sgmllib.tagfind = re.compile('[a-zA-Z][-_.:a-zA-Z0-9]*')
sgmllib.special = re.compile('<!')
sgmllib.charref = re.compile('&#(x?[0-9A-Fa-f]+)[^0-9A-Fa-f]')

SUPPORTED_VERSIONS = {
    '': 'unknown',
    'rss090': 'RSS 0.90',
    'rss091n': 'RSS 0.91 (Netscape)',
    'rss091u': 'RSS 0.91 (Userland)',
    'rss092': 'RSS 0.92',
    'rss093': 'RSS 0.93',
    'rss094': 'RSS 0.94',
    'rss20': 'RSS 2.0',
    'rss10': 'RSS 1.0',
    'rss': 'RSS (unknown version)',
    'atom01': 'Atom 0.1',
    'atom02': 'Atom 0.2',
    'atom03': 'Atom 0.3',
    'atom10': 'Atom 1.0',
    'atom': 'Atom (unknown version)',
    'cdf': 'CDF',
    'hotrss': 'Hot RSS',
    }

try:
    UserDict = dict
except NameError:

    # Python 2.1 does not have dict

    from UserDict import UserDict


    def dict(aList):
        rc = {}
        for (k, v) in aList:
            rc[k] = v
        return rc


class FeedParserDict(UserDict):

    keymap = {
        'channel': 'feed',
        'items': 'entries',
        'guid': 'id',
        'date': 'updated',
        'date_parsed': 'updated_parsed',
        'description': ['subtitle', 'summary'],
        'url': ['href'],
        'modified': 'updated',
        'modified_parsed': 'updated_parsed',
        'issued': 'published',
        'issued_parsed': 'published_parsed',
        'copyright': 'rights',
        'copyright_detail': 'rights_detail',
        'tagline': 'subtitle',
        'tagline_detail': 'subtitle_detail',
        }

    def __getitem__(self, key):
        if key == 'category':

            return UserDict.__getitem__(self, 'tags')[0]['term']









        if key == 'categories':
            return [(tag['scheme'], tag['term']) for tag in
                    UserDict.__getitem__(self, 'tags')]
        realkey = self.keymap.get(key, key)
        if type(realkey) == types.ListType:
            for k in realkey:
                if UserDict.has_key(self, k):
                    return UserDict.__getitem__(self, k)
        if UserDict.has_key(self, key):
            return UserDict.__getitem__(self, key)
        return UserDict.__getitem__(self, realkey)

    def __setitem__(self, key, value):

        for k in self.keymap.keys():
            if key == k:

                key = self.keymap[k]

                if type(key) == types.ListType:
                    key = key[0]
        return UserDict.__setitem__(self, key, value)

    def get(self, key, default=None):
        if self.has_key(key):

            return self[key]
        else:
            return default







    def setdefault(self, key, value):
        if not self.has_key(key):
            self[key] = value
        return self[key]

    def has_key(self, key):
        try:
            return hasattr(self, key) or UserDict.has_key(self, key)
        except AttributeError:
            return False

    def __getattr__(self, key):


        try:
            return self.__dict__[key]
        except KeyError:
            pass
        try:
            assert not key.startswith('_')
            return self.__getitem__(key)
        except:
            raise AttributeError, "object has no attribute '%s'" % key

    def __setattr__(self, key, value):
        if key.startswith('_') or key == 'data':
            self.__dict__[key] = value
        else:
            return self.__setitem__(key, value)

    def __contains__(self, key):
        return self.has_key(key)


def zopeCompatibilityHack():
    global FeedParserDict
    del FeedParserDict

    def FeedParserDict(aDict=None):
        rc = {}
        if aDict:
            rc.update(aDict)
        return rc


_ebcdic_to_ascii_map = None


def _ebcdic_to_ascii(s):
    global _ebcdic_to_ascii_map
    if not _ebcdic_to_ascii_map:
        emap = (
            0,
            1,
            2,
            3,
            156,
            9,
            134,
            127,
            151,
            141,
            142,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            157,
            133,
            8,
            135,
            24,
            25,
            146,
            143,
            28,
            29,
            30,
            31,
            128,
            129,
            130,
            131,
            132,
            10,
            23,
            27,
            136,
            137,
            138,
            139,
            140,
            5,
            6,
            7,
            144,
            145,
            22,
            147,
            148,
            149,
            150,
            4,
            152,
            153,
            154,
            155,
            20,
            21,
            158,
            26,
            32,
            160,
            161,
            162,
            163,
            164,
            165,
            166,
            167,
            168,
            91,
            46,
            60,
            40,
            43,
            33,
            38,
            169,
            170,
            171,
            172,
            173,
            174,
            175,
            176,
            177,
            93,
            36,
            42,
            41,
            59,
            94,
            45,
            47,
            178,
            179,
            180,
            181,
            182,
            183,
            184,
            185,
            124,
            44,
            37,
            95,
            62,
            63,
            186,
            187,
            188,
            189,
            190,
            191,
            192,
            193,
            194,
            96,
            58,
            35,
            64,
            39,
            61,
            34,
            195,
            97,
            98,
            99,
            100,
            101,
            102,
            103,
            104,
            105,
            196,
            197,
            198,
            199,
            200,
            201,
            202,
            106,
            107,
            108,
            109,
            110,
            111,
            112,
            113,
            114,
            203,
            204,
            205,
            206,
            207,
            208,
            209,
            126,
            115,
            116,
            117,
            118,
            119,
            120,
            121,
            122,
            210,
            211,
            212,
            213,
            214,
            215,
            216,
            217,
            218,
            219,
            220,
            221,
            222,
            223,
            224,
            225,
            226,
            227,
            228,
            229,
            230,
            231,
            123,
            65,
            66,
            67,
            68,
            69,
            70,
            71,
            72,
            73,
            232,
            233,
            234,
            235,
            236,
            237,
            125,
            74,
            75,
            76,
            77,
            78,
            79,
            80,
            81,
            82,
            238,
            239,
            240,
            241,
            242,
            243,
            92,
            159,
            83,
            84,
            85,
            86,
            87,
            88,
            89,
            90,
            244,
            245,
            246,
            247,
            248,
            249,
            48,
            49,
            50,
            51,
            52,
            53,
            54,
            55,
            56,
            57,
            250,
            251,
            252,
            253,
            254,
            255,
            )
        import string
        _ebcdic_to_ascii_map = string.maketrans(''.join(map(chr,
                range(256))), ''.join(map(chr, emap)))
    return s.translate(_ebcdic_to_ascii_map)






























_urifixer = re.compile('^([A-Za-z][A-Za-z0-9+-.]*://)(/*)(.*?)')


def _urljoin(base, uri):
    uri = _urifixer.sub(r'\1\3', uri)

    return urlparse.urljoin(base, uri)







class _FeedParserMixin:

    namespaces = {
        '': '',
        'http://backend.userland.com/rss': '',
        'http://blogs.law.harvard.edu/tech/rss': '',
        'http://purl.org/rss/1.0/': '',
        'http://my.netscape.com/rdf/simple/0.9/': '',
        'http://example.com/newformat#': '',
        'http://example.com/necho': '',
        'http://purl.org/echo/': '',
        'uri/of/echo/namespace#': '',
        'http://purl.org/pie/': '',
        'http://purl.org/atom/ns#': '',
        'http://www.w3.org/2005/Atom': '',
        'http://purl.org/rss/1.0/modules/rss091#': '',

        'http://webns.net/mvcb/': 'admin',
        'http://purl.org/rss/1.0/modules/aggregation/': 'ag',
        'http://purl.org/rss/1.0/modules/annotate/': 'annotate',
        'http://media.tangent.org/rss/1.0/': 'audio',
        'http://backend.userland.com/blogChannelModule': 'blogChannel',
        'http://web.resource.org/cc/': 'cc',
        'http://backend.userland.com/creativeCommonsRssModule': 'creativeCommons',
        'http://purl.org/rss/1.0/modules/company': 'co',
        'http://purl.org/rss/1.0/modules/content/': 'content',
        'http://my.theinfo.org/changed/1.0/rss/': 'cp',
        'http://purl.org/dc/elements/1.1/': 'dc',
        'http://purl.org/dc/terms/': 'dcterms',
        'http://purl.org/rss/1.0/modules/email/': 'email',
        'http://purl.org/rss/1.0/modules/event/': 'ev',
        'http://rssnamespace.org/feedburner/ext/1.0': 'feedburner',
        'http://freshmeat.net/rss/fm/': 'fm',
        'http://xmlns.com/foaf/0.1/': 'foaf',
        'http://www.w3.org/2003/01/geo/wgs84_pos#': 'geo',
        'http://postneo.com/icbm/': 'icbm',
        'http://purl.org/rss/1.0/modules/image/': 'image',
        'http://www.itunes.com/DTDs/PodCast-1.0.dtd': 'itunes',
        'http://example.com/DTDs/PodCast-1.0.dtd': 'itunes',
        'http://purl.org/rss/1.0/modules/link/': 'l',


        'http://search.yahoo.com/mrss': 'media',
        'http://madskills.com/public/xml/rss/module/pingback/': 'pingback',
        'http://prismstandard.org/namespaces/1.2/basic/': 'prism',
        'http://www.w3.org/1999/02/22-rdf-syntax-ns#': 'rdf',
        'http://www.w3.org/2000/01/rdf-schema#': 'rdfs',
        'http://purl.org/rss/1.0/modules/reference/': 'ref',
        'http://purl.org/rss/1.0/modules/richequiv/': 'reqv',
        'http://purl.org/rss/1.0/modules/search/': 'search',
        'http://purl.org/rss/1.0/modules/slash/': 'slash',
        'http://schemas.xmlsoap.org/soap/envelope/': 'soap',
        'http://purl.org/rss/1.0/modules/servicestatus/': 'ss',
        'http://hacks.benhammersley.com/rss/streaming/': 'str',
        'http://purl.org/rss/1.0/modules/subscription/': 'sub',
        'http://purl.org/rss/1.0/modules/syndication/': 'sy',

        'http://purl.org/rss/1.0/modules/taxonomy/': 'taxo',
        'http://purl.org/rss/1.0/modules/threading/': 'thr',
        'http://purl.org/rss/1.0/modules/textinput/': 'ti',
        'http://madskills.com/public/xml/rss/module/trackback/': 'trackback',
        'http://wellformedweb.org/commentAPI/': 'wfw',
        'http://purl.org/rss/1.0/modules/wiki/': 'wiki',
        'http://www.w3.org/1999/xhtml': 'xhtml',

        'http://www.w3.org/XML/1998/namespace': 'xml',
        'http://schemas.pocketsoap.com/rss/myDescModule/': 'szf',
        }
    _matchnamespaces = {}

    can_be_relative_uri = [
        'link',
        'id',
        'wfw_comment',
        'wfw_commentrss',
        'docs',
        'url',
        'href',
        'comments',
        'license',
        'icon',
        'logo',
        ]
    can_contain_relative_uris = [
        'content',
        'title',
        'summary',
        'info',
        'tagline',
        'subtitle',
        'copyright',
        'rights',
        'description',
        ]
    can_contain_dangerous_markup = [
        'content',
        'title',
        'summary',
        'info',
        'tagline',
        'subtitle',
        'copyright',
        'rights',
        'description',
        ]
    html_types = ['text/html', 'application/xhtml+xml']

    def __init__(
        self,
        baseuri=None,
        baselang=None,
        encoding='utf-8',
        ):
        if _debug:
            sys.stderr.write('initializing FeedParser\n')
        if not self._matchnamespaces:
            for (k, v) in self.namespaces.items():
                self._matchnamespaces[k.lower()] = v
        self.feeddata = FeedParserDict()  # feed-level data
        self.encoding = encoding  # character encoding
        self.entries = []  # list of entry-level data
        self.version = ''  # feed type/version, see SUPPORTED_VERSIONS
        self.namespacesInUse = {}  # dictionary of namespaces defined by the feed

        # the following are used internally to track state;
        # this is really out of control and should be refactored

        self.infeed = 0
        self.inentry = 0
        self.incontent = 0
        self.intextinput = 0
        self.inimage = 0
        self.inauthor = 0
        self.incontributor = 0
        self.inpublisher = 0
        self.insource = 0
        self.sourcedata = FeedParserDict()
        self.contentparams = FeedParserDict()
        self._summaryKey = None
        self.namespacemap = {}
        self.elementstack = []
        self.basestack = []
        self.langstack = []
        self.baseuri = baseuri or ''
        self.lang = baselang or None


        if baselang:
            self.feeddata['language'] = baselang

    def unknown_starttag(self, tag, attrs):







        if _debug:
            sys.stderr.write('start %s with %s\n' % (tag, attrs))




        # normalize attrs

        attrs = [(k.lower(), v) for (k, v) in attrs]
        attrs = [(k, k in ('rel', 'type') and v.lower() or v) for (k,
                 v) in attrs]

        # track xml:base and xml:lang

        attrsD = dict(attrs)
        baseuri = attrsD.get('xml:base', attrsD.get('base'))\




             or self.baseuri


        self.baseuri = _urljoin(self.baseuri, baseuri)
        lang = attrsD.get('xml:lang', attrsD.get('lang'))
        if lang == '':

            # xml:lang could be explicitly set to '', we need to capture that

            lang = None
        elif lang is None:

            # if no xml:lang is specified, use parent lang

            lang = self.lang
        if lang:
            if tag in ('feed', 'rss', 'rdf:RDF'):
                self.feeddata['language'] = lang
        self.lang = lang
        self.basestack.append(self.baseuri)
        self.langstack.append(lang)

        # track namespaces

        for (prefix, uri) in attrs:
            if prefix.startswith('xmlns:'):
                self.trackNamespace(prefix[6:], uri)
            elif prefix == 'xmlns':
                self.trackNamespace(None, uri)

        # track inline content

        if self.incontent and self.contentparams.has_key('type')\
             and not self.contentparams.get('type', 'xml'
                ).endswith('xml'):

            # element declared itself as escaped markup, but it isn't really

            self.contentparams['type'] = 'application/xhtml+xml'
        if self.incontent and self.contentparams.get('type')\
             == 'application/xhtml+xml':

            # Note: probably shouldn't simply recreate localname here, but



            # our namespace handling isn't actually 100% correct in cases where
            # the feed redefines the default namespace (which is actually
            # the usual case for inline content, thanks Sam), so here we
            # cheat and just reconstruct the element based on localname
            # because that compensates for the bugs in our namespace handling.
            # This will horribly munge inline content with non-empty qnames,
            # but nobody actually does that, so I'm not fixing it.

            tag = tag.split(':')[-1]

            return self.handle_data('<%s%s>' % (tag, ''.join([' %s="%s"'
                                     % t for t in attrs])), escape=0)

        # match namespaces

        if tag.find(':') != -1:
            (prefix, suffix) = tag.split(':', 1)
        else:
            (prefix, suffix) = ('', tag)
        prefix = self.namespacemap.get(prefix, prefix)
        if prefix:
            prefix = prefix + '_'

        # special hack for better tracking of empty textinput/image elements in illformed feeds

        if not prefix and tag not in ('title', 'link', 'description',
                'name'):
            self.intextinput = 0
        if not prefix and tag not in (
            'title',
            'link',
            'description',
            'url',
            'href',
            'width',
            'height',
            ):
            self.inimage = 0

        # call special handler (if defined) or default handler

        methodname = '_start_' + prefix + suffix
        try:
            method = getattr(self, methodname)
            return method(attrsD)
        except AttributeError:




            return self.push(prefix + suffix, 1)





    def unknown_endtag(self, tag):
        if _debug:
            sys.stderr.write('end %s\n' % tag)

        # match namespaces

        if tag.find(':') != -1:
            (prefix, suffix) = tag.split(':', 1)
        else:
            (prefix, suffix) = ('', tag)
        prefix = self.namespacemap.get(prefix, prefix)
        if prefix:
            prefix = prefix + '_'



        # call special handler (if defined) or default handler

        methodname = '_end_' + prefix + suffix
        try:


            method = getattr(self, methodname)
            method()
        except AttributeError:
            self.pop(prefix + suffix)

        # track inline content

        if self.incontent and self.contentparams.has_key('type')\
             and not self.contentparams.get('type', 'xml'
                ).endswith('xml'):

            # element declared itself as escaped markup, but it isn't really


            self.contentparams['type'] = 'application/xhtml+xml'
        if self.incontent and self.contentparams.get('type')\
             == 'application/xhtml+xml':
            tag = tag.split(':')[-1]
            self.handle_data('</%s>' % tag, escape=0)

        # track xml:base and xml:lang going out of scope

        if self.basestack:
            self.basestack.pop()
            if self.basestack and self.basestack[-1]:
                self.baseuri = self.basestack[-1]
        if self.langstack:
            self.langstack.pop()
            if self.langstack:  # and (self.langstack[-1] is not None):
                self.lang = self.langstack[-1]

    def handle_charref(self, ref):

        # called for each character reference, e.g. for '&#160;', ref will be '160'

        if not self.elementstack:
            return
        ref = ref.lower()
        if ref in (
            '34',
            '38',
            '39',
            '60',
            '62',
            'x22',
            'x26',
            'x27',
            'x3c',
            'x3e',
            ):
            text = '&#%s;' % ref
        else:
            if ref[0] == 'x':
                c = int(ref[1:], 16)
            else:
                c = int(ref)
            text = unichr(c).encode('utf-8')
        self.elementstack[-1][2].append(text)

    def handle_entityref(self, ref):

        # called for each entity reference, e.g. for '&copy;', ref will be 'copy'

        if not self.elementstack:
            return
        if _debug:
            sys.stderr.write('entering handle_entityref with %s\n'
                              % ref)
        if ref in ('lt', 'gt', 'quot', 'amp', 'apos'):
            text = '&%s;' % ref
        else:

            # entity resolution graciously donated by Aaron Swartz

            def name2cp(k):
                import htmlentitydefs
                if hasattr(htmlentitydefs, 'name2codepoint'):  # requires Python 2.3
                    return htmlentitydefs.name2codepoint[k]
                k = htmlentitydefs.entitydefs[k]
                if k.startswith('&#') and k.endswith(';'):
                    return int(k[2:-1])  # not in latin-1
                return ord(k)

            try:
                name2cp(ref)
            except KeyError:
                text = '&%s;' % ref
            else:
                text = unichr(name2cp(ref)).encode('utf-8')
        self.elementstack[-1][2].append(text)

    def handle_data(self, text, escape=1):

        # called for each block of plain text, i.e. outside of any tag and
        # not containing any character or entity references

        if not self.elementstack:
            return
        if escape and self.contentparams.get('type')\
             == 'application/xhtml+xml':
            text = _xmlescape(text)
        self.elementstack[-1][2].append(text)

    def handle_comment(self, text):

        # called for each comment, e.g. <!-- insert message here -->

        pass

    def handle_pi(self, text):

        # called for each processing instruction, e.g. <?instruction>

        pass

    def handle_decl(self, text):
        pass

    def parse_declaration(self, i):

        # override internal declaration handler to handle CDATA blocks

        if _debug:
            sys.stderr.write('entering parse_declaration\n')
        if self.rawdata[i:i + 9] == '<![CDATA[':
            k = self.rawdata.find(']]>', i)
            if k == -1:

                k = len(self.rawdata)

            self.handle_data(_xmlescape(self.rawdata[i + 9:k]), 0)
            return k + 3
        else:
            k = self.rawdata.find('>', i)

            return k + 1




    def mapContentType(self, contentType):
        contentType = contentType.lower()
        if contentType == 'text':
            contentType = 'text/plain'
        elif contentType == 'html':
            contentType = 'text/html'
        elif contentType == 'xhtml':
            contentType = 'application/xhtml+xml'
        return contentType

    def trackNamespace(self, prefix, uri):
        loweruri = uri.lower()
        if (prefix, loweruri) == (None,
                                  'http://my.netscape.com/rdf/simple/0.9/'
                                  ) and not self.version:
            self.version = 'rss090'
        if loweruri == 'http://purl.org/rss/1.0/' and not self.version:
            self.version = 'rss10'
        if loweruri == 'http://www.w3.org/2005/atom'\
             and not self.version:
            self.version = 'atom10'
        if loweruri.find('backend.userland.com/rss') != -1:

            # match any backend.userland.com namespace

            uri = 'http://backend.userland.com/rss'
            loweruri = uri
        if self._matchnamespaces.has_key(loweruri):
            self.namespacemap[prefix] = self._matchnamespaces[loweruri]
            self.namespacesInUse[self._matchnamespaces[loweruri]] = uri
        else:
            self.namespacesInUse[prefix or ''] = uri

    def resolveURI(self, uri):
        return _urljoin(self.baseuri or '', uri)

    def decodeEntities(self, element, data):
        return data




    def push(self, element, expectingText):
        self.elementstack.append([element, expectingText, []])

    def pop(self, element, stripWhitespace=1):
        if not self.elementstack:
            return
        if self.elementstack[-1][0] != element:
            return

        (element, expectingText, pieces) = self.elementstack.pop()



























        output = ''.join(pieces)
        if stripWhitespace:
            output = output.strip()
        if not expectingText:
            return output

        # decode base64 content

        if base64 and self.contentparams.get('base64', 0):
            try:
                output = base64.decodestring(output)
            except binascii.Error:
                pass
            except binascii.Incomplete:
                pass





        # resolve relative URIs

        if element in self.can_be_relative_uri and output:
            output = self.resolveURI(output)

        # decode entities within embedded markup

        if not self.contentparams.get('base64', 0):
            output = self.decodeEntities(element, output)





        # remove temporary cruft from contentparams


        try:
            del self.contentparams['mode']
        except KeyError:
            pass
        try:
            del self.contentparams['base64']
        except KeyError:
            pass


        # resolve relative URIs within embedded markup

        if self.mapContentType(self.contentparams.get('type',
                               'text/html')) in self.html_types:
            if element in self.can_contain_relative_uris:
                output = _resolveRelativeURIs(output, self.baseuri,
                        self.encoding)
















        # sanitize embedded markup

        if self.mapContentType(self.contentparams.get('type',
                               'text/html')) in self.html_types:
            if element in self.can_contain_dangerous_markup:
                output = _sanitizeHTML(output, self.encoding)

        if self.encoding and type(output) != type(u''):





            try:
                output = unicode(output, self.encoding)
            except:
                pass





        # categories/tags/keywords/whatever are handled in _end_category



        if element == 'category':
            return output

        # store output in appropriate place(s)

        if self.inentry and not self.insource:
            if element == 'content':
                self.entries[-1].setdefault(element, [])
                contentparams = copy.deepcopy(self.contentparams)
                contentparams['value'] = output
                self.entries[-1][element].append(contentparams)
            elif element == 'link':





                self.entries[-1][element] = output
                if output:
                    self.entries[-1]['links'][-1]['href'] = output
            else:
                if element == 'description':
                    element = 'summary'
                self.entries[-1][element] = output
                if self.incontent:
                    contentparams = copy.deepcopy(self.contentparams)
                    contentparams['value'] = output
                    self.entries[-1][element + '_detail'] = \
                        contentparams
        elif (self.infeed or self.insource) and not self.intextinput\
             and not self.inimage:
            context = self._getContext()
            if element == 'description':
                element = 'subtitle'
            context[element] = output
            if element == 'link':



                context['links'][-1]['href'] = output
            elif self.incontent:
                contentparams = copy.deepcopy(self.contentparams)
                contentparams['value'] = output
                context[element + '_detail'] = contentparams
        return output

    def pushContent(
        self,
        tag,
        attrsD,
        defaultContentType,
        expectingText,
        ):
        self.incontent += 1


        self.contentparams = FeedParserDict({'type'
                : self.mapContentType(attrsD.get('type',
                defaultContentType)), 'language': self.lang, 'base'
                : self.baseuri})
        self.contentparams['base64'] = self._isBase64(attrsD,
                self.contentparams)
        self.push(tag, expectingText)

    def popContent(self, tag):
        value = self.pop(tag)
        self.incontent -= 1
        self.contentparams.clear()
        return value






















    def _mapToStandardPrefix(self, name):
        colonpos = name.find(':')
        if colonpos != -1:
            prefix = name[:colonpos]
            suffix = name[colonpos + 1:]
            prefix = self.namespacemap.get(prefix, prefix)
            name = prefix + ':' + suffix
        return name

    def _getAttribute(self, attrsD, name):
        return attrsD.get(self._mapToStandardPrefix(name))

    def _isBase64(self, attrsD, contentparams):
        if attrsD.get('mode', '') == 'base64':
            return 1
        if self.contentparams['type'].startswith('text/'):
            return 0
        if self.contentparams['type'].endswith('+xml'):
            return 0
        if self.contentparams['type'].endswith('/xml'):
            return 0
        return 1

    def _itsAnHrefDamnIt(self, attrsD):
        href = attrsD.get('url', attrsD.get('uri', attrsD.get('href',
                          None)))
        if href:
            try:
                del attrsD['url']
            except KeyError:
                pass
            try:
                del attrsD['uri']
            except KeyError:
                pass
            attrsD['href'] = href
        return attrsD

    def _save(self, key, value):
        context = self._getContext()



        context.setdefault(key, value)

    def _start_rss(self, attrsD):
        versionmap = {
            '0.91': 'rss091u',
            '0.92': 'rss092',
            '0.93': 'rss093',
            '0.94': 'rss094',
            }



        if not self.version:
            attr_version = attrsD.get('version', '')
            version = versionmap.get(attr_version)
            if version:
                self.version = version
            elif attr_version.startswith('2.'):
                self.version = 'rss20'
            else:
                self.version = 'rss'

    def _start_dlhottitles(self, attrsD):
        self.version = 'hotrss'

    def _start_channel(self, attrsD):
        self.infeed = 1
        self._cdf_common(attrsD)

    _start_feedinfo = _start_channel

    def _cdf_common(self, attrsD):
        if attrsD.has_key('lastmod'):
            self._start_modified({})
            self.elementstack[-1][-1] = attrsD['lastmod']
            self._end_modified()
        if attrsD.has_key('href'):
            self._start_link({})
            self.elementstack[-1][-1] = attrsD['href']
            self._end_link()

    def _start_feed(self, attrsD):
        self.infeed = 1
        versionmap = {'0.1': 'atom01', '0.2': 'atom02', '0.3': 'atom03'}


        if not self.version:
            attr_version = attrsD.get('version')
            version = versionmap.get(attr_version)
            if version:
                self.version = version
            else:
                self.version = 'atom'

    def _end_channel(self):
        self.infeed = 0

    _end_feed = _end_channel

    def _start_image(self, attrsD):
        self.inimage = 1
        self.push('image', 0)
        context = self._getContext()

        context.setdefault('image', FeedParserDict())




    def _end_image(self):
        self.pop('image')
        self.inimage = 0

    def _start_textinput(self, attrsD):
        self.intextinput = 1
        self.push('textinput', 0)
        context = self._getContext()
        context.setdefault('textinput', FeedParserDict())



    _start_textInput = _start_textinput

    def _end_textinput(self):
        self.pop('textinput')
        self.intextinput = 0

    _end_textInput = _end_textinput

    def _start_author(self, attrsD):
        self.inauthor = 1
        self.push('author', 1)




    _start_managingeditor = _start_author
    _start_dc_author = _start_author
    _start_dc_creator = _start_author
    _start_itunes_author = _start_author

    def _end_author(self):
        self.pop('author')
        self.inauthor = 0
        self._sync_author_detail()

    _end_managingeditor = _end_author
    _end_dc_author = _end_author
    _end_dc_creator = _end_author
    _end_itunes_author = _end_author

    def _start_itunes_owner(self, attrsD):
        self.inpublisher = 1







|
|
|
|
|
|
|
>
>
>




<
|
<



<
<
|




<
|




<




>

>
>
>
|
>
>
>

|
>
>
>
>

>
>
>
>
>
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

>
|
|
|
|
|


>
>
>
>

>
>
>
|
|
|




<


|



|






<


<

<
|

<
<
|



>
>

|
|
<
>
>
>
>
>

>
>
>

|
<
|
>
>
|
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<


|



|




<


<
>
|
|
>
>
>
>
>
>
>
|
|


<
<
|
<
<
<
<
|
<
<
<
<
|
<
<
<
<
|
<
<
<
<
|

<
<
<
<
<
<
<
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<


>
|
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|

|
>
|
|
>
|
>
|
|
<


<
>
|
|

>
>
>
>
>
>


|

|
<
<
<
<
<
|


>
>

<
<
<
<
<

|


<
<
<
<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<




<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<

<
|
|


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
<


>
|
|
>
>
>
>
>


<
|
<
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
>
|
<
|


|
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
|

|
<
<
<
<
<
<
<

|

|
|
|
|
|



<
















|

>
>

|

|
>
>
>
>
>
>
>
|
<
>
>

>

|
<
<
<


<

|
>
>
>
>
|
>
>
|


<

<


<

<



|





<
|






<
|
|
<
|

<
|
|
<
|
<
>
>
>
|
|
<
<
<
<
<
|
|
>
|
<


<
|
|

|





<
|
<

|
<
<
<
<
<
<
<
<



<





>
>
>
>
|
>
>
>
>


<
<
<

<
|
|

|



>
>


<


>
>






<
|
<
<
<

|
>
|
|
<




<






|



<

<



|
<
<
<
<
<
<
<
<
<
<
<










<

<


<
<
<


<
|
<
|
<
<
<
<
<
|
<
|
|

|



|



<


<


|
<




<

<



<

<






<

<
<
<
|


>

>
|
|


>
|
>
>
>



|
|

|

|




|
<
<
|

|
|
<
|
|
<

<
|








|




>
>
>









|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|






<


|




>
>
>
>


<
|



<



>
>
>
>
|

>









>

|
<
<

|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|
<
<

|

|
>
>
>
>
>

|
|


>
>
>
>

>
>

|



<







>
>
>
>
>
|
|
|







|
<
|
<





>
>
>







|
<
<
<
<
<
<

>
>
|
|
|
|
|
<







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|

|










|

|

|




|
<












|

>
>
>
|


|
<
|
|
|
<
>
>
>
|





|

<
<
<
|





<
<












|
>
>






|



<



<
<

>
|
>
>
>






<
<


|
>
>





<





|
>
>
>









<







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50

51
52
53


54
55
56
57
58

59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
162

163
164
165
166
167
168
169
170
171
172
173
174
175

176
177

178

179
180


181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264
265

266
267

268
269
270
271
272
273
274
275
276
277
278
279
280
281


282




283




284




285




286
287







288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

304
305
















306

307

308
309
310
311
312
313
314
315
316
317
318
319
320
321


322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355

356
357

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372





373
374
375
376
377
378





379
380
381
382





383















384


385
386
387
388




389















390











391















392
















393















394
















395













396



















397











398















399















400


















401












402
















403
























404





405

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439


440
441
442
443
444
445
446
447
448
449
450
451

452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

515
516
517
518












519










520










521
522
523







524
525
526
527
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566

567
568
569
570
571
572



573
574

575
576
577
578
579
580
581
582
583
584
585
586

587

588
589

590

591
592
593
594
595
596
597
598
599

600
601
602
603
604
605
606

607
608

609
610

611
612

613

614
615
616
617
618





619
620
621
622

623
624

625
626
627
628
629
630
631
632
633

634

635
636








637
638
639

640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655



656

657
658
659
660
661
662
663
664
665
666
667

668
669
670
671
672
673
674
675
676
677

678



679
680
681
682
683

684
685
686
687

688
689
690
691
692
693
694
695
696
697

698

699
700
701
702











703
704
705
706
707
708
709
710
711
712

713

714
715



716
717

718

719





720

721
722
723
724
725
726
727
728
729
730
731

732
733

734
735
736

737
738
739
740

741

742
743
744

745

746
747
748
749
750
751

752



753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781


782
783
784
785

786
787

788

789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849

850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865
866

867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888


889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909


910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958

959

960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975






976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037

1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061

1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072



1073
1074
1075
1076
1077
1078


1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106


1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118


1119
1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146

1147
1148
1149
1150
1151
1152
1153
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE."""
__author__ = "Mark Pilgrim <http://diveintomark.org/>"
__contributors__ = ["Jason Diamond <http://injektilo.org/>",
                    "John Beimler <http://john.beimler.org/>",
                    "Fazal Majid <http://www.majid.info/mylos/weblog/>",
                    "Aaron Swartz <http://aaronsw.com/>",
                    "Kevin Marks <http://epeus.blogspot.com/>",
                    "Sam Ruby <http://intertwingly.net/>",
                    "Ade Oshineye <http://blog.oshineye.com/>",
                    "Martin Pool <http://sourcefrog.net/>",
                    "Kurt McKee <http://kurtmckee.org/>"]

# HTTP "User-Agent" header to send to servers when downloading feeds.
# If you are embedding feedparser in a larger application, you should
# change this to your application name and URL.

USER_AGENT = "UniversalFeedParser/%s +http://feedparser.org/" % __version__


# HTTP "Accept" header to send to servers when downloading feeds.  If you don't
# want to send an Accept header, set this to None.


ACCEPT_HEADER = "application/atom+xml,application/rdf+xml,application/rss+xml,application/x-netcdf,application/xml;q=0.9,text/xml;q=0.2,*/*;q=0.1"

# List of preferred XML parsers, by SAX driver name.  These will be tried first,
# but if they're not installed, Python will keep searching through its own list
# of pre-installed parsers until it finds one that supports everything we need.

PREFERRED_XML_PARSERS = ["drv_libxml2"]

# If you want feedparser to automatically run HTML markup through HTML Tidy, set
# this to 1.  Requires mxTidy <http://www.egenix.com/files/python/mxTidy.html>
# or utidylib <http://utidylib.berlios.de/>.

TIDY_MARKUP = 0

# List of Python interfaces for HTML Tidy, in order of preference.  Only useful
# if TIDY_MARKUP = 1
PREFERRED_TIDY_INTERFACES = ["uTidy", "mxTidy"]

# If you want feedparser to automatically resolve all relative URIs, set this
# to 1.
RESOLVE_RELATIVE_URIS = 1

# If you want feedparser to automatically sanitize all potentially unsafe
# HTML content, set this to 1.
SANITIZE_HTML = 1

# ---------- Python 3 modules (make it work if possible) ----------
try:
    import rfc822
except ImportError:
    from email import _parseaddr as rfc822

try:
    # Python 3.1 introduces bytes.maketrans and simultaneously
    # deprecates string.maketrans; use bytes.maketrans if possible
    _maketrans = bytes.maketrans
except (NameError, AttributeError):
    import string
    _maketrans = string.maketrans

# base64 support for Atom feeds that contain embedded binary data
try:
    import base64, binascii
except ImportError:
    base64 = binascii = None
else:
    # Python 3.1 deprecates decodestring in favor of decodebytes
    _base64decode = getattr(base64, 'decodebytes', base64.decodestring)

def _s2bytes(s):
  # Convert a UTF-8 str to bytes if the interpreter is Python 3
  try:
    return bytes(s, 'utf8')
  except (NameError, TypeError):
    # In Python 2.5 and below, bytes doesn't exist (NameError)
    # In Python 2.6 and above, bytes and str are the same (TypeError)
    return s

def _l2bytes(l):
  # Convert a list of ints to bytes if the interpreter is Python 3
  try:
    if bytes is not str:
      # In Python 2.6 and above, this call won't raise an exception
      # but it will return bytes([65]) as '[65]' instead of 'A'
      return bytes(l)
    raise NameError
  except NameError:
    return ''.join(map(chr, l))

# If you want feedparser to allow all URL schemes, set this to ()
# List culled from Python's urlparse documentation at:
#   http://docs.python.org/library/urlparse.html
# as well as from "URI scheme" at Wikipedia:
#   https://secure.wikimedia.org/wikipedia/en/wiki/URI_scheme
# Many more will likely need to be added!
ACCEPTABLE_URI_SCHEMES = (
    'file', 'ftp', 'gopher', 'h323', 'hdl', 'http', 'https', 'imap', 'mailto',
    'mms', 'news', 'nntp', 'prospero', 'rsync', 'rtsp', 'rtspu', 'sftp',
    'shttp', 'sip', 'sips', 'snews', 'svn', 'svn+ssh', 'telnet', 'wais',
    # Additional common-but-unofficial schemes
    'aim', 'callto', 'cvs', 'facetime', 'feed', 'git', 'gtalk', 'irc', 'ircs',
    'irc6', 'itms', 'mms', 'msnim', 'skype', 'ssh', 'smb', 'svn', 'ymsg',
)
#ACCEPTABLE_URI_SCHEMES = ()

# ---------- required modules (should come with any Python distribution) ----------
import cgi
import copy
import datetime
import re
import struct
import sys
import time
import types
import urllib
import urllib2
import urlparse

from htmlentitydefs import name2codepoint, codepoint2name, entitydefs

try:
    from io import BytesIO as _StringIO
except ImportError:
    try:
        from cStringIO import StringIO as _StringIO
    except ImportError:
        from StringIO import StringIO as _StringIO

# ---------- optional modules (feedparser will work without these, but with reduced functionality) ----------

# gzip is included with most Python distributions, but may not be available if you compiled your own

try:
    import gzip
except ImportError:
    gzip = None
try:
    import zlib
except ImportError:
    zlib = None

# If a real XML parser is available, feedparser will attempt to use it.  feedparser has
# been tested with the built-in SAX parser, PyXML, and libxml2.  On platforms where the
# Python distribution does not come with an XML parser (such as Mac OS X 10.2 and some
# versions of FreeBSD), feedparser will quietly fall back on regex-based parsing.

try:
    import xml.sax

    from xml.sax.saxutils import escape as _xmlescape

except ImportError:
    _XML_AVAILABLE = 0


    def _xmlescape(data,entities={}):
        data = data.replace('&', '&amp;')
        data = data.replace('>', '&gt;')
        data = data.replace('<', '&lt;')
        for char, entity in entities:
            data = data.replace(char, entity)
        return data
else:
    try:

        xml.sax.make_parser(PREFERRED_XML_PARSERS) # test for valid parsers
    except xml.sax.SAXReaderNotAvailable:
        _XML_AVAILABLE = 0
    else:
        _XML_AVAILABLE = 1

# sgmllib is not available by default in Python 3; if the end user doesn't have
# it available then we'll lose illformed XML parsing, content santizing, and
# microformat support (at least while feedparser depends on BeautifulSoup).
try:
    import sgmllib

except ImportError:
    # This is probably Python 3, which doesn't include sgmllib anymore
    _SGML_AVAILABLE = 0

    # Mock sgmllib enough to allow subclassing later on
    class sgmllib(object):
        class SGMLParser(object):
            def goahead(self, i):
                pass
            def parse_starttag(self, i):
                pass
else:
    _SGML_AVAILABLE = 1

    # sgmllib defines a number of module-level regular expressions that are
    # insufficient for the XML parsing feedparser needs. Rather than modify
    # the variables directly in sgmllib, they're defined here using the same
    # names, and the compiled code objects of several sgmllib.SGMLParser
    # methods are copied into _BaseHTMLProcessor so that they execute in
    # feedparser's scope instead of sgmllib's scope.
    charref = re.compile('&#(\d+|[xX][0-9a-fA-F]+);')
    tagfind = re.compile('[a-zA-Z][-_.:a-zA-Z0-9]*')

    # Unfortunately, these must be copied over to prevent NameError exceptions
    attrfind = sgmllib.attrfind
    entityref = sgmllib.entityref
    incomplete = sgmllib.incomplete
    interesting = sgmllib.interesting
    shorttag = sgmllib.shorttag
    shorttagopen = sgmllib.shorttagopen
    starttagopen = sgmllib.starttagopen

    class _EndBracketRegEx:
        def __init__(self):
            # Overriding the built-in sgmllib.endbracket regex allows the
            # parser to find angle brackets embedded in element attributes.
            self.endbracket = re.compile('''([^'"<>]|"[^"]*"(?=>|/|\s|\w+=)|'[^']*'(?=>|/|\s|\w+=))*(?=[<>])|.*?(?=[<>])''')
        def search(self, target, index=0):
            match = self.endbracket.match(target, index)
            if match is not None:
                # Returning a new object in the calling thread's context
                # resolves a thread-safety.
                return EndBracketMatch(match)
            return None
    class EndBracketMatch:
        def __init__(self, match):
            self.match = match
        def start(self, n):
            return self.match.end(n)
    endbracket = _EndBracketRegEx()


# cjkcodecs and iconv_codec provide support for more character encodings.
# Both are available from http://cjkpython.i18n.org/

try:
    import cjkcodecs.aliases
except ImportError:
    pass
try:
    import iconv_codec
except ImportError:
    pass

# chardet library auto-detects character encodings
# Download from http://chardet.feedparser.org/

try:
    import chardet

except ImportError:
    chardet = None

# BeautifulSoup parser used for parsing microformats from embedded HTML content
# http://www.crummy.com/software/BeautifulSoup/
# feedparser is tested with BeautifulSoup 3.0.x, but it might work with the
# older 2.x series.  If it doesn't, and you can figure out why, I'll accept a
# patch and modify the compatibility statement accordingly.
try:
    import BeautifulSoup
except ImportError:
    BeautifulSoup = None

# ---------- don't touch these ----------


class ThingsNobodyCaresAboutButMe(Exception): pass




class CharacterEncodingOverride(ThingsNobodyCaresAboutButMe): pass




class CharacterEncodingUnknown(ThingsNobodyCaresAboutButMe): pass




class NonXMLContentType(ThingsNobodyCaresAboutButMe): pass




class UndeclaredNamespace(Exception): pass








SUPPORTED_VERSIONS = {'': u'unknown',

                      'rss090': u'RSS 0.90',
                      'rss091n': u'RSS 0.91 (Netscape)',
                      'rss091u': u'RSS 0.91 (Userland)',
                      'rss092': u'RSS 0.92',
                      'rss093': u'RSS 0.93',
                      'rss094': u'RSS 0.94',
                      'rss20': u'RSS 2.0',
                      'rss10': u'RSS 1.0',
                      'rss': u'RSS (unknown version)',
                      'atom01': u'Atom 0.1',
                      'atom02': u'Atom 0.2',
                      'atom03': u'Atom 0.3',
                      'atom10': u'Atom 1.0',
                      'atom': u'Atom (unknown version)',
                      'cdf': u'CDF',

                      }

















class FeedParserDict(dict):

    keymap = {'channel': 'feed',

              'items': 'entries',
              'guid': 'id',
              'date': 'updated',
              'date_parsed': 'updated_parsed',
              'description': ['summary', 'subtitle'],
              'url': ['href'],
              'modified': 'updated',
              'modified_parsed': 'updated_parsed',
              'issued': 'published',
              'issued_parsed': 'published_parsed',
              'copyright': 'rights',
              'copyright_detail': 'rights_detail',
              'tagline': 'subtitle',
              'tagline_detail': 'subtitle_detail'}


    def __getitem__(self, key):
        if key == 'category':
            try:
                return dict.__getitem__(self, 'tags')[0]['term']
            except IndexError:
                raise KeyError, "object doesn't have key 'category'"
        elif key == 'enclosures':
            norel = lambda link: FeedParserDict([(name,value) for (name,value) in link.items() if name!='rel'])
            return [norel(link) for link in dict.__getitem__(self, 'links') if link['rel']==u'enclosure']
        elif key == 'license':
            for link in dict.__getitem__(self, 'links'):
                if link['rel']==u'license' and link.has_key('href'):
                    return link['href']
        elif key == 'categories':
            return [(tag['scheme'], tag['term']) for tag in dict.__getitem__(self, 'tags')]
        else:
            realkey = self.keymap.get(key, key)
            if isinstance(realkey, list):
                for k in realkey:
                    if dict.__contains__(self, k):
                        return dict.__getitem__(self, k)
            elif dict.__contains__(self, realkey):
                return dict.__getitem__(self, realkey)
        return dict.__getitem__(self, key)

    def __contains__(self, key):
        try:
            self.__getitem__(key)
        except KeyError:
            return False
        else:
            return True

    has_key = __contains__


    def get(self, key, default=None):

        try:
            return self.__getitem__(key)
        except KeyError:
            return default

    def __setitem__(self, key, value):
        key = self.keymap.get(key, key)
        if isinstance(key, list):
            key = key[0]
        return dict.__setitem__(self, key, value)

    def setdefault(self, key, value):
        if key not in self:
            self[key] = value
            return value





        return self[key]

    def __getattr__(self, key):
        # __getattribute__() is called first; this will be called
        # only if an attribute was not already found
        try:





            return self.__getitem__(key)
        except KeyError:
            raise AttributeError, "object has no attribute '%s'" % key






















_ebcdic_to_ascii_map = None


def _ebcdic_to_ascii(s):
    global _ebcdic_to_ascii_map
    if not _ebcdic_to_ascii_map:
        emap = (




            0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15,















            16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31,











            128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7,















            144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26,
















            32,160,161,162,163,164,165,166,167,168,91,46,60,40,43,33,















            38,169,170,171,172,173,174,175,176,177,93,36,42,41,59,94,
















            45,47,178,179,180,181,182,183,184,185,124,44,37,95,62,63,













            186,187,188,189,190,191,192,193,194,96,58,35,64,39,61,34,



















            195,97,98,99,100,101,102,103,104,105,196,197,198,199,200,201,











            202,106,107,108,109,110,111,112,113,114,203,204,205,206,207,208,















            209,126,115,116,117,118,119,120,121,122,210,211,212,213,214,215,















            216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,


















            123,65,66,67,68,69,70,71,72,73,232,233,234,235,236,237,












            125,74,75,76,77,78,79,80,81,82,238,239,240,241,242,243,
















            92,159,83,84,85,86,87,88,89,90,244,245,246,247,248,249,
























            48,49,50,51,52,53,54,55,56,57,250,251,252,253,254,255





            )

        _ebcdic_to_ascii_map = _maketrans( \
            _l2bytes(range(256)), _l2bytes(emap))
    return s.translate(_ebcdic_to_ascii_map)

_cp1252 = {
  unichr(128): unichr(8364), # euro sign
  unichr(130): unichr(8218), # single low-9 quotation mark
  unichr(131): unichr( 402), # latin small letter f with hook
  unichr(132): unichr(8222), # double low-9 quotation mark
  unichr(133): unichr(8230), # horizontal ellipsis
  unichr(134): unichr(8224), # dagger
  unichr(135): unichr(8225), # double dagger
  unichr(136): unichr( 710), # modifier letter circumflex accent
  unichr(137): unichr(8240), # per mille sign
  unichr(138): unichr( 352), # latin capital letter s with caron
  unichr(139): unichr(8249), # single left-pointing angle quotation mark
  unichr(140): unichr( 338), # latin capital ligature oe
  unichr(142): unichr( 381), # latin capital letter z with caron
  unichr(145): unichr(8216), # left single quotation mark
  unichr(146): unichr(8217), # right single quotation mark
  unichr(147): unichr(8220), # left double quotation mark
  unichr(148): unichr(8221), # right double quotation mark
  unichr(149): unichr(8226), # bullet
  unichr(150): unichr(8211), # en dash
  unichr(151): unichr(8212), # em dash
  unichr(152): unichr( 732), # small tilde
  unichr(153): unichr(8482), # trade mark sign
  unichr(154): unichr( 353), # latin small letter s with caron
  unichr(155): unichr(8250), # single right-pointing angle quotation mark
  unichr(156): unichr( 339), # latin small ligature oe
  unichr(158): unichr( 382), # latin small letter z with caron
  unichr(159): unichr( 376)} # latin capital letter y with diaeresis

_urifixer = re.compile('^([A-Za-z][A-Za-z0-9+-.]*://)(/*)(.*?)')


def _urljoin(base, uri):
    uri = _urifixer.sub(r'\1\3', uri)
    #try:
    uri = urlparse.urljoin(base, uri)
    if not isinstance(uri, unicode):
        return uri.decode('utf-8', 'ignore')
    return uri
    #except:
    #    uri = urlparse.urlunparse([urllib.quote(part) for part in urlparse.urlparse(uri)])
    #    return urlparse.urljoin(base, uri)

class _FeedParserMixin:

    namespaces = {'': '',

                  'http://backend.userland.com/rss': '',
                  'http://blogs.law.harvard.edu/tech/rss': '',
                  'http://purl.org/rss/1.0/': '',
                  'http://my.netscape.com/rdf/simple/0.9/': '',
                  'http://example.com/newformat#': '',
                  'http://example.com/necho': '',
                  'http://purl.org/echo/': '',
                  'uri/of/echo/namespace#': '',
                  'http://purl.org/pie/': '',
                  'http://purl.org/atom/ns#': '',
                  'http://www.w3.org/2005/Atom': '',
                  'http://purl.org/rss/1.0/modules/rss091#': '',

                  'http://webns.net/mvcb/':                               'admin',
                  'http://purl.org/rss/1.0/modules/aggregation/':         'ag',
                  'http://purl.org/rss/1.0/modules/annotate/':            'annotate',
                  'http://media.tangent.org/rss/1.0/':                    'audio',
                  'http://backend.userland.com/blogChannelModule':        'blogChannel',
                  'http://web.resource.org/cc/':                          'cc',
                  'http://backend.userland.com/creativeCommonsRssModule': 'creativeCommons',
                  'http://purl.org/rss/1.0/modules/company':              'co',
                  'http://purl.org/rss/1.0/modules/content/':             'content',
                  'http://my.theinfo.org/changed/1.0/rss/':               'cp',
                  'http://purl.org/dc/elements/1.1/':                     'dc',
                  'http://purl.org/dc/terms/':                            'dcterms',
                  'http://purl.org/rss/1.0/modules/email/':               'email',
                  'http://purl.org/rss/1.0/modules/event/':               'ev',
                  'http://rssnamespace.org/feedburner/ext/1.0':           'feedburner',
                  'http://freshmeat.net/rss/fm/':                         'fm',
                  'http://xmlns.com/foaf/0.1/':                           'foaf',
                  'http://www.w3.org/2003/01/geo/wgs84_pos#':             'geo',
                  'http://postneo.com/icbm/':                             'icbm',
                  'http://purl.org/rss/1.0/modules/image/':               'image',
                  'http://www.itunes.com/DTDs/PodCast-1.0.dtd':           'itunes',
                  'http://example.com/DTDs/PodCast-1.0.dtd':              'itunes',
                  'http://purl.org/rss/1.0/modules/link/':                'l',
                  'http://search.yahoo.com/mrss':                         'media',
                  #Version 1.1.2 of the Media RSS spec added the trailing slash on the namespace
                  'http://search.yahoo.com/mrss/':                         'media',
                  'http://madskills.com/public/xml/rss/module/pingback/': 'pingback',
                  'http://prismstandard.org/namespaces/1.2/basic/':       'prism',
                  'http://www.w3.org/1999/02/22-rdf-syntax-ns#':          'rdf',
                  'http://www.w3.org/2000/01/rdf-schema#':                'rdfs',
                  'http://purl.org/rss/1.0/modules/reference/':           'ref',
                  'http://purl.org/rss/1.0/modules/richequiv/':           'reqv',
                  'http://purl.org/rss/1.0/modules/search/':              'search',
                  'http://purl.org/rss/1.0/modules/slash/':               'slash',
                  'http://schemas.xmlsoap.org/soap/envelope/':            'soap',
                  'http://purl.org/rss/1.0/modules/servicestatus/':       'ss',
                  'http://hacks.benhammersley.com/rss/streaming/':        'str',
                  'http://purl.org/rss/1.0/modules/subscription/':        'sub',
                  'http://purl.org/rss/1.0/modules/syndication/':         'sy',
                  'http://schemas.pocketsoap.com/rss/myDescModule/':      'szf',
                  'http://purl.org/rss/1.0/modules/taxonomy/':            'taxo',
                  'http://purl.org/rss/1.0/modules/threading/':           'thr',
                  'http://purl.org/rss/1.0/modules/textinput/':           'ti',
                  'http://madskills.com/public/xml/rss/module/trackback/':'trackback',
                  'http://wellformedweb.org/commentAPI/':                 'wfw',
                  'http://purl.org/rss/1.0/modules/wiki/':                'wiki',
                  'http://www.w3.org/1999/xhtml':                         'xhtml',
                  'http://www.w3.org/1999/xlink':                         'xlink',
                  'http://www.w3.org/XML/1998/namespace':                 'xml'

}
    _matchnamespaces = {}

    can_be_relative_uri = ['link', 'id', 'wfw_comment', 'wfw_commentrss', 'docs', 'url', 'href', 'comments', 'icon', 'logo']












    can_contain_relative_uris = ['content', 'title', 'summary', 'info', 'tagline', 'subtitle', 'copyright', 'rights', 'description']










    can_contain_dangerous_markup = ['content', 'title', 'summary', 'info', 'tagline', 'subtitle', 'copyright', 'rights', 'description']










    html_types = [u'text/html', u'application/xhtml+xml']

    def __init__(self, baseuri=None, baselang=None, encoding=u'utf-8'):







        if not self._matchnamespaces:
            for k, v in self.namespaces.items():
                self._matchnamespaces[k.lower()] = v
        self.feeddata = FeedParserDict() # feed-level data
        self.encoding = encoding # character encoding
        self.entries = [] # list of entry-level data
        self.version = u'' # feed type/version, see SUPPORTED_VERSIONS
        self.namespacesInUse = {} # dictionary of namespaces defined by the feed

        # the following are used internally to track state;
        # this is really out of control and should be refactored

        self.infeed = 0
        self.inentry = 0
        self.incontent = 0
        self.intextinput = 0
        self.inimage = 0
        self.inauthor = 0
        self.incontributor = 0
        self.inpublisher = 0
        self.insource = 0
        self.sourcedata = FeedParserDict()
        self.contentparams = FeedParserDict()
        self._summaryKey = None
        self.namespacemap = {}
        self.elementstack = []
        self.basestack = []
        self.langstack = []
        self.baseuri = baseuri or u''
        self.lang = baselang or None
        self.svgOK = 0
        self.hasTitle = 0
        if baselang:
            self.feeddata['language'] = baselang.replace('_','-')

    def _normalize_attributes(self, kv):
        k = kv[0].lower()
        v = k in ('rel', 'type') and kv[1].lower() or kv[1]
        # the sgml parser doesn't handle entities in attributes, nor
        # does it pass the attribute values through as unicode, while
        # strict xml parsers do -- account for this difference
        if isinstance(self, _LooseFeedParser):
            v = v.replace('&amp;', '&')
            if not isinstance(v, unicode):

                v = v.decode('utf-8')
        return (k, v)

    def unknown_starttag(self, tag, attrs):
        # normalize attrs
        attrs = map(self._normalize_attributes, attrs)




        # track xml:base and xml:lang

        attrsD = dict(attrs)
        baseuri = attrsD.get('xml:base', attrsD.get('base')) or self.baseuri
        if not isinstance(baseuri, unicode):
            baseuri = baseuri.decode(self.encoding, 'ignore')
        # ensure that self.baseuri is always an absolute URI that
        # uses a whitelisted URI scheme (e.g. not `javscript:`)
        if self.baseuri:
            self.baseuri = _makeSafeAbsoluteURI(self.baseuri, baseuri) or self.baseuri
        else:
            self.baseuri = _urljoin(self.baseuri, baseuri)
        lang = attrsD.get('xml:lang', attrsD.get('lang'))
        if lang == '':

            # xml:lang could be explicitly set to '', we need to capture that

            lang = None
        elif lang is None:

            # if no xml:lang is specified, use parent lang

            lang = self.lang
        if lang:
            if tag in ('feed', 'rss', 'rdf:RDF'):
                self.feeddata['language'] = lang.replace('_','-')
        self.lang = lang
        self.basestack.append(self.baseuri)
        self.langstack.append(lang)

        # track namespaces

        for prefix, uri in attrs:
            if prefix.startswith('xmlns:'):
                self.trackNamespace(prefix[6:], uri)
            elif prefix == 'xmlns':
                self.trackNamespace(None, uri)

        # track inline content

        if self.incontent and self.contentparams.has_key('type') and not self.contentparams.get('type', u'xml').endswith(u'xml'):
            if tag in ['xhtml:div', 'div']:

                return # typepad does this 10/2007
            # element declared itself as escaped markup, but it isn't really

            self.contentparams['type'] = u'application/xhtml+xml'
        if self.incontent and self.contentparams.get('type') == u'application/xhtml+xml':

            if tag.find(':') <> -1:

                prefix, tag = tag.split(':', 1)
                namespace = self.namespacesInUse.get(prefix, '')
                if tag=='math' and namespace=='http://www.w3.org/1998/Math/MathML':
                    attrs.append(('xmlns',namespace))
                if tag=='svg' and namespace=='http://www.w3.org/2000/svg':





                    attrs.append(('xmlns',namespace))
            if tag == 'svg':
                self.svgOK += 1
            return self.handle_data('<%s%s>' % (tag, self.strattrs(attrs)), escape=0)


        # match namespaces

        if tag.find(':') <> -1:
            prefix, suffix = tag.split(':', 1)
        else:
            prefix, suffix = '', tag
        prefix = self.namespacemap.get(prefix, prefix)
        if prefix:
            prefix = prefix + '_'

        # special hack for better tracking of empty textinput/image elements in illformed feeds

        if (not prefix) and tag not in ('title', 'link', 'description', 'name'):

            self.intextinput = 0
        if (not prefix) and tag not in ('title', 'link', 'description', 'url', 'href', 'width', 'height'):








            self.inimage = 0

        # call special handler (if defined) or default handler

        methodname = '_start_' + prefix + suffix
        try:
            method = getattr(self, methodname)
            return method(attrsD)
        except AttributeError:
            # Since there's no handler or something has gone wrong we explicitly add the element and its attributes
            unknown_tag = prefix + suffix
            if len(attrsD) == 0:
                # No attributes so merge it into the encosing dictionary
                return self.push(unknown_tag, 1)
            else:
                # Has attributes so create it in its own dictionary
                context = self._getContext()
                context[unknown_tag] = attrsD

    def unknown_endtag(self, tag):



        # match namespaces

        if tag.find(':') <> -1:
            prefix, suffix = tag.split(':', 1)
        else:
            prefix, suffix = '', tag
        prefix = self.namespacemap.get(prefix, prefix)
        if prefix:
            prefix = prefix + '_'
        if suffix == 'svg' and self.svgOK:
            self.svgOK -= 1

        # call special handler (if defined) or default handler

        methodname = '_end_' + prefix + suffix
        try:
            if self.svgOK:
                raise AttributeError()
            method = getattr(self, methodname)
            method()
        except AttributeError:
            self.pop(prefix + suffix)

        # track inline content

        if self.incontent and self.contentparams.has_key('type') and not self.contentparams.get('type', u'xml').endswith(u'xml'):



            # element declared itself as escaped markup, but it isn't really
            if tag in ['xhtml:div', 'div']:
                return # typepad does this 10/2007
            self.contentparams['type'] = u'application/xhtml+xml'
        if self.incontent and self.contentparams.get('type') == u'application/xhtml+xml':

            tag = tag.split(':')[-1]
            self.handle_data('</%s>' % tag, escape=0)

        # track xml:base and xml:lang going out of scope

        if self.basestack:
            self.basestack.pop()
            if self.basestack and self.basestack[-1]:
                self.baseuri = self.basestack[-1]
        if self.langstack:
            self.langstack.pop()
            if self.langstack: # and (self.langstack[-1] is not None):
                self.lang = self.langstack[-1]

    def handle_charref(self, ref):

        # called for each character reference, e.g. for '&#160;', ref will be '160'

        if not self.elementstack:
            return
        ref = ref.lower()
        if ref in ('34', '38', '39', '60', '62', 'x22', 'x26', 'x27', 'x3c', 'x3e'):











            text = '&#%s;' % ref
        else:
            if ref[0] == 'x':
                c = int(ref[1:], 16)
            else:
                c = int(ref)
            text = unichr(c).encode('utf-8')
        self.elementstack[-1][2].append(text)

    def handle_entityref(self, ref):

        # called for each entity reference, e.g. for '&copy;', ref will be 'copy'

        if not self.elementstack:
            return



        if ref in ('lt', 'gt', 'quot', 'amp', 'apos'):
            text = '&%s;' % ref

        elif ref in self.entities.keys():

            text = self.entities[ref]





            if text.startswith('&#') and text.endswith(';'):

                return self.handle_entityref(text)
        else:
            try:
                name2codepoint[ref]
            except KeyError:
                text = '&%s;' % ref
            else:
                text = unichr(name2codepoint[ref]).encode('utf-8')
        self.elementstack[-1][2].append(text)

    def handle_data(self, text, escape=1):

        # called for each block of plain text, i.e. outside of any tag and
        # not containing any character or entity references

        if not self.elementstack:
            return
        if escape and self.contentparams.get('type') == u'application/xhtml+xml':

            text = _xmlescape(text)
        self.elementstack[-1][2].append(text)

    def handle_comment(self, text):

        # called for each comment, e.g. <!-- insert message here -->

        pass

    def handle_pi(self, text):

        # called for each processing instruction, e.g. <?instruction>

        pass

    def handle_decl(self, text):
        pass

    def parse_declaration(self, i):

        # override internal declaration handler to handle CDATA blocks



        if self.rawdata[i:i+9] == '<![CDATA[':
            k = self.rawdata.find(']]>', i)
            if k == -1:
                # CDATA block began but didn't finish
                k = len(self.rawdata)
                return k
            self.handle_data(_xmlescape(self.rawdata[i+9:k]), 0)
            return k+3
        else:
            k = self.rawdata.find('>', i)
            if k >= 0:
                return k+1
            else:
                # We have an incomplete CDATA block.
                return k

    def mapContentType(self, contentType):
        contentType = contentType.lower()
        if contentType == 'text' or contentType == 'plain':
            contentType = u'text/plain'
        elif contentType == 'html':
            contentType = u'text/html'
        elif contentType == 'xhtml':
            contentType = u'application/xhtml+xml'
        return contentType

    def trackNamespace(self, prefix, uri):
        loweruri = uri.lower()
        if (prefix, loweruri) == (None, 'http://my.netscape.com/rdf/simple/0.9/') and not self.version:


            self.version = u'rss090'
        if loweruri == 'http://purl.org/rss/1.0/' and not self.version:
            self.version = u'rss10'
        if loweruri == 'http://www.w3.org/2005/atom' and not self.version:

            self.version = u'atom10'
        if loweruri.find(u'backend.userland.com/rss') <> -1:

            # match any backend.userland.com namespace

            uri = u'http://backend.userland.com/rss'
            loweruri = uri
        if self._matchnamespaces.has_key(loweruri):
            self.namespacemap[prefix] = self._matchnamespaces[loweruri]
            self.namespacesInUse[self._matchnamespaces[loweruri]] = uri
        else:
            self.namespacesInUse[prefix or ''] = uri

    def resolveURI(self, uri):
        return _urljoin(self.baseuri or u'', uri)

    def decodeEntities(self, element, data):
        return data

    def strattrs(self, attrs):
        return ''.join([' %s="%s"' % (t[0],_xmlescape(t[1],{'"':'&quot;'})) for t in attrs])

    def push(self, element, expectingText):
        self.elementstack.append([element, expectingText, []])

    def pop(self, element, stripWhitespace=1):
        if not self.elementstack:
            return
        if self.elementstack[-1][0] != element:
            return

        element, expectingText, pieces = self.elementstack.pop()

        if self.version == u'atom10' and self.contentparams.get('type', u'text') == u'application/xhtml+xml':
            # remove enclosing child element, but only if it is a <div> and
            # only if all the remaining content is nested underneath it.
            # This means that the divs would be retained in the following:
            #    <div>foo</div><div>bar</div>
            while pieces and len(pieces)>1 and not pieces[-1].strip():
                del pieces[-1]
            while pieces and len(pieces)>1 and not pieces[0].strip():
                del pieces[0]
            if pieces and (pieces[0] == '<div>' or pieces[0].startswith('<div ')) and pieces[-1]=='</div>':
                depth = 0
                for piece in pieces[:-1]:
                    if piece.startswith('</'):
                        depth -= 1
                        if depth == 0:
                            break
                    elif piece.startswith('<') and not piece.endswith('/>'):
                        depth += 1
                else:
                    pieces = pieces[1:-1]

        # Ensure each piece is a str for Python 3
        for (i, v) in enumerate(pieces):
            if not isinstance(v, unicode):
                pieces[i] = v.decode('utf-8')

        output = u''.join(pieces)
        if stripWhitespace:
            output = output.strip()
        if not expectingText:
            return output

        # decode base64 content

        if base64 and self.contentparams.get('base64', 0):
            try:
                output = _base64decode(output)
            except binascii.Error:
                pass
            except binascii.Incomplete:
                pass
            except TypeError:
                # In Python 3, base64 takes and outputs bytes, not str
                # This may not be the most correct way to accomplish this
                output = _base64decode(output.encode('utf-8')).decode('utf-8')

        # resolve relative URIs

        if (element in self.can_be_relative_uri) and output:
            output = self.resolveURI(output)

        # decode entities within embedded markup

        if not self.contentparams.get('base64', 0):
            output = self.decodeEntities(element, output)

        # some feed formats require consumers to guess
        # whether the content is html or plain text
        if not self.version.startswith(u'atom') and self.contentparams.get('type') == u'text/plain':
            if self.lookslikehtml(output):
                self.contentparams['type'] = u'text/html'

        # remove temporary cruft from contentparams
        try:
            del self.contentparams['mode']
        except KeyError:
            pass
        try:
            del self.contentparams['base64']
        except KeyError:
            pass

        is_htmlish = self.mapContentType(self.contentparams.get('type', u'text/html')) in self.html_types
        # resolve relative URIs within embedded markup
        if is_htmlish and RESOLVE_RELATIVE_URIS:


            if element in self.can_contain_relative_uris:
                output = _resolveRelativeURIs(output, self.baseuri, self.encoding, self.contentparams.get('type', u'text/html'))

        # parse microformats
        # (must do this before sanitizing because some microformats
        # rely on elements that we sanitize)
        if is_htmlish and element in ['content', 'description', 'summary']:
            mfresults = _parseMicroformats(output, self.baseuri, self.encoding)
            if mfresults:
                for tag in mfresults.get('tags', []):
                    self._addTag(tag['term'], tag['scheme'], tag['label'])
                for enclosure in mfresults.get('enclosures', []):
                    self._start_enclosure(enclosure)
                for xfn in mfresults.get('xfn', []):
                    self._addXFN(xfn['relationships'], xfn['href'], xfn['name'])
                vcard = mfresults.get('vcard')
                if vcard:
                    self._getContext()['vcard'] = vcard

        # sanitize embedded markup
        if is_htmlish and SANITIZE_HTML:


            if element in self.can_contain_dangerous_markup:
                output = _sanitizeHTML(output, self.encoding, self.contentparams.get('type', u'text/html'))

        if self.encoding and not isinstance(output, unicode):
            output = output.decode(self.encoding, 'ignore')

        # address common error where people take data that is already
        # utf-8, presume that it is iso-8859-1, and re-encode it.
        if self.encoding in (u'utf-8', u'utf-8_INVALID_PYTHON_3') and isinstance(output, unicode):
            try:
                output = output.encode('iso-8859-1').decode('utf-8')
            except (UnicodeEncodeError, UnicodeDecodeError):
                pass

        # map win-1252 extensions to the proper code points
        if isinstance(output, unicode):
            output = u''.join([c in _cp1252.keys() and _cp1252[c] or c for c in output])

        # categories/tags/keywords/whatever are handled in _end_category
        if element == 'category':
            return output

        if element == 'title' and self.hasTitle:
            return output

        # store output in appropriate place(s)

        if self.inentry and not self.insource:
            if element == 'content':
                self.entries[-1].setdefault(element, [])
                contentparams = copy.deepcopy(self.contentparams)
                contentparams['value'] = output
                self.entries[-1][element].append(contentparams)
            elif element == 'link':
                if not self.inimage:
                    # query variables in urls in link elements are improperly
                    # converted from `?a=1&b=2` to `?a=1&b;=2` as if they're
                    # unhandled character references. fix this special case.
                    output = re.sub("&([A-Za-z0-9_]+);", "&\g<1>", output)
                    self.entries[-1][element] = output
                    if output:
                        self.entries[-1]['links'][-1]['href'] = output
            else:
                if element == 'description':
                    element = 'summary'
                self.entries[-1][element] = output
                if self.incontent:
                    contentparams = copy.deepcopy(self.contentparams)
                    contentparams['value'] = output
                    self.entries[-1][element + '_detail'] = contentparams

        elif (self.infeed or self.insource):# and (not self.intextinput) and (not self.inimage):

            context = self._getContext()
            if element == 'description':
                element = 'subtitle'
            context[element] = output
            if element == 'link':
                # fix query variables; see above for the explanation
                output = re.sub("&([A-Za-z0-9_]+);", "&\g<1>", output)
                context[element] = output
                context['links'][-1]['href'] = output
            elif self.incontent:
                contentparams = copy.deepcopy(self.contentparams)
                contentparams['value'] = output
                context[element + '_detail'] = contentparams
        return output

    def pushContent(self, tag, attrsD, defaultContentType, expectingText):






        self.incontent += 1
        if self.lang:
            self.lang=self.lang.replace('_','-')
        self.contentparams = FeedParserDict({
            'type': self.mapContentType(attrsD.get('type', defaultContentType)),
            'language': self.lang,
            'base': self.baseuri})
        self.contentparams['base64'] = self._isBase64(attrsD, self.contentparams)

        self.push(tag, expectingText)

    def popContent(self, tag):
        value = self.pop(tag)
        self.incontent -= 1
        self.contentparams.clear()
        return value

    # a number of elements in a number of RSS variants are nominally plain
    # text, but this is routinely ignored.  This is an attempt to detect
    # the most common cases.  As false positives often result in silent
    # data loss, this function errs on the conservative side.
    @staticmethod
    def lookslikehtml(s):
        # must have a close tag or a entity reference to qualify
        if not (re.search(r'</(\w+)>',s) or re.search("&#?\w+;",s)):
            return

        # all tags must be in a restricted subset of valid HTML tags
        if filter(lambda t: t.lower() not in _HTMLSanitizer.acceptable_elements,
            re.findall(r'</?(\w+)',s)):
            return

        # all entities must have been defined as valid HTML entities
        if filter(lambda e: e not in entitydefs.keys(), re.findall(r'&(\w+);', s)):
            return

        return 1

    def _mapToStandardPrefix(self, name):
        colonpos = name.find(':')
        if colonpos <> -1:
            prefix = name[:colonpos]
            suffix = name[colonpos+1:]
            prefix = self.namespacemap.get(prefix, prefix)
            name = prefix + ':' + suffix
        return name

    def _getAttribute(self, attrsD, name):
        return attrsD.get(self._mapToStandardPrefix(name))

    def _isBase64(self, attrsD, contentparams):
        if attrsD.get('mode', '') == 'base64':
            return 1
        if self.contentparams['type'].startswith(u'text/'):
            return 0
        if self.contentparams['type'].endswith(u'+xml'):
            return 0
        if self.contentparams['type'].endswith(u'/xml'):
            return 0
        return 1

    def _itsAnHrefDamnIt(self, attrsD):
        href = attrsD.get('url', attrsD.get('uri', attrsD.get('href', None)))

        if href:
            try:
                del attrsD['url']
            except KeyError:
                pass
            try:
                del attrsD['uri']
            except KeyError:
                pass
            attrsD['href'] = href
        return attrsD

    def _save(self, key, value, overwrite=False):
        context = self._getContext()
        if overwrite:
            context[key] = value
        else:
            context.setdefault(key, value)

    def _start_rss(self, attrsD):
        versionmap = {'0.91': u'rss091u',

                      '0.92': u'rss092',
                      '0.93': u'rss093',
                      '0.94': u'rss094'}

        #If we're here then this is an RSS feed.
        #If we don't have a version or have a version that starts with something
        #other than RSS then there's been a mistake. Correct it.
        if not self.version or not self.version.startswith(u'rss'):
            attr_version = attrsD.get('version', '')
            version = versionmap.get(attr_version)
            if version:
                self.version = version
            elif attr_version.startswith('2.'):
                self.version = u'rss20'
            else:



                self.version = u'rss'

    def _start_channel(self, attrsD):
        self.infeed = 1
        self._cdf_common(attrsD)



    def _cdf_common(self, attrsD):
        if attrsD.has_key('lastmod'):
            self._start_modified({})
            self.elementstack[-1][-1] = attrsD['lastmod']
            self._end_modified()
        if attrsD.has_key('href'):
            self._start_link({})
            self.elementstack[-1][-1] = attrsD['href']
            self._end_link()

    def _start_feed(self, attrsD):
        self.infeed = 1
        versionmap = {'0.1': u'atom01',
                      '0.2': u'atom02',
                      '0.3': u'atom03'}
        if not self.version:
            attr_version = attrsD.get('version')
            version = versionmap.get(attr_version)
            if version:
                self.version = version
            else:
                self.version = u'atom'

    def _end_channel(self):
        self.infeed = 0

    _end_feed = _end_channel

    def _start_image(self, attrsD):


        context = self._getContext()
        if not self.inentry:
            context.setdefault('image', FeedParserDict())
        self.inimage = 1
        self.hasTitle = 0
        self.push('image', 0)

    def _end_image(self):
        self.pop('image')
        self.inimage = 0

    def _start_textinput(self, attrsD):


        context = self._getContext()
        context.setdefault('textinput', FeedParserDict())
        self.intextinput = 1
        self.hasTitle = 0
        self.push('textinput', 0)
    _start_textInput = _start_textinput

    def _end_textinput(self):
        self.pop('textinput')
        self.intextinput = 0

    _end_textInput = _end_textinput

    def _start_author(self, attrsD):
        self.inauthor = 1
        self.push('author', 1)
        # Append a new FeedParserDict when expecting an author
        context = self._getContext()
        context.setdefault('authors', [])
        context['authors'].append(FeedParserDict())
    _start_managingeditor = _start_author
    _start_dc_author = _start_author
    _start_dc_creator = _start_author
    _start_itunes_author = _start_author

    def _end_author(self):
        self.pop('author')
        self.inauthor = 0
        self._sync_author_detail()

    _end_managingeditor = _end_author
    _end_dc_author = _end_author
    _end_dc_creator = _end_author
    _end_itunes_author = _end_author

    def _start_itunes_owner(self, attrsD):
        self.inpublisher = 1
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417




1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433


1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466

1467
1468
1469
1470
1471
1472

1473

1474

1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592


1593
1594
1595
1596
1597
1598

1599
1600
1601








1602
1603
1604
1605



1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631




1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653

1654
1655
1656
1657
1658
1659



1660

1661
1662
1663
1664
1665
1666

1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706

1707
1708
1709
1710
1711
1712
1713


1714


1715
1716
1717
1718
1719
1720


1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750

1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766

    def _end_dc_contributor(self):
        self._end_name()
        self.incontributor = 0

    def _start_name(self, attrsD):
        self.push('name', 0)

    _start_itunes_name = _start_name

    def _end_name(self):
        value = self.pop('name')
        if self.inpublisher:
            self._save_author('name', value, 'publisher')
        elif self.inauthor:
            self._save_author('name', value)
        elif self.incontributor:
            self._save_contributor('name', value)
        elif self.intextinput:
            context = self._getContext()
            context['textinput']['name'] = value

    _end_itunes_name = _end_name

    def _start_width(self, attrsD):
        self.push('width', 0)

    def _end_width(self):
        value = self.pop('width')
        try:
            value = int(value)
        except:
            value = 0
        if self.inimage:
            context = self._getContext()
            context['image']['width'] = value

    def _start_height(self, attrsD):
        self.push('height', 0)

    def _end_height(self):
        value = self.pop('height')
        try:
            value = int(value)
        except:
            value = 0
        if self.inimage:
            context = self._getContext()
            context['image']['height'] = value

    def _start_url(self, attrsD):
        self.push('href', 1)

    _start_homepage = _start_url
    _start_uri = _start_url

    def _end_url(self):
        value = self.pop('href')
        if self.inauthor:
            self._save_author('href', value)
        elif self.incontributor:
            self._save_contributor('href', value)
        elif self.inimage:
            context = self._getContext()
            context['image']['href'] = value
        elif self.intextinput:
            context = self._getContext()
            context['textinput']['link'] = value

    _end_homepage = _end_url
    _end_uri = _end_url

    def _start_email(self, attrsD):
        self.push('email', 0)

    _start_itunes_email = _start_email

    def _end_email(self):
        value = self.pop('email')
        if self.inpublisher:
            self._save_author('email', value, 'publisher')
        elif self.inauthor:
            self._save_author('email', value)
        elif self.incontributor:
            self._save_contributor('email', value)

    _end_itunes_email = _end_email

    def _getContext(self):
        if self.insource:
            context = self.sourcedata




        elif self.inentry:
            context = self.entries[-1]
        else:
            context = self.feeddata
        return context

    def _save_author(
        self,
        key,
        value,
        prefix='author',
        ):
        context = self._getContext()
        context.setdefault(prefix + '_detail', FeedParserDict())
        context[prefix + '_detail'][key] = value
        self._sync_author_detail()



    def _save_contributor(self, key, value):
        context = self._getContext()
        context.setdefault('contributors', [FeedParserDict()])
        context['contributors'][-1][key] = value

    def _sync_author_detail(self, key='author'):
        context = self._getContext()
        detail = context.get('%s_detail' % key)
        if detail:
            name = detail.get('name')
            email = detail.get('email')
            if name and email:
                context[key] = '%s (%s)' % (name, email)
            elif name:
                context[key] = name
            elif email:
                context[key] = email
        else:
            author = context.get(key)
            if not author:
                return
            emailmatch = \
                re.search(r'''(([a-zA-Z0-9\_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))'''
                          , author)
            if not emailmatch:
                return
            email = emailmatch.group(0)

            # probably a better way to do the following, but it passes all the tests

            author = author.replace(email, '')
            author = author.replace('()', '')

            author = author.strip()
            if author and author[0] == '(':
                author = author[1:]
            if author and author[-1] == ')':
                author = author[:-1]
            author = author.strip()

            context.setdefault('%s_detail' % key, FeedParserDict())

            context['%s_detail' % key]['name'] = author

            context['%s_detail' % key]['email'] = email

    def _start_subtitle(self, attrsD):
        self.pushContent('subtitle', attrsD, 'text/plain', 1)

    _start_tagline = _start_subtitle
    _start_itunes_subtitle = _start_subtitle

    def _end_subtitle(self):
        self.popContent('subtitle')

    _end_tagline = _end_subtitle
    _end_itunes_subtitle = _end_subtitle

    def _start_rights(self, attrsD):
        self.pushContent('rights', attrsD, 'text/plain', 1)

    _start_dc_rights = _start_rights
    _start_copyright = _start_rights

    def _end_rights(self):
        self.popContent('rights')

    _end_dc_rights = _end_rights
    _end_copyright = _end_rights

    def _start_item(self, attrsD):
        self.entries.append(FeedParserDict())
        self.push('item', 0)
        self.inentry = 1
        self.guidislink = 0

        id = self._getAttribute(attrsD, 'rdf:about')
        if id:
            context = self._getContext()
            context['id'] = id
        self._cdf_common(attrsD)

    _start_entry = _start_item
    _start_product = _start_item

    def _end_item(self):
        self.pop('item')
        self.inentry = 0

    _end_entry = _end_item

    def _start_dc_language(self, attrsD):
        self.push('language', 1)

    _start_language = _start_dc_language

    def _end_dc_language(self):
        self.lang = self.pop('language')

    _end_language = _end_dc_language

    def _start_dc_publisher(self, attrsD):
        self.push('publisher', 1)

    _start_webmaster = _start_dc_publisher

    def _end_dc_publisher(self):
        self.pop('publisher')
        self._sync_author_detail('publisher')

    _end_webmaster = _end_dc_publisher

    def _start_published(self, attrsD):
        self.push('published', 1)

    _start_dcterms_issued = _start_published
    _start_issued = _start_published

    def _end_published(self):
        value = self.pop('published')
        self._save('published_parsed', _parse_date(value))

    _end_dcterms_issued = _end_published
    _end_issued = _end_published

    def _start_updated(self, attrsD):
        self.push('updated', 1)

    _start_modified = _start_updated
    _start_dcterms_modified = _start_updated
    _start_pubdate = _start_updated
    _start_dc_date = _start_updated


    def _end_updated(self):
        value = self.pop('updated')
        parsed_value = _parse_date(value)
        self._save('updated_parsed', parsed_value)

    _end_modified = _end_updated
    _end_dcterms_modified = _end_updated
    _end_pubdate = _end_updated
    _end_dc_date = _end_updated


    def _start_created(self, attrsD):
        self.push('created', 1)

    _start_dcterms_created = _start_created

    def _end_created(self):
        value = self.pop('created')
        self._save('created_parsed', _parse_date(value))

    _end_dcterms_created = _end_created

    def _start_expirationdate(self, attrsD):
        self.push('expired', 1)

    def _end_expirationdate(self):
        self._save('expired_parsed', _parse_date(self.pop('expired')))

    def _start_cc_license(self, attrsD):
        self.push('license', 1)
        value = self._getAttribute(attrsD, 'rdf:resource')


        if value:
            self.elementstack[-1][2].append(value)
        self.pop('license')

    def _start_creativecommons_license(self, attrsD):
        self.push('license', 1)


    def _end_creativecommons_license(self):
        self.pop('license')









    def _addTag(
        self,
        term,



        scheme,
        label,
        ):
        context = self._getContext()
        tags = context.setdefault('tags', [])
        if not term and not scheme and not label:
            return
        value = FeedParserDict({'term': term, 'scheme': scheme, 'label'
                               : label})
        if value not in tags:
            tags.append(FeedParserDict({'term': term, 'scheme': scheme,
                        'label': label}))

    def _start_category(self, attrsD):
        if _debug:
            sys.stderr.write('entering _start_category with %s\n'
                              % repr(attrsD))
        term = attrsD.get('term')
        scheme = attrsD.get('scheme', attrsD.get('domain'))
        label = attrsD.get('label')
        self._addTag(term, scheme, label)
        self.push('category', 1)

    _start_dc_subject = _start_category
    _start_keywords = _start_category





    def _end_itunes_keywords(self):
        for term in self.pop('itunes_keywords').split():
            self._addTag(term, 'http://www.itunes.com/', None)

    def _start_itunes_category(self, attrsD):
        self._addTag(attrsD.get('text'), 'http://www.itunes.com/', None)
        self.push('category', 1)

    def _end_category(self):
        value = self.pop('category')
        if not value:
            return
        context = self._getContext()
        tags = context['tags']
        if value and len(tags) and not tags[-1]['term']:
            tags[-1]['term'] = value
        else:
            self._addTag(value, None, None)

    _end_dc_subject = _end_category
    _end_keywords = _end_category
    _end_itunes_category = _end_category


    def _start_cloud(self, attrsD):
        self._getContext()['cloud'] = FeedParserDict(attrsD)

    def _start_link(self, attrsD):
        attrsD.setdefault('rel', 'alternate')



        attrsD.setdefault('type', 'text/html')

        attrsD = self._itsAnHrefDamnIt(attrsD)
        if attrsD.has_key('href'):
            attrsD['href'] = self.resolveURI(attrsD['href'])
        expectingText = self.infeed or self.inentry or self.insource
        context = self._getContext()
        context.setdefault('links', [])

        context['links'].append(FeedParserDict(attrsD))
        if attrsD['rel'] == 'enclosure':
            self._start_enclosure(attrsD)
        if attrsD.has_key('href'):
            expectingText = 0
            if attrsD.get('rel') == 'alternate'\
                 and self.mapContentType(attrsD.get('type'))\
                 in self.html_types:
                context['link'] = attrsD['href']
        else:
            self.push('link', expectingText)

    _start_producturl = _start_link

    def _end_link(self):
        value = self.pop('link')
        context = self._getContext()
        if self.intextinput:
            context['textinput']['link'] = value
        if self.inimage:
            context['image']['link'] = value

    _end_producturl = _end_link

    def _start_guid(self, attrsD):
        self.guidislink = attrsD.get('ispermalink', 'true') == 'true'
        self.push('id', 1)

    def _end_guid(self):
        value = self.pop('id')
        self._save('guidislink', self.guidislink
                    and not self._getContext().has_key('link'))
        if self.guidislink:

            # guid acts as link, but only if 'ispermalink' is not present or is 'true',
            # and only if the item doesn't already have a link element

            self._save('link', value)

    def _start_title(self, attrsD):

        self.pushContent('title', attrsD, 'text/plain', self.infeed
                          or self.inentry or self.insource)

    _start_dc_title = _start_title
    _start_media_title = _start_title

    def _end_title(self):


        value = self.popContent('title')


        context = self._getContext()
        if self.intextinput:
            context['textinput']['title'] = value
        elif self.inimage:
            context['image']['title'] = value



    _end_dc_title = _end_title
    _end_media_title = _end_title

    def _start_description(self, attrsD):
        context = self._getContext()
        if context.has_key('summary'):
            self._summaryKey = 'content'
            self._start_content(attrsD)
        else:
            self.pushContent('description', attrsD, 'text/html',
                             self.infeed or self.inentry
                              or self.insource)

    def _start_abstract(self, attrsD):
        self.pushContent('description', attrsD, 'text/plain',
                         self.infeed or self.inentry or self.insource)

    def _end_description(self):
        if self._summaryKey == 'content':
            self._end_content()
        else:
            value = self.popContent('description')
            context = self._getContext()
            if self.intextinput:
                context['textinput']['description'] = value
            elif self.inimage:
                context['image']['description'] = value
        self._summaryKey = None

    _end_abstract = _end_description


    def _start_info(self, attrsD):
        self.pushContent('info', attrsD, 'text/plain', 1)

    _start_feedburner_browserfriendly = _start_info

    def _end_info(self):
        self.popContent('info')

    _end_feedburner_browserfriendly = _end_info

    def _start_generator(self, attrsD):
        if attrsD:
            attrsD = self._itsAnHrefDamnIt(attrsD)
            if attrsD.has_key('href'):
                attrsD['href'] = self.resolveURI(attrsD['href'])







<












|
<









|



|








|



|



<









<
<
<
<
<
<
<





<










<





>
>
>
>






|
<
<
<
<
<




>
>













|





|


<
|
<
|
<
|
<
|
|
|
|
>
|
|
|
|
|
|
>
|
>
|
>
|


|
<





<




|
<





<








>





<

<




<




<




<




<





<




<





|
<





<




>




|
<




>



<




|
<






|


|

>
>

|
|



>


|
>
>
>
>
>
>
>
>

|
|
|
>
>
>
|
|
<


|

|
<

|
<


<
<
<





<



>
>
>
>


|


|












<



>





|
>
>
>
|
>




<

>
|
<
<


<
|
<




<
<



<
<
<
<

<
<

|




|
<

<


<



>
|
|
<




>
>

>
>

<
<
|
|

>
>
|
|







|
|
<


|
<






<
<
<
<
<

<

>


|
<




<







1178
1179
1180
1181
1182
1183
1184

1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197

1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227

1228
1229
1230
1231
1232
1233
1234
1235
1236







1237
1238
1239
1240
1241

1242
1243
1244
1245
1246
1247
1248
1249
1250
1251

1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267





1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295

1296

1297

1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318

1319
1320
1321
1322
1323

1324
1325
1326
1327
1328

1329
1330
1331
1332
1333

1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

1348

1349
1350
1351
1352

1353
1354
1355
1356

1357
1358
1359
1360

1361
1362
1363
1364

1365
1366
1367
1368
1369

1370
1371
1372
1373

1374
1375
1376
1377
1378
1379

1380
1381
1382
1383
1384

1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402

1403
1404
1405
1406
1407

1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447

1448
1449
1450
1451
1452

1453
1454

1455
1456



1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486

1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508


1509
1510

1511

1512
1513
1514
1515


1516
1517
1518




1519


1520
1521
1522
1523
1524
1525
1526

1527

1528
1529

1530
1531
1532
1533
1534
1535

1536
1537
1538
1539
1540
1541
1542
1543
1544
1545


1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561

1562
1563
1564

1565
1566
1567
1568
1569
1570





1571

1572
1573
1574
1575
1576

1577
1578
1579
1580

1581
1582
1583
1584
1585
1586
1587

    def _end_dc_contributor(self):
        self._end_name()
        self.incontributor = 0

    def _start_name(self, attrsD):
        self.push('name', 0)

    _start_itunes_name = _start_name

    def _end_name(self):
        value = self.pop('name')
        if self.inpublisher:
            self._save_author('name', value, 'publisher')
        elif self.inauthor:
            self._save_author('name', value)
        elif self.incontributor:
            self._save_contributor('name', value)
        elif self.intextinput:
            context = self._getContext()
            context['name'] = value

    _end_itunes_name = _end_name

    def _start_width(self, attrsD):
        self.push('width', 0)

    def _end_width(self):
        value = self.pop('width')
        try:
            value = int(value)
        except ValueError:
            value = 0
        if self.inimage:
            context = self._getContext()
            context['width'] = value

    def _start_height(self, attrsD):
        self.push('height', 0)

    def _end_height(self):
        value = self.pop('height')
        try:
            value = int(value)
        except ValueError:
            value = 0
        if self.inimage:
            context = self._getContext()
            context['height'] = value

    def _start_url(self, attrsD):
        self.push('href', 1)

    _start_homepage = _start_url
    _start_uri = _start_url

    def _end_url(self):
        value = self.pop('href')
        if self.inauthor:
            self._save_author('href', value)
        elif self.incontributor:
            self._save_contributor('href', value)







    _end_homepage = _end_url
    _end_uri = _end_url

    def _start_email(self, attrsD):
        self.push('email', 0)

    _start_itunes_email = _start_email

    def _end_email(self):
        value = self.pop('email')
        if self.inpublisher:
            self._save_author('email', value, 'publisher')
        elif self.inauthor:
            self._save_author('email', value)
        elif self.incontributor:
            self._save_contributor('email', value)

    _end_itunes_email = _end_email

    def _getContext(self):
        if self.insource:
            context = self.sourcedata
        elif self.inimage and self.feeddata.has_key('image'):
            context = self.feeddata['image']
        elif self.intextinput:
            context = self.feeddata['textinput']
        elif self.inentry:
            context = self.entries[-1]
        else:
            context = self.feeddata
        return context

    def _save_author(self, key, value, prefix='author'):





        context = self._getContext()
        context.setdefault(prefix + '_detail', FeedParserDict())
        context[prefix + '_detail'][key] = value
        self._sync_author_detail()
        context.setdefault('authors', [FeedParserDict()])
        context['authors'][-1][key] = value

    def _save_contributor(self, key, value):
        context = self._getContext()
        context.setdefault('contributors', [FeedParserDict()])
        context['contributors'][-1][key] = value

    def _sync_author_detail(self, key='author'):
        context = self._getContext()
        detail = context.get('%s_detail' % key)
        if detail:
            name = detail.get('name')
            email = detail.get('email')
            if name and email:
                context[key] = u'%s (%s)' % (name, email)
            elif name:
                context[key] = name
            elif email:
                context[key] = email
        else:
            author, email = context.get(key), None
            if not author:
                return

            emailmatch = re.search(ur'''(([a-zA-Z0-9\_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))(\?subject=\S+)?''', author)

            if emailmatch:

                email = emailmatch.group(0)

                # probably a better way to do the following, but it passes all the tests
                author = author.replace(email, u'')
                author = author.replace(u'()', u'')
                author = author.replace(u'<>', u'')
                author = author.replace(u'&lt;&gt;', u'')
                author = author.strip()
                if author and (author[0] == u'('):
                    author = author[1:]
                if author and (author[-1] == u')'):
                    author = author[:-1]
                author = author.strip()
            if author or email:
                context.setdefault('%s_detail' % key, FeedParserDict())
            if author:
                context['%s_detail' % key]['name'] = author
            if email:
                context['%s_detail' % key]['email'] = email

    def _start_subtitle(self, attrsD):
        self.pushContent('subtitle', attrsD, u'text/plain', 1)

    _start_tagline = _start_subtitle
    _start_itunes_subtitle = _start_subtitle

    def _end_subtitle(self):
        self.popContent('subtitle')

    _end_tagline = _end_subtitle
    _end_itunes_subtitle = _end_subtitle

    def _start_rights(self, attrsD):
        self.pushContent('rights', attrsD, u'text/plain', 1)

    _start_dc_rights = _start_rights
    _start_copyright = _start_rights

    def _end_rights(self):
        self.popContent('rights')

    _end_dc_rights = _end_rights
    _end_copyright = _end_rights

    def _start_item(self, attrsD):
        self.entries.append(FeedParserDict())
        self.push('item', 0)
        self.inentry = 1
        self.guidislink = 0
        self.hasTitle = 0
        id = self._getAttribute(attrsD, 'rdf:about')
        if id:
            context = self._getContext()
            context['id'] = id
        self._cdf_common(attrsD)

    _start_entry = _start_item


    def _end_item(self):
        self.pop('item')
        self.inentry = 0

    _end_entry = _end_item

    def _start_dc_language(self, attrsD):
        self.push('language', 1)

    _start_language = _start_dc_language

    def _end_dc_language(self):
        self.lang = self.pop('language')

    _end_language = _end_dc_language

    def _start_dc_publisher(self, attrsD):
        self.push('publisher', 1)

    _start_webmaster = _start_dc_publisher

    def _end_dc_publisher(self):
        self.pop('publisher')
        self._sync_author_detail('publisher')

    _end_webmaster = _end_dc_publisher

    def _start_published(self, attrsD):
        self.push('published', 1)

    _start_dcterms_issued = _start_published
    _start_issued = _start_published

    def _end_published(self):
        value = self.pop('published')
        self._save('published_parsed', _parse_date(value), overwrite=True)

    _end_dcterms_issued = _end_published
    _end_issued = _end_published

    def _start_updated(self, attrsD):
        self.push('updated', 1)

    _start_modified = _start_updated
    _start_dcterms_modified = _start_updated
    _start_pubdate = _start_updated
    _start_dc_date = _start_updated
    _start_lastbuilddate = _start_updated

    def _end_updated(self):
        value = self.pop('updated')
        parsed_value = _parse_date(value)
        self._save('updated_parsed', parsed_value, overwrite=True)

    _end_modified = _end_updated
    _end_dcterms_modified = _end_updated
    _end_pubdate = _end_updated
    _end_dc_date = _end_updated
    _end_lastbuilddate = _end_updated

    def _start_created(self, attrsD):
        self.push('created', 1)

    _start_dcterms_created = _start_created

    def _end_created(self):
        value = self.pop('created')
        self._save('created_parsed', _parse_date(value), overwrite=True)

    _end_dcterms_created = _end_created

    def _start_expirationdate(self, attrsD):
        self.push('expired', 1)

    def _end_expirationdate(self):
        self._save('expired_parsed', _parse_date(self.pop('expired')), overwrite=True)

    def _start_cc_license(self, attrsD):
        context = self._getContext()
        value = self._getAttribute(attrsD, 'rdf:resource')
        attrsD = FeedParserDict()
        attrsD['rel'] = u'license'
        if value:
            attrsD['href']=value
        context.setdefault('links', []).append(attrsD)

    def _start_creativecommons_license(self, attrsD):
        self.push('license', 1)
    _start_creativeCommons_license = _start_creativecommons_license

    def _end_creativecommons_license(self):
        value = self.pop('license')
        context = self._getContext()
        attrsD = FeedParserDict()
        attrsD['rel'] = u'license'
        if value:
            attrsD['href'] = value
        context.setdefault('links', []).append(attrsD)
        del context['license']
    _end_creativeCommons_license = _end_creativecommons_license

    def _addXFN(self, relationships, href, name):
        context = self._getContext()
        xfn = context.setdefault('xfn', [])
        value = FeedParserDict({'relationships': relationships, 'href': href, 'name': name})
        if value not in xfn:
            xfn.append(value)

    def _addTag(self, term, scheme, label):

        context = self._getContext()
        tags = context.setdefault('tags', [])
        if (not term) and (not scheme) and (not label):
            return
        value = FeedParserDict({'term': term, 'scheme': scheme, 'label': label})

        if value not in tags:
            tags.append(value)


    def _start_category(self, attrsD):



        term = attrsD.get('term')
        scheme = attrsD.get('scheme', attrsD.get('domain'))
        label = attrsD.get('label')
        self._addTag(term, scheme, label)
        self.push('category', 1)

    _start_dc_subject = _start_category
    _start_keywords = _start_category

    def _start_media_category(self, attrsD):
        attrsD.setdefault('scheme', u'http://search.yahoo.com/mrss/category_schema')
        self._start_category(attrsD)

    def _end_itunes_keywords(self):
        for term in self.pop('itunes_keywords').split():
            self._addTag(term, u'http://www.itunes.com/', None)

    def _start_itunes_category(self, attrsD):
        self._addTag(attrsD.get('text'), u'http://www.itunes.com/', None)
        self.push('category', 1)

    def _end_category(self):
        value = self.pop('category')
        if not value:
            return
        context = self._getContext()
        tags = context['tags']
        if value and len(tags) and not tags[-1]['term']:
            tags[-1]['term'] = value
        else:
            self._addTag(value, None, None)

    _end_dc_subject = _end_category
    _end_keywords = _end_category
    _end_itunes_category = _end_category
    _end_media_category = _end_category

    def _start_cloud(self, attrsD):
        self._getContext()['cloud'] = FeedParserDict(attrsD)

    def _start_link(self, attrsD):
        attrsD.setdefault('rel', u'alternate')
        if attrsD['rel'] == u'self':
            attrsD.setdefault('type', u'application/atom+xml')
        else:
            attrsD.setdefault('type', u'text/html')
        context = self._getContext()
        attrsD = self._itsAnHrefDamnIt(attrsD)
        if attrsD.has_key('href'):
            attrsD['href'] = self.resolveURI(attrsD['href'])
        expectingText = self.infeed or self.inentry or self.insource

        context.setdefault('links', [])
        if not (self.inentry and self.inimage):
            context['links'].append(FeedParserDict(attrsD))


        if attrsD.has_key('href'):
            expectingText = 0

            if (attrsD.get('rel') == u'alternate') and (self.mapContentType(attrsD.get('type')) in self.html_types):

                context['link'] = attrsD['href']
        else:
            self.push('link', expectingText)



    def _end_link(self):
        value = self.pop('link')
        context = self._getContext()







    def _start_guid(self, attrsD):
        self.guidislink = (attrsD.get('ispermalink', 'true') == 'true')
        self.push('id', 1)

    def _end_guid(self):
        value = self.pop('id')
        self._save('guidislink', self.guidislink and not self._getContext().has_key('link'))

        if self.guidislink:

            # guid acts as link, but only if 'ispermalink' is not present or is 'true',
            # and only if the item doesn't already have a link element

            self._save('link', value)

    def _start_title(self, attrsD):
        if self.svgOK:
            return self.unknown_starttag('title', attrsD.items())
        self.pushContent('title', attrsD, u'text/plain', self.infeed or self.inentry or self.insource)

    _start_dc_title = _start_title
    _start_media_title = _start_title

    def _end_title(self):
        if self.svgOK:
            return
        value = self.popContent('title')
        if not value:
            return
        context = self._getContext()


        self.hasTitle = 1
    _end_dc_title = _end_title

    def _end_media_title(self):
        hasTitle = self.hasTitle
        self._end_title()
        self.hasTitle = hasTitle

    def _start_description(self, attrsD):
        context = self._getContext()
        if context.has_key('summary'):
            self._summaryKey = 'content'
            self._start_content(attrsD)
        else:
            self.pushContent('description', attrsD, u'text/html', self.infeed or self.inentry or self.insource)
    _start_dc_description = _start_description


    def _start_abstract(self, attrsD):
        self.pushContent('description', attrsD, u'text/plain', self.infeed or self.inentry or self.insource)


    def _end_description(self):
        if self._summaryKey == 'content':
            self._end_content()
        else:
            value = self.popContent('description')





        self._summaryKey = None

    _end_abstract = _end_description
    _end_dc_description = _end_description

    def _start_info(self, attrsD):
        self.pushContent('info', attrsD, u'text/plain', 1)

    _start_feedburner_browserfriendly = _start_info

    def _end_info(self):
        self.popContent('info')

    _end_feedburner_browserfriendly = _end_info

    def _start_generator(self, attrsD):
        if attrsD:
            attrsD = self._itsAnHrefDamnIt(attrsD)
            if attrsD.has_key('href'):
                attrsD['href'] = self.resolveURI(attrsD['href'])
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818

1819
1820
1821
1822




1823

1824
1825
1826



1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876



1877
1878
1879




1880
1881




1882






1883


1884
1885




1886
1887
1888
1889
1890




1891

1892
1893
1894

1895
1896
1897
1898

1899
1900




1901


1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949





1950







1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977





1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991

1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025





2026


2027



2028






2029


2030
2031
2032
2033
2034






2035
2036
2037

2038
2039
2040

2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058




2059
2060
2061
2062
2063


2064


2065


2066


2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083




2084



2085
2086
2087
2088
2089
2090
2091
2092


2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144


2145
2146

2147

2148
2149
2150
2151
2152
2153
2154







2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165


2166
2167
2168
2169

2170
2171

2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187


























































































































































































































































































































































































































































2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235

2236
2237
2238
2239
2240















2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254


2255

2256
2257
2258
2259


2260

2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278




2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317

2318




2319
2320
2321
2322
2323
2324
2325
2326
2327
2328

2329
2330
2331
2332
2333
2334
2335

2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371







2372



2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390


2391
2392


2393
2394
2395
2396


2397
2398


2399
2400
2401



































2402








2403
2404
2405









2406
2407
2408
2409
2410
2411








2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424



2425






































2426


2427

2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477

2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511

2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537

2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565


2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599

2600
2601

2602
2603
2604
2605
2606
2607
2608
2609
2610



2611
2612
2613
2614
2615
2616
2617
2618

2619

2620



2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634

2635


2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715

2716
2717
2718










2719











2720





































2721

2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753


2754
2755

2756
2757
2758
2759
2760

2761
2762

2763


2764

2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984

2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006

3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053

3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227


3228
3229
3230
3231
3232
3233
3234
3235
3236
3237




3238
3239
3240
3241





3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257





3258











3259
3260
3261

3262
3263
3264


3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290

    def _start_admin_generatoragent(self, attrsD):
        self.push('generator', 1)
        value = self._getAttribute(attrsD, 'rdf:resource')
        if value:
            self.elementstack[-1][2].append(value)
        self.pop('generator')
        self._getContext()['generator_detail'] = FeedParserDict({'href'
                : value})

    def _start_admin_errorreportsto(self, attrsD):
        self.push('errorreportsto', 1)
        value = self._getAttribute(attrsD, 'rdf:resource')
        if value:
            self.elementstack[-1][2].append(value)
        self.pop('errorreportsto')

    def _start_summary(self, attrsD):
        context = self._getContext()
        if context.has_key('summary'):
            self._summaryKey = 'content'
            self._start_content(attrsD)
        else:
            self._summaryKey = 'summary'
            self.pushContent(self._summaryKey, attrsD, 'text/plain', 1)

    _start_itunes_summary = _start_summary

    def _end_summary(self):
        if self._summaryKey == 'content':
            self._end_content()
        else:
            self.popContent(self._summaryKey or 'summary')
        self._summaryKey = None

    _end_itunes_summary = _end_summary

    def _start_enclosure(self, attrsD):
        attrsD = self._itsAnHrefDamnIt(attrsD)
        self._getContext().setdefault('enclosures',
                []).append(FeedParserDict(attrsD))
        href = attrsD.get('href')
        if href:
            context = self._getContext()

            if not context.get('id'):
                context['id'] = href

    def _start_source(self, attrsD):




        self.insource = 1


    def _end_source(self):
        self.insource = 0



        self._getContext()['source'] = copy.deepcopy(self.sourcedata)
        self.sourcedata.clear()

    def _start_content(self, attrsD):
        self.pushContent('content', attrsD, 'text/plain', 1)
        src = attrsD.get('src')
        if src:
            self.contentparams['src'] = src
        self.push('content', 1)

    def _start_prodlink(self, attrsD):
        self.pushContent('content', attrsD, 'text/html', 1)

    def _start_body(self, attrsD):
        self.pushContent('content', attrsD, 'application/xhtml+xml', 1)

    _start_xhtml_body = _start_body

    def _start_content_encoded(self, attrsD):
        self.pushContent('content', attrsD, 'text/html', 1)

    _start_fullitem = _start_content_encoded

    def _end_content(self):
        copyToDescription = \
            self.mapContentType(self.contentparams.get('type'))\
             in ['text/plain'] + self.html_types
        value = self.popContent('content')
        if copyToDescription:
            self._save('description', value)

    _end_body = _end_content
    _end_xhtml_body = _end_content
    _end_content_encoded = _end_content
    _end_fullitem = _end_content
    _end_prodlink = _end_content

    def _start_itunes_image(self, attrsD):
        self.push('itunes_image', 0)
        self._getContext()['image'] = FeedParserDict({'href'
                : attrsD.get('href')})

    _start_itunes_link = _start_itunes_image

    def _end_itunes_block(self):
        value = self.pop('itunes_block', 0)
        self._getContext()['itunes_block'] = value == 'yes' and 1 or 0

    def _end_itunes_explicit(self):
        value = self.pop('itunes_explicit', 0)



        self._getContext()['itunes_explicit'] = value == 'yes' and 1\
             or 0






if _XML_AVAILABLE:














    class _StrictFeedParser(_FeedParserMixin,
        xml.sax.handler.ContentHandler):





        def __init__(
            self,
            baseuri,
            baselang,




            encoding,

            ):
            if _debug:
                sys.stderr.write('trying StrictFeedParser\n')

            xml.sax.handler.ContentHandler.__init__(self)
            _FeedParserMixin.__init__(self, baseuri, baselang, encoding)
            self.bozo = 0
            self.exc = None


        def startPrefixMapping(self, prefix, uri):




            self.trackNamespace(prefix, uri)



        def startElementNS(
            self,
            name,
            qname,
            attrs,
            ):
            (namespace, localname) = name
            lowernamespace = str(namespace or '').lower()
            if lowernamespace.find('backend.userland.com/rss') != -1:

                # match any backend.userland.com namespace

                namespace = 'http://backend.userland.com/rss'
                lowernamespace = namespace
            if qname and qname.find(':') > 0:
                givenprefix = qname.split(':')[0]
            else:
                givenprefix = None
            prefix = self._matchnamespaces.get(lowernamespace,
                    givenprefix)
            if givenprefix and (prefix == None or prefix == ''
                                 and lowernamespace == '')\
                 and not self.namespacesInUse.has_key(givenprefix):
                raise UndeclaredNamespace, \
                    "'%s' is not associated with a namespace"\
                     % givenprefix
            if prefix:
                localname = prefix + ':' + localname
            localname = str(localname).lower()
            if _debug:
                sys.stderr.write('startElementNS: qname = %s, namespace = %s, givenprefix = %s, prefix = %s, attrs = %s, localname = %s\n'
                                  % (
                    qname,
                    namespace,
                    givenprefix,
                    prefix,
                    attrs.items(),
                    localname,
                    ))

            # qname implementation is horribly broken in Python 2.1 (it
            # doesn't report any), and slightly broken in Python 2.2 (it
            # doesn't report the xml: namespace). So we match up namespaces
            # with a known list first, and then possibly override them with
            # the qnames the SAX parser gives us (if indeed it gives us any
            # at all).  Thanks to MatejC for helping me test this and
            # tirelessly telling me that it didn't work yet.













            attrsD = {}
            for ((namespace, attrlocalname), attrvalue) in \
                attrs._attrs.items():
                lowernamespace = (namespace or '').lower()
                prefix = self._matchnamespaces.get(lowernamespace, '')
                if prefix:
                    attrlocalname = prefix + ':' + attrlocalname
                attrsD[str(attrlocalname).lower()] = attrvalue
            for qname in attrs.getQNames():
                attrsD[str(qname).lower()] = \
                    attrs.getValueByQName(qname)
            self.unknown_starttag(localname, attrsD.items())

        def characters(self, text):
            self.handle_data(text)

        def endElementNS(self, name, qname):
            (namespace, localname) = name
            lowernamespace = str(namespace or '').lower()
            if qname and qname.find(':') > 0:
                givenprefix = qname.split(':')[0]
            else:
                givenprefix = ''
            prefix = self._matchnamespaces.get(lowernamespace,
                    givenprefix)
            if prefix:
                localname = prefix + ':' + localname





            localname = str(localname).lower()
            self.unknown_endtag(localname)

        def error(self, exc):
            self.bozo = 1
            self.exc = exc

        def fatalError(self, exc):
            self.error(exc)
            raise exc


class _BaseHTMLProcessor(sgmllib.SGMLParser):


    elements_no_end_tag = [
        'area',
        'base',
        'basefont',
        'br',
        'col',
        'frame',
        'hr',
        'img',
        'input',
        'isindex',
        'link',
        'meta',
        'param',
        ]

    def __init__(self, encoding):
        self.encoding = encoding
        if _debug:
            sys.stderr.write('entering BaseHTMLProcessor, encoding=%s\n'
                              % self.encoding)
        sgmllib.SGMLParser.__init__(self)

    def reset(self):
        self.pieces = []
        sgmllib.SGMLParser.reset(self)

    def _shorttag_replace(self, match):
        tag = match.group(1)
        if tag in self.elements_no_end_tag:
            return '<' + tag + ' />'
        else:
            return '<' + tag + '></' + tag + '>'






    def feed(self, data):


        data = re.compile(r'<!((?!DOCTYPE|--|\[))',



                          re.IGNORECASE).sub(r'&lt;!\1', data)









        # data = re.sub(r'<(\S+?)\s*?/>', self._shorttag_replace, data) # bug [ 1399464 ] Bad regexp for _shorttag_replace

        data = re.sub(r'<([^<\s]+?)\s*/>', self._shorttag_replace, data)
        data = data.replace('&#39;', "'")
        data = data.replace('&#34;', '"')






        if self.encoding and type(data) == type(u''):
            data = data.encode(self.encoding)
        sgmllib.SGMLParser.feed(self, data)


    def normalize_attrs(self, attrs):


        # utility method to be called by descendants

        attrs = [(k.lower(), v) for (k, v) in attrs]
        attrs = [(k, k in ('rel', 'type') and v.lower() or v) for (k,
                 v) in attrs]
        return attrs

    def unknown_starttag(self, tag, attrs):

        # called for each start tag
        # attrs is a list of (attr, value) tuples
        # e.g. for <pre class='screen'>, tag='pre', attrs=[('class', 'screen')]

        if _debug:
            sys.stderr.write('_BaseHTMLProcessor, unknown_starttag, tag=%s\n'
                              % tag)
        uattrs = []





        # thanks to Kevin Marks for this breathtaking hack to deal with (valid) high-bit attribute values in UTF-8 feeds

        for (key, value) in attrs:
            if type(value) != type(u''):
                value = unicode(value, self.encoding)


            uattrs.append((unicode(key, self.encoding), value))


        strattrs = u''.join([u' %s="%s"' % (key, value) for (key,


                            value) in uattrs]).encode(self.encoding)


        if tag in self.elements_no_end_tag:
            self.pieces.append('<%(tag)s%(strattrs)s />' % locals())
        else:
            self.pieces.append('<%(tag)s%(strattrs)s>' % locals())

    def unknown_endtag(self, tag):

        # called for each end tag, e.g. for </pre>, tag will be 'pre'
        # Reconstruct the original end tag.

        if tag not in self.elements_no_end_tag:
            self.pieces.append('</%(tag)s>' % locals())

    def handle_charref(self, ref):

        # called for each character reference, e.g. for '&#160;', ref will be '160'
        # Reconstruct the original character reference.








        self.pieces.append('&#%(ref)s;' % locals())

    def handle_entityref(self, ref):

        # called for each entity reference, e.g. for '&copy;', ref will be 'copy'
        # Reconstruct the original entity reference.

        self.pieces.append('&%(ref)s;' % locals())



    def handle_data(self, text):

        # called for each block of plain text, i.e. outside of any tag and
        # not containing any character or entity references
        # Store the original text verbatim.

        if _debug:
            sys.stderr.write('_BaseHTMLProcessor, handle_text, text=%s\n'
                              % text)
        self.pieces.append(text)

    def handle_comment(self, text):

        # called for each HTML comment, e.g. <!-- insert Javascript code here -->
        # Reconstruct the original comment.

        self.pieces.append('<!--%(text)s-->' % locals())

    def handle_pi(self, text):

        # called for each processing instruction, e.g. <?instruction>
        # Reconstruct original processing instruction.

        self.pieces.append('<?%(text)s>' % locals())

    def handle_decl(self, text):

        # called for the DOCTYPE, if present, e.g.
        # <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        #     "http://www.w3.org/TR/html4/loose.dtd">
        # Reconstruct original DOCTYPE

        self.pieces.append('<!%(text)s>' % locals())

    _new_declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9:]*\s*'
            ).match

    def _scan_name(self, i, declstartpos):
        rawdata = self.rawdata
        n = len(rawdata)
        if i == n:
            return (None, -1)
        m = self._new_declname_match(rawdata, i)
        if m:
            s = m.group()
            name = s.strip()
            if i + len(s) == n:
                return (None, -1)  # end of buffer
            return (name.lower(), m.end())
        else:
            self.handle_data(rawdata)



#            self.updatepos(declstartpos, i)



            return (None, -1)

    def output(self):
        """Return processed HTML as a single string"""

        return ''.join([str(p) for p in self.pieces])









class _LooseFeedParser(_FeedParserMixin, _BaseHTMLProcessor):

    def __init__(
        self,
        baseuri,
        baselang,
        encoding,
        ):
        sgmllib.SGMLParser.__init__(self)
        _FeedParserMixin.__init__(self, baseuri, baselang, encoding)



    def decodeEntities(self, element, data):
        data = data.replace('&#60;', '&lt;')
        data = data.replace('&#x3c;', '&lt;')

        data = data.replace('&#62;', '&gt;')
        data = data.replace('&#x3e;', '&gt;')

        data = data.replace('&#38;', '&amp;')
        data = data.replace('&#x26;', '&amp;')
        data = data.replace('&#34;', '&quot;')
        data = data.replace('&#x22;', '&quot;')
        data = data.replace('&#39;', '&apos;')
        data = data.replace('&#x27;', '&apos;')
        if self.contentparams.has_key('type')\
             and not self.contentparams.get('type', 'xml'
                ).endswith('xml'):
            data = data.replace('&lt;', '<')
            data = data.replace('&gt;', '>')
            data = data.replace('&amp;', '&')
            data = data.replace('&quot;', '"')
            data = data.replace('&apos;', "'")
        return data




























































































































































































































































































































































































































































class _RelativeURIResolver(_BaseHTMLProcessor):

    relative_uris = [
        ('a', 'href'),
        ('applet', 'codebase'),
        ('area', 'href'),
        ('blockquote', 'cite'),
        ('body', 'background'),
        ('del', 'cite'),
        ('form', 'action'),
        ('frame', 'longdesc'),
        ('frame', 'src'),
        ('iframe', 'longdesc'),
        ('iframe', 'src'),
        ('head', 'profile'),
        ('img', 'longdesc'),
        ('img', 'src'),
        ('img', 'usemap'),
        ('input', 'src'),
        ('input', 'usemap'),
        ('ins', 'cite'),
        ('link', 'href'),
        ('object', 'classid'),
        ('object', 'codebase'),
        ('object', 'data'),
        ('object', 'usemap'),
        ('q', 'cite'),
        ('script', 'src'),
        ]

    def __init__(self, baseuri, encoding):
        _BaseHTMLProcessor.__init__(self, encoding)
        self.baseuri = baseuri

    def resolveURI(self, uri):
        return _urljoin(self.baseuri, uri)

    def unknown_starttag(self, tag, attrs):
        attrs = self.normalize_attrs(attrs)
        attrs = [(key, (tag, key) in self.relative_uris
                  and self.resolveURI(value) or value) for (key,
                 value) in attrs]
        _BaseHTMLProcessor.unknown_starttag(self, tag, attrs)


def _resolveRelativeURIs(htmlSource, baseURI, encoding):
    if _debug:

        sys.stderr.write('entering _resolveRelativeURIs\n')
    p = _RelativeURIResolver(baseURI, encoding)
    p.feed(htmlSource)
    return p.output()

















class _HTMLSanitizer(_BaseHTMLProcessor):

    acceptable_elements = [
        'a',
        'abbr',
        'acronym',
        'address',
        'area',
        'b',
        'big',
        'blockquote',
        'br',
        'button',


        'caption',

        'center',
        'cite',
        'code',
        'col',


        'colgroup',

        'dd',
        'del',
        'dfn',
        'dir',
        'div',
        'dl',
        'dt',
        'em',
        'fieldset',
        'font',
        'form',
        'h1',
        'h2',
        'h3',
        'h4',
        'h5',
        'h6',
        'hr',




        'i',
        'img',
        'input',
        'ins',
        'kbd',
        'label',
        'legend',
        'li',
        'map',
        'menu',
        'ol',
        'optgroup',
        'option',
        'p',
        'pre',
        'q',
        's',
        'samp',
        'select',
        'small',
        'span',
        'strike',
        'strong',
        'sub',
        'sup',
        'table',
        'tbody',
        'td',
        'textarea',
        'tfoot',
        'th',
        'thead',
        'tr',
        'tt',
        'u',
        'ul',
        'var',
        ]


    acceptable_attributes = [




        'abbr',
        'accept',
        'accept-charset',
        'accesskey',
        'action',
        'align',
        'alt',
        'axis',
        'border',
        'cellpadding',

        'cellspacing',
        'char',
        'charoff',
        'charset',
        'checked',
        'cite',
        'class',

        'clear',
        'cols',
        'colspan',
        'color',
        'compact',
        'coords',
        'datetime',
        'dir',
        'disabled',
        'enctype',
        'for',
        'frame',
        'headers',
        'height',
        'href',
        'hreflang',
        'hspace',
        'id',
        'ismap',
        'label',
        'lang',
        'longdesc',
        'maxlength',
        'media',
        'method',
        'multiple',
        'name',
        'nohref',
        'noshade',
        'nowrap',
        'prompt',
        'readonly',
        'rel',
        'rev',
        'rows',
        'rowspan',







        'rules',



        'scope',
        'selected',
        'shape',
        'size',
        'span',
        'src',
        'start',
        'summary',
        'tabindex',
        'target',
        'title',
        'type',
        'usemap',
        'valign',
        'value',
        'vspace',
        'width',
        ]



    unacceptable_elements_with_end_tag = ['script', 'applet']



    def reset(self):
        _BaseHTMLProcessor.reset(self)
        self.unacceptablestack = 0



    def unknown_starttag(self, tag, attrs):


        if not tag in self.acceptable_elements:
            if tag in self.unacceptable_elements_with_end_tag:
                self.unacceptablestack += 1



































            return








        attrs = self.normalize_attrs(attrs)
        attrs = [(key, value) for (key, value) in attrs if key
                  in self.acceptable_attributes]









        _BaseHTMLProcessor.unknown_starttag(self, tag, attrs)

    def unknown_endtag(self, tag):
        if not tag in self.acceptable_elements:
            if tag in self.unacceptable_elements_with_end_tag:
                self.unacceptablestack -= 1








            return
        _BaseHTMLProcessor.unknown_endtag(self, tag)

    def handle_pi(self, text):
        pass

    def handle_decl(self, text):
        pass

    def handle_data(self, text):
        if not self.unacceptablestack:
            _BaseHTMLProcessor.handle_data(self, text)











































def _sanitizeHTML(htmlSource, encoding):


    p = _HTMLSanitizer(encoding)

    p.feed(htmlSource)
    data = p.output()
    if TIDY_MARKUP:

        # loop through list of preferred Tidy interfaces looking for one that's installed,
        # then set up a common _tidy function to wrap the interface-specific API.

        _tidy = None
        for tidy_interface in PREFERRED_TIDY_INTERFACES:
            try:
                if tidy_interface == 'uTidy':
                    from tidy import parseString as _utidy

                    def _tidy(data, **kwargs):
                        return str(_utidy(data, **kwargs))

                    break
                elif tidy_interface == 'mxTidy':
                    from mx.Tidy import Tidy as _mxtidy

                    def _tidy(data, **kwargs):
                        (nerrors, nwarnings, data, errordata) = \
                            _mxtidy.tidy(data, **kwargs)
                        return data

                    break
            except:
                pass
        if _tidy:
            utf8 = type(data) == type(u'')
            if utf8:
                data = data.encode('utf-8')
            data = _tidy(data, output_xhtml=1, numeric_entities=1,
                         wrap=0, char_encoding='utf8')
            if utf8:
                data = unicode(data, 'utf-8')
            if data.count('<body'):
                data = data.split('<body', 1)[1]
                if data.count('>'):
                    data = data.split('>', 1)[1]
            if data.count('</body'):
                data = data.split('</body', 1)[0]
    data = data.strip().replace('\r\n', '\n')
    return data


class _FeedURLHandler(urllib2.HTTPDigestAuthHandler,
    urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler):

    def http_error_default(

        self,
        req,
        fp,
        code,
        msg,
        headers,
        ):
        if code / 100 == 3 and code != 304:
            return self.http_error_302(req, fp, code, msg, headers)
        infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        infourl.status = code
        return infourl

    def http_error_302(
        self,
        req,
        fp,
        code,
        msg,
        headers,
        ):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_302(
                self,
                req,
                fp,
                code,
                msg,
                headers,
                )
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code

        return infourl

    def http_error_301(
        self,
        req,
        fp,
        code,
        msg,
        headers,
        ):
        if headers.dict.has_key('location'):
            infourl = urllib2.HTTPRedirectHandler.http_error_301(
                self,
                req,
                fp,
                code,
                msg,
                headers,
                )
        else:
            infourl = urllib.addinfourl(fp, headers, req.get_full_url())
        if not hasattr(infourl, 'status'):
            infourl.status = code
        return infourl

    http_error_300 = http_error_302

    http_error_303 = http_error_302
    http_error_307 = http_error_302

    def http_error_401(
        self,
        req,
        fp,
        code,
        msg,
        headers,
        ):

        # Check if
        # - server requires digest auth, AND
        # - we tried (unsuccessfully) with basic auth, AND
        # - we're using Python 2.3.3 or later (digest auth is irreparably broken in earlier versions)
        # If all conditions hold, parse authentication information
        # out of the Authorization header we sent the first time
        # (for the username and password) and the WWW-Authenticate
        # header the server sent back (for the realm) and retry
        # the request with the appropriate digest auth headers instead.
        # This evil genius hack has been brought to you by Aaron Swartz.

        host = urlparse.urlparse(req.get_full_url())[1]
        try:
            assert sys.version.split()[0] >= '2.3.3'
            assert base64 != None
            (user, passw) = \


                base64.decodestring(req.headers['Authorization'
                                    ].split(' ')[1]).split(':')
            realm = re.findall('realm="([^"]*)"',
                               headers['WWW-Authenticate'])[0]
            self.add_password(realm, host, user, passw)
            retry = self.http_error_auth_reqed('www-authenticate',
                    host, req, headers)
            self.reset_retry_count()
            return retry
        except:
            return self.http_error_default(req, fp, code, msg, headers)


def _open_resource(
    url_file_stream_or_string,
    etag,
    modified,
    agent,
    referrer,
    handlers,
    ):
    """URL, filename, or string --> stream

    This function lets you define parsers that take any input source
    (URL, pathname to local or network file, or actual data as a string)
    and deal with it in a uniform manner.  Returned object is guaranteed
    to have all the basic stdio read methods (read, readline, readlines).
    Just .close() the object when you're done with it.

    If the etag argument is supplied, it will be used as the value of an
    If-None-Match request header.

    If the modified argument is supplied, it must be a tuple of 9 integers
    as returned by gmtime() in the standard Python time module. This MUST

    be in GMT (Greenwich Mean Time). The formatted date/time will be used
    as the value of an If-Modified-Since request header.


    If the agent argument is supplied, it will be used as the value of a
    User-Agent request header.

    If the referrer argument is supplied, it will be used as the value of a
    Referer[sic] request header.

    If handlers is supplied, it is a list of handlers used to build a
    urllib2 opener.



    """

    if hasattr(url_file_stream_or_string, 'read'):
        return url_file_stream_or_string

    if url_file_stream_or_string == '-':
        return sys.stdin


    if urlparse.urlparse(url_file_stream_or_string)[0] in ('http',

            'https', 'ftp'):



        if not agent:
            agent = USER_AGENT

        # test for inline user:password for basic auth

        auth = None
        if base64:
            (urltype, rest) = \
                urllib.splittype(url_file_stream_or_string)
            (realhost, rest) = urllib.splithost(rest)
            if realhost:
                (user_passwd, realhost) = urllib.splituser(realhost)
                if user_passwd:
                    url_file_stream_or_string = '%s://%s%s' % (urltype,

                            realhost, rest)


                    auth = base64.encodestring(user_passwd).strip()

        # try to open with urllib2 (to use optional headers)

        request = urllib2.Request(url_file_stream_or_string)
        request.add_header('User-Agent', agent)
        if etag:
            request.add_header('If-None-Match', etag)
        if modified:

            # format into an RFC 1123-compliant timestamp. We can't use
            # time.strftime() since the %a and %b directives can be affected
            # by the current locale, but RFC 2616 states that dates must be
            # in English.

            short_weekdays = [
                'Mon',
                'Tue',
                'Wed',
                'Thu',
                'Fri',
                'Sat',
                'Sun',
                ]
            months = [
                'Jan',
                'Feb',
                'Mar',
                'Apr',
                'May',
                'Jun',
                'Jul',
                'Aug',
                'Sep',
                'Oct',
                'Nov',
                'Dec',
                ]
            request.add_header('If-Modified-Since',
                               '%s, %02d %s %04d %02d:%02d:%02d GMT' % (
                short_weekdays[modified[6]],
                modified[2],
                months[modified[1] - 1],
                modified[0],
                modified[3],
                modified[4],
                modified[5],
                ))
        if referrer:
            request.add_header('Referer', referrer)
        if gzip and zlib:
            request.add_header('Accept-encoding', 'gzip, deflate')
        elif gzip:
            request.add_header('Accept-encoding', 'gzip')
        elif zlib:
            request.add_header('Accept-encoding', 'deflate')
        else:
            request.add_header('Accept-encoding', '')
        if auth:
            request.add_header('Authorization', 'Basic %s' % auth)
        if ACCEPT_HEADER:
            request.add_header('Accept', ACCEPT_HEADER)
        request.add_header('A-IM', 'feed')  # RFC 3229 support
        opener = apply(urllib2.build_opener, tuple([_FeedURLHandler()]
                        + handlers))
        opener.addheaders = []  # RMK - must clear so we only send our custom User-Agent
        try:
            return opener.open(request)
        finally:
            opener.close()  # JohnD

    # try to open with native open function (if url_file_stream_or_string is a filename)

    try:
        return open(url_file_stream_or_string)
    except:
        pass

    # treat url_file_stream_or_string as string


    return _StringIO(str(url_file_stream_or_string))












_date_handlers = []



















































def registerDateHandler(func):
    """Register a date handler function (takes string, returns 9-tuple date in GMT)"""

    _date_handlers.insert(0, func)


# ISO-8601 date parsing routines written by Fazal Majid.
# The ISO 8601 standard is very convoluted and irregular - a full ISO 8601
# parser is beyond the scope of feedparser and would be a worthwhile addition
# to the Python library.
# A single regular expression cannot parse ISO 8601 date formats into groups
# as the standard is highly irregular (for instance is 030104 2003-01-04 or
# 0301-04-01), so we use templates instead.
# Please note the order in templates is significant because we need a
# greedy match.

_iso8601_tmpl = [
    'YYYY-?MM-?DD',
    'YYYY-MM',
    'YYYY-?OOO',
    'YY-?MM-?DD',
    'YY-?OOO',
    'YYYY',
    '-YY-?MM',
    '-OOO',
    '-YY',
    '--MM-?DD',
    '--MM',
    '---DD',
    'CC',
    '',
    ]


_iso8601_re = [tmpl.replace('YYYY', r'(?P<year>\d{4})').replace('YY',
               r'(?P<year>\d\d)').replace('MM', r'(?P<month>[01]\d)'

               ).replace('DD', r'(?P<day>[0123]\d)').replace('OOO',
               r'(?P<ordinal>[0123]\d\d)').replace('CC',
               r'(?P<century>\d\d$)')
                + r'(T?(?P<hour>\d{2}):(?P<minute>\d{2})'
                + r'(:(?P<second>\d{2}))?'

                + r'(?P<tz>[+-](?P<tzhour>\d{2})(:(?P<tzmin>\d{2}))?|Z)?)?'
                for tmpl in _iso8601_tmpl]

del tmpl


_iso8601_matches = [re.compile(regex).match for regex in _iso8601_re]

del regex


def _parse_date_iso8601(dateString):
    """Parse a variety of ISO-8601-compatible formats like 20040105"""

    m = None
    for _iso8601_match in _iso8601_matches:
        m = _iso8601_match(dateString)
        if m:
            break
    if not m:
        return
    if m.span() == (0, 0):
        return
    params = m.groupdict()
    ordinal = params.get('ordinal', 0)
    if ordinal:
        ordinal = int(ordinal)
    else:
        ordinal = 0
    year = params.get('year', '--')
    if not year or year == '--':
        year = time.gmtime()[0]
    elif len(year) == 2:

        # ISO 8601 assumes current century, i.e. 93 -> 2093, NOT 1993

        year = 100 * int(time.gmtime()[0] / 100) + int(year)
    else:
        year = int(year)
    month = params.get('month', '-')
    if not month or month == '-':

        # ordinals are NOT normalized by mktime, we simulate them
        # by setting month=1, day=ordinal

        if ordinal:
            month = 1
        else:
            month = time.gmtime()[1]
    month = int(month)
    day = params.get('day', 0)
    if not day:

        # see above

        if ordinal:
            day = ordinal
        elif params.get('century', 0) or params.get('year', 0)\
             or params.get('month', 0):
            day = 1
        else:
            day = time.gmtime()[2]
    else:
        day = int(day)

    # special case of the century - is the first year of the 21st century
    # 2000 or 2001 ? The debate goes on...

    if 'century' in params.keys():
        year = (int(params['century']) - 1) * 100 + 1

    # in ISO 8601 most fields are optional

    for field in ['hour', 'minute', 'second', 'tzhour', 'tzmin']:
        if not params.get(field, None):
            params[field] = 0
    hour = int(params.get('hour', 0))
    minute = int(params.get('minute', 0))
    second = int(params.get('second', 0))

    # weekday is normalized by mktime(), we can ignore it

    weekday = 0

    # daylight savings is complex, but not needed for feedparser's purposes
    # as time zones, if specified, include mention of whether it is active
    # (e.g. PST vs. PDT, CET). Using -1 is implementation-dependent and
    # and most implementations have DST bugs

    daylight_savings_flag = 0
    tm = [
        year,
        month,
        day,
        hour,
        minute,
        second,
        weekday,
        ordinal,
        daylight_savings_flag,
        ]

    # ISO 8601 time zone adjustments

    tz = params.get('tz')
    if tz and tz != 'Z':
        if tz[0] == '-':
            tm[3] += int(params.get('tzhour', 0))
            tm[4] += int(params.get('tzmin', 0))
        elif tz[0] == '+':
            tm[3] -= int(params.get('tzhour', 0))
            tm[4] -= int(params.get('tzmin', 0))
        else:
            return None

    # Python's time.mktime() is a wrapper around the ANSI C mktime(3c)
    # which is guaranteed to normalize d/m/y/h/m/s.
    # Many implementations have bugs, but we'll pretend they don't.

    return time.localtime(time.mktime(tm))


registerDateHandler(_parse_date_iso8601)

# 8-bit date handling routines written by ytrewq1.

_korean_year = u'\ub144'  # b3e2 in euc-kr
_korean_month = u'\uc6d4'  # bff9 in euc-kr
_korean_day = u'\uc77c'  # c0cf in euc-kr
_korean_am = u'\uc624\uc804'  # bfc0 c0fc in euc-kr
_korean_pm = u'\uc624\ud6c4'  # bfc0 c8c4 in euc-kr

_korean_onblog_date_re = \
    re.compile('(\d{4})%s\s+(\d{2})%s\s+(\d{2})%s\s+(\d{2}):(\d{2}):(\d{2})'
                % (_korean_year, _korean_month, _korean_day))
_korean_nate_date_re = \
    re.compile(u'(\d{4})-(\d{2})-(\d{2})\s+(%s|%s)\s+(\d{,2}):(\d{,2}):(\d{,2})'
                % (_korean_am, _korean_pm))


def _parse_date_onblog(dateString):
    """Parse a string according to the OnBlog 8-bit date format"""

    m = _korean_onblog_date_re.match(dateString)
    if not m:
        return
    w3dtfdate = \
        '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s'\
         % {
        'year': m.group(1),
        'month': m.group(2),
        'day': m.group(3),
        'hour': m.group(4),
        'minute': m.group(5),
        'second': m.group(6),
        'zonediff': '+09:00',
        }
    if _debug:
        sys.stderr.write('OnBlog date parsed as: %s\n' % w3dtfdate)
    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_onblog)


def _parse_date_nate(dateString):
    """Parse a string according to the Nate 8-bit date format"""

    m = _korean_nate_date_re.match(dateString)
    if not m:
        return
    hour = int(m.group(5))
    ampm = m.group(4)
    if ampm == _korean_pm:
        hour += 12
    hour = str(hour)
    if len(hour) == 1:
        hour = '0' + hour
    w3dtfdate = \
        '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s'\
         % {
        'year': m.group(1),
        'month': m.group(2),
        'day': m.group(3),
        'hour': hour,
        'minute': m.group(6),
        'second': m.group(7),
        'zonediff': '+09:00',
        }
    if _debug:
        sys.stderr.write('Nate date parsed as: %s\n' % w3dtfdate)
    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_nate)

_mssql_date_re = \
    re.compile('(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})(\.\d+)?'
               )


def _parse_date_mssql(dateString):
    """Parse a string according to the MS SQL date format"""

    m = _mssql_date_re.match(dateString)
    if not m:
        return
    w3dtfdate = \
        '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s'\
         % {
        'year': m.group(1),
        'month': m.group(2),
        'day': m.group(3),
        'hour': m.group(4),
        'minute': m.group(5),
        'second': m.group(6),
        'zonediff': '+09:00',
        }
    if _debug:
        sys.stderr.write('MS SQL date parsed as: %s\n' % w3dtfdate)
    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_mssql)

# Unicode strings for Greek date strings

_greek_months = {

    u'\u0399\u03b1\u03bd': u'Jan',
    u'\u03a6\u03b5\u03b2': u'Feb',
    u'\u039c\u03ac\u03ce': u'Mar',
    u'\u039c\u03b1\u03ce': u'Mar',
    u'\u0391\u03c0\u03c1': u'Apr',
    u'\u039c\u03ac\u03b9': u'May',
    u'\u039c\u03b1\u03ca': u'May',
    u'\u039c\u03b1\u03b9': u'May',
    u'\u0399\u03bf\u03cd\u03bd': u'Jun',
    u'\u0399\u03bf\u03bd': u'Jun',
    u'\u0399\u03bf\u03cd\u03bb': u'Jul',
    u'\u0399\u03bf\u03bb': u'Jul',
    u'\u0391\u03cd\u03b3': u'Aug',
    u'\u0391\u03c5\u03b3': u'Aug',
    u'\u03a3\u03b5\u03c0': u'Sep',
    u'\u039f\u03ba\u03c4': u'Oct',
    u'\u039d\u03bf\u03ad': u'Nov',
    u'\u039d\u03bf\u03b5': u'Nov',
    u'\u0394\u03b5\u03ba': u'Dec',
    }

_greek_wdays = {

    u'\u039a\u03c5\u03c1': u'Sun',
    u'\u0394\u03b5\u03c5': u'Mon',
    u'\u03a4\u03c1\u03b9': u'Tue',
    u'\u03a4\u03b5\u03c4': u'Wed',
    u'\u03a0\u03b5\u03bc': u'Thu',
    u'\u03a0\u03b1\u03c1': u'Fri',
    u'\u03a3\u03b1\u03b2': u'Sat',
    }

_greek_date_format_re = \
    re.compile(u'([^,]+),\s+(\d{2})\s+([^\s]+)\s+(\d{4})\s+(\d{2}):(\d{2}):(\d{2})\s+([^\s]+)'
               )


def _parse_date_greek(dateString):
    """Parse a string according to a Greek 8-bit date format."""

    m = _greek_date_format_re.match(dateString)
    if not m:
        return
    try:
        wday = _greek_wdays[m.group(1)]
        month = _greek_months[m.group(3)]
    except:
        return
    rfc822date = \
        '%(wday)s, %(day)s %(month)s %(year)s %(hour)s:%(minute)s:%(second)s %(zonediff)s'\
         % {
        'wday': wday,
        'day': m.group(2),
        'month': month,
        'year': m.group(4),
        'hour': m.group(5),
        'minute': m.group(6),
        'second': m.group(7),
        'zonediff': m.group(8),
        }
    if _debug:
        sys.stderr.write('Greek date parsed as: %s\n' % rfc822date)
    return _parse_date_rfc822(rfc822date)


registerDateHandler(_parse_date_greek)

# Unicode strings for Hungarian date strings

_hungarian_months = {

    u'janu\u00e1r': u'01',
    u'febru\u00e1ri': u'02',
    u'm\u00e1rcius': u'03',
    u'\u00e1prilis': u'04',
    u'm\u00e1ujus': u'05',
    u'j\u00fanius': u'06',
    u'j\u00falius': u'07',
    u'augusztus': u'08',
    u'szeptember': u'09',
    u'okt\u00f3ber': u'10',
    u'november': u'11',
    u'december': u'12',
    }

_hungarian_date_format_re = \
    re.compile(u'(\d{4})-([^-]+)-(\d{,2})T(\d{,2}):(\d{2})((\+|-)(\d{,2}:\d{2}))'
               )


def _parse_date_hungarian(dateString):
    """Parse a string according to a Hungarian 8-bit date format."""

    m = _hungarian_date_format_re.match(dateString)
    if not m:
        return
    try:
        month = _hungarian_months[m.group(2)]
        day = m.group(3)
        if len(day) == 1:
            day = '0' + day
        hour = m.group(4)
        if len(hour) == 1:
            hour = '0' + hour
    except:
        return
    w3dtfdate = \
        '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s%(zonediff)s' % {
        'year': m.group(1),
        'month': month,
        'day': day,
        'hour': hour,
        'minute': m.group(5),
        'zonediff': m.group(6),
        }
    if _debug:
        sys.stderr.write('Hungarian date parsed as: %s\n' % w3dtfdate)
    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_hungarian)

# W3DTF-style date parsing adapted from PyXML xml.utils.iso8601, written by
# Drake and licensed under the Python license.  Removed all range checking
# for month, day, hour, minute, and second, since mktime will normalize
# these later


def _parse_date_w3dtf(dateString):

    def __extract_date(m):
        year = int(m.group('year'))
        if year < 100:
            year = 100 * int(time.gmtime()[0] / 100) + int(year)
        if year < 1000:
            return (0, 0, 0)
        julian = m.group('julian')
        if julian:
            julian = int(julian)
            month = julian / 30 + 1
            day = julian % 30 + 1
            jday = None
            while jday != julian:
                t = time.mktime((
                    year,
                    month,
                    day,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    ))
                jday = time.gmtime(t)[-2]
                diff = abs(jday - julian)
                if jday > julian:
                    if diff < day:
                        day = day - diff
                    else:
                        month = month - 1
                        day = 31
                elif jday < julian:
                    if day + diff < 28:
                        day = day + diff
                    else:
                        month = month + 1
            return (year, month, day)
        month = m.group('month')
        day = 1
        if month is None:
            month = 1
        else:
            month = int(month)
            day = m.group('day')
            if day:
                day = int(day)
            else:
                day = 1
        return (year, month, day)

    def __extract_time(m):
        if not m:
            return (0, 0, 0)
        hours = m.group('hours')
        if not hours:
            return (0, 0, 0)
        hours = int(hours)
        minutes = int(m.group('minutes'))
        seconds = m.group('seconds')
        if seconds:
            seconds = int(seconds)
        else:
            seconds = 0
        return (hours, minutes, seconds)

    def __extract_tzd(m):
        """Return the Time Zone Designator as an offset in seconds from UTC."""

        if not m:
            return 0
        tzd = m.group('tzd')
        if not tzd:
            return 0
        if tzd == 'Z':
            return 0
        hours = int(m.group('tzdhours'))
        minutes = m.group('tzdminutes')
        if minutes:
            minutes = int(minutes)
        else:
            minutes = 0
        offset = (hours * 60 + minutes) * 60
        if tzd[0] == '+':
            return -offset
        return offset

    __date_re = \
        '(?P<year>\\d\\d\\d\\d)(?:(?P<dsep>-|)(?:(?P<julian>\\d\\d\\d)|(?P<month>\\d\\d)(?:(?P=dsep)(?P<day>\\d\\d))?))?'

    __tzd_re = \
        '(?P<tzd>[-+](?P<tzdhours>\d\d)(?::?(?P<tzdminutes>\d\d))|Z)'
    __tzd_rx = re.compile(__tzd_re)
    __time_re = \
        '(?P<hours>\\d\\d)(?P<tsep>:|)(?P<minutes>\\d\\d)(?:(?P=tsep)(?P<seconds>\\d\\d(?:[.,]\\d+)?))?'\
         + __tzd_re
    __datetime_re = '%s(?:T%s)?' % (__date_re, __time_re)
    __datetime_rx = re.compile(__datetime_re)
    m = __datetime_rx.match(dateString)
    if m is None or m.group() != dateString:
        return
    gmt = __extract_date(m) + __extract_time(m) + (0, 0, 0)
    if gmt[0] == 0:
        return
    return time.gmtime((time.mktime(gmt) + __extract_tzd(m))
                        - time.timezone)


registerDateHandler(_parse_date_w3dtf)


def _parse_date_rfc822(dateString):
    """Parse an RFC822, RFC1123, RFC2822, or asctime-style date"""

    data = dateString.split()


    if data[0][-1] in (',', '.') or data[0].lower() in rfc822._daynames:
        del data[0]
    if len(data) == 4:
        s = data[3]
        i = s.find('+')
        if i > 0:
            data[3:] = [s[:i], s[i + 1:]]
        else:
            data.append('')
        dateString = ' '.join(data)




    if len(data) < 5:
        dateString += ' 00:00:00 GMT'
    tm = rfc822.parsedate_tz(dateString)
    if tm:





        return time.gmtime(rfc822.mktime_tz(tm))


# rfc822.py defines several time zones, but we define some extra ones.
# 'ET' is equivalent to 'EST', etc.

_additional_timezones = {
    'AT': -400,
    'ET': -500,
    'CT': -600,
    'MT': -700,
    'PT': -800,
    }
rfc822._timezones.update(_additional_timezones)
registerDateHandler(_parse_date_rfc822)


















def _parse_date(dateString):
    """Parses a variety of date formats into a 9-tuple in GMT"""


    for handler in _date_handlers:
        try:
            date9tuple = handler(dateString)


            if not date9tuple:
                continue
            if len(date9tuple) != 9:
                if _debug:
                    sys.stderr.write('date handler function must return 9-tuple\n'
                            )
                raise ValueError, 'date handler function must return 9-tuple'
            map(int, date9tuple)
            return date9tuple
        except Exception, e:
            if _debug:
                sys.stderr.write('%s raised %s\n' % (handler.__name__,
                                 repr(e)))
            pass
    return None


def _getCharacterEncoding(http_headers, xml_data):
    """Get the character encoding of the XML document

    http_headers is a dictionary
    xml_data is a raw string (not Unicode)

    This is so much trickier than it sounds, it's not even funny.
    According to RFC 3023 ('XML Media Types'), if the HTTP Content-Type
    is application/xml, application/*+xml,







|
<















|
<








<




<
<
<
<
|
>
|
<


>
>
>
>

>



>
>
>




|





<
<
<

|
<



|
<



<
|
<

|
|





<



<
|
|




|



>
>
>
|
<

>
>
>
>

|
>
>
>
>

>
>
>
>
>
>

>
>
|
|
>
>
>
>

|
|
|
|
>
>
>
>
|
>
|
|
|
>




>


>
>
>
>

>
>

|
<
<
<
<
<
|

|
<

<
|





|
<
|
<
<
|
<
<
<
<

<
<
<
<
<
<
<
<
<
<








>
>
>
>
>

>
>
>
>
>
>
>
|
|
<






|
<






|





|
<


>
>
>
>
>











<

|
>

|
<
<
<
<
<
<
<
<
|
|
<
<
|

|

<
<
|













>
>
>
>
>
|
>
>
|
>
>
>
|
>
>
>
>
>
>

>
>
|
<
|


>
>
>
>
>
>
|
|

>


|
>

<
|
|
|



<



<
<
<
<

|
>
>
>
>
|
|
<
<
|
>
>
|
>
>
|
>
>
|
>
>






<


<

|


<


>
>
>
>

>
>
>
|


<


|
|
>
>


<



<
<
<
<



<


<



<


<



<




<


|
<
<




|




|
|
|


>
>

|
>

>
|


|
<


>
>
>
>
>
>
>


<
|
<
<
<
<
<


>
>




>


>






|
<
<







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|



|



<
|
<


<
|
|
>
|
|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
|
<
<
<
<
<
<
<
|
<
|
>
>
|
>
|
<
<
|
>
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
|
<
<
<
<
<
<
|
<
<
<
<
|
|
>
|
>
>
>
>
|
|
<
<
|
|
<
<
<
|
>
|
|
|
|
<
|
|
>
|
|
|
|
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
|
>
>
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
>
>

|
>
>




>
>


>
>
|


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
|
<
|
>
>
>
>
>
>
>
>
>
|





>
>
>
>
>
>
>
>
|












>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
>



<


<



|

<


<

|

<

|
<

<




|


|
<











<
|
<
<
|
>
|
<
<
<
<
<
<
<
<
<
|
|

|
<
<
<
<
<
<
<
<
|
<
<
<
|
<
<
<
<
<
<
|
>
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
>
|
|

|
<
<
<
<
<
<
<
<



<






<

<
<
|
<
>
>
|
|
|
<
|
|
<
|
|
<
<

<
|
<
<
<
<
<
<
<











|
|
>
|
|
>









>
>
>








>
|
>
|
>
>
>


<

<


<
|
|

|

|
>
|
>
>
|


|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|



|


<

|
|



|
>
|

|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>

|
<

<










<
|
<
<
<
|
<
<
|
<
<
|
<
|
|
<
<
>
>
|
|
>
|
|
|
|
|
>
|
|
>
|
>
>

>
|
|
|

|
<



















<

<





<


<







<

<


|
|





<


<


<

<





|
<

<

<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
|
<
<

<










<



<
|
<
<



<
|
|
|
|
|


|
|

|
|
<
<

|
<



<
|
<
<
|
<
|
<
<
|
<
<
<

<
<


<

|
<





|




<
|
<
<
|
<
|
<
<
|
<
<
<

<
<



|
<
<
<

|
<



<
|
<
<
|
<
|
<
<
|
<
<
<

<
<



<
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
>
|
|
|
|
|
|
|
|


|
|
<
<

|
<



<
|
|
<
<
<
|
<
<
<
<
|
|
<
<
|
<
<
<

<
<



<
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|


|
|
<
<

|
<

|
|
<
|
|
|
|
|
|
|
<
<
<
|
|
<
<
|
<
|
<
<
<

<
<






<
<

<





|







|
<
<
<
<
<
<
<
<
<
<










|


|











|



|


|







|


|
<













|




|
|
|
|
|

|
|
|



|




|
<
<
<


<

|
<

>
>






|


|
>
>
>
>




>
>
>
>
>

<
<


<
|
<
<
<
<
<
<



>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>

|
|
>



>
>
|
|
|
<
<
<
<
|
|
<
<
<
<
<


<

|







1596
1597
1598
1599
1600
1601
1602
1603

1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619

1620
1621
1622
1623
1624
1625
1626
1627

1628
1629
1630
1631




1632
1633
1634

1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658



1659
1660

1661
1662
1663
1664

1665
1666
1667

1668

1669
1670
1671
1672
1673
1674
1675
1676

1677
1678
1679

1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693

1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751





1752
1753
1754

1755

1756
1757
1758
1759
1760
1761
1762

1763


1764




1765










1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788

1789
1790
1791
1792
1793
1794
1795

1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808

1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826

1827
1828
1829
1830
1831








1832
1833


1834
1835
1836
1837


1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874

1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892

1893
1894
1895
1896
1897
1898

1899
1900
1901




1902
1903
1904
1905
1906
1907
1908
1909


1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927

1928
1929

1930
1931
1932
1933

1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946

1947
1948
1949
1950
1951
1952
1953
1954

1955
1956
1957




1958
1959
1960

1961
1962

1963
1964
1965

1966
1967

1968
1969
1970

1971
1972
1973
1974

1975
1976
1977


1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002

2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013

2014





2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033


2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484

2485

2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510

2511
2512
2513
2514
2515
2516
2517
2518
2519

2520

2521
2522

2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547

2548







2549

2550
2551
2552
2553
2554
2555


2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603




2604






2605




2606
2607
2608
2609
2610
2611
2612
2613
2614
2615


2616
2617



2618
2619
2620
2621
2622
2623

2624
2625
2626
2627
2628
2629
2630
2631






2632







2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
















2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726

2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813

2814
2815

2816
2817
2818
2819
2820

2821
2822

2823
2824
2825

2826
2827

2828

2829
2830
2831
2832
2833
2834
2835
2836

2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847

2848


2849
2850
2851









2852
2853
2854
2855








2856



2857






2858
2859
2860
2861
2862





















2863
2864
2865
2866
2867
2868
2869








2870
2871
2872

2873
2874
2875
2876
2877
2878

2879


2880

2881
2882
2883
2884
2885

2886
2887

2888
2889


2890

2891







2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937

2938

2939
2940

2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954



























































2955

2956
2957
2958
2959
2960
2961
2962

2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037

3038

3039
3040
3041
3042
3043
3044
3045
3046
3047
3048

3049



3050


3051


3052

3053
3054


3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078

3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097

3098

3099
3100
3101
3102
3103

3104
3105

3106
3107
3108
3109
3110
3111
3112

3113

3114
3115
3116
3117
3118
3119
3120
3121
3122

3123
3124

3125
3126

3127

3128
3129
3130
3131
3132
3133

3134

3135






3136
3137








3138


3139

3140
3141
3142
3143
3144
3145
3146
3147
3148
3149

3150
3151
3152

3153


3154
3155
3156

3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168


3169
3170

3171
3172
3173

3174


3175

3176


3177



3178


3179
3180

3181
3182

3183
3184
3185
3186
3187
3188
3189
3190
3191
3192

3193


3194

3195


3196



3197


3198
3199
3200
3201



3202
3203

3204
3205
3206

3207


3208

3209


3210



3211


3212
3213
3214

3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251


3252
3253

3254
3255
3256

3257
3258



3259




3260
3261


3262



3263


3264
3265
3266

3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285


3286
3287

3288
3289
3290

3291
3292
3293
3294
3295
3296
3297



3298
3299


3300

3301



3302


3303
3304
3305
3306
3307
3308


3309

3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323










3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367

3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403



3404
3405

3406
3407

3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434


3435
3436

3437






3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469




3470
3471





3472
3473

3474
3475
3476
3477
3478
3479
3480
3481
3482

    def _start_admin_generatoragent(self, attrsD):
        self.push('generator', 1)
        value = self._getAttribute(attrsD, 'rdf:resource')
        if value:
            self.elementstack[-1][2].append(value)
        self.pop('generator')
        self._getContext()['generator_detail'] = FeedParserDict({'href': value})


    def _start_admin_errorreportsto(self, attrsD):
        self.push('errorreportsto', 1)
        value = self._getAttribute(attrsD, 'rdf:resource')
        if value:
            self.elementstack[-1][2].append(value)
        self.pop('errorreportsto')

    def _start_summary(self, attrsD):
        context = self._getContext()
        if context.has_key('summary'):
            self._summaryKey = 'content'
            self._start_content(attrsD)
        else:
            self._summaryKey = 'summary'
            self.pushContent(self._summaryKey, attrsD, u'text/plain', 1)

    _start_itunes_summary = _start_summary

    def _end_summary(self):
        if self._summaryKey == 'content':
            self._end_content()
        else:
            self.popContent(self._summaryKey or 'summary')
        self._summaryKey = None

    _end_itunes_summary = _end_summary

    def _start_enclosure(self, attrsD):
        attrsD = self._itsAnHrefDamnIt(attrsD)




        context = self._getContext()
        attrsD['rel'] = u'enclosure'
        context.setdefault('links', []).append(FeedParserDict(attrsD))


    def _start_source(self, attrsD):
        if 'url' in attrsD:
          # This means that we're processing a source element from an RSS 2.0 feed
          self.sourcedata['href'] = attrsD[u'url']
        self.push('source', 1)
        self.insource = 1
        self.hasTitle = 0

    def _end_source(self):
        self.insource = 0
        value = self.pop('source')
        if value:
          self.sourcedata['title'] = value
        self._getContext()['source'] = copy.deepcopy(self.sourcedata)
        self.sourcedata.clear()

    def _start_content(self, attrsD):
        self.pushContent('content', attrsD, u'text/plain', 1)
        src = attrsD.get('src')
        if src:
            self.contentparams['src'] = src
        self.push('content', 1)




    def _start_body(self, attrsD):
        self.pushContent('content', attrsD, u'application/xhtml+xml', 1)

    _start_xhtml_body = _start_body

    def _start_content_encoded(self, attrsD):
        self.pushContent('content', attrsD, u'text/html', 1)

    _start_fullitem = _start_content_encoded

    def _end_content(self):

        copyToSummary = self.mapContentType(self.contentparams.get('type')) in ([u'text/plain'] + self.html_types)

        value = self.popContent('content')
        if copyToSummary:
            self._save('summary', value)

    _end_body = _end_content
    _end_xhtml_body = _end_content
    _end_content_encoded = _end_content
    _end_fullitem = _end_content


    def _start_itunes_image(self, attrsD):
        self.push('itunes_image', 0)

        if attrsD.get('href'):
            self._getContext()['image'] = FeedParserDict({'href': attrsD.get('href')})
    _start_itunes_link = _start_itunes_image

    def _end_itunes_block(self):
        value = self.pop('itunes_block', 0)
        self._getContext()['itunes_block'] = (value == 'yes') and 1 or 0

    def _end_itunes_explicit(self):
        value = self.pop('itunes_explicit', 0)
        # Convert 'yes' -> True, 'clean' to False, and any other value to None
        # False and None both evaluate as False, so the difference can be ignored
        # by applications that only need to know if the content is explicit.
        self._getContext()['itunes_explicit'] = (None, False, True)[(value == 'yes' and 2) or value == 'clean' or 0]


    def _start_media_content(self, attrsD):
        context = self._getContext()
        context.setdefault('media_content', [])
        context['media_content'].append(attrsD)

    def _start_media_thumbnail(self, attrsD):
        context = self._getContext()
        context.setdefault('media_thumbnail', [])
        self.push('url', 1) # new
        context['media_thumbnail'].append(attrsD)

    def _end_media_thumbnail(self):
        url = self.pop('url')
        context = self._getContext()
        if url != None and len(url.strip()) != 0:
            if not context['media_thumbnail'][-1].has_key('url'):
                context['media_thumbnail'][-1]['url'] = url

    def _start_media_player(self, attrsD):
        self.push('media_player', 0)
        self._getContext()['media_player'] = FeedParserDict(attrsD)

    def _end_media_player(self):
        value = self.pop('media_player')
        context = self._getContext()
        context['media_player']['content'] = value

    def _start_newlocation(self, attrsD):
        self.push('newlocation', 1)

    def _end_newlocation(self):
        url = self.pop('newlocation')
        context = self._getContext()
        # don't set newlocation if the context isn't right
        if context is not self.feeddata:
            return
        context['newlocation'] = _makeSafeAbsoluteURI(self.baseuri, url.strip())

if _XML_AVAILABLE:
    class _StrictFeedParser(_FeedParserMixin, xml.sax.handler.ContentHandler):
        def __init__(self, baseuri, baselang, encoding):
            xml.sax.handler.ContentHandler.__init__(self)
            _FeedParserMixin.__init__(self, baseuri, baselang, encoding)
            self.bozo = 0
            self.exc = None
            self.decls = {}

        def startPrefixMapping(self, prefix, uri):
            if not uri:
                return
            # Jython uses '' instead of None; standardize on None
            prefix = prefix or None
            self.trackNamespace(prefix, uri)
            if prefix and uri == 'http://www.w3.org/1999/xlink':
                self.decls['xmlns:' + prefix] = uri

        def startElementNS(self, name, qname, attrs):





            namespace, localname = name
            lowernamespace = str(namespace or '').lower()
            if lowernamespace.find(u'backend.userland.com/rss') <> -1:

                # match any backend.userland.com namespace

                namespace = u'http://backend.userland.com/rss'
                lowernamespace = namespace
            if qname and qname.find(':') > 0:
                givenprefix = qname.split(':')[0]
            else:
                givenprefix = None
            prefix = self._matchnamespaces.get(lowernamespace, givenprefix)

            if givenprefix and (prefix == None or (prefix == '' and lowernamespace == '')) and not self.namespacesInUse.has_key(givenprefix):


                    raise UndeclaredNamespace, "'%s' is not associated with a namespace" % givenprefix




            localname = str(localname).lower()











            # qname implementation is horribly broken in Python 2.1 (it
            # doesn't report any), and slightly broken in Python 2.2 (it
            # doesn't report the xml: namespace). So we match up namespaces
            # with a known list first, and then possibly override them with
            # the qnames the SAX parser gives us (if indeed it gives us any
            # at all).  Thanks to MatejC for helping me test this and
            # tirelessly telling me that it didn't work yet.
            attrsD, self.decls = self.decls, {}
            if localname=='math' and namespace=='http://www.w3.org/1998/Math/MathML':
                attrsD['xmlns']=namespace
            if localname=='svg' and namespace=='http://www.w3.org/2000/svg':
                attrsD['xmlns']=namespace

            if prefix:
                localname = prefix.lower() + ':' + localname
            elif namespace and not qname: #Expat
                for name,value in self.namespacesInUse.items():
                     if name and value == namespace:
                         localname = name + ':' + localname
                         break

            for (namespace, attrlocalname), attrvalue in attrs.items():

                lowernamespace = (namespace or '').lower()
                prefix = self._matchnamespaces.get(lowernamespace, '')
                if prefix:
                    attrlocalname = prefix + ':' + attrlocalname
                attrsD[str(attrlocalname).lower()] = attrvalue
            for qname in attrs.getQNames():
                attrsD[str(qname).lower()] = attrs.getValueByQName(qname)

            self.unknown_starttag(localname, attrsD.items())

        def characters(self, text):
            self.handle_data(text)

        def endElementNS(self, name, qname):
            namespace, localname = name
            lowernamespace = str(namespace or '').lower()
            if qname and qname.find(':') > 0:
                givenprefix = qname.split(':')[0]
            else:
                givenprefix = ''
            prefix = self._matchnamespaces.get(lowernamespace, givenprefix)

            if prefix:
                localname = prefix + ':' + localname
            elif namespace and not qname: #Expat
                for name,value in self.namespacesInUse.items():
                     if name and value == namespace:
                         localname = name + ':' + localname
                         break
            localname = str(localname).lower()
            self.unknown_endtag(localname)

        def error(self, exc):
            self.bozo = 1
            self.exc = exc

        def fatalError(self, exc):
            self.error(exc)
            raise exc


class _BaseHTMLProcessor(sgmllib.SGMLParser):
    special = re.compile('''[<>'"]''')
    bare_ampersand = re.compile("&(?!#\d+;|#x[0-9a-fA-F]+;|\w+;)")
    elements_no_end_tag = [
      'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame',








      'hr', 'img', 'input', 'isindex', 'keygen', 'link', 'meta', 'param',
      'source', 'track', 'wbr'


    ]

    def __init__(self, encoding, _type):
        self.encoding = encoding


        self._type = _type
        sgmllib.SGMLParser.__init__(self)

    def reset(self):
        self.pieces = []
        sgmllib.SGMLParser.reset(self)

    def _shorttag_replace(self, match):
        tag = match.group(1)
        if tag in self.elements_no_end_tag:
            return '<' + tag + ' />'
        else:
            return '<' + tag + '></' + tag + '>'

    # By declaring these methods and overriding their compiled code
    # with the code from sgmllib, the original code will execute in
    # feedparser's scope instead of sgmllib's. This means that the
    # `tagfind` and `charref` regular expressions will be found as
    # they're declared above, not as they're declared in sgmllib.
    def goahead(self, i):
        pass
    goahead.func_code = sgmllib.SGMLParser.goahead.func_code

    def __parse_starttag(self, i):
        pass
    __parse_starttag.func_code = sgmllib.SGMLParser.parse_starttag.func_code

    def parse_starttag(self,i):
        j = self.__parse_starttag(i)
        if self._type == 'application/xhtml+xml':
            if j>2 and self.rawdata[j-2:j]=='/>':
                self.unknown_endtag(self.lasttag)
        return j

    def feed(self, data):
        data = re.compile(r'<!((?!DOCTYPE|--|\[))', re.IGNORECASE).sub(r'&lt;!\1', data)
        #data = re.sub(r'<(\S+?)\s*?/>', self._shorttag_replace, data) # bug [ 1399464 ] Bad regexp for _shorttag_replace

        data = re.sub(r'<([^<>\s]+?)\s*/>', self._shorttag_replace, data)
        data = data.replace('&#39;', "'")
        data = data.replace('&#34;', '"')
        try:
            bytes
            if bytes is str:
                raise NameError
            self.encoding = self.encoding + u'_INVALID_PYTHON_3'
        except NameError:
            if self.encoding and isinstance(data, unicode):
                data = data.encode(self.encoding)
        sgmllib.SGMLParser.feed(self, data)
        sgmllib.SGMLParser.close(self)

    def normalize_attrs(self, attrs):
        if not attrs:
            return attrs
        # utility method to be called by descendants

        attrs = dict([(k.lower(), v) for k, v in attrs]).items()
        attrs = [(k, k in ('rel', 'type') and v.lower() or v) for k, v in attrs]
        attrs.sort()
        return attrs

    def unknown_starttag(self, tag, attrs):

        # called for each start tag
        # attrs is a list of (attr, value) tuples
        # e.g. for <pre class='screen'>, tag='pre', attrs=[('class', 'screen')]




        uattrs = []
        strattrs=''
        if attrs:
            for key, value in attrs:
                value=value.replace('>','&gt;').replace('<','&lt;').replace('"','&quot;')
                value = self.bare_ampersand.sub("&amp;", value)
                # thanks to Kevin Marks for this breathtaking hack to deal with (valid) high-bit attribute values in UTF-8 feeds
                if not isinstance(value, unicode):


                    value = value.decode(self.encoding, 'ignore')
                try:
                    # Currently, in Python 3 the key is already a str, and cannot be decoded again
                    uattrs.append((unicode(key, self.encoding), value))
                except TypeError:
                    uattrs.append((key, value))
            strattrs = u''.join([u' %s="%s"' % (key, value) for key, value in uattrs])
            if self.encoding:
                try:
                    strattrs = strattrs.encode(self.encoding)
                except (UnicodeEncodeError, LookupError):
                    pass
        if tag in self.elements_no_end_tag:
            self.pieces.append('<%(tag)s%(strattrs)s />' % locals())
        else:
            self.pieces.append('<%(tag)s%(strattrs)s>' % locals())

    def unknown_endtag(self, tag):

        # called for each end tag, e.g. for </pre>, tag will be 'pre'
        # Reconstruct the original end tag.

        if tag not in self.elements_no_end_tag:
            self.pieces.append("</%(tag)s>" % locals())

    def handle_charref(self, ref):

        # called for each character reference, e.g. for '&#160;', ref will be '160'
        # Reconstruct the original character reference.
        if ref.startswith('x'):
            value = unichr(int(ref[1:],16))
        else:
            value = unichr(int(ref))

        if value in _cp1252.keys():
            self.pieces.append('&#%s;' % hex(ord(_cp1252[value]))[1:])
        else:
            self.pieces.append('&#%(ref)s;' % locals())

    def handle_entityref(self, ref):

        # called for each entity reference, e.g. for '&copy;', ref will be 'copy'
        # Reconstruct the original entity reference.
        if name2codepoint.has_key(ref):
            self.pieces.append('&%(ref)s;' % locals())
        else:
            self.pieces.append('&amp;%(ref)s' % locals())

    def handle_data(self, text):

        # called for each block of plain text, i.e. outside of any tag and
        # not containing any character or entity references
        # Store the original text verbatim.




        self.pieces.append(text)

    def handle_comment(self, text):

        # called for each HTML comment, e.g. <!-- insert Javascript code here -->
        # Reconstruct the original comment.

        self.pieces.append('<!--%(text)s-->' % locals())

    def handle_pi(self, text):

        # called for each processing instruction, e.g. <?instruction>
        # Reconstruct original processing instruction.

        self.pieces.append('<?%(text)s>' % locals())

    def handle_decl(self, text):

        # called for the DOCTYPE, if present, e.g.
        # <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        #     "http://www.w3.org/TR/html4/loose.dtd">
        # Reconstruct original DOCTYPE

        self.pieces.append('<!%(text)s>' % locals())

    _new_declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9:]*\s*').match


    def _scan_name(self, i, declstartpos):
        rawdata = self.rawdata
        n = len(rawdata)
        if i == n:
            return None, -1
        m = self._new_declname_match(rawdata, i)
        if m:
            s = m.group()
            name = s.strip()
            if (i + len(s)) == n:
                return None, -1  # end of buffer
            return name.lower(), m.end()
        else:
            self.handle_data(rawdata)
#            self.updatepos(declstartpos, i)
            return None, -1

    def convert_charref(self, name):
        return '&#%s;' % name

    def convert_entityref(self, name):
        return '&%s;' % name

    def output(self):
        '''Return processed HTML as a single string'''

        return ''.join([str(p) for p in self.pieces])

    def parse_declaration(self, i):
        try:
            return sgmllib.SGMLParser.parse_declaration(self, i)
        except sgmllib.SGMLParseError:
            # escape the doctype declaration and continue parsing
            self.handle_data('&lt;')
            return i+1

class _LooseFeedParser(_FeedParserMixin, _BaseHTMLProcessor):

    def __init__(self, baseuri, baselang, encoding, entities):





        sgmllib.SGMLParser.__init__(self)
        _FeedParserMixin.__init__(self, baseuri, baselang, encoding)
        _BaseHTMLProcessor.__init__(self, encoding, 'application/xhtml+xml')
        self.entities=entities

    def decodeEntities(self, element, data):
        data = data.replace('&#60;', '&lt;')
        data = data.replace('&#x3c;', '&lt;')
        data = data.replace('&#x3C;', '&lt;')
        data = data.replace('&#62;', '&gt;')
        data = data.replace('&#x3e;', '&gt;')
        data = data.replace('&#x3E;', '&gt;')
        data = data.replace('&#38;', '&amp;')
        data = data.replace('&#x26;', '&amp;')
        data = data.replace('&#34;', '&quot;')
        data = data.replace('&#x22;', '&quot;')
        data = data.replace('&#39;', '&apos;')
        data = data.replace('&#x27;', '&apos;')
        if self.contentparams.has_key('type') and not self.contentparams.get('type', u'xml').endswith(u'xml'):


            data = data.replace('&lt;', '<')
            data = data.replace('&gt;', '>')
            data = data.replace('&amp;', '&')
            data = data.replace('&quot;', '"')
            data = data.replace('&apos;', "'")
        return data

    def strattrs(self, attrs):
        return ''.join([' %s="%s"' % (n,v.replace('"','&quot;')) for n,v in attrs])

class _MicroformatsParser:
    STRING = 1
    DATE = 2
    URI = 3
    NODE = 4
    EMAIL = 5

    known_xfn_relationships = ['contact', 'acquaintance', 'friend', 'met', 'co-worker', 'coworker', 'colleague', 'co-resident', 'coresident', 'neighbor', 'child', 'parent', 'sibling', 'brother', 'sister', 'spouse', 'wife', 'husband', 'kin', 'relative', 'muse', 'crush', 'date', 'sweetheart', 'me']
    known_binary_extensions =  ['zip','rar','exe','gz','tar','tgz','tbz2','bz2','z','7z','dmg','img','sit','sitx','hqx','deb','rpm','bz2','jar','rar','iso','bin','msi','mp2','mp3','ogg','ogm','mp4','m4v','m4a','avi','wma','wmv']

    def __init__(self, data, baseuri, encoding):
        self.document = BeautifulSoup.BeautifulSoup(data)
        self.baseuri = baseuri
        self.encoding = encoding
        if isinstance(data, unicode):
            data = data.encode(encoding)
        self.tags = []
        self.enclosures = []
        self.xfn = []
        self.vcard = None

    def vcardEscape(self, s):
        if isinstance(s, basestring):
            s = s.replace(',', '\\,').replace(';', '\\;').replace('\n', '\\n')
        return s

    def vcardFold(self, s):
        s = re.sub(';+$', '', s)
        sFolded = ''
        iMax = 75
        sPrefix = ''
        while len(s) > iMax:
            sFolded += sPrefix + s[:iMax] + '\n'
            s = s[iMax:]
            sPrefix = ' '
            iMax = 74
        sFolded += sPrefix + s
        return sFolded

    def normalize(self, s):
        return re.sub(r'\s+', ' ', s).strip()

    def unique(self, aList):
        results = []
        for element in aList:
            if element not in results:
                results.append(element)
        return results

    def toISO8601(self, dt):
        return time.strftime('%Y-%m-%dT%H:%M:%SZ', dt)

    def getPropertyValue(self, elmRoot, sProperty, iPropertyType=4, bAllowMultiple=0, bAutoEscape=0):
        all = lambda x: 1
        sProperty = sProperty.lower()
        bFound = 0
        bNormalize = 1
        propertyMatch = {'class': re.compile(r'\b%s\b' % sProperty)}
        if bAllowMultiple and (iPropertyType != self.NODE):
            snapResults = []
            containers = elmRoot(['ul', 'ol'], propertyMatch)
            for container in containers:
                snapResults.extend(container('li'))
            bFound = (len(snapResults) != 0)
        if not bFound:
            snapResults = elmRoot(all, propertyMatch)
            bFound = (len(snapResults) != 0)
        if (not bFound) and (sProperty == 'value'):
            snapResults = elmRoot('pre')
            bFound = (len(snapResults) != 0)
            bNormalize = not bFound
            if not bFound:
                snapResults = [elmRoot]
                bFound = (len(snapResults) != 0)
        arFilter = []
        if sProperty == 'vcard':
            snapFilter = elmRoot(all, propertyMatch)
            for node in snapFilter:
                if node.findParent(all, propertyMatch):
                    arFilter.append(node)
        arResults = []
        for node in snapResults:
            if node not in arFilter:
                arResults.append(node)
        bFound = (len(arResults) != 0)
        if not bFound:
            if bAllowMultiple:
                return []
            elif iPropertyType == self.STRING:
                return ''
            elif iPropertyType == self.DATE:
                return None
            elif iPropertyType == self.URI:
                return ''
            elif iPropertyType == self.NODE:
                return None
            else:
                return None
        arValues = []
        for elmResult in arResults:
            sValue = None
            if iPropertyType == self.NODE:
                if bAllowMultiple:
                    arValues.append(elmResult)
                    continue
                else:
                    return elmResult
            sNodeName = elmResult.name.lower()
            if (iPropertyType == self.EMAIL) and (sNodeName == 'a'):
                sValue = (elmResult.get('href') or '').split('mailto:').pop().split('?')[0]
            if sValue:
                sValue = bNormalize and self.normalize(sValue) or sValue.strip()
            if (not sValue) and (sNodeName == 'abbr'):
                sValue = elmResult.get('title')
            if sValue:
                sValue = bNormalize and self.normalize(sValue) or sValue.strip()
            if (not sValue) and (iPropertyType == self.URI):
                if sNodeName == 'a':
                    sValue = elmResult.get('href')
                elif sNodeName == 'img':
                    sValue = elmResult.get('src')
                elif sNodeName == 'object':
                    sValue = elmResult.get('data')
            if sValue:
                sValue = bNormalize and self.normalize(sValue) or sValue.strip()
            if (not sValue) and (sNodeName == 'img'):
                sValue = elmResult.get('alt')
            if sValue:
                sValue = bNormalize and self.normalize(sValue) or sValue.strip()
            if not sValue:
                sValue = elmResult.renderContents()
                sValue = re.sub(r'<\S[^>]*>', '', sValue)
                sValue = sValue.replace('\r\n', '\n')
                sValue = sValue.replace('\r', '\n')
            if sValue:
                sValue = bNormalize and self.normalize(sValue) or sValue.strip()
            if not sValue:
                continue
            if iPropertyType == self.DATE:
                sValue = _parse_date_iso8601(sValue)
            if bAllowMultiple:
                arValues.append(bAutoEscape and self.vcardEscape(sValue) or sValue)
            else:
                return bAutoEscape and self.vcardEscape(sValue) or sValue
        return arValues

    def findVCards(self, elmRoot, bAgentParsing=0):
        sVCards = ''

        if not bAgentParsing:
            arCards = self.getPropertyValue(elmRoot, 'vcard', bAllowMultiple=1)
        else:
            arCards = [elmRoot]

        for elmCard in arCards:
            arLines = []

            def processSingleString(sProperty):
                sValue = self.getPropertyValue(elmCard, sProperty, self.STRING, bAutoEscape=1).decode(self.encoding)
                if sValue:
                    arLines.append(self.vcardFold(sProperty.upper() + ':' + sValue))
                return sValue or u''

            def processSingleURI(sProperty):
                sValue = self.getPropertyValue(elmCard, sProperty, self.URI)
                if sValue:
                    sContentType = ''
                    sEncoding = ''
                    sValueKey = ''
                    if sValue.startswith('data:'):
                        sEncoding = ';ENCODING=b'
                        sContentType = sValue.split(';')[0].split('/').pop()
                        sValue = sValue.split(',', 1).pop()
                    else:
                        elmValue = self.getPropertyValue(elmCard, sProperty)
                        if elmValue:
                            if sProperty != 'url':
                                sValueKey = ';VALUE=uri'
                            sContentType = elmValue.get('type', '').strip().split('/').pop().strip()
                    sContentType = sContentType.upper()
                    if sContentType == 'OCTET-STREAM':
                        sContentType = ''
                    if sContentType:
                        sContentType = ';TYPE=' + sContentType.upper()
                    arLines.append(self.vcardFold(sProperty.upper() + sEncoding + sContentType + sValueKey + ':' + sValue))

            def processTypeValue(sProperty, arDefaultType, arForceType=None):
                arResults = self.getPropertyValue(elmCard, sProperty, bAllowMultiple=1)
                for elmResult in arResults:
                    arType = self.getPropertyValue(elmResult, 'type', self.STRING, 1, 1)
                    if arForceType:
                        arType = self.unique(arForceType + arType)
                    if not arType:
                        arType = arDefaultType
                    sValue = self.getPropertyValue(elmResult, 'value', self.EMAIL, 0)
                    if sValue:
                        arLines.append(self.vcardFold(sProperty.upper() + ';TYPE=' + ','.join(arType) + ':' + sValue))

            # AGENT
            # must do this before all other properties because it is destructive
            # (removes nested class="vcard" nodes so they don't interfere with
            # this vcard's other properties)
            arAgent = self.getPropertyValue(elmCard, 'agent', bAllowMultiple=1)
            for elmAgent in arAgent:
                if re.compile(r'\bvcard\b').search(elmAgent.get('class')):
                    sAgentValue = self.findVCards(elmAgent, 1) + '\n'
                    sAgentValue = sAgentValue.replace('\n', '\\n')
                    sAgentValue = sAgentValue.replace(';', '\\;')
                    if sAgentValue:
                        arLines.append(self.vcardFold('AGENT:' + sAgentValue))
                    # Completely remove the agent element from the parse tree
                    elmAgent.extract()
                else:
                    sAgentValue = self.getPropertyValue(elmAgent, 'value', self.URI, bAutoEscape=1);
                    if sAgentValue:
                        arLines.append(self.vcardFold('AGENT;VALUE=uri:' + sAgentValue))

            # FN (full name)
            sFN = processSingleString('fn')

            # N (name)
            elmName = self.getPropertyValue(elmCard, 'n')
            if elmName:
                sFamilyName = self.getPropertyValue(elmName, 'family-name', self.STRING, bAutoEscape=1)
                sGivenName = self.getPropertyValue(elmName, 'given-name', self.STRING, bAutoEscape=1)
                arAdditionalNames = self.getPropertyValue(elmName, 'additional-name', self.STRING, 1, 1) + self.getPropertyValue(elmName, 'additional-names', self.STRING, 1, 1)
                arHonorificPrefixes = self.getPropertyValue(elmName, 'honorific-prefix', self.STRING, 1, 1) + self.getPropertyValue(elmName, 'honorific-prefixes', self.STRING, 1, 1)
                arHonorificSuffixes = self.getPropertyValue(elmName, 'honorific-suffix', self.STRING, 1, 1) + self.getPropertyValue(elmName, 'honorific-suffixes', self.STRING, 1, 1)
                arLines.append(self.vcardFold('N:' + sFamilyName + ';' +
                                         sGivenName + ';' +
                                         ','.join(arAdditionalNames) + ';' +
                                         ','.join(arHonorificPrefixes) + ';' +
                                         ','.join(arHonorificSuffixes)))
            elif sFN:
                # implied "N" optimization
                # http://microformats.org/wiki/hcard#Implied_.22N.22_Optimization
                arNames = self.normalize(sFN).split()
                if len(arNames) == 2:
                    bFamilyNameFirst = (arNames[0].endswith(',') or
                                        len(arNames[1]) == 1 or
                                        ((len(arNames[1]) == 2) and (arNames[1].endswith('.'))))
                    if bFamilyNameFirst:
                        arLines.append(self.vcardFold('N:' + arNames[0] + ';' + arNames[1]))
                    else:
                        arLines.append(self.vcardFold('N:' + arNames[1] + ';' + arNames[0]))

            # SORT-STRING
            sSortString = self.getPropertyValue(elmCard, 'sort-string', self.STRING, bAutoEscape=1)
            if sSortString:
                arLines.append(self.vcardFold('SORT-STRING:' + sSortString))

            # NICKNAME
            arNickname = self.getPropertyValue(elmCard, 'nickname', self.STRING, 1, 1)
            if arNickname:
                arLines.append(self.vcardFold('NICKNAME:' + ','.join(arNickname)))

            # PHOTO
            processSingleURI('photo')

            # BDAY
            dtBday = self.getPropertyValue(elmCard, 'bday', self.DATE)
            if dtBday:
                arLines.append(self.vcardFold('BDAY:' + self.toISO8601(dtBday)))

            # ADR (address)
            arAdr = self.getPropertyValue(elmCard, 'adr', bAllowMultiple=1)
            for elmAdr in arAdr:
                arType = self.getPropertyValue(elmAdr, 'type', self.STRING, 1, 1)
                if not arType:
                    arType = ['intl','postal','parcel','work'] # default adr types, see RFC 2426 section 3.2.1
                sPostOfficeBox = self.getPropertyValue(elmAdr, 'post-office-box', self.STRING, 0, 1)
                sExtendedAddress = self.getPropertyValue(elmAdr, 'extended-address', self.STRING, 0, 1)
                sStreetAddress = self.getPropertyValue(elmAdr, 'street-address', self.STRING, 0, 1)
                sLocality = self.getPropertyValue(elmAdr, 'locality', self.STRING, 0, 1)
                sRegion = self.getPropertyValue(elmAdr, 'region', self.STRING, 0, 1)
                sPostalCode = self.getPropertyValue(elmAdr, 'postal-code', self.STRING, 0, 1)
                sCountryName = self.getPropertyValue(elmAdr, 'country-name', self.STRING, 0, 1)
                arLines.append(self.vcardFold('ADR;TYPE=' + ','.join(arType) + ':' +
                                         sPostOfficeBox + ';' +
                                         sExtendedAddress + ';' +
                                         sStreetAddress + ';' +
                                         sLocality + ';' +
                                         sRegion + ';' +
                                         sPostalCode + ';' +
                                         sCountryName))

            # LABEL
            processTypeValue('label', ['intl','postal','parcel','work'])

            # TEL (phone number)
            processTypeValue('tel', ['voice'])

            # EMAIL
            processTypeValue('email', ['internet'], ['internet'])

            # MAILER
            processSingleString('mailer')

            # TZ (timezone)
            processSingleString('tz')

            # GEO (geographical information)
            elmGeo = self.getPropertyValue(elmCard, 'geo')
            if elmGeo:
                sLatitude = self.getPropertyValue(elmGeo, 'latitude', self.STRING, 0, 1)
                sLongitude = self.getPropertyValue(elmGeo, 'longitude', self.STRING, 0, 1)
                arLines.append(self.vcardFold('GEO:' + sLatitude + ';' + sLongitude))

            # TITLE
            processSingleString('title')

            # ROLE
            processSingleString('role')

            # LOGO
            processSingleURI('logo')

            # ORG (organization)
            elmOrg = self.getPropertyValue(elmCard, 'org')
            if elmOrg:
                sOrganizationName = self.getPropertyValue(elmOrg, 'organization-name', self.STRING, 0, 1)
                if not sOrganizationName:
                    # implied "organization-name" optimization
                    # http://microformats.org/wiki/hcard#Implied_.22organization-name.22_Optimization
                    sOrganizationName = self.getPropertyValue(elmCard, 'org', self.STRING, 0, 1)
                    if sOrganizationName:
                        arLines.append(self.vcardFold('ORG:' + sOrganizationName))
                else:
                    arOrganizationUnit = self.getPropertyValue(elmOrg, 'organization-unit', self.STRING, 1, 1)
                    arLines.append(self.vcardFold('ORG:' + sOrganizationName + ';' + ';'.join(arOrganizationUnit)))

            # CATEGORY
            arCategory = self.getPropertyValue(elmCard, 'category', self.STRING, 1, 1) + self.getPropertyValue(elmCard, 'categories', self.STRING, 1, 1)
            if arCategory:
                arLines.append(self.vcardFold('CATEGORIES:' + ','.join(arCategory)))

            # NOTE
            processSingleString('note')

            # REV
            processSingleString('rev')

            # SOUND
            processSingleURI('sound')

            # UID
            processSingleString('uid')

            # URL
            processSingleURI('url')

            # CLASS
            processSingleString('class')

            # KEY
            processSingleURI('key')

            if arLines:
                arLines = [u'BEGIN:vCard',u'VERSION:3.0'] + arLines + [u'END:vCard']
                # XXX - this is super ugly; properly fix this with issue 148
                for i, s in enumerate(arLines):
                    if not isinstance(s, unicode):
                        arLines[i] = s.decode('utf-8', 'ignore')
                sVCards += u'\n'.join(arLines) + u'\n'

        return sVCards.strip()

    def isProbablyDownloadable(self, elm):
        attrsD = elm.attrMap
        if not attrsD.has_key('href'):
            return 0
        linktype = attrsD.get('type', '').strip()
        if linktype.startswith('audio/') or \
           linktype.startswith('video/') or \
           (linktype.startswith('application/') and not linktype.endswith('xml')):
            return 1
        path = urlparse.urlparse(attrsD['href'])[2]
        if path.find('.') == -1:
            return 0
        fileext = path.split('.').pop().lower()
        return fileext in self.known_binary_extensions

    def findTags(self):
        all = lambda x: 1
        for elm in self.document(all, {'rel': re.compile(r'\btag\b')}):
            href = elm.get('href')
            if not href:
                continue
            urlscheme, domain, path, params, query, fragment = \
                       urlparse.urlparse(_urljoin(self.baseuri, href))
            segments = path.split('/')
            tag = segments.pop()
            if not tag:
                if segments:
                    tag = segments.pop()
                else:
                    # there are no tags
                    continue
            tagscheme = urlparse.urlunparse((urlscheme, domain, '/'.join(segments), '', '', ''))
            if not tagscheme.endswith('/'):
                tagscheme += '/'
            self.tags.append(FeedParserDict({"term": tag, "scheme": tagscheme, "label": elm.string or ''}))

    def findEnclosures(self):
        all = lambda x: 1
        enclosure_match = re.compile(r'\benclosure\b')
        for elm in self.document(all, {'href': re.compile(r'.+')}):
            if not enclosure_match.search(elm.get('rel', u'')) and not self.isProbablyDownloadable(elm):
                continue
            if elm.attrMap not in self.enclosures:
                self.enclosures.append(elm.attrMap)
                if elm.string and not elm.get('title'):
                    self.enclosures[-1]['title'] = elm.string

    def findXFN(self):
        all = lambda x: 1
        for elm in self.document(all, {'rel': re.compile('.+'), 'href': re.compile('.+')}):
            rels = elm.get('rel', u'').split()
            xfn_rels = []
            for rel in rels:
                if rel in self.known_xfn_relationships:
                    xfn_rels.append(rel)
            if xfn_rels:
                self.xfn.append({"relationships": xfn_rels, "href": elm.get('href', ''), "name": elm.string})

def _parseMicroformats(htmlSource, baseURI, encoding):
    if not BeautifulSoup:
        return
    try:
        p = _MicroformatsParser(htmlSource, baseURI, encoding)
    except UnicodeEncodeError:
        # sgmllib throws this exception when performing lookups of tags
        # with non-ASCII characters in them.
        return
    p.vcard = p.findVCards(p.document)
    p.findTags()
    p.findEnclosures()
    p.findXFN()
    return {"tags": p.tags, "enclosures": p.enclosures, "xfn": p.xfn, "vcard": p.vcard}

class _RelativeURIResolver(_BaseHTMLProcessor):

    relative_uris = [('a', 'href'),

                     ('applet', 'codebase'),
                     ('area', 'href'),
                     ('blockquote', 'cite'),
                     ('body', 'background'),
                     ('del', 'cite'),
                     ('form', 'action'),
                     ('frame', 'longdesc'),
                     ('frame', 'src'),
                     ('iframe', 'longdesc'),
                     ('iframe', 'src'),
                     ('head', 'profile'),
                     ('img', 'longdesc'),
                     ('img', 'src'),
                     ('img', 'usemap'),
                     ('input', 'src'),
                     ('input', 'usemap'),
                     ('ins', 'cite'),
                     ('link', 'href'),
                     ('object', 'classid'),
                     ('object', 'codebase'),
                     ('object', 'data'),
                     ('object', 'usemap'),
                     ('q', 'cite'),
                     ('script', 'src')]


    def __init__(self, baseuri, encoding, _type):
        _BaseHTMLProcessor.__init__(self, encoding, _type)
        self.baseuri = baseuri

    def resolveURI(self, uri):
        return _makeSafeAbsoluteURI(_urljoin(self.baseuri, uri.strip()))

    def unknown_starttag(self, tag, attrs):
        attrs = self.normalize_attrs(attrs)

        attrs = [(key, ((tag, key) in self.relative_uris) and self.resolveURI(value) or value) for key, value in attrs]

        _BaseHTMLProcessor.unknown_starttag(self, tag, attrs)


def _resolveRelativeURIs(htmlSource, baseURI, encoding, _type):
    if not _SGML_AVAILABLE:
        return htmlSource

    p = _RelativeURIResolver(baseURI, encoding, _type)
    p.feed(htmlSource)
    return p.output()

def _makeSafeAbsoluteURI(base, rel=None):
    # bail if ACCEPTABLE_URI_SCHEMES is empty
    if not ACCEPTABLE_URI_SCHEMES:
        return _urljoin(base, rel or u'')
    if not base:
        return rel or u''
    if not rel:
        scheme = urlparse.urlparse(base)[0]
        if not scheme or scheme in ACCEPTABLE_URI_SCHEMES:
            return base
        return u''
    uri = _urljoin(base, rel)
    if uri.strip().split(':', 1)[0] not in ACCEPTABLE_URI_SCHEMES:
        return u''
    return uri

class _HTMLSanitizer(_BaseHTMLProcessor):

    acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area',







        'article', 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button',

        'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
        'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn',
        'dialog', 'dir', 'div', 'dl', 'dt', 'em', 'event-source', 'fieldset',
        'figcaption', 'figure', 'footer', 'font', 'form', 'header', 'h1',
        'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input', 'ins',
        'keygen', 'kbd', 'label', 'legend', 'li', 'm', 'map', 'menu', 'meter',


        'multicol', 'nav', 'nextid', 'ol', 'output', 'optgroup', 'option',
        'p', 'pre', 'progress', 'q', 's', 'samp', 'section', 'select',
        'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
        'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
        'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video', 'noscript']

    acceptable_attributes = ['abbr', 'accept', 'accept-charset', 'accesskey',
      'action', 'align', 'alt', 'autocomplete', 'autofocus', 'axis',
      'background', 'balance', 'bgcolor', 'bgproperties', 'border',
      'bordercolor', 'bordercolordark', 'bordercolorlight', 'bottompadding',
      'cellpadding', 'cellspacing', 'ch', 'challenge', 'char', 'charoff',
      'choff', 'charset', 'checked', 'cite', 'class', 'clear', 'color', 'cols',
      'colspan', 'compact', 'contenteditable', 'controls', 'coords', 'data',
      'datafld', 'datapagesize', 'datasrc', 'datetime', 'default', 'delay',
      'dir', 'disabled', 'draggable', 'dynsrc', 'enctype', 'end', 'face', 'for',
      'form', 'frame', 'galleryimg', 'gutter', 'headers', 'height', 'hidefocus',
      'hidden', 'high', 'href', 'hreflang', 'hspace', 'icon', 'id', 'inputmode',
      'ismap', 'keytype', 'label', 'leftspacing', 'lang', 'list', 'longdesc',
      'loop', 'loopcount', 'loopend', 'loopstart', 'low', 'lowsrc', 'max',
      'maxlength', 'media', 'method', 'min', 'multiple', 'name', 'nohref',
      'noshade', 'nowrap', 'open', 'optimum', 'pattern', 'ping', 'point-size',
      'prompt', 'pqg', 'radiogroup', 'readonly', 'rel', 'repeat-max',
      'repeat-min', 'replace', 'required', 'rev', 'rightspacing', 'rows',
      'rowspan', 'rules', 'scope', 'selected', 'shape', 'size', 'span', 'src',
      'start', 'step', 'summary', 'suppress', 'tabindex', 'target', 'template',
      'title', 'toppadding', 'type', 'unselectable', 'usemap', 'urn', 'valign',
      'value', 'variable', 'volume', 'vspace', 'vrml', 'width', 'wrap',
      'xml:lang']

    unacceptable_elements_with_end_tag = ['script', 'applet', 'style']

    acceptable_css_properties = ['azimuth', 'background-color',
      'border-bottom-color', 'border-collapse', 'border-color',
      'border-left-color', 'border-right-color', 'border-top-color', 'clear',
      'color', 'cursor', 'direction', 'display', 'elevation', 'float', 'font',
      'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight',
      'height', 'letter-spacing', 'line-height', 'overflow', 'pause',
      'pause-after', 'pause-before', 'pitch', 'pitch-range', 'richness',
      'speak', 'speak-header', 'speak-numeral', 'speak-punctuation',
      'speech-rate', 'stress', 'text-align', 'text-decoration', 'text-indent',
      'unicode-bidi', 'vertical-align', 'voice-family', 'volume',
      'white-space', 'width']

    # survey of common keywords found in feeds
    acceptable_css_keywords = ['auto', 'aqua', 'black', 'block', 'blue',
      'bold', 'both', 'bottom', 'brown', 'center', 'collapse', 'dashed',
      'dotted', 'fuchsia', 'gray', 'green', '!important', 'italic', 'left',
      'lime', 'maroon', 'medium', 'none', 'navy', 'normal', 'nowrap', 'olive',




      'pointer', 'purple', 'red', 'right', 'solid', 'silver', 'teal', 'top',






      'transparent', 'underline', 'white', 'yellow']





    valid_css_values = re.compile('^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|' +
      '\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$')

    mathml_elements = ['annotation', 'annotation-xml', 'maction', 'math',
      'merror', 'mfenced', 'mfrac', 'mi', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded',
      'mphantom', 'mprescripts', 'mroot', 'mrow', 'mspace', 'msqrt', 'mstyle',
      'msub', 'msubsup', 'msup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder',
      'munderover', 'none', 'semantics']



    mathml_attributes = ['actiontype', 'align', 'columnalign', 'columnalign',
      'columnalign', 'close', 'columnlines', 'columnspacing', 'columnspan', 'depth',



      'display', 'displaystyle', 'encoding', 'equalcolumns', 'equalrows',
      'fence', 'fontstyle', 'fontweight', 'frame', 'height', 'linethickness',
      'lspace', 'mathbackground', 'mathcolor', 'mathvariant', 'mathvariant',
      'maxsize', 'minsize', 'open', 'other', 'rowalign', 'rowalign', 'rowalign',
      'rowlines', 'rowspacing', 'rowspan', 'rspace', 'scriptlevel', 'selection',
      'separator', 'separators', 'stretchy', 'width', 'width', 'xlink:href',

      'xlink:show', 'xlink:type', 'xmlns', 'xmlns:xlink']

    # svgtiny - foreignObject + linearGradient + radialGradient + stop
    svg_elements = ['a', 'animate', 'animateColor', 'animateMotion',
      'animateTransform', 'circle', 'defs', 'desc', 'ellipse', 'foreignObject',
      'font-face', 'font-face-name', 'font-face-src', 'g', 'glyph', 'hkern',
      'linearGradient', 'line', 'marker', 'metadata', 'missing-glyph', 'mpath',
      'path', 'polygon', 'polyline', 'radialGradient', 'rect', 'set', 'stop',






      'svg', 'switch', 'text', 'title', 'tspan', 'use']








    # svgtiny + class + opacity + offset + xmlns + xmlns:xlink
    svg_attributes = ['accent-height', 'accumulate', 'additive', 'alphabetic',
       'arabic-form', 'ascent', 'attributeName', 'attributeType',
       'baseProfile', 'bbox', 'begin', 'by', 'calcMode', 'cap-height',
       'class', 'color', 'color-rendering', 'content', 'cx', 'cy', 'd', 'dx',
       'dy', 'descent', 'display', 'dur', 'end', 'fill', 'fill-opacity',
       'fill-rule', 'font-family', 'font-size', 'font-stretch', 'font-style',
       'font-variant', 'font-weight', 'from', 'fx', 'fy', 'g1', 'g2',
       'glyph-name', 'gradientUnits', 'hanging', 'height', 'horiz-adv-x',
       'horiz-origin-x', 'id', 'ideographic', 'k', 'keyPoints', 'keySplines',
       'keyTimes', 'lang', 'mathematical', 'marker-end', 'marker-mid',
       'marker-start', 'markerHeight', 'markerUnits', 'markerWidth', 'max',
       'min', 'name', 'offset', 'opacity', 'orient', 'origin',
       'overline-position', 'overline-thickness', 'panose-1', 'path',
       'pathLength', 'points', 'preserveAspectRatio', 'r', 'refX', 'refY',
       'repeatCount', 'repeatDur', 'requiredExtensions', 'requiredFeatures',
       'restart', 'rotate', 'rx', 'ry', 'slope', 'stemh', 'stemv',
       'stop-color', 'stop-opacity', 'strikethrough-position',
       'strikethrough-thickness', 'stroke', 'stroke-dasharray',
       'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin',
       'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'systemLanguage',
       'target', 'text-anchor', 'to', 'transform', 'type', 'u1', 'u2',
       'underline-position', 'underline-thickness', 'unicode', 'unicode-range',
       'units-per-em', 'values', 'version', 'viewBox', 'visibility', 'width',
       'widths', 'x', 'x-height', 'x1', 'x2', 'xlink:actuate', 'xlink:arcrole',
       'xlink:href', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type',
       'xml:base', 'xml:lang', 'xml:space', 'xmlns', 'xmlns:xlink', 'y', 'y1',
       'y2', 'zoomAndPan']

















    svg_attr_map = None
    svg_elem_map = None

    acceptable_svg_properties = [ 'fill', 'fill-opacity', 'fill-rule',
      'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin',
      'stroke-opacity']

    def reset(self):
        _BaseHTMLProcessor.reset(self)
        self.unacceptablestack = 0
        self.mathmlOK = 0
        self.svgOK = 0

    def unknown_starttag(self, tag, attrs):
        acceptable_attributes = self.acceptable_attributes
        keymap = {}
        if not tag in self.acceptable_elements or self.svgOK:
            if tag in self.unacceptable_elements_with_end_tag:
                self.unacceptablestack += 1

            # add implicit namespaces to html5 inline svg/mathml
            if self._type.endswith('html'):
                if not dict(attrs).get('xmlns'):
                    if tag=='svg':
                        attrs.append( ('xmlns','http://www.w3.org/2000/svg') )
                    if tag=='math':
                        attrs.append( ('xmlns','http://www.w3.org/1998/Math/MathML') )

            # not otherwise acceptable, perhaps it is MathML or SVG?
            if tag=='math' and ('xmlns','http://www.w3.org/1998/Math/MathML') in attrs:
                self.mathmlOK += 1
            if tag=='svg' and ('xmlns','http://www.w3.org/2000/svg') in attrs:
                self.svgOK += 1

            # chose acceptable attributes based on tag class, else bail
            if  self.mathmlOK and tag in self.mathml_elements:
                acceptable_attributes = self.mathml_attributes
            elif self.svgOK and tag in self.svg_elements:
                # for most vocabularies, lowercasing is a good idea.  Many
                # svg elements, however, are camel case
                if not self.svg_attr_map:
                    lower=[attr.lower() for attr in self.svg_attributes]
                    mix=[a for a in self.svg_attributes if a not in lower]
                    self.svg_attributes = lower
                    self.svg_attr_map = dict([(a.lower(),a) for a in mix])

                    lower=[attr.lower() for attr in self.svg_elements]
                    mix=[a for a in self.svg_elements if a not in lower]
                    self.svg_elements = lower
                    self.svg_elem_map = dict([(a.lower(),a) for a in mix])
                acceptable_attributes = self.svg_attributes
                tag = self.svg_elem_map.get(tag,tag)
                keymap = self.svg_attr_map
            elif not tag in self.acceptable_elements:
                return

        # declare xlink namespace, if needed
        if self.mathmlOK or self.svgOK:
            if filter(lambda (n,v): n.startswith('xlink:'),attrs):
                if not ('xmlns:xlink','http://www.w3.org/1999/xlink') in attrs:
                    attrs.append(('xmlns:xlink','http://www.w3.org/1999/xlink'))

        clean_attrs = []
        for key, value in self.normalize_attrs(attrs):

            if key in acceptable_attributes:
                key=keymap.get(key,key)
                # make sure the uri uses an acceptable uri scheme
                if key == u'href':
                    value = _makeSafeAbsoluteURI(value)
                clean_attrs.append((key,value))
            elif key=='style':
                clean_value = self.sanitize_style(value)
                if clean_value:
                    clean_attrs.append((key,clean_value))
        _BaseHTMLProcessor.unknown_starttag(self, tag, clean_attrs)

    def unknown_endtag(self, tag):
        if not tag in self.acceptable_elements:
            if tag in self.unacceptable_elements_with_end_tag:
                self.unacceptablestack -= 1
            if self.mathmlOK and tag in self.mathml_elements:
                if tag == 'math' and self.mathmlOK:
                    self.mathmlOK -= 1
            elif self.svgOK and tag in self.svg_elements:
                tag = self.svg_elem_map.get(tag,tag)
                if tag == 'svg' and self.svgOK:
                    self.svgOK -= 1
            else:
                return
        _BaseHTMLProcessor.unknown_endtag(self, tag)

    def handle_pi(self, text):
        pass

    def handle_decl(self, text):
        pass

    def handle_data(self, text):
        if not self.unacceptablestack:
            _BaseHTMLProcessor.handle_data(self, text)

    def sanitize_style(self, style):
        # disallow urls
        style=re.compile('url\s*\(\s*[^\s)]+?\s*\)\s*').sub(' ',style)

        # gauntlet
        if not re.match("""^([:,;#%.\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'|"[\s\w]+"|\([\d,\s]+\))*$""", style):
            return ''
        # This replaced a regexp that used re.match and was prone to pathological back-tracking.
        if re.sub("\s*[-\w]+\s*:\s*[^:;]*;?", '', style).strip():
            return ''

        clean = []
        for prop,value in re.findall("([-\w]+)\s*:\s*([^:;]*)",style):
            if not value:
                continue
            if prop.lower() in self.acceptable_css_properties:
                clean.append(prop + ': ' + value + ';')
            elif prop.split('-')[0].lower() in ['background','border','margin','padding']:
                for keyword in value.split():
                    if not keyword in self.acceptable_css_keywords and \
                        not self.valid_css_values.match(keyword):
                        break
                else:
                    clean.append(prop + ': ' + value + ';')
            elif self.svgOK and prop.lower() in self.acceptable_svg_properties:
                clean.append(prop + ': ' + value + ';')

        return ' '.join(clean)

    def parse_comment(self, i, report=1):
        ret = _BaseHTMLProcessor.parse_comment(self, i, report)
        if ret >= 0:
            return ret
        # if ret == -1, this may be a malicious attempt to circumvent
        # sanitization, or a page-destroying unclosed comment
        match = re.compile(r'--[^>]*>').search(self.rawdata, i+4)
        if match:
            return match.end()
        # unclosed comment; deliberately fail to handle_data()
        return len(self.rawdata)


def _sanitizeHTML(htmlSource, encoding, _type):
    if not _SGML_AVAILABLE:
        return htmlSource
    p = _HTMLSanitizer(encoding, _type)
    htmlSource = htmlSource.replace('<![CDATA[', '&lt;![CDATA[')
    p.feed(htmlSource)
    data = p.output()
    if TIDY_MARKUP:

        # loop through list of preferred Tidy interfaces looking for one that's installed,
        # then set up a common _tidy function to wrap the interface-specific API.

        _tidy = None
        for tidy_interface in PREFERRED_TIDY_INTERFACES:
            try:
                if tidy_interface == "uTidy":
                    from tidy import parseString as _utidy

                    def _tidy(data, **kwargs):
                        return str(_utidy(data, **kwargs))

                    break
                elif tidy_interface == "mxTidy":
                    from mx.Tidy import Tidy as _mxtidy

                    def _tidy(data, **kwargs):
                        nerrors, nwarnings, data, errordata = _mxtidy.tidy(data, **kwargs)

                        return data

                    break
            except:
                pass
        if _tidy:
            utf8 = isinstance(data, unicode)
            if utf8:
                data = data.encode('utf-8')
            data = _tidy(data, output_xhtml=1, numeric_entities=1, wrap=0, char_encoding="utf8")

            if utf8:
                data = unicode(data, 'utf-8')
            if data.count('<body'):
                data = data.split('<body', 1)[1]
                if data.count('>'):
                    data = data.split('>', 1)[1]
            if data.count('</body'):
                data = data.split('</body', 1)[0]
    data = data.strip().replace('\r\n', '\n')
    return data


class _FeedURLHandler(urllib2.HTTPDigestAuthHandler, urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler):


    def http_error_default(self, req, fp, code, msg, headers):
        # The default implementation just raises HTTPError.
        # Forget that.









        fp.status = code
        return fp

    def http_error_301(self, req, fp, code, msg, hdrs):








        result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp,



                                                            code, msg, hdrs)






        result.status = code
        result.newurl = result.geturl()
        return result
    # The default implementations in urllib2.HTTPRedirectHandler
    # are identical, so hardcoding a http_error_301 call above





















    # won't affect anything
    http_error_300 = http_error_301
    http_error_302 = http_error_301
    http_error_303 = http_error_301
    http_error_307 = http_error_301

    def http_error_401(self, req, fp, code, msg, headers):








        # Check if
        # - server requires digest auth, AND
        # - we tried (unsuccessfully) with basic auth, AND

        # If all conditions hold, parse authentication information
        # out of the Authorization header we sent the first time
        # (for the username and password) and the WWW-Authenticate
        # header the server sent back (for the realm) and retry
        # the request with the appropriate digest auth headers instead.
        # This evil genius hack has been brought to you by Aaron Swartz.

        host = urlparse.urlparse(req.get_full_url())[1]


        if base64 is None or 'Authorization' not in req.headers \

                          or 'WWW-Authenticate' not in headers:
            return self.http_error_default(req, fp, code, msg, headers)
        auth = _base64decode(req.headers['Authorization'].split(' ')[1])
        user, passw = auth.split(':')
        realm = re.findall('realm="([^"]*)"', headers['WWW-Authenticate'])[0]

        self.add_password(realm, host, user, passw)
        retry = self.http_error_auth_reqed('www-authenticate', host, req, headers)

        self.reset_retry_count()
        return retry




def _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers):







    """URL, filename, or string --> stream

    This function lets you define parsers that take any input source
    (URL, pathname to local or network file, or actual data as a string)
    and deal with it in a uniform manner.  Returned object is guaranteed
    to have all the basic stdio read methods (read, readline, readlines).
    Just .close() the object when you're done with it.

    If the etag argument is supplied, it will be used as the value of an
    If-None-Match request header.

    If the modified argument is supplied, it can be a tuple of 9 integers
    (as returned by gmtime() in the standard Python time module) or a date
    string in any format supported by feedparser. Regardless, it MUST
    be in GMT (Greenwich Mean Time). It will be reformatted into an
    RFC 1123-compliant date and used as the value of an If-Modified-Since
    request header.

    If the agent argument is supplied, it will be used as the value of a
    User-Agent request header.

    If the referrer argument is supplied, it will be used as the value of a
    Referer[sic] request header.

    If handlers is supplied, it is a list of handlers used to build a
    urllib2 opener.

    if request_headers is supplied it is a dictionary of HTTP request headers
    that will override the values generated by FeedParser.
    """

    if hasattr(url_file_stream_or_string, 'read'):
        return url_file_stream_or_string

    if url_file_stream_or_string == '-':
        return sys.stdin

    if isinstance(url_file_stream_or_string, basestring) \
       and urlparse.urlparse(url_file_stream_or_string)[0] in ('http', 'https', 'ftp', 'file', 'feed'):
        # Deal with the feed URI scheme
        if url_file_stream_or_string.startswith('feed:http'):
            url_file_stream_or_string = url_file_stream_or_string[5:]
        elif url_file_stream_or_string.startswith('feed:'):
            url_file_stream_or_string = 'http:' + url_file_stream_or_string[5:]
        if not agent:
            agent = USER_AGENT

        # test for inline user:password for basic auth

        auth = None
        if base64:

            urltype, rest = urllib.splittype(url_file_stream_or_string)
            realhost, rest = urllib.splithost(rest)
            if realhost:
                user_passwd, realhost = urllib.splituser(realhost)
                if user_passwd:
                    url_file_stream_or_string = '%s://%s%s' % (urltype, realhost, rest)
                    auth = base64.standard_b64encode(user_passwd).strip()

        # iri support
        if isinstance(url_file_stream_or_string, unicode):
            url_file_stream_or_string = _convert_to_idn(url_file_stream_or_string)

        # try to open with urllib2 (to use optional headers)
        request = _build_urllib2_request(url_file_stream_or_string, agent, etag, modified, referrer, auth, request_headers)



























































        opener = apply(urllib2.build_opener, tuple(handlers + [_FeedURLHandler()]))

        opener.addheaders = [] # RMK - must clear so we only send our custom User-Agent
        try:
            return opener.open(request)
        finally:
            opener.close() # JohnD

    # try to open with native open function (if url_file_stream_or_string is a filename)

    try:
        return open(url_file_stream_or_string, 'rb')
    except IOError:
        pass

    # treat url_file_stream_or_string as string
    if isinstance(url_file_stream_or_string, unicode):
        return _StringIO(url_file_stream_or_string.encode('utf-8'))
    return _StringIO(url_file_stream_or_string)

def _convert_to_idn(url):
    """Convert a URL to IDN notation"""
    # this function should only be called with a unicode string
    # strategy: if the host cannot be encoded in ascii, then
    # it'll be necessary to encode it in idn form
    parts = list(urlparse.urlsplit(url))
    try:
        parts[1].encode('ascii')
    except UnicodeEncodeError:
        # the url needs to be converted to idn notation
        host = parts[1].rsplit(':', 1)
        newhost = []
        port = u''
        if len(host) == 2:
            port = host.pop()
        for h in host[0].split('.'):
            newhost.append(h.encode('idna').decode('utf-8'))
        parts[1] = '.'.join(newhost)
        if port:
            parts[1] += ':' + port
        return urlparse.urlunsplit(parts)
    else:
        return url

def _build_urllib2_request(url, agent, etag, modified, referrer, auth, request_headers):
    request = urllib2.Request(url)
    request.add_header('User-Agent', agent)
    if etag:
        request.add_header('If-None-Match', etag)
    if isinstance(modified, basestring):
        modified = _parse_date(modified)
    elif isinstance(modified, datetime.datetime):
        modified = modified.utctimetuple()
    if modified:
        # format into an RFC 1123-compliant timestamp. We can't use
        # time.strftime() since the %a and %b directives can be affected
        # by the current locale, but RFC 2616 states that dates must be
        # in English.
        short_weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        request.add_header('If-Modified-Since', '%s, %02d %s %04d %02d:%02d:%02d GMT' % (short_weekdays[modified[6]], modified[2], months[modified[1] - 1], modified[0], modified[3], modified[4], modified[5]))
    if referrer:
        request.add_header('Referer', referrer)
    if gzip and zlib:
        request.add_header('Accept-encoding', 'gzip, deflate')
    elif gzip:
        request.add_header('Accept-encoding', 'gzip')
    elif zlib:
        request.add_header('Accept-encoding', 'deflate')
    else:
        request.add_header('Accept-encoding', '')
    if auth:
        request.add_header('Authorization', 'Basic %s' % auth)
    if ACCEPT_HEADER:
        request.add_header('Accept', ACCEPT_HEADER)
    # use this for whatever -- cookies, special headers, etc
    # [('Cookie','Something'),('x-special-header','Another Value')]
    for header_name, header_value in request_headers.items():
        request.add_header(header_name, header_value)
    request.add_header('A-IM', 'feed') # RFC 3229 support
    return request

_date_handlers = []
def registerDateHandler(func):
    '''Register a date handler function (takes string, returns 9-tuple date in GMT)'''

    _date_handlers.insert(0, func)


# ISO-8601 date parsing routines written by Fazal Majid.
# The ISO 8601 standard is very convoluted and irregular - a full ISO 8601
# parser is beyond the scope of feedparser and would be a worthwhile addition
# to the Python library.
# A single regular expression cannot parse ISO 8601 date formats into groups
# as the standard is highly irregular (for instance is 030104 2003-01-04 or
# 0301-04-01), so we use templates instead.
# Please note the order in templates is significant because we need a
# greedy match.

_iso8601_tmpl = ['YYYY-?MM-?DD', 'YYYY-0MM?-?DD', 'YYYY-MM', 'YYYY-?OOO',



                'YY-?MM-?DD', 'YY-?OOO', 'YYYY',


                '-YY-?MM', '-OOO', '-YY',


                '--MM-?DD', '--MM',

                '---DD',
                'CC', '']


_iso8601_re = [
    tmpl.replace(
    'YYYY', r'(?P<year>\d{4})').replace(
    'YY', r'(?P<year>\d\d)').replace(
    'MM', r'(?P<month>[01]\d)').replace(
    'DD', r'(?P<day>[0123]\d)').replace(
    'OOO', r'(?P<ordinal>[0123]\d\d)').replace(
    'CC', r'(?P<century>\d\d$)')
    + r'(T?(?P<hour>\d{2}):(?P<minute>\d{2})'
    + r'(:(?P<second>\d{2}))?'
    + r'(\.(?P<fracsecond>\d+))?'
    + r'(?P<tz>[+-](?P<tzhour>\d{2})(:(?P<tzmin>\d{2}))?|Z)?)?'
    for tmpl in _iso8601_tmpl]
try:
    del tmpl
except NameError:
    pass
_iso8601_matches = [re.compile(regex).match for regex in _iso8601_re]
try:
    del regex
except NameError:
    pass
def _parse_date_iso8601(dateString):
    '''Parse a variety of ISO-8601-compatible formats like 20040105'''

    m = None
    for _iso8601_match in _iso8601_matches:
        m = _iso8601_match(dateString)
        if m:
            break
    if not m:
        return
    if m.span() == (0, 0):
        return
    params = m.groupdict()
    ordinal = params.get('ordinal', 0)
    if ordinal:
        ordinal = int(ordinal)
    else:
        ordinal = 0
    year = params.get('year', '--')
    if not year or year == '--':
        year = time.gmtime()[0]
    elif len(year) == 2:

        # ISO 8601 assumes current century, i.e. 93 -> 2093, NOT 1993

        year = 100 * int(time.gmtime()[0] / 100) + int(year)
    else:
        year = int(year)
    month = params.get('month', '-')
    if not month or month == '-':

        # ordinals are NOT normalized by mktime, we simulate them
        # by setting month=1, day=ordinal

        if ordinal:
            month = 1
        else:
            month = time.gmtime()[1]
    month = int(month)
    day = params.get('day', 0)
    if not day:

        # see above

        if ordinal:
            day = ordinal
        elif params.get('century', 0) or \
                 params.get('year', 0) or params.get('month', 0):
            day = 1
        else:
            day = time.gmtime()[2]
    else:
        day = int(day)

    # special case of the century - is the first year of the 21st century
    # 2000 or 2001 ? The debate goes on...

    if 'century' in params.keys():
        year = (int(params['century']) - 1) * 100 + 1

    # in ISO 8601 most fields are optional

    for field in ['hour', 'minute', 'second', 'tzhour', 'tzmin']:
        if not params.get(field, None):
            params[field] = 0
    hour = int(params.get('hour', 0))
    minute = int(params.get('minute', 0))
    second = int(float(params.get('second', 0)))

    # weekday is normalized by mktime(), we can ignore it

    weekday = 0






    daylight_savings_flag = -1
    tm = [year, month, day, hour, minute, second, weekday,








          ordinal, daylight_savings_flag]


    # ISO 8601 time zone adjustments

    tz = params.get('tz')
    if tz and tz != 'Z':
        if tz[0] == '-':
            tm[3] += int(params.get('tzhour', 0))
            tm[4] += int(params.get('tzmin', 0))
        elif tz[0] == '+':
            tm[3] -= int(params.get('tzhour', 0))
            tm[4] -= int(params.get('tzmin', 0))
        else:
            return None

    # Python's time.mktime() is a wrapper around the ANSI C mktime(3c)
    # which is guaranteed to normalize d/m/y/h/m/s.
    # Many implementations have bugs, but we'll pretend they don't.

    return time.localtime(time.mktime(tuple(tm)))


registerDateHandler(_parse_date_iso8601)

# 8-bit date handling routines written by ytrewq1.

_korean_year  = u'\ub144' # b3e2 in euc-kr
_korean_month = u'\uc6d4' # bff9 in euc-kr
_korean_day   = u'\uc77c' # c0cf in euc-kr
_korean_am    = u'\uc624\uc804' # bfc0 c0fc in euc-kr
_korean_pm    = u'\uc624\ud6c4' # bfc0 c8c4 in euc-kr

_korean_onblog_date_re = \
    re.compile('(\d{4})%s\s+(\d{2})%s\s+(\d{2})%s\s+(\d{2}):(\d{2}):(\d{2})' % \
               (_korean_year, _korean_month, _korean_day))
_korean_nate_date_re = \
    re.compile(u'(\d{4})-(\d{2})-(\d{2})\s+(%s|%s)\s+(\d{,2}):(\d{,2}):(\d{,2})' % \
               (_korean_am, _korean_pm))


def _parse_date_onblog(dateString):
    '''Parse a string according to the OnBlog 8-bit date format'''

    m = _korean_onblog_date_re.match(dateString)
    if not m:
        return

    w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \


                {'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\

                 'hour': m.group(4), 'minute': m.group(5), 'second': m.group(6),\


                 'zonediff': '+09:00'}



    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_onblog)


def _parse_date_nate(dateString):
    '''Parse a string according to the Nate 8-bit date format'''

    m = _korean_nate_date_re.match(dateString)
    if not m:
        return
    hour = int(m.group(5))
    ampm = m.group(4)
    if (ampm == _korean_pm):
        hour += 12
    hour = str(hour)
    if len(hour) == 1:
        hour = '0' + hour

    w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \


                {'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\

                 'hour': hour, 'minute': m.group(6), 'second': m.group(7),\


                 'zonediff': '+09:00'}



    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_nate)

_mssql_date_re = \
    re.compile('(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})(\.\d+)?')



def _parse_date_mssql(dateString):
    '''Parse a string according to the MS SQL date format'''

    m = _mssql_date_re.match(dateString)
    if not m:
        return

    w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \


                {'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\

                 'hour': m.group(4), 'minute': m.group(5), 'second': m.group(6),\


                 'zonediff': '+09:00'}



    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_mssql)

# Unicode strings for Greek date strings

_greek_months = \
  { \
   u'\u0399\u03b1\u03bd': u'Jan',       # c9e1ed in iso-8859-7
   u'\u03a6\u03b5\u03b2': u'Feb',       # d6e5e2 in iso-8859-7
   u'\u039c\u03ac\u03ce': u'Mar',       # ccdcfe in iso-8859-7
   u'\u039c\u03b1\u03ce': u'Mar',       # cce1fe in iso-8859-7
   u'\u0391\u03c0\u03c1': u'Apr',       # c1f0f1 in iso-8859-7
   u'\u039c\u03ac\u03b9': u'May',       # ccdce9 in iso-8859-7
   u'\u039c\u03b1\u03ca': u'May',       # cce1fa in iso-8859-7
   u'\u039c\u03b1\u03b9': u'May',       # cce1e9 in iso-8859-7
   u'\u0399\u03bf\u03cd\u03bd': u'Jun', # c9effded in iso-8859-7
   u'\u0399\u03bf\u03bd': u'Jun',       # c9efed in iso-8859-7
   u'\u0399\u03bf\u03cd\u03bb': u'Jul', # c9effdeb in iso-8859-7
   u'\u0399\u03bf\u03bb': u'Jul',       # c9f9eb in iso-8859-7
   u'\u0391\u03cd\u03b3': u'Aug',       # c1fde3 in iso-8859-7
   u'\u0391\u03c5\u03b3': u'Aug',       # c1f5e3 in iso-8859-7
   u'\u03a3\u03b5\u03c0': u'Sep',       # d3e5f0 in iso-8859-7
   u'\u039f\u03ba\u03c4': u'Oct',       # cfeaf4 in iso-8859-7
   u'\u039d\u03bf\u03ad': u'Nov',       # cdefdd in iso-8859-7
   u'\u039d\u03bf\u03b5': u'Nov',       # cdefe5 in iso-8859-7
   u'\u0394\u03b5\u03ba': u'Dec',       # c4e5ea in iso-8859-7
  }

_greek_wdays = \
  { \
   u'\u039a\u03c5\u03c1': u'Sun', # caf5f1 in iso-8859-7
   u'\u0394\u03b5\u03c5': u'Mon', # c4e5f5 in iso-8859-7
   u'\u03a4\u03c1\u03b9': u'Tue', # d4f1e9 in iso-8859-7
   u'\u03a4\u03b5\u03c4': u'Wed', # d4e5f4 in iso-8859-7
   u'\u03a0\u03b5\u03bc': u'Thu', # d0e5ec in iso-8859-7
   u'\u03a0\u03b1\u03c1': u'Fri', # d0e1f1 in iso-8859-7
   u'\u03a3\u03b1\u03b2': u'Sat', # d3e1e2 in iso-8859-7
  }

_greek_date_format_re = \
    re.compile(u'([^,]+),\s+(\d{2})\s+([^\s]+)\s+(\d{4})\s+(\d{2}):(\d{2}):(\d{2})\s+([^\s]+)')



def _parse_date_greek(dateString):
    '''Parse a string according to a Greek 8-bit date format.'''

    m = _greek_date_format_re.match(dateString)
    if not m:
        return

    wday = _greek_wdays[m.group(1)]
    month = _greek_months[m.group(3)]



    rfc822date = '%(wday)s, %(day)s %(month)s %(year)s %(hour)s:%(minute)s:%(second)s %(zonediff)s' % \




                 {'wday': wday, 'day': m.group(2), 'month': month, 'year': m.group(4),\
                  'hour': m.group(5), 'minute': m.group(6), 'second': m.group(7),\


                  'zonediff': m.group(8)}



    return _parse_date_rfc822(rfc822date)


registerDateHandler(_parse_date_greek)

# Unicode strings for Hungarian date strings

_hungarian_months = \
  { \
    u'janu\u00e1r':   u'01',  # e1 in iso-8859-2
    u'febru\u00e1ri': u'02',  # e1 in iso-8859-2
    u'm\u00e1rcius':  u'03',  # e1 in iso-8859-2
    u'\u00e1prilis':  u'04',  # e1 in iso-8859-2
    u'm\u00e1ujus':   u'05',  # e1 in iso-8859-2
    u'j\u00fanius':   u'06',  # fa in iso-8859-2
    u'j\u00falius':   u'07',  # fa in iso-8859-2
    u'augusztus':     u'08',
    u'szeptember':    u'09',
    u'okt\u00f3ber':  u'10',  # f3 in iso-8859-2
    u'november':      u'11',
    u'december':      u'12',
  }

_hungarian_date_format_re = \
  re.compile(u'(\d{4})-([^-]+)-(\d{,2})T(\d{,2}):(\d{2})((\+|-)(\d{,2}:\d{2}))')



def _parse_date_hungarian(dateString):
    '''Parse a string according to a Hungarian 8-bit date format.'''

    m = _hungarian_date_format_re.match(dateString)
    if not m or m.group(2) not in _hungarian_months:
        return None

    month = _hungarian_months[m.group(2)]
    day = m.group(3)
    if len(day) == 1:
        day = '0' + day
    hour = m.group(4)
    if len(hour) == 1:
        hour = '0' + hour



    w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s%(zonediff)s' % \
                {'year': m.group(1), 'month': month, 'day': day,\


                 'hour': hour, 'minute': m.group(5),\

                 'zonediff': m.group(6)}



    return _parse_date_w3dtf(w3dtfdate)


registerDateHandler(_parse_date_hungarian)

# W3DTF-style date parsing adapted from PyXML xml.utils.iso8601, written by
# Drake and licensed under the Python license.  Removed all range checking
# for month, day, hour, minute, and second, since mktime will normalize
# these later


def _parse_date_w3dtf(dateString):

    def __extract_date(m):
        year = int(m.group('year'))
        if year < 100:
            year = 100 * int(time.gmtime()[0] / 100) + int(year)
        if year < 1000:
            return 0, 0, 0
        julian = m.group('julian')
        if julian:
            julian = int(julian)
            month = julian / 30 + 1
            day = julian % 30 + 1
            jday = None
            while jday != julian:
                t = time.mktime((year, month, day, 0, 0, 0, 0, 0, 0))










                jday = time.gmtime(t)[-2]
                diff = abs(jday - julian)
                if jday > julian:
                    if diff < day:
                        day = day - diff
                    else:
                        month = month - 1
                        day = 31
                elif jday < julian:
                    if day + diff < 28:
                       day = day + diff
                    else:
                        month = month + 1
            return year, month, day
        month = m.group('month')
        day = 1
        if month is None:
            month = 1
        else:
            month = int(month)
            day = m.group('day')
            if day:
                day = int(day)
            else:
                day = 1
        return year, month, day

    def __extract_time(m):
        if not m:
            return 0, 0, 0
        hours = m.group('hours')
        if not hours:
            return 0, 0, 0
        hours = int(hours)
        minutes = int(m.group('minutes'))
        seconds = m.group('seconds')
        if seconds:
            seconds = int(seconds)
        else:
            seconds = 0
        return hours, minutes, seconds

    def __extract_tzd(m):
        '''Return the Time Zone Designator as an offset in seconds from UTC.'''

        if not m:
            return 0
        tzd = m.group('tzd')
        if not tzd:
            return 0
        if tzd == 'Z':
            return 0
        hours = int(m.group('tzdhours'))
        minutes = m.group('tzdminutes')
        if minutes:
            minutes = int(minutes)
        else:
            minutes = 0
        offset = (hours*60 + minutes) * 60
        if tzd[0] == '+':
            return -offset
        return offset

    __date_re = ('(?P<year>\d\d\d\d)'
                 '(?:(?P<dsep>-|)'
                 '(?:(?P<month>\d\d)(?:(?P=dsep)(?P<day>\d\d))?'
                 '|(?P<julian>\d\d\d)))?')
    __tzd_re = '(?P<tzd>[-+](?P<tzdhours>\d\d)(?::?(?P<tzdminutes>\d\d))|Z)'
    __tzd_rx = re.compile(__tzd_re)
    __time_re = ('(?P<hours>\d\d)(?P<tsep>:|)(?P<minutes>\d\d)'
                 '(?:(?P=tsep)(?P<seconds>\d\d)(?:[.,]\d+)?)?'
                 + __tzd_re)
    __datetime_re = '%s(?:T%s)?' % (__date_re, __time_re)
    __datetime_rx = re.compile(__datetime_re)
    m = __datetime_rx.match(dateString)
    if (m is None) or (m.group() != dateString):
        return
    gmt = __extract_date(m) + __extract_time(m) + (0, 0, 0)
    if gmt[0] == 0:
        return
    return time.gmtime(time.mktime(gmt) + __extract_tzd(m) - time.timezone)



registerDateHandler(_parse_date_w3dtf)


def _parse_date_rfc822(dateString):
    '''Parse an RFC822, RFC1123, RFC2822, or asctime-style date'''

    data = dateString.split()
    if not data:
        return None
    if data[0][-1] in (',', '.') or data[0].lower() in rfc822._daynames:
        del data[0]
    if len(data) == 4:
        s = data[3]
        i = s.find('+')
        if i > 0:
            data[3:] = [s[:i], s[i+1:]]
        else:
            data.append('')
        dateString = " ".join(data)
    # Account for the Etc/GMT timezone by stripping 'Etc/'
    elif len(data) == 5 and data[4].lower().startswith('etc/'):
        data[4] = data[4][4:]
        dateString = " ".join(data)
    if len(data) < 5:
        dateString += ' 00:00:00 GMT'
    tm = rfc822.parsedate_tz(dateString)
    if tm:
        # Jython doesn't adjust for 2-digit years like CPython does,
        # so account for it by shifting the year so that it's in the
        # range 1970-2069 (1970 being the year of the Unix epoch).
        if tm[0] < 100:
            tm = (tm[0] + (1900, 2000)[tm[0] < 70],) + tm[1:]
        return time.gmtime(rfc822.mktime_tz(tm))


# rfc822.py defines several time zones, but we define some extra ones.
# 'ET' is equivalent to 'EST', etc.

_additional_timezones = {'AT': -400, 'ET': -500, 'CT': -600, 'MT': -700, 'PT': -800}






rfc822._timezones.update(_additional_timezones)
registerDateHandler(_parse_date_rfc822)

def _parse_date_perforce(aDateString):
    """parse a date in yyyy/mm/dd hh:mm:ss TTT format"""
    # Fri, 2006/09/15 08:19:53 EDT
    _my_date_pattern = re.compile( \
        r'(\w{,3}), (\d{,4})/(\d{,2})/(\d{2}) (\d{,2}):(\d{2}):(\d{2}) (\w{,3})')

    m = _my_date_pattern.search(aDateString)
    if m is None:
        return None
    dow, year, month, day, hour, minute, second, tz = m.groups()
    months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    dateString = "%s, %s %s %s %s:%s:%s %s" % (dow, day, months[int(month) - 1], year, hour, minute, second, tz)
    tm = rfc822.parsedate_tz(dateString)
    if tm:
        return time.gmtime(rfc822.mktime_tz(tm))
registerDateHandler(_parse_date_perforce)

def _parse_date(dateString):
    '''Parses a variety of date formats into a 9-tuple in GMT'''
    if not dateString:
        return None
    for handler in _date_handlers:
        try:
            date9tuple = handler(dateString)
        except (KeyError, OverflowError, ValueError):
            continue
        if not date9tuple:
            continue
        if len(date9tuple) != 9:




            continue
        return date9tuple





    return None


def _getCharacterEncoding(http_headers, xml_data):
    '''Get the character encoding of the XML document

    http_headers is a dictionary
    xml_data is a raw string (not Unicode)

    This is so much trickier than it sounds, it's not even funny.
    According to RFC 3023 ('XML Media Types'), if the HTTP Content-Type
    is application/xml, application/*+xml,
3321
3322
3323
3324
3325
3326
3327
3328

3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341



3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464



3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537




3538
3539

3540
3541
3542
3543
3544
3545
3546
3547








3548
3549
3550

3551
3552
3553
3554



3555
3556
3557
3558
3559
3560




3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585






3586

3587
3588
3589
3590
3591
3592

3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611


3612
3613

3614
3615

3616
3617
3618



3619
3620
3621
3622
3623
3624
3625
3626
3627



3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646

3647
3648

3649



3650


3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682



3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695

3696
3697
3698
3699
3700

3701
3702
3703
3704
3705
3706

3707
3708
3709
3710
3711

3712
3713
3714

3715







3716
3717

3718
3719
3720
3721
3722

3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
    to find the encoding attribute, which will tell us the true encoding.

    Of course, none of this guarantees that we will be able to parse the
    feed in the declared character encoding (assuming it was declared
    correctly, which many are not).  CJKCodecs and iconv_codec help a lot;
    you should definitely install them if you can.
    http://cjkpython.i18n.org/
    """


    def _parseHTTPContentType(content_type):
        """takes HTTP Content-Type header and returns (content type, charset)

        If no charset is specified, returns (content type, '')
        If no content type is specified, returns ('', '')
        Both return parameters are guaranteed to be lowercase strings
        """

        content_type = content_type or ''
        (content_type, params) = cgi.parse_header(content_type)
        return (content_type, params.get('charset', '').replace("'", ''
                ))




    sniffed_xml_encoding = ''
    xml_encoding = ''
    true_encoding = ''
    (http_content_type, http_encoding) = \
        _parseHTTPContentType(http_headers.get('content-type'))

    # Must sniff for non-ASCII-compatible character encodings before
    # searching for XML declaration.  This heuristic is defined in
    # section F of the XML specification:
    # http://www.w3.org/TR/REC-xml/#sec-guessing-no-ext-info

    try:
        if xml_data[:4] == '\x4c\x6f\xa7\x94':

            # EBCDIC

            xml_data = _ebcdic_to_ascii(xml_data)
        elif xml_data[:4] == '\x00\x3c\x00\x3f':

            # UTF-16BE

            sniffed_xml_encoding = 'utf-16be'
            xml_data = unicode(xml_data, 'utf-16be').encode('utf-8')
        elif len(xml_data) >= 4 and xml_data[:2] == '\xfe\xff'\
             and xml_data[2:4] != '\x00\x00':

            # UTF-16BE with BOM

            sniffed_xml_encoding = 'utf-16be'
            xml_data = unicode(xml_data[2:], 'utf-16be').encode('utf-8')
        elif xml_data[:4] == '\x3c\x00\x3f\x00':

            # UTF-16LE

            sniffed_xml_encoding = 'utf-16le'
            xml_data = unicode(xml_data, 'utf-16le').encode('utf-8')
        elif len(xml_data) >= 4 and xml_data[:2] == '\xff\xfe'\
             and xml_data[2:4] != '\x00\x00':

            # UTF-16LE with BOM

            sniffed_xml_encoding = 'utf-16le'
            xml_data = unicode(xml_data[2:], 'utf-16le').encode('utf-8')
        elif xml_data[:4] == '\x00\x00\x00\x3c':

            # UTF-32BE

            sniffed_xml_encoding = 'utf-32be'
            xml_data = unicode(xml_data, 'utf-32be').encode('utf-8')
        elif xml_data[:4] == '\x3c\x00\x00\x00':

            # UTF-32LE

            sniffed_xml_encoding = 'utf-32le'
            xml_data = unicode(xml_data, 'utf-32le').encode('utf-8')
        elif xml_data[:4] == '\x00\x00\xfe\xff':

            # UTF-32BE with BOM

            sniffed_xml_encoding = 'utf-32be'
            xml_data = unicode(xml_data[4:], 'utf-32be').encode('utf-8')
        elif xml_data[:4] == '\xff\xfe\x00\x00':

            # UTF-32LE with BOM

            sniffed_xml_encoding = 'utf-32le'
            xml_data = unicode(xml_data[4:], 'utf-32le').encode('utf-8')
        elif xml_data[:3] == '\xef\xbb\xbf':

            # UTF-8 with BOM

            sniffed_xml_encoding = 'utf-8'
            xml_data = unicode(xml_data[3:], 'utf-8').encode('utf-8')
        else:

            # ASCII-compatible

            pass
        xml_encoding_match = \
            re.compile('^<\?.*encoding=[\'"](.*?)[\'"].*\?>'
                       ).match(xml_data)
    except:
        xml_encoding_match = None
    if xml_encoding_match:
        xml_encoding = xml_encoding_match.groups()[0].lower()
        if sniffed_xml_encoding and xml_encoding in (
            'iso-10646-ucs-2',
            'ucs-2',
            'csunicode',
            'iso-10646-ucs-4',
            'ucs-4',
            'csucs4',
            'utf-16',
            'utf-32',
            'utf_16',
            'utf_32',
            'utf16',
            'u16',
            ):
            xml_encoding = sniffed_xml_encoding
    acceptable_content_type = 0
    application_content_types = ('application/xml',
                                 'application/xml-dtd',
                                 'application/xml-external-parsed-entity'
                                 )
    text_content_types = ('text/xml', 'text/xml-external-parsed-entity')
    if http_content_type in application_content_types\
         or http_content_type.startswith('application/')\
         and http_content_type.endswith('+xml'):
        acceptable_content_type = 1
        true_encoding = http_encoding or xml_encoding or 'utf-8'
    elif http_content_type in text_content_types\
         or http_content_type.startswith('text/')\
         and http_content_type.endswith('+xml'):
        acceptable_content_type = 1
        true_encoding = http_encoding or 'us-ascii'
    elif http_content_type.startswith('text/'):
        true_encoding = http_encoding or 'us-ascii'
    elif http_headers and not http_headers.has_key('content-type'):
        true_encoding = xml_encoding or 'iso-8859-1'
    else:
        true_encoding = xml_encoding or 'utf-8'



    return (true_encoding, http_encoding, xml_encoding,
            sniffed_xml_encoding, acceptable_content_type)


def _toUTF8(data, encoding):
    """Changes an XML data stream on the fly to specify a new encoding

    data is a raw sequence of bytes (not Unicode) that is presumed to be in %encoding already
    encoding is a string recognized by encodings.aliases
    """

    if _debug:
        sys.stderr.write('entering _toUTF8, trying encoding %s\n'
                          % encoding)

    # strip Byte Order Mark (if present)

    if len(data) >= 4 and data[:2] == '\xfe\xff' and data[2:4]\
         != '\x00\x00':
        if _debug:
            sys.stderr.write('stripping BOM\n')
            if encoding != 'utf-16be':
                sys.stderr.write('trying utf-16be instead\n')
        encoding = 'utf-16be'
        data = data[2:]
    elif len(data) >= 4 and data[:2] == '\xff\xfe' and data[2:4]\
         != '\x00\x00':
        if _debug:
            sys.stderr.write('stripping BOM\n')
            if encoding != 'utf-16le':
                sys.stderr.write('trying utf-16le instead\n')
        encoding = 'utf-16le'
        data = data[2:]
    elif data[:3] == '\xef\xbb\xbf':
        if _debug:
            sys.stderr.write('stripping BOM\n')
            if encoding != 'utf-8':
                sys.stderr.write('trying utf-8 instead\n')
        encoding = 'utf-8'
        data = data[3:]
    elif data[:4] == '\x00\x00\xfe\xff':
        if _debug:
            sys.stderr.write('stripping BOM\n')
            if encoding != 'utf-32be':
                sys.stderr.write('trying utf-32be instead\n')
        encoding = 'utf-32be'
        data = data[4:]
    elif data[:4] == '\xff\xfe\x00\x00':
        if _debug:
            sys.stderr.write('stripping BOM\n')
            if encoding != 'utf-32le':
                sys.stderr.write('trying utf-32le instead\n')
        encoding = 'utf-32le'
        data = data[4:]
    newdata = unicode(data, encoding)
    if _debug:
        sys.stderr.write('successfully converted %s data to unicode\n'
                          % encoding)
    declmatch = re.compile('^<\?xml[^>]*?>')
    newdecl = '''<?xml version='1.0' encoding='utf-8'?>'''
    if declmatch.search(newdata):
        newdata = declmatch.sub(newdecl, newdata)
    else:
        newdata = newdecl + u'\n' + newdata
    return newdata.encode('utf-8')


def _stripDoctype(data):
    """Strips DOCTYPE from XML document, returns (rss_version, stripped_data)

    rss_version may be 'rss091n' or None
    stripped_data is the same XML document, minus the DOCTYPE
    """





    entity_pattern = re.compile(r'<!ENTITY([^>]*?)>', re.MULTILINE)

    data = entity_pattern.sub('', data)
    doctype_pattern = re.compile(r'<!DOCTYPE([^>]*?)>', re.MULTILINE)
    doctype_results = doctype_pattern.findall(data)
    doctype = doctype_results and doctype_results[0] or ''
    if doctype.lower().count('netscape'):
        version = 'rss091n'
    else:
        version = None








    data = doctype_pattern.sub('', data)
    return (version, data)



def parse(
    url_file_stream_or_string,
    etag=None,



    modified=None,
    agent=None,
    referrer=None,
    handlers=[],
    ):
    """Parse a feed from a URL, file, stream, or string"""





    result = FeedParserDict()
    result['feed'] = FeedParserDict()
    result['entries'] = []
    if _XML_AVAILABLE:
        result['bozo'] = 0
    if type(handlers) == types.InstanceType:
        handlers = [handlers]
    try:
        f = _open_resource(
            url_file_stream_or_string,
            etag,
            modified,
            agent,
            referrer,
            handlers,
            )
        data = f.read()
    except Exception, e:
        result['bozo'] = 1
        result['bozo_exception'] = e
        data = ''
        f = None

    # if feed is gzip-compressed, decompress it








    if f and data and hasattr(f, 'headers'):
        if gzip and f.headers.get('content-encoding', '') == 'gzip':
            try:
                data = gzip.GzipFile(fileobj=_StringIO(data)).read()
            except Exception, e:


                # Some feeds claim to be gzipped but they're not, so
                # we get garbage.  Ideally, we should re-request the
                # feed without the 'Accept-encoding: gzip' header,
                # but we don't.

                result['bozo'] = 1
                result['bozo_exception'] = e
                data = ''
        elif zlib and f.headers.get('content-encoding', '')\
             == 'deflate':
            try:
                data = zlib.decompress(data, -zlib.MAX_WBITS)
            except Exception, e:
                result['bozo'] = 1
                result['bozo_exception'] = e
                data = ''

    # save HTTP headers



    if hasattr(f, 'info'):
        info = f.info()

        result['etag'] = info.getheader('ETag')
        last_modified = info.getheader('Last-Modified')

        if last_modified:
            result['modified'] = _parse_date(last_modified)
    if hasattr(f, 'url'):



        result['href'] = f.url
        result['status'] = 200
    if hasattr(f, 'status'):
        result['status'] = f.status
    if hasattr(f, 'headers'):
        result['headers'] = f.headers.dict
    if hasattr(f, 'close'):
        f.close()




    # there are four encodings to keep track of:
    # - http_encoding is the encoding declared in the Content-Type HTTP header
    # - xml_encoding is the encoding declared in the <?xml declaration
    # - sniffed_encoding is the encoding sniffed from the first 4 bytes of the XML data
    # - result['encoding'] is the actual encoding, as per RFC 3023 and a variety of other conflicting specifications

    http_headers = result.get('headers', {})
    (result['encoding'], http_encoding, xml_encoding,
     sniffed_xml_encoding, acceptable_content_type) = \
        _getCharacterEncoding(http_headers, data)
    if http_headers and not acceptable_content_type:
        if http_headers.has_key('content-type'):
            bozo_message = '%s is not an XML media type'\
                 % http_headers['content-type']
        else:
            bozo_message = 'no Content-type specified'
        result['bozo'] = 1
        result['bozo_exception'] = NonXMLContentType(bozo_message)


    (result['version'], data) = _stripDoctype(data)


    baseuri = http_headers.get('content-location', result.get('href'))



    baselang = http_headers.get('content-language', None)



    # if server sent 304, we're done

    if result.get('status', 0) == 304:
        result['version'] = ''
        result['debug_message'] = \
            'The feed has not changed since you last checked, '\
             + 'so the server sent no data.  This is a feature, not a bug!'
        return result

    # if there was a problem downloading, we're done

    if not data:
        return result

    # determine character encoding

    use_strict_parser = 0
    known_encoding = 0
    tried_encodings = []

    # try: HTTP encoding, declared XML encoding, encoding sniffed from BOM

    for proposed_encoding in (result['encoding'], xml_encoding,
                              sniffed_xml_encoding):
        if not proposed_encoding:
            continue
        if proposed_encoding in tried_encodings:
            continue
        tried_encodings.append(proposed_encoding)
        try:
            data = _toUTF8(data, proposed_encoding)



            known_encoding = use_strict_parser = 1
            break
        except:
            pass

    # if no luck and we have auto-detection library, try that

    if not known_encoding and chardet:
        try:
            proposed_encoding = chardet.detect(data)['encoding']
            if proposed_encoding and proposed_encoding\
                 not in tried_encodings:
                tried_encodings.append(proposed_encoding)

                data = _toUTF8(data, proposed_encoding)
                known_encoding = use_strict_parser = 1
        except:
            pass


    # if still no luck and we haven't tried utf-8 yet, try that

    if not known_encoding and 'utf-8' not in tried_encodings:
        try:
            proposed_encoding = 'utf-8'
            tried_encodings.append(proposed_encoding)

            data = _toUTF8(data, proposed_encoding)
            known_encoding = use_strict_parser = 1
        except:
            pass


    # if still no luck and we haven't tried windows-1252 yet, try that

    if not known_encoding and 'windows-1252' not in tried_encodings:

        try:







            proposed_encoding = 'windows-1252'
            tried_encodings.append(proposed_encoding)

            data = _toUTF8(data, proposed_encoding)
            known_encoding = use_strict_parser = 1
        except:
            pass


    # if still no luck, give up

    if not known_encoding:
        result['bozo'] = 1
        result['bozo_exception'] = \
            CharacterEncodingUnknown('document encoding unknown, I tried '
                 + '%s, %s, utf-8, and windows-1252 but nothing worked'
                 % (result['encoding'], xml_encoding))
        result['encoding'] = ''
    elif proposed_encoding != result['encoding']:
        result['bozo'] = 1
        result['bozo_exception'] = \
            CharacterEncodingOverride('documented declared as %s, but parsed as %s'
                 % (result['encoding'], proposed_encoding))
        result['encoding'] = proposed_encoding

    if not _XML_AVAILABLE:
        use_strict_parser = 0
    if use_strict_parser:

        # initialize the SAX parser

        feedparser = _StrictFeedParser(baseuri, baselang, 'utf-8')
        saxparser = xml.sax.make_parser(PREFERRED_XML_PARSERS)
        saxparser.setFeature(xml.sax.handler.feature_namespaces, 1)
        saxparser.setContentHandler(feedparser)
        saxparser.setErrorHandler(feedparser)
        source = xml.sax.xmlreader.InputSource()
        source.setByteStream(_StringIO(data))
        if hasattr(saxparser, '_ns_stack'):

            # work around bug in built-in SAX parser (doesn't recognize xml: namespace)
            # PyXML doesn't have this problem, and it doesn't have _ns_stack either

            saxparser._ns_stack.append({'http://www.w3.org/XML/1998/namespace'
                    : 'xml'})
        try:
            saxparser.parse(source)
        except Exception, e:
            if _debug:
                import traceback
                traceback.print_stack()
                traceback.print_exc()
                sys.stderr.write('xml parsing failed\n')
            result['bozo'] = 1
            result['bozo_exception'] = feedparser.exc or e
            use_strict_parser = 0
    if not use_strict_parser:
        feedparser = _LooseFeedParser(baseuri, baselang, known_encoding
                 and 'utf-8' or '')
        feedparser.feed(data)
    result['feed'] = feedparser.feeddata
    result['entries'] = feedparser.entries
    result['version'] = result['version'] or feedparser.version
    result['namespaces'] = feedparser.namespacesInUse
    return result


if __name__ == '__main__':
    if not sys.argv[1:]:
        print __doc__
        sys.exit(0)
    else:
        urls = sys.argv[1:]
    zopeCompatibilityHack()
    from pprint import pprint
    for url in urls:
        print url
        print
        result = parse(url)
        pprint(result)
        print

# REVISION HISTORY
# 1.0 - 9/27/2002 - MAP - fixed namespace processing on prefixed RSS 2.0 elements,
#  added Simon Fell's test suite
# 1.1 - 9/29/2002 - MAP - fixed infinite loop on incomplete CDATA sections
# 2.0 - 10/19/2002
#  JD - use inchannel to watch out for image and textinput elements which can
#  also contain title, link, and description elements
#  JD - check for isPermaLink='false' attribute on guid elements
#  JD - replaced openAnything with open_resource supporting ETag and
#  If-Modified-Since request headers
#  JD - parse now accepts etag, modified, agent, and referrer optional
#  arguments
#  JD - modified parse to return a dictionary instead of a tuple so that any
#  etag or modified information can be returned and cached by the caller
# 2.0.1 - 10/21/2002 - MAP - changed parse() so that if we don't get anything
#  because of etag/modified, return the old etag/modified to the caller to
#  indicate why nothing is being returned
# 2.0.2 - 10/21/2002 - JB - added the inchannel to the if statement, otherwise its
#  useless.  Fixes the problem JD was addressing by adding it.
# 2.1 - 11/14/2002 - MAP - added gzip support
# 2.2 - 1/27/2003 - MAP - added attribute support, admin:generatorAgent.
#  start_admingeneratoragent is an example of how to handle elements with
#  only attributes, no content.
# 2.3 - 6/11/2003 - MAP - added USER_AGENT for default (if caller doesn't specify);
#  also, make sure we send the User-Agent even if urllib2 isn't available.
#  Match any variation of backend.userland.com/rss namespace.
# 2.3.1 - 6/12/2003 - MAP - if item has both link and guid, return both as-is.
# 2.4 - 7/9/2003 - MAP - added preliminary Pie/Atom/Echo support based on Sam Ruby's
#  snapshot of July 1 <http://www.intertwingly.net/blog/1506.html>; changed
#  project name
# 2.5 - 7/25/2003 - MAP - changed to Python license (all contributors agree);
#  removed unnecessary urllib code -- urllib2 should always be available anyway;
#  return actual url, status, and full HTTP headers (as result['url'],
#  result['status'], and result['headers']) if parsing a remote feed over HTTP --
#  this should pass all the HTTP tests at <http://diveintomark.org/tests/client/http/>;
#  added the latest namespace-of-the-week for RSS 2.0
# 2.5.1 - 7/26/2003 - RMK - clear opener.addheaders so we only send our custom
#  User-Agent (otherwise urllib2 sends two, which confuses some servers)
# 2.5.2 - 7/28/2003 - MAP - entity-decode inline xml properly; added support for
#  inline <xhtml:body> and <xhtml:div> as used in some RSS 2.0 feeds
# 2.5.3 - 8/6/2003 - TvdV - patch to track whether we're inside an image or
#  textInput, and also to return the character encoding (if specified)
# 2.6 - 1/1/2004 - MAP - dc:author support (MarekK); fixed bug tracking
#  nested divs within content (JohnD); fixed missing sys import (JohanS);
#  fixed regular expression to capture XML character encoding (Andrei);
#  added support for Atom 0.3-style links; fixed bug with textInput tracking;
#  added support for cloud (MartijnP); added support for multiple
#  category/dc:subject (MartijnP); normalize content model: 'description' gets
#  description (which can come from description, summary, or full content if no
#  description), 'content' gets dict of base/language/type/value (which can come
#  from content:encoded, xhtml:body, content, or fullitem);
#  fixed bug matching arbitrary Userland namespaces; added xml:base and xml:lang
#  tracking; fixed bug tracking unknown tags; fixed bug tracking content when
#  <content> element is not in default namespace (like Pocketsoap feed);
#  resolve relative URLs in link, guid, docs, url, comments, wfw:comment,
#  wfw:commentRSS; resolve relative URLs within embedded HTML markup in
#  description, xhtml:body, content, content:encoded, title, subtitle,
#  summary, info, tagline, and copyright; added support for pingback and
#  trackback namespaces
# 2.7 - 1/5/2004 - MAP - really added support for trackback and pingback
#  namespaces, as opposed to 2.6 when I said I did but didn't really;
#  sanitize HTML markup within some elements; added mxTidy support (if
#  installed) to tidy HTML markup within some elements; fixed indentation
#  bug in _parse_date (FazalM); use socket.setdefaulttimeout if available
#  (FazalM); universal date parsing and normalization (FazalM): 'created', modified',
#  'issued' are parsed into 9-tuple date format and stored in 'created_parsed',
#  'modified_parsed', and 'issued_parsed'; 'date' is duplicated in 'modified'
#  and vice-versa; 'date_parsed' is duplicated in 'modified_parsed' and vice-versa
# 2.7.1 - 1/9/2004 - MAP - fixed bug handling &quot; and &apos;.  fixed memory
#  leak not closing url opener (JohnD); added dc:publisher support (MarekK);
#  added admin:errorReportsTo support (MarekK); Python 2.1 dict support (MarekK)
# 2.7.4 - 1/14/2004 - MAP - added workaround for improperly formed <br/> tags in
#  encoded HTML (skadz); fixed unicode handling in normalize_attrs (ChrisL);
#  fixed relative URI processing for guid (skadz); added ICBM support; added
#  base64 support
# 2.7.5 - 1/15/2004 - MAP - added workaround for malformed DOCTYPE (seen on many
#  blogspot.com sites); added _debug variable
# 2.7.6 - 1/16/2004 - MAP - fixed bug with StringIO importing
# 3.0b3 - 1/23/2004 - MAP - parse entire feed with real XML parser (if available);
#  added several new supported namespaces; fixed bug tracking naked markup in
#  description; added support for enclosure; added support for source; re-added
#  support for cloud which got dropped somehow; added support for expirationDate
# 3.0b4 - 1/26/2004 - MAP - fixed xml:lang inheritance; fixed multiple bugs tracking
#  xml:base URI, one for documents that don't define one explicitly and one for
#  documents that define an outer and an inner xml:base that goes out of scope
#  before the end of the document
# 3.0b5 - 1/26/2004 - MAP - fixed bug parsing multiple links at feed level
# 3.0b6 - 1/27/2004 - MAP - added feed type and version detection, result['version']
#  will be one of SUPPORTED_VERSIONS.keys() or empty string if unrecognized;
#  added support for creativeCommons:license and cc:license; added support for
#  full Atom content model in title, tagline, info, copyright, summary; fixed bug
#  with gzip encoding (not always telling server we support it when we do)
# 3.0b7 - 1/28/2004 - MAP - support Atom-style author element in author_detail
#  (dictionary of 'name', 'url', 'email'); map author to author_detail if author
#  contains name + email address
# 3.0b8 - 1/28/2004 - MAP - added support for contributor
# 3.0b9 - 1/29/2004 - MAP - fixed check for presence of dict function; added
#  support for summary
# 3.0b10 - 1/31/2004 - MAP - incorporated ISO-8601 date parsing routines from
#  xml.util.iso8601
# 3.0b11 - 2/2/2004 - MAP - added 'rights' to list of elements that can contain
#  dangerous markup; fiddled with decodeEntities (not right); liberalized
#  date parsing even further
# 3.0b12 - 2/6/2004 - MAP - fiddled with decodeEntities (still not right);
#  added support to Atom 0.2 subtitle; added support for Atom content model
#  in copyright; better sanitizing of dangerous HTML elements with end tags
#  (script, frameset)
# 3.0b13 - 2/8/2004 - MAP - better handling of empty HTML tags (br, hr, img,
#  etc.) in embedded markup, in either HTML or XHTML form (<br>, <br/>, <br />)
# 3.0b14 - 2/8/2004 - MAP - fixed CDATA handling in non-wellformed feeds under
#  Python 2.1
# 3.0b15 - 2/11/2004 - MAP - fixed bug resolving relative links in wfw:commentRSS;
#  fixed bug capturing author and contributor URL; fixed bug resolving relative
#  links in author and contributor URL; fixed bug resolvin relative links in
#  generator URL; added support for recognizing RSS 1.0; passed Simon Fell's
#  namespace tests, and included them permanently in the test suite with his
#  permission; fixed namespace handling under Python 2.1
# 3.0b16 - 2/12/2004 - MAP - fixed support for RSS 0.90 (broken in b15)
# 3.0b17 - 2/13/2004 - MAP - determine character encoding as per RFC 3023
# 3.0b18 - 2/17/2004 - MAP - always map description to summary_detail (Andrei);
#  use libxml2 (if available)
# 3.0b19 - 3/15/2004 - MAP - fixed bug exploding author information when author
#  name was in parentheses; removed ultra-problematic mxTidy support; patch to
#  workaround crash in PyXML/expat when encountering invalid entities
#  (MarkMoraes); support for textinput/textInput
# 3.0b20 - 4/7/2004 - MAP - added CDF support
# 3.0b21 - 4/14/2004 - MAP - added Hot RSS support
# 3.0b22 - 4/19/2004 - MAP - changed 'channel' to 'feed', 'item' to 'entries' in
#  results dict; changed results dict to allow getting values with results.key
#  as well as results[key]; work around embedded illformed HTML with half
#  a DOCTYPE; work around malformed Content-Type header; if character encoding
#  is wrong, try several common ones before falling back to regexes (if this
#  works, bozo_exception is set to CharacterEncodingOverride); fixed character
#  encoding issues in BaseHTMLProcessor by tracking encoding and converting
#  from Unicode to raw strings before feeding data to sgmllib.SGMLParser;
#  convert each value in results to Unicode (if possible), even if using
#  regex-based parsing
# 3.0b23 - 4/21/2004 - MAP - fixed UnicodeDecodeError for feeds that contain
#  high-bit characters in attributes in embedded HTML in description (thanks
#  Thijs van de Vossen); moved guid, date, and date_parsed to mapped keys in
#  FeedParserDict; tweaked FeedParserDict.has_key to return True if asking
#  about a mapped key
# 3.0fc1 - 4/23/2004 - MAP - made results.entries[0].links[0] and
#  results.entries[0].enclosures[0] into FeedParserDict; fixed typo that could
#  cause the same encoding to be tried twice (even if it failed the first time);
#  fixed DOCTYPE stripping when DOCTYPE contained entity declarations;
#  better textinput and image tracking in illformed RSS 1.0 feeds
# 3.0fc2 - 5/10/2004 - MAP - added and passed Sam's amp tests; added and passed
#  my blink tag tests
# 3.0fc3 - 6/18/2004 - MAP - fixed bug in _changeEncodingDeclaration that
#  failed to parse utf-16 encoded feeds; made source into a FeedParserDict;
#  duplicate admin:generatorAgent/@rdf:resource in generator_detail.url;
#  added support for image; refactored parse() fallback logic to try other
#  encodings if SAX parsing fails (previously it would only try other encodings
#  if re-encoding failed); remove unichr madness in normalize_attrs now that
#  we're properly tracking encoding in and out of BaseHTMLProcessor; set
#  feed.language from root-level xml:lang; set entry.id from rdf:about;
#  send Accept header
# 3.0 - 6/21/2004 - MAP - don't try iso-8859-1 (can't distinguish between
#  iso-8859-1 and windows-1252 anyway, and most incorrectly marked feeds are
#  windows-1252); fixed regression that could cause the same encoding to be
#  tried twice (even if it failed the first time)
# 3.0.1 - 6/22/2004 - MAP - default to us-ascii for all text/* content types;
#  recover from malformed content-type header parameter with no equals sign
#  ('text/xml; charset:iso-8859-1')
# 3.1 - 6/28/2004 - MAP - added and passed tests for converting HTML entities
#  to Unicode equivalents in illformed feeds (aaronsw); added and
#  passed tests for converting character entities to Unicode equivalents
#  in illformed feeds (aaronsw); test for valid parsers when setting
#  XML_AVAILABLE; make version and encoding available when server returns
#  a 304; add handlers parameter to pass arbitrary urllib2 handlers (like
#  digest auth or proxy support); add code to parse username/password
#  out of url and send as basic authentication; expose downloading-related
#  exceptions in bozo_exception (aaronsw); added __contains__ method to
#  FeedParserDict (aaronsw); added publisher_detail (aaronsw)
# 3.2 - 7/3/2004 - MAP - use cjkcodecs and iconv_codec if available; always
#  convert feed to UTF-8 before passing to XML parser; completely revamped
#  logic for determining character encoding and attempting XML parsing
#  (much faster); increased default timeout to 20 seconds; test for presence
#  of Location header on redirects; added tests for many alternate character
#  encodings; support various EBCDIC encodings; support UTF-16BE and
#  UTF16-LE with or without a BOM; support UTF-8 with a BOM; support
#  UTF-32BE and UTF-32LE with or without a BOM; fixed crashing bug if no
#  XML parsers are available; added support for 'Content-encoding: deflate';
#  send blank 'Accept-encoding: ' header if neither gzip nor zlib modules
#  are available
# 3.3 - 7/15/2004 - MAP - optimize EBCDIC to ASCII conversion; fix obscure
#  problem tracking xml:base and xml:lang if element declares it, child
#  doesn't, first grandchild redeclares it, and second grandchild doesn't;
#  refactored date parsing; defined public registerDateHandler so callers
#  can add support for additional date formats at runtime; added support
#  for OnBlog, Nate, MSSQL, Greek, and Hungarian dates (ytrewq1); added
#  zopeCompatibilityHack() which turns FeedParserDict into a regular
#  dictionary, required for Zope compatibility, and also makes command-
#  line debugging easier because pprint module formats real dictionaries
#  better than dictionary-like objects; added NonXMLContentType exception,
#  which is stored in bozo_exception when a feed is served with a non-XML
#  media type such as 'text/plain'; respect Content-Language as default
#  language if not xml:lang is present; cloud dict is now FeedParserDict;
#  generator dict is now FeedParserDict; better tracking of xml:lang,
#  including support for xml:lang='' to unset the current language;
#  recognize RSS 1.0 feeds even when RSS 1.0 namespace is not the default
#  namespace; don't overwrite final status on redirects (scenarios:
#  redirecting to a URL that returns 304, redirecting to a URL that
#  redirects to another URL with a different type of redirect); add
#  support for HTTP 303 redirects
# 4.0 - MAP - support for relative URIs in xml:base attribute; fixed
#  encoding issue with mxTidy (phopkins); preliminary support for RFC 3229;
#  support for Atom 1.0; support for iTunes extensions; new 'tags' for
#  categories/keywords/etc. as array of dict
#  {'term': term, 'scheme': scheme, 'label': label} to match Atom 1.0
#  terminology; parse RFC 822-style dates with no time; lots of other
#  bug fixes
# 4.1 - MAP - removed socket timeout; added support for chardet library








<
>


|




<
|

|
|
<
>
>
>

|
|
|
<
|
<




<

|
<

<

|
<

<
|

<
<
|

<
|

|
<

<
|

<
<
|

<
|

|
<

<
|

|
<

<
|

|
<

<
|

|
<

<
|

|
<

<
|


<

<

|
<
<
|


|
|
<
<
<
<
<
<
<
<
<
<
<
<
<


|
<
|
<
<
|
<
|

|
|
<
|

|
|
|
|
|

|
>
>
>
|
|

<

|



<
|
<
<
<
<

|
<
<
<
<
<
<


|
<
<
<
<
<


|
<
<
<
<


|
<
<
<
<


|
<
<
<
<



<
<
<








<

|



<
>
>
>
>

|
>
|
|
|
|
|
|


>
>
>
>
>
>
>
>
|
<

>

|
|
|
>
>
>
|
|
<
|
<
<
>
>
>
>




<
|
|


|
<
<
<
<
<
<
<




|


|
>
>
>
>
>
>

>
|
|


|
|
>




<


|
|
<

|
|


|


|
>
>
|
|
>
|
|
>
|
|

>
>
>
|



<
<



>
>
>





<

|
<

|
|
|
<





>
|

>
|
>
>
>
|
>
>


<

|
<
|
|



<
|



<



<

<
|
<







>
>
>


<
<
<

<
|
<
|
|
<
|
>

<
|
|
|
>

<
|
<
|
|
>

<
|

|
>

|
|
>

>
>
>
>
>
>
>
|
|
>

<
|

|
>

<


|
|
|
|
|


|
|
|





<

<








<


<
|
<


|
<
<
<
<
<



|
|
<
|






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
3513
3514
3515
3516
3517
3518
3519

3520
3521
3522
3523
3524
3525
3526
3527

3528
3529
3530
3531

3532
3533
3534
3535
3536
3537
3538

3539

3540
3541
3542
3543

3544
3545

3546

3547
3548

3549

3550
3551


3552
3553

3554
3555
3556

3557

3558
3559


3560
3561

3562
3563
3564

3565

3566
3567
3568

3569

3570
3571
3572

3573

3574
3575
3576

3577

3578
3579
3580

3581

3582
3583
3584

3585

3586
3587


3588
3589
3590
3591
3592













3593
3594
3595

3596


3597

3598
3599
3600
3601

3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616

3617
3618
3619
3620
3621

3622




3623
3624






3625
3626
3627





3628
3629
3630




3631
3632
3633




3634
3635
3636




3637
3638
3639



3640
3641
3642
3643
3644
3645
3646
3647

3648
3649
3650
3651
3652

3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676

3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687

3688


3689
3690
3691
3692
3693
3694
3695
3696

3697
3698
3699
3700
3701







3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728

3729
3730
3731
3732

3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759


3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770

3771
3772

3773
3774
3775
3776

3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794

3795
3796

3797
3798
3799
3800
3801

3802
3803
3804
3805

3806
3807
3808

3809

3810

3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822



3823

3824

3825
3826

3827
3828
3829

3830
3831
3832
3833
3834

3835

3836
3837
3838
3839

3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859

3860
3861
3862
3863
3864

3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881

3882

3883
3884
3885
3886
3887
3888
3889
3890

3891
3892

3893

3894
3895
3896





3897
3898
3899
3900
3901

3902
3903
3904
3905
3906
3907
3908







































































































































































































































    to find the encoding attribute, which will tell us the true encoding.

    Of course, none of this guarantees that we will be able to parse the
    feed in the declared character encoding (assuming it was declared
    correctly, which many are not).  CJKCodecs and iconv_codec help a lot;
    you should definitely install them if you can.
    http://cjkpython.i18n.org/

    '''

    def _parseHTTPContentType(content_type):
        '''takes HTTP Content-Type header and returns (content type, charset)

        If no charset is specified, returns (content type, '')
        If no content type is specified, returns ('', '')
        Both return parameters are guaranteed to be lowercase strings

        '''
        content_type = content_type or ''
        content_type, params = cgi.parse_header(content_type)
        charset = params.get('charset', '').replace("'", "")

        if not isinstance(charset, unicode):
            charset = charset.decode('utf-8', 'ignore')
        return content_type, charset

    sniffed_xml_encoding = u''
    xml_encoding = u''
    true_encoding = u''

    http_content_type, http_encoding = _parseHTTPContentType(http_headers.get('content-type', http_headers.get('Content-type')))

    # Must sniff for non-ASCII-compatible character encodings before
    # searching for XML declaration.  This heuristic is defined in
    # section F of the XML specification:
    # http://www.w3.org/TR/REC-xml/#sec-guessing-no-ext-info

    try:
        if xml_data[:4] == _l2bytes([0x4c, 0x6f, 0xa7, 0x94]):

            # EBCDIC

            xml_data = _ebcdic_to_ascii(xml_data)
        elif xml_data[:4] == _l2bytes([0x00, 0x3c, 0x00, 0x3f]):

            # UTF-16BE

            sniffed_xml_encoding = u'utf-16be'
            xml_data = unicode(xml_data, 'utf-16be').encode('utf-8')


        elif (len(xml_data) >= 4) and (xml_data[:2] == _l2bytes([0xfe, 0xff])) and (xml_data[2:4] != _l2bytes([0x00, 0x00])):
            # UTF-16BE with BOM

            sniffed_xml_encoding = u'utf-16be'
            xml_data = unicode(xml_data[2:], 'utf-16be').encode('utf-8')
        elif xml_data[:4] == _l2bytes([0x3c, 0x00, 0x3f, 0x00]):

            # UTF-16LE

            sniffed_xml_encoding = u'utf-16le'
            xml_data = unicode(xml_data, 'utf-16le').encode('utf-8')


        elif (len(xml_data) >= 4) and (xml_data[:2] == _l2bytes([0xff, 0xfe])) and (xml_data[2:4] != _l2bytes([0x00, 0x00])):
            # UTF-16LE with BOM

            sniffed_xml_encoding = u'utf-16le'
            xml_data = unicode(xml_data[2:], 'utf-16le').encode('utf-8')
        elif xml_data[:4] == _l2bytes([0x00, 0x00, 0x00, 0x3c]):

            # UTF-32BE

            sniffed_xml_encoding = u'utf-32be'
            xml_data = unicode(xml_data, 'utf-32be').encode('utf-8')
        elif xml_data[:4] == _l2bytes([0x3c, 0x00, 0x00, 0x00]):

            # UTF-32LE

            sniffed_xml_encoding = u'utf-32le'
            xml_data = unicode(xml_data, 'utf-32le').encode('utf-8')
        elif xml_data[:4] == _l2bytes([0x00, 0x00, 0xfe, 0xff]):

            # UTF-32BE with BOM

            sniffed_xml_encoding = u'utf-32be'
            xml_data = unicode(xml_data[4:], 'utf-32be').encode('utf-8')
        elif xml_data[:4] == _l2bytes([0xff, 0xfe, 0x00, 0x00]):

            # UTF-32LE with BOM

            sniffed_xml_encoding = u'utf-32le'
            xml_data = unicode(xml_data[4:], 'utf-32le').encode('utf-8')
        elif xml_data[:3] == _l2bytes([0xef, 0xbb, 0xbf]):

            # UTF-8 with BOM

            sniffed_xml_encoding = u'utf-8'
            xml_data = unicode(xml_data[3:], 'utf-8').encode('utf-8')
        else:

            # ASCII-compatible

            pass
        xml_encoding_match = re.compile(_s2bytes('^<\?.*encoding=[\'"](.*?)[\'"].*\?>')).match(xml_data)


    except UnicodeDecodeError:
        xml_encoding_match = None
    if xml_encoding_match:
        xml_encoding = xml_encoding_match.groups()[0].decode('utf-8').lower()
        if sniffed_xml_encoding and (xml_encoding in (u'iso-10646-ucs-2', u'ucs-2', u'csunicode', u'iso-10646-ucs-4', u'ucs-4', u'csucs4', u'utf-16', u'utf-32', u'utf_16', u'utf_32', u'utf16', u'u16')):













            xml_encoding = sniffed_xml_encoding
    acceptable_content_type = 0
    application_content_types = (u'application/xml', u'application/xml-dtd', u'application/xml-external-parsed-entity')

    text_content_types = (u'text/xml', u'text/xml-external-parsed-entity')


    if (http_content_type in application_content_types) or \

       (http_content_type.startswith(u'application/') and http_content_type.endswith(u'+xml')):
        acceptable_content_type = 1
        true_encoding = http_encoding or xml_encoding or u'utf-8'
    elif (http_content_type in text_content_types) or \

         (http_content_type.startswith(u'text/')) and http_content_type.endswith(u'+xml'):
        acceptable_content_type = 1
        true_encoding = http_encoding or u'us-ascii'
    elif http_content_type.startswith(u'text/'):
        true_encoding = http_encoding or u'us-ascii'
    elif http_headers and (not (http_headers.has_key('content-type') or http_headers.has_key('Content-type'))):
        true_encoding = xml_encoding or u'iso-8859-1'
    else:
        true_encoding = xml_encoding or u'utf-8'
    # some feeds claim to be gb2312 but are actually gb18030.
    # apparently MSIE and Firefox both do the following switch:
    if true_encoding.lower() == u'gb2312':
        true_encoding = u'gb18030'
    return true_encoding, http_encoding, xml_encoding, sniffed_xml_encoding, acceptable_content_type


def _toUTF8(data, encoding):
    '''Changes an XML data stream on the fly to specify a new encoding

    data is a raw sequence of bytes (not Unicode) that is presumed to be in %encoding already
    encoding is a string recognized by encodings.aliases

    '''




    # strip Byte Order Mark (if present)
    if (len(data) >= 4) and (data[:2] == _l2bytes([0xfe, 0xff])) and (data[2:4] != _l2bytes([0x00, 0x00])):






        encoding = 'utf-16be'
        data = data[2:]
    elif (len(data) >= 4) and (data[:2] == _l2bytes([0xff, 0xfe])) and (data[2:4] != _l2bytes([0x00, 0x00])):





        encoding = 'utf-16le'
        data = data[2:]
    elif data[:3] == _l2bytes([0xef, 0xbb, 0xbf]):




        encoding = 'utf-8'
        data = data[3:]
    elif data[:4] == _l2bytes([0x00, 0x00, 0xfe, 0xff]):




        encoding = 'utf-32be'
        data = data[4:]
    elif data[:4] == _l2bytes([0xff, 0xfe, 0x00, 0x00]):




        encoding = 'utf-32le'
        data = data[4:]
    newdata = unicode(data, encoding)



    declmatch = re.compile('^<\?xml[^>]*?>')
    newdecl = '''<?xml version='1.0' encoding='utf-8'?>'''
    if declmatch.search(newdata):
        newdata = declmatch.sub(newdecl, newdata)
    else:
        newdata = newdecl + u'\n' + newdata
    return newdata.encode('utf-8')


def _stripDoctype(data):
    '''Strips DOCTYPE from XML document, returns (rss_version, stripped_data)

    rss_version may be 'rss091n' or None
    stripped_data is the same XML document, minus the DOCTYPE

    '''
    start = re.search(_s2bytes('<\w'), data)
    start = start and start.start() or -1
    head,data = data[:start+1], data[start+1:]

    entity_pattern = re.compile(_s2bytes(r'^\s*<!ENTITY([^>]*?)>'), re.MULTILINE)
    entity_results=entity_pattern.findall(head)
    head = entity_pattern.sub(_s2bytes(''), head)
    doctype_pattern = re.compile(_s2bytes(r'^\s*<!DOCTYPE([^>]*?)>'), re.MULTILINE)
    doctype_results = doctype_pattern.findall(head)
    doctype = doctype_results and doctype_results[0] or _s2bytes('')
    if doctype.lower().count(_s2bytes('netscape')):
        version = u'rss091n'
    else:
        version = None

    # only allow in 'safe' inline entity definitions
    replacement=_s2bytes('')
    if len(doctype_results)==1 and entity_results:
       safe_pattern=re.compile(_s2bytes('\s+(\w+)\s+"(&#\w+;|[^&"]*)"'))
       safe_entities=filter(lambda e: safe_pattern.match(e),entity_results)
       if safe_entities:
           replacement=_s2bytes('<!DOCTYPE feed [\n  <!ENTITY') + _s2bytes('>\n  <!ENTITY ').join(safe_entities) + _s2bytes('>\n]>')
    data = doctype_pattern.sub(replacement, head) + data


    return version, data, dict(replacement and [(k.decode('utf-8'), v.decode('utf-8')) for k, v in safe_pattern.findall(replacement)])

def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=None, request_headers=None, response_headers=None):
    '''Parse a feed from a URL, file, stream, or string.

    request_headers, if given, is a dict from http header name to value to add
    to the request; this overrides internally generated values.
    '''

    if handlers is None:

        handlers = []


    if request_headers is None:
        request_headers = {}
    if response_headers is None:
        response_headers = {}

    result = FeedParserDict()
    result['feed'] = FeedParserDict()
    result['entries'] = []

    result['bozo'] = 0
    if not isinstance(handlers, list):
        handlers = [handlers]
    try:
        f = _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers)







        data = f.read()
    except Exception, e:
        result['bozo'] = 1
        result['bozo_exception'] = e
        data = None
        f = None

    if hasattr(f, 'headers'):
        result['headers'] = dict(f.headers)
    # overwrite existing headers using response_headers
    if 'headers' in result:
        result['headers'].update(response_headers)
    elif response_headers:
        result['headers'] = copy.deepcopy(response_headers)

    # if feed is gzip-compressed, decompress it
    if f and data and 'headers' in result:
        if gzip and 'gzip' in (result['headers'].get('content-encoding'), result['headers'].get('Content-Encoding')):
            try:
                data = gzip.GzipFile(fileobj=_StringIO(data)).read()
            except (IOError, struct.error), e:
                # IOError can occur if the gzip header is bad
                # struct.error can occur if the data is damaged
                # Some feeds claim to be gzipped but they're not, so
                # we get garbage.  Ideally, we should re-request the
                # feed without the 'Accept-encoding: gzip' header,
                # but we don't.

                result['bozo'] = 1
                result['bozo_exception'] = e
                data = None
        elif zlib and 'deflate' in (result['headers'].get('content-encoding'), result['headers'].get('Content-Encoding')):

            try:
                data = zlib.decompress(data)
            except zlib.error, e:
                result['bozo'] = 1
                result['bozo_exception'] = e
                data = None

    # save HTTP headers
    if 'headers' in result:
        if 'etag' in result['headers'] or 'ETag' in result['headers']:
            etag = result['headers'].get('etag', result['headers'].get('ETag', u''))
            if not isinstance(etag, unicode):
                etag = etag.decode('utf-8', 'ignore')
            if etag:
                result['etag'] = etag
        if 'last-modified' in result['headers'] or 'Last-Modified' in result['headers']:
            modified = result['headers'].get('last-modified', result['headers'].get('Last-Modified'))
            if modified:
                result['modified'] = _parse_date(modified)
    if hasattr(f, 'url'):
        if not isinstance(f.url, unicode):
            result['href'] = f.url.decode('utf-8', 'ignore')
        else:
            result['href'] = f.url
        result['status'] = 200
    if hasattr(f, 'status'):
        result['status'] = f.status


    if hasattr(f, 'close'):
        f.close()

    if data is None:
        return result

    # there are four encodings to keep track of:
    # - http_encoding is the encoding declared in the Content-Type HTTP header
    # - xml_encoding is the encoding declared in the <?xml declaration
    # - sniffed_encoding is the encoding sniffed from the first 4 bytes of the XML data
    # - result['encoding'] is the actual encoding, as per RFC 3023 and a variety of other conflicting specifications

    http_headers = result.get('headers', {})
    result['encoding'], http_encoding, xml_encoding, sniffed_xml_encoding, acceptable_content_type = \

        _getCharacterEncoding(http_headers, data)
    if http_headers and (not acceptable_content_type):
        if http_headers.has_key('content-type') or http_headers.has_key('Content-type'):
            bozo_message = '%s is not an XML media type' % http_headers.get('content-type', http_headers.get('Content-type'))

        else:
            bozo_message = 'no Content-type specified'
        result['bozo'] = 1
        result['bozo_exception'] = NonXMLContentType(bozo_message)

    if data is not None:
        result['version'], data, entities = _stripDoctype(data)

    # ensure that baseuri is an absolute uri using an acceptable URI scheme
    contentloc = http_headers.get('content-location', http_headers.get('Content-Location', u''))
    href = result.get('href', u'')
    baseuri = _makeSafeAbsoluteURI(href, contentloc) or _makeSafeAbsoluteURI(contentloc) or href

    baselang = http_headers.get('content-language', http_headers.get('Content-Language', None))
    if not isinstance(baselang, unicode) and baselang is not None:
        baselang = baselang.decode('utf-8', 'ignore')

    # if server sent 304, we're done

    if result.get('status', 0) == 304:
        result['version'] = u''

        result['debug_message'] = 'The feed has not changed since you last checked, ' + \
            'so the server sent no data.  This is a feature, not a bug!'
        return result

    # if there was a problem downloading, we're done

    if data is None:
        return result

    # determine character encoding

    use_strict_parser = 0
    known_encoding = 0
    tried_encodings = []

    # try: HTTP encoding, declared XML encoding, encoding sniffed from BOM

    for proposed_encoding in (result['encoding'], xml_encoding, sniffed_xml_encoding):

        if not proposed_encoding:
            continue
        if proposed_encoding in tried_encodings:
            continue
        tried_encodings.append(proposed_encoding)
        try:
            data = _toUTF8(data, proposed_encoding)
        except (UnicodeDecodeError, LookupError):
            pass
        else:
            known_encoding = use_strict_parser = 1
            break



    # if no luck and we have auto-detection library, try that

    if (not known_encoding) and chardet:

        proposed_encoding = chardet.detect(data)['encoding']
        if proposed_encoding and (proposed_encoding not in tried_encodings):

            tried_encodings.append(proposed_encoding)
            try:
                data = _toUTF8(data, proposed_encoding)

            except (UnicodeDecodeError, LookupError):
                pass
            else:
                known_encoding = use_strict_parser = 1
    # if still no luck and we haven't tried utf-8 yet, try that

    if (not known_encoding) and (u'utf-8' not in tried_encodings):

        proposed_encoding = u'utf-8'
        tried_encodings.append(proposed_encoding)
        try:
            data = _toUTF8(data, proposed_encoding)

        except UnicodeDecodeError:
            pass
        else:
            known_encoding = use_strict_parser = 1
    # if still no luck and we haven't tried windows-1252 yet, try that
    if (not known_encoding) and (u'windows-1252' not in tried_encodings):
        proposed_encoding = u'windows-1252'
        tried_encodings.append(proposed_encoding)
        try:
            data = _toUTF8(data, proposed_encoding)
        except UnicodeDecodeError:
            pass
        else:
            known_encoding = use_strict_parser = 1
    # if still no luck and we haven't tried iso-8859-2 yet, try that.
    if (not known_encoding) and (u'iso-8859-2' not in tried_encodings):
        proposed_encoding = u'iso-8859-2'
        tried_encodings.append(proposed_encoding)
        try:
            data = _toUTF8(data, proposed_encoding)

        except UnicodeDecodeError:
            pass
        else:
            known_encoding = use_strict_parser = 1
    # if still no luck, give up

    if not known_encoding:
        result['bozo'] = 1
        result['bozo_exception'] = CharacterEncodingUnknown( \
            'document encoding unknown, I tried ' + \
            '%s, %s, utf-8, windows-1252, and iso-8859-2 but nothing worked' % \
            (result['encoding'], xml_encoding))
        result['encoding'] = u''
    elif proposed_encoding != result['encoding']:
        result['bozo'] = 1
        result['bozo_exception'] = CharacterEncodingOverride( \
            'document declared as %s, but parsed as %s' % \
            (result['encoding'], proposed_encoding))
        result['encoding'] = proposed_encoding

    if not _XML_AVAILABLE:
        use_strict_parser = 0
    if use_strict_parser:

        # initialize the SAX parser

        feedparser = _StrictFeedParser(baseuri, baselang, 'utf-8')
        saxparser = xml.sax.make_parser(PREFERRED_XML_PARSERS)
        saxparser.setFeature(xml.sax.handler.feature_namespaces, 1)
        saxparser.setContentHandler(feedparser)
        saxparser.setErrorHandler(feedparser)
        source = xml.sax.xmlreader.InputSource()
        source.setByteStream(_StringIO(data))
        if hasattr(saxparser, '_ns_stack'):

            # work around bug in built-in SAX parser (doesn't recognize xml: namespace)
            # PyXML doesn't have this problem, and it doesn't have _ns_stack either

            saxparser._ns_stack.append({'http://www.w3.org/XML/1998/namespace':'xml'})

        try:
            saxparser.parse(source)
        except xml.sax.SAXParseException, e:





            result['bozo'] = 1
            result['bozo_exception'] = feedparser.exc or e
            use_strict_parser = 0
    if not use_strict_parser and _SGML_AVAILABLE:
        feedparser = _LooseFeedParser(baseuri, baselang, 'utf-8', entities)

        feedparser.feed(data.decode('utf-8', 'replace'))
    result['feed'] = feedparser.feeddata
    result['entries'] = feedparser.entries
    result['version'] = result['version'] or feedparser.version
    result['namespaces'] = feedparser.namespacesInUse
    return result








































































































































































































































Modified gluon/contrib/gae_retry.py from [1cb2d390ab] to [d1acb30472].
80
81
82
83
84
85
86

87
                    vals = '\n'.join([str(a) for a in args])
                logging.warning(msg % (errors[errno], count, sleep, vals))
                time.sleep(sleep)

    setattr(wrapper, '_autoretry_datastore_timeouts', False)
    if getattr(wrapped, '_autoretry_datastore_timeouts', True):
        apiproxy_stub_map.MakeSyncCall = wrapper









>

80
81
82
83
84
85
86
87
88
                    vals = '\n'.join([str(a) for a in args])
                logging.warning(msg % (errors[errno], count, sleep, vals))
                time.sleep(sleep)

    setattr(wrapper, '_autoretry_datastore_timeouts', False)
    if getattr(wrapped, '_autoretry_datastore_timeouts', True):
        apiproxy_stub_map.MakeSyncCall = wrapper


Modified gluon/contrib/gateways/__init__.py from [adc83b19e7] to [71853c6197].

1


>

1
2


Modified gluon/contrib/gateways/fcgi.py from [7ac081e792] to [d4488e5a46].
1325
1326
1327
1328
1329
1330
1331

            yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
                field.name, field.value)

        yield '</table>\n' \
              '</body></html>\n'

    WSGIServer(test_app).run()








>
1325
1326
1327
1328
1329
1330
1331
1332
            yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
                field.name, field.value)

        yield '</table>\n' \
              '</body></html>\n'

    WSGIServer(test_app).run()

Modified gluon/contrib/generics.py from [adcdc0c9ce] to [390d0316f6].
57
58
59
60
61
62
63

64

def pdf_from_html(html):
    # try use latex and pdflatex
    if os.system('which pdflatex > /dev/null')==0:
        return pdflatex_from_html(html)
    else:
        return pyfpdf_from_html(html)









>

57
58
59
60
61
62
63
64
65

def pdf_from_html(html):
    # try use latex and pdflatex
    if os.system('which pdflatex > /dev/null')==0:
        return pdflatex_from_html(html)
    else:
        return pyfpdf_from_html(html)


Modified gluon/contrib/gql.py from [3aaca8ca98] to [0d590a942a].
1
2
3
4
5

6
# this file exists for backward compatibility

__all__ = ['DAL','Field','drivers','gae']

from gluon.dal import DAL, Field, Table, Query, Set, Expression, Row, Rows, drivers, BaseAdapter, SQLField, SQLTable, SQLXorable, SQLQuery, SQLSet, SQLRows, SQLStorage, SQLDB, GQLDB, SQLALL, SQLCustomType, gae







>

1
2
3
4
5
6
7
# this file exists for backward compatibility

__all__ = ['DAL','Field','drivers','gae']

from gluon.dal import DAL, Field, Table, Query, Set, Expression, Row, Rows, drivers, BaseAdapter, SQLField, SQLTable, SQLXorable, SQLQuery, SQLSet, SQLRows, SQLStorage, SQLDB, GQLDB, SQLALL, SQLCustomType, gae


Modified gluon/contrib/login_methods/__init__.py from [adc83b19e7] to [71853c6197].

1


>

1
2


Modified gluon/contrib/login_methods/basic_auth.py from [2e3886c513] to [8fc3dad06c].
18
19
20
21
22
23
24

        request = urllib2.Request(server, None, headers)
        try:
            urllib2.urlopen(request)
            return True
        except (urllib2.URLError, urllib2.HTTPError):
            return False
    return basic_login_aux








>
18
19
20
21
22
23
24
25
        request = urllib2.Request(server, None, headers)
        try:
            urllib2.urlopen(request)
            return True
        except (urllib2.URLError, urllib2.HTTPError):
            return False
    return basic_login_aux

Modified gluon/contrib/login_methods/cas_auth.py from [d133c59928] to [e55e655978].
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        self.cas_check_url="%s/%s"%(self.urlbase,actions[1])
        self.cas_logout_url="%s/%s"%(self.urlbase,actions[2])
        self.maps=maps
        self.casversion = casversion
        self.casusername = casusername
        http_host=current.request.env.http_x_forwarded_host
        if not http_host: http_host=current.request.env.http_host
        if current.request.env.wsgi_url_scheme in [ 'https', 'HTTPS' ]: 
            scheme = 'https' 
        else: 
            scheme = 'http' 
        self.cas_my_url='%s://%s%s'%( scheme, http_host, current.request.env.path_info ) 
    
    def login_url( self, next = "/" ):
        current.session.token=self._CAS_login()
        return next
    def logout_url( self, next = "/" ):
        current.session.token=None
        current.session.auth=None
        self._CAS_logout()







|
|
|
|
|
|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        self.cas_check_url="%s/%s"%(self.urlbase,actions[1])
        self.cas_logout_url="%s/%s"%(self.urlbase,actions[2])
        self.maps=maps
        self.casversion = casversion
        self.casusername = casusername
        http_host=current.request.env.http_x_forwarded_host
        if not http_host: http_host=current.request.env.http_host
        if current.request.env.wsgi_url_scheme in [ 'https', 'HTTPS' ]:
            scheme = 'https'
        else:
            scheme = 'http'
        self.cas_my_url='%s://%s%s'%( scheme, http_host, current.request.env.path_info )

    def login_url( self, next = "/" ):
        current.session.token=self._CAS_login()
        return next
    def logout_url( self, next = "/" ):
        current.session.token=None
        current.session.auth=None
        self._CAS_logout()
125
126
127
128
129
130
131

    def _CAS_logout( self ):
        """
        exposed CAS.logout()
        redirects to the CAS logout page
        """
        import urllib
        redirect("%s?service=%s" % (self.cas_logout_url,self.cas_my_url))








>
125
126
127
128
129
130
131
132
    def _CAS_logout( self ):
        """
        exposed CAS.logout()
        redirects to the CAS logout page
        """
        import urllib
        redirect("%s?service=%s" % (self.cas_logout_url,self.cas_my_url))

Modified gluon/contrib/login_methods/email_auth.py from [e3e7a81207] to [5bde81e3c1].
30
31
32
33
34
35
36

            server.quit()
            return True
        except:
            if server:
                server.quit()
            return False
    return email_auth_aux








>
30
31
32
33
34
35
36
37
            server.quit()
            return True
        except:
            if server:
                server.quit()
            return False
    return email_auth_aux

Modified gluon/contrib/login_methods/extended_login_form.py from [3b801e0ba3] to [6b873fea64].
96
97
98
99
100
101
102


        self.auth.settings.login_form = self.auth
        form = DIV(self.auth())
        self.auth.settings.login_form = self

        form.components.append(self.alt_login_form.login_form())
        return form








>
96
97
98
99
100
101
102
103

        self.auth.settings.login_form = self.auth
        form = DIV(self.auth())
        self.auth.settings.login_form = self

        form.components.append(self.alt_login_form.login_form())
        return form

Modified gluon/contrib/login_methods/gae_google_account.py from [d7134f9326] to [60d4e8af75].
31
32
33
34
35
36
37

        return users.create_logout_url(next)

    def get_user(self):
        user = users.get_current_user()
        if user:
            return dict(nickname=user.nickname(), email=user.email(),
                        user_id=user.user_id(), source="google account")








>
31
32
33
34
35
36
37
38
        return users.create_logout_url(next)

    def get_user(self):
        user = users.get_current_user()
        if user:
            return dict(nickname=user.nickname(), email=user.email(),
                        user_id=user.user_id(), source="google account")

Modified gluon/contrib/login_methods/ldap_auth.py from [a193ec84c7] to [bf4169c283].
164
165
166
167
168
169
170

            return False
        except IndexError, ex: # for AD membership test
            return False

    if filterstr[0] == '(' and filterstr[-1] == ')': # rfc4515 syntax
        filterstr = filterstr[1:-1] # parens added again where used
    return ldap_auth_aux








>
164
165
166
167
168
169
170
171
            return False
        except IndexError, ex: # for AD membership test
            return False

    if filterstr[0] == '(' and filterstr[-1] == ')': # rfc4515 syntax
        filterstr = filterstr[1:-1] # parens added again where used
    return ldap_auth_aux

Modified gluon/contrib/login_methods/linkedin_account.py from [895fd3ad22] to [c50499f133].
43
44
45
46
47
48
49

50
        result = self.request.vars.verifier and self.api.accessToken(verifier = self.request.vars.verifier )
        if result:
            profile = self.api.GetProfile()
            profile = self.api.GetProfile(profile).public_url = "http://www.linkedin.com/in/ozgurv"
            return dict(first_name = profile.first_name,
                        last_name = profile.last_name,
                        username = profile.id)









>

43
44
45
46
47
48
49
50
51
        result = self.request.vars.verifier and self.api.accessToken(verifier = self.request.vars.verifier )
        if result:
            profile = self.api.GetProfile()
            profile = self.api.GetProfile(profile).public_url = "http://www.linkedin.com/in/ozgurv"
            return dict(first_name = profile.first_name,
                        last_name = profile.last_name,
                        username = profile.id)


Modified gluon/contrib/login_methods/loginza.py from [9d60d8dc81] to [e22bc12e75].
105
106
107
108
109
110
111

                          _scrolling="no",
                          _frameborder="no",
                          _style="width:359px;height:300px;")
        else:
            form = DIV(A(self.prompt, _href=LOGINZA_URL % (self.language, self.token_url), _class="loginza"),
                   SCRIPT(_src="https://s3-eu-west-1.amazonaws.com/s1.loginza.ru/js/widget.js", _type="text/javascript"))
        return form








>
105
106
107
108
109
110
111
112
                          _scrolling="no",
                          _frameborder="no",
                          _style="width:359px;height:300px;")
        else:
            form = DIV(A(self.prompt, _href=LOGINZA_URL % (self.language, self.token_url), _class="loginza"),
                   SCRIPT(_src="https://s3-eu-west-1.amazonaws.com/s1.loginza.ru/js/widget.js", _type="text/javascript"))
        return form

Modified gluon/contrib/login_methods/oauth10a_account.py from [5c58b0dc60] to [429a2654f8].
181
182
183
184
185
186
187

188
189


            raise HTTP(307,
                       "You are not authenticated: you are being redirected to the <a href='" + auth_request_url + "'> authentication server</a>",
                       Location=auth_request_url)

        return None










>


181
182
183
184
185
186
187
188
189
190


            raise HTTP(307,
                       "You are not authenticated: you are being redirected to the <a href='" + auth_request_url + "'> authentication server</a>",
                       Location=auth_request_url)

        return None



Modified gluon/contrib/login_methods/oauth20_account.py from [a0753ce99b] to [fa60d45fe4].
200
201
202
203
204
205
206

                           "You are not authenticated: you are being redirected to the <a href='" + auth_request_url + "'> authentication server</a>",
                           Location=auth_request_url)
            else:
                self.session.code = self.request.vars.code
                self.accessToken()
                return self.session.code
        return None








>
200
201
202
203
204
205
206
207
                           "You are not authenticated: you are being redirected to the <a href='" + auth_request_url + "'> authentication server</a>",
                           Location=auth_request_url)
            else:
                self.session.code = self.request.vars.code
                self.accessToken()
                return self.session.code
        return None

Modified gluon/contrib/login_methods/openid_auth.py from [c162874b83] to [7ededcc3db].
624
625
626
627
628
629
630

631
    def cleanup(self):
        """
        This method should be run periodically to free the db from
        expired nonce and association entries.
        """

        return self.cleanupNonces(), self.cleanupAssociations()









>

624
625
626
627
628
629
630
631
632
    def cleanup(self):
        """
        This method should be run periodically to free the db from
        expired nonce and association entries.
        """

        return self.cleanupNonces(), self.cleanupAssociations()


Modified gluon/contrib/login_methods/pam_auth.py from [b25e852978] to [b501071923].
1
2
3
4
5
6
7
8
9
10
11
12
13

from gluon.contrib.pam import authenticate

def pam_auth():
    """
    to use pam_login:
    from gluon.contrib.login_methods.pam_auth import pam_auth
    auth.settings.login_methods.append(pam_auth())
    """

    def pam_auth_aux(username, password):
        return authenticate(username, password)

    return pam_auth_aux














>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from gluon.contrib.pam import authenticate

def pam_auth():
    """
    to use pam_login:
    from gluon.contrib.login_methods.pam_auth import pam_auth
    auth.settings.login_methods.append(pam_auth())
    """

    def pam_auth_aux(username, password):
        return authenticate(username, password)

    return pam_auth_aux

Modified gluon/contrib/login_methods/rpx_account.py from [fc14c29978] to [682968d4ff].
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# coding: utf8

"""
   RPX Authentication for web2py
   Developed by Nathan Freeze (Copyright © 2009)
   Email <nathan@freezable.com>
   Modified by Massimo Di Pierro

   This file contains code to allow using RPXNow.com (now Jainrain.com)
   services with web2py
"""


import re
import urllib
from gluon.html import *
from gluon.tools import fetch
from gluon.storage import Storage
import gluon.contrib.simplejson as json

class RPXAccount(object):

    """













>


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
# coding: utf8

"""
   RPX Authentication for web2py
   Developed by Nathan Freeze (Copyright © 2009)
   Email <nathan@freezable.com>
   Modified by Massimo Di Pierro

   This file contains code to allow using RPXNow.com (now Jainrain.com)
   services with web2py
"""

import os
import re
import urllib
from gluon import *
from gluon.tools import fetch
from gluon.storage import Storage
import gluon.contrib.simplejson as json

class RPXAccount(object):

    """
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        self.domain = domain
        self.token_url = url
        self.language = language
        self.profile = None
        self.prompt = prompt
        self.on_login_failure = on_login_failure
        self.mappings = Storage()


        self.mappings.Facebook = lambda profile:\
            dict(registration_id = profile.get("identifier",""),
                 username = profile.get("preferredUsername",""),
                 email = profile.get("email",""),
                 first_name = profile.get("name","").get("givenName",""),
                 last_name = profile.get("name","").get("familyName",""))
        self.mappings.Google = lambda profile:\
            dict(registration_id=profile.get("identifier",""),
                 username=profile.get("preferredUsername",""),
                 email=profile.get("email",""),
                 first_name=profile.get("name","").get("givenName",""),
                 last_name=profile.get("name","").get("familyName",""))
        self.mappings.default = lambda profile:\
            dict(registration_id=profile.get("identifier",""),
                 username=profile.get("preferredUsername",""),
                 email=profile.get("email",""),
                 first_name=profile.get("preferredUsername",""),
                 last_name='')








|
>
|


|
|
|
|



|
|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        self.domain = domain
        self.token_url = url
        self.language = language
        self.profile = None
        self.prompt = prompt
        self.on_login_failure = on_login_failure
        self.mappings = Storage()
        
        dn = {'givenName':'','familyName':''}
        self.mappings.Facebook = lambda profile, dn=dn:\
            dict(registration_id = profile.get("identifier",""),
                 username = profile.get("preferredUsername",""),
                 email = profile.get("email",""),                 
                 first_name = profile.get("name",dn).get("givenName",""),
                 last_name = profile.get("name",dn).get("familyName",""))
        self.mappings.Google = lambda profile, dn=dn:\
            dict(registration_id=profile.get("identifier",""),
                 username=profile.get("preferredUsername",""),
                 email=profile.get("email",""),
                 first_name=profile.get("name",dn).get("givenName",""),
                 last_name=profile.get("name",dn).get("familyName",""))
        self.mappings.default = lambda profile:\
            dict(registration_id=profile.get("identifier",""),
                 username=profile.get("preferredUsername",""),
                 email=profile.get("email",""),
                 first_name=profile.get("preferredUsername",""),
                 last_name='')

107
108
109
110
111
112
113












                          SCRIPT("RPXNOW.overlay = true;",
                                 "RPXNOW.language_preference = '%s';" % self.language,
                                 "RPXNOW.realm = '%s';" % self.domain,
                                 "RPXNOW.token_url = '%s';" % self.token_url,
                                 "RPXNOW.show();",
                                 _type="text/javascript"))
        return rpxform



















>
>
>
>
>
>
>
>
>
>
>
>
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
                          SCRIPT("RPXNOW.overlay = true;",
                                 "RPXNOW.language_preference = '%s';" % self.language,
                                 "RPXNOW.realm = '%s';" % self.domain,
                                 "RPXNOW.token_url = '%s';" % self.token_url,
                                 "RPXNOW.show();",
                                 _type="text/javascript"))
        return rpxform

def use_janrain(auth,filename='private/janrain.key',**kwargs):
    path = os.path.join(current.request.folder,filename)
    if os.path.exists(path):
        request = current.request
        domain,key = open(path,'r').read().strip().split(':')
        host = current.request.env.http_host
        url = "http://%s/%s/default/user/login" % (host,request.application)
        auth.settings.actions_disabled = \
            ['register','change_password','request_reset_password']
        auth.settings.login_form = RPXAccount(
            request, api_key=key,domain=domain, url = url,**kwargs)
Added gluon/contrib/login_methods/x509_auth.py version [43a52f429f].
Modified gluon/contrib/markdown/__init__.py from [d81967309e] to [87b3777bf4].
10
11
12
13
14
15
16

    else:
        extras=None
    text = text.decode(encoding,'replace')

    return XML(markdown(text,extras=extras,
                        safe_mode=safe_mode, html4tags=html4tags)\
                   .encode(encoding,'xmlcharrefreplace'),**attributes)








>
10
11
12
13
14
15
16
17
    else:
        extras=None
    text = text.decode(encoding,'replace')

    return XML(markdown(text,extras=extras,
                        safe_mode=safe_mode, html4tags=html4tags)\
                   .encode(encoding,'xmlcharrefreplace'),**attributes)

Modified gluon/contrib/markdown/markdown2.py from [91558b728e] to [c117c9a0ff].
1882
1883
1884
1885
1886
1887
1888

1889
                norm_html = html
                norm_perl_html = perl_html
            print "==== match? %r ====" % (norm_perl_html == norm_html)


if __name__ == "__main__":
    sys.exit( main(sys.argv) )









>

1882
1883
1884
1885
1886
1887
1888
1889
1890
                norm_html = html
                norm_perl_html = perl_html
            print "==== match? %r ====" % (norm_perl_html == norm_html)


if __name__ == "__main__":
    sys.exit( main(sys.argv) )


Modified gluon/contrib/markmin/__init__.py from [adc83b19e7] to [71853c6197].

1


>

1
2


Modified gluon/contrib/markmin/markmin2html.py from [4b3f535252] to [b5f7ebf604].
1

2
3
4
5
6
7
8
#!/usr/bin/env python                                                                                                        # created my Massimo Di Pierro

# license MIT/BSD/GPL
import re
import cgi

__all__ = ['render', 'markmin2html']

__doc__ = """
|
>







1
2
3
4
5
6
7
8
9
#!/usr/bin/env python 
# created my Massimo Di Pierro
# license MIT/BSD/GPL
import re
import cgi

__all__ = ['render', 'markmin2html']

__doc__ = """
393
394
395
396
397
398
399

400

401
402
403
404
405
406
407
    #############################################################
    # deal with paragraphs (trick <<ul, <<ol, <<table, <<h1, etc)
    # the << indicates that there should NOT be a new paragraph
    # META indicates a code block therefore no new paragraph
    #############################################################
    items = [item.strip() for item in text.split('\n\n')]
    if sep=='p':

        text = ''.join(p[:2]!='<<' and p!=META and '<p>%s</p>'%p or '%s'%p for p in items if p)

    elif sep=='br':
        text = '<br />'.join(items)

    #############################################################
    # finally get rid of <<
    #############################################################
    text=text.replace('<<','<')







>
|
>







394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
    #############################################################
    # deal with paragraphs (trick <<ul, <<ol, <<table, <<h1, etc)
    # the << indicates that there should NOT be a new paragraph
    # META indicates a code block therefore no new paragraph
    #############################################################
    items = [item.strip() for item in text.split('\n\n')]
    if sep=='p':
        text = ''.join(
            (p[:2]!='<<' and p!=META and '<p>%s</p>'%p or '%s'%p) \
                for p in items if p.strip())
    elif sep=='br':
        text = '<br />'.join(items)

    #############################################################
    # finally get rid of <<
    #############################################################
    text=text.replace('<<','<')
449
450
451
452
453
454
455

        fargv = open(sys.argv[1],'r')
        try:
            print '<html><body>'+markmin2html(fargv.read())+'</body></html>'
        finally:
            fargv.close()
    else:
        doctest.testmod()








>
452
453
454
455
456
457
458
459
        fargv = open(sys.argv[1],'r')
        try:
            print '<html><body>'+markmin2html(fargv.read())+'</body></html>'
        finally:
            fargv.close()
    else:
        doctest.testmod()

Modified gluon/contrib/markmin/markmin2latex.py from [b2aa948b56] to [fba5f42f79].
277
278
279
280
281
282
283

284
        content = '\n'.join(content_data)
        output= markmin2latex(content,wrapper=wrapper)
        if options.one:
            output=output.replace(r'\section*{',r'\chapter*{')
            output=output.replace(r'\section{',r'\chapter{')
            output=output.replace(r'subsection{',r'section{')
        print output









>

277
278
279
280
281
282
283
284
285
        content = '\n'.join(content_data)
        output= markmin2latex(content,wrapper=wrapper)
        if options.one:
            output=output.replace(r'\section*{',r'\chapter*{')
            output=output.replace(r'\section{',r'\chapter{')
            output=output.replace(r'subsection{',r'section{')
        print output


Modified gluon/contrib/markmin/markmin2pdf.py from [10244f7fd3] to [25d21339f1].
123
124
125
126
127
128
129

        if errors:
            print 'ERRORS:'+'\n'.join(errors)
            print 'WARNGINS:'+'\n'.join(warnings)
        else:
            print data
    else:
        doctest.testmod()








>
123
124
125
126
127
128
129
130
        if errors:
            print 'ERRORS:'+'\n'.join(errors)
            print 'WARNGINS:'+'\n'.join(warnings)
        else:
            print data
    else:
        doctest.testmod()

Modified gluon/contrib/memdb.py from [b91e54b5c2] to [09fdfa483b].
900
901
902
903
904
905
906

907
SQLSet = Set
SQLRows = Rows
SQLStorage = DALStorage

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









>

900
901
902
903
904
905
906
907
908
SQLSet = Set
SQLRows = Rows
SQLStorage = DALStorage

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


Modified gluon/contrib/pam.py from [0f00a610f9] to [40c18f46ed].
117
118
119
120
121
122
123

124

    retval = PAM_AUTHENTICATE(handle, 0)
    return retval == 0

if __name__ == "__main__":
    import getpass
    print authenticate(getpass.getuser(), getpass.getpass())









>

117
118
119
120
121
122
123
124
125

    retval = PAM_AUTHENTICATE(handle, 0)
    return retval == 0

if __name__ == "__main__":
    import getpass
    print authenticate(getpass.getuser(), getpass.getpass())


Modified gluon/contrib/populate.py from [5bbd5140d2] to [8da0cd7b63].

cannot compute difference between binary files

Modified gluon/contrib/pyfpdf/__init__.py from [5d666989e3] to [a690337115].
1
2
3

4
from fpdf import FPDF
from html import HTMLMixin
from template import Template





>

1
2
3
4
5
from fpdf import FPDF
from html import HTMLMixin
from template import Template


Modified gluon/contrib/pyfpdf/designer.py from [1f28537045] to [707a438744].
727
728
729
730
731
732
733

734
735


app = wx.PySimpleApp()
ogl.OGLInitialize()
frame = AppFrame()
app.MainLoop()
app.Destroy()










>


727
728
729
730
731
732
733
734
735
736


app = wx.PySimpleApp()
ogl.OGLInitialize()
frame = AppFrame()
app.MainLoop()
app.Destroy()



Modified gluon/contrib/pyfpdf/fpdf.py from [f8476450e4] to [d25003acc5].
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
                if(info['cs']=='DeviceCMYK'):
                    self._out('/Decode [1 0 1 0 1 0 1 0]')
            self._out('/BitsPerComponent '+str(info['bpc']))
            if 'f' in info:
                self._out('/Filter /'+info['f'])
            if 'parms' in info:
                self._out(info['parms'])
            if('trns' in info and type([])==info['trns']):
                trns=''
                for i in xrange(0,len(info['trns'])):
                    trns+=str(info['trns'][i])+' '+str(info['trns'][i])+' '
                self._out('/Mask ['+trns+']')
            self._out('/Length '+str(len(info['data']))+'>>')
            self._putstream(info['data'])
            self.images[filename]['data'] = None







|







1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
                if(info['cs']=='DeviceCMYK'):
                    self._out('/Decode [1 0 1 0 1 0 1 0]')
            self._out('/BitsPerComponent '+str(info['bpc']))
            if 'f' in info:
                self._out('/Filter /'+info['f'])
            if 'parms' in info:
                self._out(info['parms'])
            if('trns' in info and isinstance(info['trns'],list)):
                trns=''
                for i in xrange(0,len(info['trns'])):
                    trns+=str(info['trns'][i])+' '+str(info['trns'][i])+' '
                self._out('/Mask ['+trns+']')
            self._out('/Length '+str(len(info['data']))+'>>')
            self._putstream(info['data'])
            self.images[filename]['data'] = None
1678
1679
1680
1681
1682
1683
1684
1685
1686

    'n':761,'o':762,'p':762,'q':759,'r':759,'s':892,'t':892,'u':788,'v':784,'w':438,'x':138,'y':277,'z':415,'{':392,'|':392,'}':668,'~':668,'\x7f':0,'\x80':390,'\x81':390,'\x82':317,'\x83':317,
    '\x84':276,'\x85':276,'\x86':509,'\x87':509,'\x88':410,'\x89':410,'\x8a':234,'\x8b':234,'\x8c':334,'\x8d':334,'\x8e':0,'\x8f':0,'\x90':0,'\x91':0,'\x92':0,'\x93':0,'\x94':0,'\x95':0,'\x96':0,'\x97':0,'\x98':0,'\x99':0,
    '\x9a':0,'\x9b':0,'\x9c':0,'\x9d':0,'\x9e':0,'\x9f':0,'\xa0':0,'\xa1':732,'\xa2':544,'\xa3':544,'\xa4':910,'\xa5':667,'\xa6':760,'\xa7':760,'\xa8':776,'\xa9':595,'\xaa':694,'\xab':626,'\xac':788,'\xad':788,'\xae':788,'\xaf':788,
    '\xb0':788,'\xb1':788,'\xb2':788,'\xb3':788,'\xb4':788,'\xb5':788,'\xb6':788,'\xb7':788,'\xb8':788,'\xb9':788,'\xba':788,'\xbb':788,'\xbc':788,'\xbd':788,'\xbe':788,'\xbf':788,'\xc0':788,'\xc1':788,'\xc2':788,'\xc3':788,'\xc4':788,'\xc5':788,
    '\xc6':788,'\xc7':788,'\xc8':788,'\xc9':788,'\xca':788,'\xcb':788,'\xcc':788,'\xcd':788,'\xce':788,'\xcf':788,'\xd0':788,'\xd1':788,'\xd2':788,'\xd3':788,'\xd4':894,'\xd5':838,'\xd6':1016,'\xd7':458,'\xd8':748,'\xd9':924,'\xda':748,'\xdb':918,
    '\xdc':927,'\xdd':928,'\xde':928,'\xdf':834,'\xe0':873,'\xe1':828,'\xe2':924,'\xe3':924,'\xe4':917,'\xe5':930,'\xe6':931,'\xe7':463,'\xe8':883,'\xe9':836,'\xea':836,'\xeb':867,'\xec':867,'\xed':696,'\xee':696,'\xef':874,'\xf0':0,'\xf1':874,
    '\xf2':760,'\xf3':946,'\xf4':771,'\xf5':865,'\xf6':771,'\xf7':888,'\xf8':967,'\xf9':888,'\xfa':831,'\xfb':873,'\xfc':927,'\xfd':970,'\xfe':918,'\xff':0}












>
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
    'n':761,'o':762,'p':762,'q':759,'r':759,'s':892,'t':892,'u':788,'v':784,'w':438,'x':138,'y':277,'z':415,'{':392,'|':392,'}':668,'~':668,'\x7f':0,'\x80':390,'\x81':390,'\x82':317,'\x83':317,
    '\x84':276,'\x85':276,'\x86':509,'\x87':509,'\x88':410,'\x89':410,'\x8a':234,'\x8b':234,'\x8c':334,'\x8d':334,'\x8e':0,'\x8f':0,'\x90':0,'\x91':0,'\x92':0,'\x93':0,'\x94':0,'\x95':0,'\x96':0,'\x97':0,'\x98':0,'\x99':0,
    '\x9a':0,'\x9b':0,'\x9c':0,'\x9d':0,'\x9e':0,'\x9f':0,'\xa0':0,'\xa1':732,'\xa2':544,'\xa3':544,'\xa4':910,'\xa5':667,'\xa6':760,'\xa7':760,'\xa8':776,'\xa9':595,'\xaa':694,'\xab':626,'\xac':788,'\xad':788,'\xae':788,'\xaf':788,
    '\xb0':788,'\xb1':788,'\xb2':788,'\xb3':788,'\xb4':788,'\xb5':788,'\xb6':788,'\xb7':788,'\xb8':788,'\xb9':788,'\xba':788,'\xbb':788,'\xbc':788,'\xbd':788,'\xbe':788,'\xbf':788,'\xc0':788,'\xc1':788,'\xc2':788,'\xc3':788,'\xc4':788,'\xc5':788,
    '\xc6':788,'\xc7':788,'\xc8':788,'\xc9':788,'\xca':788,'\xcb':788,'\xcc':788,'\xcd':788,'\xce':788,'\xcf':788,'\xd0':788,'\xd1':788,'\xd2':788,'\xd3':788,'\xd4':894,'\xd5':838,'\xd6':1016,'\xd7':458,'\xd8':748,'\xd9':924,'\xda':748,'\xdb':918,
    '\xdc':927,'\xdd':928,'\xde':928,'\xdf':834,'\xe0':873,'\xe1':828,'\xe2':924,'\xe3':924,'\xe4':917,'\xe5':930,'\xe6':931,'\xe7':463,'\xe8':883,'\xe9':836,'\xea':836,'\xeb':867,'\xec':867,'\xed':696,'\xee':696,'\xef':874,'\xf0':0,'\xf1':874,
    '\xf2':760,'\xf3':946,'\xf4':771,'\xf5':865,'\xf6':771,'\xf7':888,'\xf8':967,'\xf9':888,'\xfa':831,'\xfb':873,'\xfc':927,'\xfd':970,'\xfe':918,'\xff':0}



Modified gluon/contrib/pyfpdf/html.py from [163edc0937] to [3dda777bd7].
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41


42
43
44
45
46
47
48
49
        g = int(color[3:5], 16)
        b = int(color[5:7], 16)
        return r, g, b

class HTML2FPDF(HTMLParser):
    "Render basic HTML to FPDF"

    def __init__(self, pdf, image_map):
        HTMLParser.__init__(self)
        self.image_map = image_map
        self.style = {}
        self.pre = False
        self.href = ''
        self.align = ''
        self.page_links = {}
        self.font_list = ("times","courier", "helvetica")
        self.pdf = pdf
        self.r = self.g = self.b = 0
        self.indent = 0
        self.bullet = []


        self.set_font("times", 12)
        self.table = None           # table attributes
        self.table_col_width = None # column (header) widths
        self.table_col_index = None # current column index
        self.td = None              # cell attributes
        self.th = False             # header enabled
        self.tr = None
        self.theader = None           # table header cells







|












>
>
|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        g = int(color[3:5], 16)
        b = int(color[5:7], 16)
        return r, g, b

class HTML2FPDF(HTMLParser):
    "Render basic HTML to FPDF"

    def __init__(self, pdf, image_map, **kwargs):
        HTMLParser.__init__(self)
        self.image_map = image_map
        self.style = {}
        self.pre = False
        self.href = ''
        self.align = ''
        self.page_links = {}
        self.font_list = ("times","courier", "helvetica")
        self.pdf = pdf
        self.r = self.g = self.b = 0
        self.indent = 0
        self.bullet = []
        self.font_face="times"      # initialize font      
        self.color=0                # initialize font color 
        self.set_font(kwargs.get("font","times"), kwargs.get("fontsize",12))
        self.table = None           # table attributes
        self.table_col_width = None # column (header) widths
        self.table_col_index = None # current column index
        self.td = None              # cell attributes
        self.th = False             # header enabled
        self.tr = None
        self.theader = None           # table header cells
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
                self.set_text_color(*color)
                self.color = color
            if 'face' in attrs and attrs['face'].lower() in self.font_list:
                face = attrs.get('face').lower()
                self.pdf.set_font(face)
                self.font_face = face
            if 'size' in attrs:
                face = attrs.get('size')
                self.pdf.set_font('', size)
                self.font_size = size
        if tag=='table':
            self.table = dict([(k.lower(), v) for k,v in attrs.items()])
            if not 'width' in self.table:
                self.table['width'] = '100%'
            if self.table['width'][-1]=='%':
                w = self.pdf.w - self.pdf.r_margin - self.pdf.l_margin







|
|







213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
                self.set_text_color(*color)
                self.color = color
            if 'face' in attrs and attrs['face'].lower() in self.font_list:
                face = attrs.get('face').lower()
                self.pdf.set_font(face)
                self.font_face = face
            if 'size' in attrs:
                size = int(attrs.get('size'))
                self.pdf.set_font(self.font_face, size=int(size))
                self.font_size = size
        if tag=='table':
            self.table = dict([(k.lower(), v) for k,v in attrs.items()])
            if not 'width' in self.table:
                self.table['width'] = '100%'
            if self.table['width'][-1]=='%':
                w = self.pdf.w - self.pdf.r_margin - self.pdf.l_margin
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
            self.table_col_index += int(self.td.get('colspan','1'))
            self.td = None
            self.th = False
        if tag=='font':
            if self.color:
                self.pdf.set_text_color(0,0,0)
                self.color = None
            if self.font:
                self.SetFont('Times','',12)
                self.font = None
        if tag=='center':
            self.align = None

    def set_font(self, face=None, size=None):
        if face:
            self.font_face = face
        if size:







|
|
|







323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
            self.table_col_index += int(self.td.get('colspan','1'))
            self.td = None
            self.th = False
        if tag=='font':
            if self.color:
                self.pdf.set_text_color(0,0,0)
                self.color = None
            if self.font_face:
                self.set_font('Times',12)
                
        if tag=='center':
            self.align = None

    def set_font(self, face=None, size=None):
        if face:
            self.font_face = face
        if size:
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392

    def put_line(self):
        self.pdf.ln(2)
        self.pdf.line(self.pdf.get_x(),self.pdf.get_y(),self.pdf.get_x()+187,self.pdf.get_y())
        self.pdf.ln(3)

class HTMLMixin():
    def write_html(self, text, image_map=lambda x:x):
        "Parse HTML and convert it to PDF"
        h2p = HTML2FPDF(self,image_map=image_map)
        h2p.feed(text)

if __name__=='__main__':
    html="""
<H1 align="center">html2fpdf</H1>
<h2>Basic usage</h2>
<p>You can now easily print text mixing different







|

|







378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

    def put_line(self):
        self.pdf.ln(2)
        self.pdf.line(self.pdf.get_x(),self.pdf.get_y(),self.pdf.get_x()+187,self.pdf.get_y())
        self.pdf.ln(3)

class HTMLMixin():
    def write_html(self, text, image_map=lambda x:x, **kwargs):
        "Parse HTML and convert it to PDF"
        h2p = HTML2FPDF(self,image_map=image_map,**kwargs)
        h2p.feed(text)

if __name__=='__main__':
    html="""
<H1 align="center">html2fpdf</H1>
<h2>Basic usage</h2>
<p>You can now easily print text mixing different
449
450
451
452
453
454
455
456

    #First page
    pdf.add_page()
    pdf.write_html(html)
    pdf.output('html.pdf','F')

    import os
    os.system("evince html.pdf")










>
451
452
453
454
455
456
457
458
459
    #First page
    pdf.add_page()
    pdf.write_html(html)
    pdf.output('html.pdf','F')

    import os
    os.system("evince html.pdf")


Modified gluon/contrib/pyfpdf/template.py from [8c2f756bd0] to [6ad8a4bf31].
270
271
272
273
274
275
276

277
        f['total'] = "%0.2f" % total

    f.render("./invoice.pdf")
    if sys.platform.startswith("linux"):
        os.system("evince ./invoice.pdf")
    else:
        os.system("./invoice.pdf")









>

270
271
272
273
274
275
276
277
278
        f['total'] = "%0.2f" % total

    f.render("./invoice.pdf")
    if sys.platform.startswith("linux"):
        os.system("evince ./invoice.pdf")
    else:
        os.system("./invoice.pdf")


Modified gluon/contrib/pymysql/__init__.py from [78c4ae0f0c] to [af2063e3d8].
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


def thread_safe():
    return True # match MySQLdb.thread_safe()

def install_as_MySQLdb():
    """
    After this function is called, any application that imports MySQLdb or
    _mysql will unwittingly actually use 
    """
    sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"]

__all__ = [
    'BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date',
    'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks', 'TimestampFromTicks',
    'DataError', 'DatabaseError', 'Error', 'FIELD_TYPE', 'IntegrityError',
    'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER',
    'NotSupportedError', 'DBAPISet', 'OperationalError', 'ProgrammingError',
    'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Warning', 'apilevel', 'connect',
    'connections', 'constants', 'converters', 'cursors', 'debug', 'escape',
    'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info',
    'paramstyle', 'string_literal', 'threadsafety', 'version_info',

    "install_as_MySQLdb",

    "NULL","__version__",
    ]








|


















>
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

def thread_safe():
    return True # match MySQLdb.thread_safe()

def install_as_MySQLdb():
    """
    After this function is called, any application that imports MySQLdb or
    _mysql will unwittingly actually use
    """
    sys.modules["MySQLdb"] = sys.modules["_mysql"] = sys.modules["pymysql"]

__all__ = [
    'BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date',
    'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks', 'TimestampFromTicks',
    'DataError', 'DatabaseError', 'Error', 'FIELD_TYPE', 'IntegrityError',
    'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER',
    'NotSupportedError', 'DBAPISet', 'OperationalError', 'ProgrammingError',
    'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Warning', 'apilevel', 'connect',
    'connections', 'constants', 'converters', 'cursors', 'debug', 'escape',
    'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info',
    'paramstyle', 'string_literal', 'threadsafety', 'version_info',

    "install_as_MySQLdb",

    "NULL","__version__",
    ]

Modified gluon/contrib/pymysql/charset.py from [52fa72dd4e] to [def27d46a2].
167
168
169
170
171
172
173

174
_charsets.add(Charset(210, 'utf8', 'utf8_hungarian_ci', ''))

def charset_by_name(name):
    return _charsets.by_name(name)

def charset_by_id(id):
    return _charsets.by_id(id)









>

167
168
169
170
171
172
173
174
175
_charsets.add(Charset(210, 'utf8', 'utf8_hungarian_ci', ''))

def charset_by_name(name):
    return _charsets.by_name(name)

def charset_by_id(id):
    return _charsets.by_id(id)


Modified gluon/contrib/pymysql/connections.py from [450fe7200b] to [ca9bc8dfa0].
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
UNSIGNED_INT64_LENGTH = 8

DEFAULT_CHARSET = 'latin1'
MAX_PACKET_LENGTH = 256*256*256-1


def dump_packet(data):
    
    def is_ascii(data):
        if byte2int(data) >= 65 and byte2int(data) <= 122: #data.isalnum():
            return data
        return '.'
    print "packet length %d" % len(data)
    print "method call[1]: %s" % sys._getframe(1).f_code.co_name
    print "method call[2]: %s" % sys._getframe(2).f_code.co_name







|







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
UNSIGNED_INT64_LENGTH = 8

DEFAULT_CHARSET = 'latin1'
MAX_PACKET_LENGTH = 256*256*256-1


def dump_packet(data):

    def is_ascii(data):
        if byte2int(data) >= 65 and byte2int(data) <= 122: #data.isalnum():
            return data
        return '.'
    print "packet length %d" % len(data)
    print "method call[1]: %s" % sys._getframe(1).f_code.co_name
    print "method call[2]: %s" % sys._getframe(2).f_code.co_name
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
        #sock = self.socket
        #sock.send(send_data)

        #

    def _execute_command(self, command, sql):
        self._send_command(command, sql)
        
    def _request_authentication(self):
        self._send_authentication()

    def _send_authentication(self):
        sock = self.socket
        self.client_flag |= CAPABILITIES
        if self.server_version.startswith('5'):







|







711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
        #sock = self.socket
        #sock.send(send_data)

        #

    def _execute_command(self, command, sql):
        self._send_command(command, sql)

    def _request_authentication(self):
        self._send_authentication()

    def _send_authentication(self):
        sock = self.socket
        self.client_flag |= CAPABILITIES
        if self.server_version.startswith('5'):
926
927
928
929
930
931
932

            field = self.connection.read_packet(FieldDescriptorPacket)
            self.fields.append(field)
            description.append(field.description())

        eof_packet = self.connection.read_packet()
        assert eof_packet.is_eof_packet(), 'Protocol error, expecting EOF'
        self.description = tuple(description)








>
926
927
928
929
930
931
932
933
            field = self.connection.read_packet(FieldDescriptorPacket)
            self.fields.append(field)
            description.append(field.description())

        eof_packet = self.connection.read_packet()
        assert eof_packet.is_eof_packet(), 'Protocol error, expecting EOF'
        self.description = tuple(description)

Modified gluon/contrib/pymysql/converters.py from [757622cc63] to [fb589cd37b].
340
341
342
343
344
345
346


    def escape_decimal(obj):
        return unicode(obj)
    encoders[Decimal] = escape_decimal

except ImportError:
    pass








>
340
341
342
343
344
345
346
347

    def escape_decimal(obj):
        return unicode(obj)
    encoders[Decimal] = escape_decimal

except ImportError:
    pass

Modified gluon/contrib/pymysql/cursors.py from [5fb47ad768] to [1d181823ec].
244
245
246
247
248
249
250

    DatabaseError = DatabaseError
    DataError = DataError
    OperationalError = OperationalError
    IntegrityError = IntegrityError
    InternalError = InternalError
    ProgrammingError = ProgrammingError
    NotSupportedError = NotSupportedError








>
244
245
246
247
248
249
250
251
    DatabaseError = DatabaseError
    DataError = DataError
    OperationalError = OperationalError
    IntegrityError = IntegrityError
    InternalError = InternalError
    ProgrammingError = ProgrammingError
    NotSupportedError = NotSupportedError

Modified gluon/contrib/pymysql/err.py from [5e9f1064e5] to [731d737012].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import struct


try:
    Exception, Warning
except ImportError:
    try:
        from exceptions import Exception, Warning
    except ImportError:
        import sys
        e = sys.modules['exceptions']
        Exception = e.Exception
        Warning = e.Warning
    
from constants import ER

class MySQLError(Exception):
    
    """Exception related to operation with MySQL."""


class Warning(Warning, MySQLError):

    """Exception raised for important warnings like data truncations
    while inserting, etc."""













|



|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import struct


try:
    Exception, Warning
except ImportError:
    try:
        from exceptions import Exception, Warning
    except ImportError:
        import sys
        e = sys.modules['exceptions']
        Exception = e.Exception
        Warning = e.Warning

from constants import ER

class MySQLError(Exception):

    """Exception related to operation with MySQL."""


class Warning(Warning, MySQLError):

    """Exception raised for important warnings like data truncations
    while inserting, etc."""
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
           ER.NO_REFERENCED_ROW_2, ER.ROW_IS_REFERENCED, ER.ROW_IS_REFERENCED_2,
           ER.CANNOT_ADD_FOREIGN)
_map_error(NotSupportedError, ER.WARNING_NOT_COMPLETE_ROLLBACK,
           ER.NOT_SUPPORTED_YET, ER.FEATURE_DISABLED, ER.UNKNOWN_STORAGE_ENGINE)

del _map_error, ER

    
def _get_error_info(data):
    errno = struct.unpack('<h', data[1:3])[0]
    if data[3] == "#":
        # version 4.1
        sqlstate = data[4:9].decode("utf8")
        errorvalue = data[9:].decode("utf8")
        return (errno, sqlstate, errorvalue)
    else:
        # version 4.0
        return (errno, None, data[3:].decode("utf8"))

def _check_mysql_exception(errinfo):
    errno, sqlstate, errorvalue = errinfo 
    errorclass = error_map.get(errno, None)
    if errorclass:
        raise errorclass, (errno,errorvalue)

    # couldn't find the right error number
    raise InternalError, (errno, errorvalue)

def raise_mysql_exception(data):
    errinfo = _get_error_info(data)
    _check_mysql_exception(errinfo)
    












|












|










|
>




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
           ER.NO_REFERENCED_ROW_2, ER.ROW_IS_REFERENCED, ER.ROW_IS_REFERENCED_2,
           ER.CANNOT_ADD_FOREIGN)
_map_error(NotSupportedError, ER.WARNING_NOT_COMPLETE_ROLLBACK,
           ER.NOT_SUPPORTED_YET, ER.FEATURE_DISABLED, ER.UNKNOWN_STORAGE_ENGINE)

del _map_error, ER


def _get_error_info(data):
    errno = struct.unpack('<h', data[1:3])[0]
    if data[3] == "#":
        # version 4.1
        sqlstate = data[4:9].decode("utf8")
        errorvalue = data[9:].decode("utf8")
        return (errno, sqlstate, errorvalue)
    else:
        # version 4.0
        return (errno, None, data[3:].decode("utf8"))

def _check_mysql_exception(errinfo):
    errno, sqlstate, errorvalue = errinfo
    errorclass = error_map.get(errno, None)
    if errorclass:
        raise errorclass, (errno,errorvalue)

    # couldn't find the right error number
    raise InternalError, (errno, errorvalue)

def raise_mysql_exception(data):
    errinfo = _get_error_info(data)
    _check_mysql_exception(errinfo)






Modified gluon/contrib/pymysql/times.py from [61417113cb] to [323a9ccf6a].
10
11
12
13
14
15
16

    return date(*localtime(ticks)[:3])

def TimeFromTicks(ticks):
    return time(*localtime(ticks)[3:6])

def TimestampFromTicks(ticks):
    return datetime(*localtime(ticks)[:6])








>
10
11
12
13
14
15
16
17
    return date(*localtime(ticks)[:3])

def TimeFromTicks(ticks):
    return time(*localtime(ticks)[3:6])

def TimestampFromTicks(ticks):
    return datetime(*localtime(ticks)[:6])

Modified gluon/contrib/pymysql/util.py from [22ae6bac87] to [43d79c2f5e].
13
14
15
16
17
18
19

    if len(bs) == 0:
        return ""
    else:
        rv = bs[0]
        for b in bs[1:]:
            rv += b
        return rv








>
13
14
15
16
17
18
19
20
    if len(bs) == 0:
        return ""
    else:
        rv = bs[0]
        for b in bs[1:]:
            rv += b
        return rv

Modified gluon/contrib/pyrtf/Constants.py from [2d350ca81b] to [cbebd4e93b].
151
152
153
154
155
156
157


    def _IsValid( cls, value ) :
        return value in cls.Codes
    IsValid = classmethod( _IsValid )

if __name__ == '__main__' :
    PrintHexTable()








>
151
152
153
154
155
156
157
158

    def _IsValid( cls, value ) :
        return value in cls.Codes
    IsValid = classmethod( _IsValid )

if __name__ == '__main__' :
    PrintHexTable()

Modified gluon/contrib/pyrtf/Elements.py from [35d5cf4635] to [c397df8a85].
750
751
752
753
754
755
756


    if len( params ) == 1 :
        return Text( params[ 0 ], text_props )

    result = Inline( text_props )
    apply( result.append, params )
    return result








>
750
751
752
753
754
755
756
757

    if len( params ) == 1 :
        return Text( params[ 0 ], text_props )

    result = Inline( text_props )
    apply( result.append, params )
    return result

Modified gluon/contrib/pyrtf/PropertySets.py from [3f0dc65a6d] to [8d526daf62].
482
483
484
485
486
487
488

MarginsPS   = MarginsPropertySet
ShadingPS   = ShadingPropertySet
BorderPS    = BorderPropertySet
FramePS     = FramePropertySet
TabPS       = TabPropertySet
TextPS      = TextPropertySet
ParagraphPS = ParagraphPropertySet








>
482
483
484
485
486
487
488
489
MarginsPS   = MarginsPropertySet
ShadingPS   = ShadingPropertySet
BorderPS    = BorderPropertySet
FramePS     = FramePropertySet
TabPS       = TabPropertySet
TextPS      = TextPropertySet
ParagraphPS = ParagraphPropertySet

Modified gluon/contrib/pyrtf/Renderer.py from [96ed85b1dc] to [dcaec1c401].
632
633
634
635
636
637
638


                    self._write( r'\cell' )

                else :
                    self._write( r'\pard\intbl\cell' )

            self._write( '\\row}\n' )








>
632
633
634
635
636
637
638
639

                    self._write( r'\cell' )

                else :
                    self._write( r'\pard\intbl\cell' )

            self._write( '\\row}\n' )

Modified gluon/contrib/pyrtf/Styles.py from [8959273adb] to [ce1838c3a2].
87
88
89
90
91
92
93


    def SetNext( self, value ) :
        """Set the Paragraph Style that should follow this one."""

        assert not value or isinstance( value, ParagraphStyle )
        self.Next    = value
        return self








>
87
88
89
90
91
92
93
94

    def SetNext( self, value ) :
        """Set the Paragraph Style that should follow this one."""

        assert not value or isinstance( value, ParagraphStyle )
        self.Next    = value
        return self

Modified gluon/contrib/pyrtf/__init__.py from [8899891f0b] to [b8639d16f2].
1
2
3
4
5
6
7
8
9
10
11

from    PropertySets    import  *
from    Elements    import  *
from    Styles      import  *
from    Renderer    import  *

def dumps(doc):
    import cStringIO
    s=cStringIO.StringIO()
    r=Renderer()
    r.Write(doc,s)
    return s.getvalue()












>
1
2
3
4
5
6
7
8
9
10
11
12
from    PropertySets    import  *
from    Elements    import  *
from    Styles      import  *
from    Renderer    import  *

def dumps(doc):
    import cStringIO
    s=cStringIO.StringIO()
    r=Renderer()
    r.Write(doc,s)
    return s.getvalue()

Modified gluon/contrib/pysimplesoap/__init__.py from [5bfa6115e7] to [cf49d9cce3].
1
2
3

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"Contributed modules"




>
1
2
3
4
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"Contributed modules"

Modified gluon/contrib/pysimplesoap/client.py from [08dd76e0d3] to [52b298d0e3].
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
except ImportError:
    import urllib2
    class Http(): # wrapper to use when httplib2 not available
        def request(self, url, method, body, headers):
            f = urllib2.urlopen(urllib2.Request(url, body, headers))
            return f.info(), f.read()

    
from simplexml import SimpleXMLElement, TYPE_MAP, OrderedDict

class SoapFault(RuntimeError):
    def __init__(self,faultcode,faultstring):
        self.faultcode = faultcode
        self.faultstring = faultstring

# soap protocol specification & namespace
soap_namespaces = dict(
    soap11="http://schemas.xmlsoap.org/soap/envelope/",
    soap="http://schemas.xmlsoap.org/soap/envelope/",
    soapenv="http://schemas.xmlsoap.org/soap/envelope/",
    soap12="http://www.w3.org/2003/05/soap-env",
)

class SoapClient(object):
    "Simple SOAP Client (s�mil PHP)"
    def __init__(self, location = None, action = None, namespace = None,
                 cert = None, trace = False, exceptions = True, proxy = None, ns=False, 
                 soap_ns=None, wsdl = None, cache = False):
        self.certssl = cert             
        self.keyssl = None              
        self.location = location        # server location (url)
        self.action = action            # SOAP base action
        self.namespace = namespace      # message 
        self.trace = trace              # show debug messages
        self.exceptions = exceptions    # lanzar execpiones? (Soap Faults)
        self.xml_request = self.xml_response = ''
        if not soap_ns and not ns:
            self.__soap_ns = 'soap' # 1.1
        elif not soap_ns and ns:
            self.__soap_ns = 'soapenv' # 1.2
        else:
            self.__soap_ns = soap_ns
        
        # parse wsdl url
        self.services = wsdl and self.wsdl(wsdl, debug=trace, cache=cache) 
        self.service_port = None                 # service port for late binding

        if not proxy:
            self.http = Http()
        else:
            import socks
            ##httplib2.debuglevel=4
            self.http = httplib2.Http(proxy_info = httplib2.ProxyInfo(
                proxy_type=socks.PROXY_TYPE_HTTP, **proxy))
        #if self.certssl: # esto funciona para validar al server?
        #    self.http.add_certificate(self.keyssl, self.keyssl, self.certssl)
        self.__ns = ns # namespace prefix or False to not use it
        if not ns:
            self.__xml = """<?xml version="1.0" encoding="UTF-8"?> 
<%(soap_ns)s:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:%(soap_ns)s="%(soap_uri)s">
<%(soap_ns)s:Body>
    <%(method)s xmlns="%(namespace)s">
    </%(method)s>
</%(soap_ns)s:Body>
</%(soap_ns)s:Envelope>"""
        else:







|


















|

|
|


|









|

|













|
|
|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
except ImportError:
    import urllib2
    class Http(): # wrapper to use when httplib2 not available
        def request(self, url, method, body, headers):
            f = urllib2.urlopen(urllib2.Request(url, body, headers))
            return f.info(), f.read()


from simplexml import SimpleXMLElement, TYPE_MAP, OrderedDict

class SoapFault(RuntimeError):
    def __init__(self,faultcode,faultstring):
        self.faultcode = faultcode
        self.faultstring = faultstring

# soap protocol specification & namespace
soap_namespaces = dict(
    soap11="http://schemas.xmlsoap.org/soap/envelope/",
    soap="http://schemas.xmlsoap.org/soap/envelope/",
    soapenv="http://schemas.xmlsoap.org/soap/envelope/",
    soap12="http://www.w3.org/2003/05/soap-env",
)

class SoapClient(object):
    "Simple SOAP Client (s�mil PHP)"
    def __init__(self, location = None, action = None, namespace = None,
                 cert = None, trace = False, exceptions = True, proxy = None, ns=False,
                 soap_ns=None, wsdl = None, cache = False):
        self.certssl = cert
        self.keyssl = None
        self.location = location        # server location (url)
        self.action = action            # SOAP base action
        self.namespace = namespace      # message
        self.trace = trace              # show debug messages
        self.exceptions = exceptions    # lanzar execpiones? (Soap Faults)
        self.xml_request = self.xml_response = ''
        if not soap_ns and not ns:
            self.__soap_ns = 'soap' # 1.1
        elif not soap_ns and ns:
            self.__soap_ns = 'soapenv' # 1.2
        else:
            self.__soap_ns = soap_ns

        # parse wsdl url
        self.services = wsdl and self.wsdl(wsdl, debug=trace, cache=cache)
        self.service_port = None                 # service port for late binding

        if not proxy:
            self.http = Http()
        else:
            import socks
            ##httplib2.debuglevel=4
            self.http = httplib2.Http(proxy_info = httplib2.ProxyInfo(
                proxy_type=socks.PROXY_TYPE_HTTP, **proxy))
        #if self.certssl: # esto funciona para validar al server?
        #    self.http.add_certificate(self.keyssl, self.keyssl, self.certssl)
        self.__ns = ns # namespace prefix or False to not use it
        if not ns:
            self.__xml = """<?xml version="1.0" encoding="UTF-8"?>
<%(soap_ns)s:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:%(soap_ns)s="%(soap_uri)s">
<%(soap_ns)s:Body>
    <%(method)s xmlns="%(namespace)s">
    </%(method)s>
</%(soap_ns)s:Body>
</%(soap_ns)s:Envelope>"""
        else:
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

    def __getattr__(self, attr):
        "Return a pseudo-method that can be called"
        if not self.services: # not using WSDL?
            return lambda self=self, *args, **kwargs: self.call(attr,*args,**kwargs)
        else: # using WSDL:
            return lambda self=self, *args, **kwargs: self.wsdl_call(attr,*args,**kwargs)
        
    def call(self, method, *args, **kwargs):
        "Prepare xml request and make SOAP call, returning a SimpleXMLElement"                
        #TODO: method != input_message
        # Basic SOAP request:
        xml = self.__xml % dict(method=method, namespace=self.namespace, ns=self.__ns,
                                soap_ns=self.__soap_ns, soap_uri=soap_namespaces[self.__soap_ns])
        request = SimpleXMLElement(xml,namespace=self.__ns and self.namespace, prefix=self.__ns)
        # serialize parameters
        if kwargs:







|

|







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

    def __getattr__(self, attr):
        "Return a pseudo-method that can be called"
        if not self.services: # not using WSDL?
            return lambda self=self, *args, **kwargs: self.call(attr,*args,**kwargs)
        else: # using WSDL:
            return lambda self=self, *args, **kwargs: self.wsdl_call(attr,*args,**kwargs)

    def call(self, method, *args, **kwargs):
        "Prepare xml request and make SOAP call, returning a SimpleXMLElement"
        #TODO: method != input_message
        # Basic SOAP request:
        xml = self.__xml % dict(method=method, namespace=self.namespace, ns=self.__ns,
                                soap_ns=self.__soap_ns, soap_uri=soap_namespaces[self.__soap_ns])
        request = SimpleXMLElement(xml,namespace=self.__ns and self.namespace, prefix=self.__ns)
        # serialize parameters
        if kwargs:
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
162
163
164
165
                getattr(request,method).marshall(k,v)
        self.xml_request = request.as_xml()
        self.xml_response = self.send(method, self.xml_request)
        response = SimpleXMLElement(self.xml_response, namespace=self.namespace)
        if self.exceptions and response("Fault", ns=soap_namespaces.values(), error=False):
            raise SoapFault(unicode(response.faultcode), unicode(response.faultstring))
        return response
    
    def send(self, method, xml):
        "Send SOAP request using HTTP"
        if self.location == 'test': return
        location = "%s" % self.location #?op=%s" % (self.location, method)
        if self.services:
            soap_action = self.action 
        else:
            soap_action = self.action+method
        headers={
                'Content-type': 'text/xml; charset="UTF-8"',
                'Content-length': str(len(xml)),
                "SOAPAction": "\"%s\"" % (soap_action)
                }
        if self.trace:
            print "-"*80
            print "POST %s" % location
            print '\n'.join(["%s: %s" % (k,v) for k,v in headers.items()])
            print u"\n%s" % xml.decode("utf8","ignore")
        response, content = self.http.request(
            location,"POST", body=xml, headers=headers )
        self.response = response
        self.content = content
        if self.trace: 
            print 
            print '\n'.join(["%s: %s" % (k,v) for k,v in response.items()])
            print content#.decode("utf8","ignore")
            print "="*80
        return content

    def get_operation(self, method):
        # try to find operation in wsdl file







|





|
















|
|







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
162
163
164
165
                getattr(request,method).marshall(k,v)
        self.xml_request = request.as_xml()
        self.xml_response = self.send(method, self.xml_request)
        response = SimpleXMLElement(self.xml_response, namespace=self.namespace)
        if self.exceptions and response("Fault", ns=soap_namespaces.values(), error=False):
            raise SoapFault(unicode(response.faultcode), unicode(response.faultstring))
        return response

    def send(self, method, xml):
        "Send SOAP request using HTTP"
        if self.location == 'test': return
        location = "%s" % self.location #?op=%s" % (self.location, method)
        if self.services:
            soap_action = self.action
        else:
            soap_action = self.action+method
        headers={
                'Content-type': 'text/xml; charset="UTF-8"',
                'Content-length': str(len(xml)),
                "SOAPAction": "\"%s\"" % (soap_action)
                }
        if self.trace:
            print "-"*80
            print "POST %s" % location
            print '\n'.join(["%s: %s" % (k,v) for k,v in headers.items()])
            print u"\n%s" % xml.decode("utf8","ignore")
        response, content = self.http.request(
            location,"POST", body=xml, headers=headers )
        self.response = response
        self.content = content
        if self.trace:
            print
            print '\n'.join(["%s: %s" % (k,v) for k,v in response.items()])
            print content#.decode("utf8","ignore")
            print "="*80
        return content

    def get_operation(self, method):
        # try to find operation in wsdl file
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
        self.location = port['location']
        operation = port['operations'].get(unicode(method))
        if not operation:
            raise RuntimeError("Operation %s not found in WSDL: "
                               "Service/Port Type: %s" %
                               (method, self.service_port))
        return operation
    
    def wsdl_call(self, method, *args, **kwargs):
        "Pre and post process SOAP call, input and output parameters using WSDL"
        soap_uri = soap_namespaces[self.__soap_ns]
        operation = self.get_operation(method)
        # get i/o type declarations:
        input = operation['input']
        output = operation['output']
        if 'action' in operation:
            self.action = operation['action']
        # sort parameters (same order as xsd:sequence)
        def sort_dict(od, d):
            if isinstance(od, dict):
                ret = OrderedDict()
                for k in od.keys():
                    v = d.get(k)
                    if v:
                        if isinstance(v, dict):
                            v = sort_dict(od[k], v)
                        elif isinstance(v, list):
                            v = [sort_dict(od[k][0], v1) 
                                    for v1 in v]
                        ret[str(k)] = v 
                return ret
            else:
                return d
        if input and kwargs:
            params = sort_dict(input.values()[0], kwargs).items()
            method = input.keys()[0]
        #elif not input:
            #TODO: no message! (see wsmtxca.dummy) 
        else:
            params = kwargs and kwargs.items()
        # call remote procedure
        response = self.call(method, *params)
        # parse results:
        resp = response('Body',ns=soap_uri).children().unmarshall(output)
        return resp and resp.values()[0] # pass Response tag children

    def help(self, method):
        "Return operation documentation and invocation/returned value example"
        operation = self.get_operation(method)
        input = operation['input'].values()
        input = input and input[0]
        output = operation['output'].values()[0] 
        return u"%s(%s)\n -> %s:\n\n%s" % (
            method, 
            input and ", ".join("%s=%s" % (k,repr(v)) for k,v 
                                 in input.items()) or "",
            output and output or "",
            operation.get("documentation",""),
            )

    def wsdl(self, url, debug=False, cache=False):
        "Parse Web Service Description v1.1"
        soap_ns = {
            "http://schemas.xmlsoap.org/wsdl/soap/": 'soap11',
            "http://schemas.xmlsoap.org/wsdl/soap12/": 'soap12',
            }
        wsdl_uri="http://schemas.xmlsoap.org/wsdl/"
        xsd_uri="http://www.w3.org/2001/XMLSchema"
        xsi_uri="http://www.w3.org/2001/XMLSchema-instance"
        
        get_local_name = lambda s: str((':' in s) and s.split(':')[1] or s)
        
        REVERSE_TYPE_MAP = dict([(v,k) for k,v in TYPE_MAP.items()])

        def fetch(url):
            "Fetch a document from a URL, save it locally if cache enabled"
            import os, hashlib
            # make md5 hash of the url for caching... 
            filename = "%s.xml" % hashlib.md5(url).hexdigest()
            if isinstance(cache, basestring):
                filename = os.path.join(cache, filename) 
            if cache and os.path.exists(filename):
                if debug: print "Reading file %s" % (filename, )
                f = open(filename, "r")
                xml = f.read()
                f.close()
            else:
                if debug: print "Fetching url %s" % (url, )
                f = urllib.urlopen(url)
                xml = f.read()
                if cache:
                    if debug: print "Writing file %s" % (filename, )
                    f = open(filename, "w")
                    f.write(xml)
                    f.close()
            return xml
            
        # Open uri and read xml:
        xml = fetch(url)
        # Parse WSDL XML:
        wsdl = SimpleXMLElement(xml, namespace=wsdl_uri)

        # detect soap prefix and uri (xmlns attributes of <definitions>)
        xsd_ns = None
        soap_uris = {}
        for k, v in wsdl[:]:
            if v in soap_ns and k.startswith("xmlns:"):
                soap_uris[get_local_name(k)] = v
            if v== xsd_uri and k.startswith("xmlns:"):
                xsd_ns = get_local_name(k)

        # Extract useful data:
        self.namespace = wsdl['targetNamespace']
        self.documentation = unicode(wsdl('documentation', error=False) or '')
        
        services = {}
        bindings = {}           # binding_name: binding
        operations = {}         # operation_name: operation
        port_type_bindings = {} # port_type_name: binding
        messages = {}           # message: element
        elements = {}           # element: type def
        
        for service in wsdl.service:
            service_name=service['name']
            if not service_name:
                continue # empty service?
            if debug: print "Processing service", service_name
            serv = services.setdefault(service_name, {'ports': {}})
            serv['documentation']=service['documentation'] or ''
            for port in service.port:
                binding_name = get_local_name(port['binding'])
                address = port('address', ns=soap_uris.values(), error=False)
                location = address and address['location'] or None
                soap_uri = address and soap_uris.get(address.get_prefix())
                soap_ver = soap_uri and soap_ns.get(soap_uri)
                bindings[binding_name] = {'service_name': service_name,
                    'location': location,
                    'soap_uri': soap_uri, 'soap_ver': soap_ver,
                    }
                serv['ports'][port['name']] = bindings[binding_name]
             
        for binding in wsdl.binding:
            binding_name = binding['name']
            if debug: print "Processing binding", service_name
            soap_binding = binding('binding', ns=soap_uris.values(), error=False)
            transport = soap_binding and soap_binding['transport'] or None
            port_type_name = get_local_name(binding['type'])
            bindings[binding_name].update({







|



















|

|







|













|

|
|














|

|





|


|















|

















|






|


















|







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
        self.location = port['location']
        operation = port['operations'].get(unicode(method))
        if not operation:
            raise RuntimeError("Operation %s not found in WSDL: "
                               "Service/Port Type: %s" %
                               (method, self.service_port))
        return operation

    def wsdl_call(self, method, *args, **kwargs):
        "Pre and post process SOAP call, input and output parameters using WSDL"
        soap_uri = soap_namespaces[self.__soap_ns]
        operation = self.get_operation(method)
        # get i/o type declarations:
        input = operation['input']
        output = operation['output']
        if 'action' in operation:
            self.action = operation['action']
        # sort parameters (same order as xsd:sequence)
        def sort_dict(od, d):
            if isinstance(od, dict):
                ret = OrderedDict()
                for k in od.keys():
                    v = d.get(k)
                    if v:
                        if isinstance(v, dict):
                            v = sort_dict(od[k], v)
                        elif isinstance(v, list):
                            v = [sort_dict(od[k][0], v1)
                                    for v1 in v]
                        ret[str(k)] = v
                return ret
            else:
                return d
        if input and kwargs:
            params = sort_dict(input.values()[0], kwargs).items()
            method = input.keys()[0]
        #elif not input:
            #TODO: no message! (see wsmtxca.dummy)
        else:
            params = kwargs and kwargs.items()
        # call remote procedure
        response = self.call(method, *params)
        # parse results:
        resp = response('Body',ns=soap_uri).children().unmarshall(output)
        return resp and resp.values()[0] # pass Response tag children

    def help(self, method):
        "Return operation documentation and invocation/returned value example"
        operation = self.get_operation(method)
        input = operation['input'].values()
        input = input and input[0]
        output = operation['output'].values()[0]
        return u"%s(%s)\n -> %s:\n\n%s" % (
            method,
            input and ", ".join("%s=%s" % (k,repr(v)) for k,v
                                 in input.items()) or "",
            output and output or "",
            operation.get("documentation",""),
            )

    def wsdl(self, url, debug=False, cache=False):
        "Parse Web Service Description v1.1"
        soap_ns = {
            "http://schemas.xmlsoap.org/wsdl/soap/": 'soap11',
            "http://schemas.xmlsoap.org/wsdl/soap12/": 'soap12',
            }
        wsdl_uri="http://schemas.xmlsoap.org/wsdl/"
        xsd_uri="http://www.w3.org/2001/XMLSchema"
        xsi_uri="http://www.w3.org/2001/XMLSchema-instance"

        get_local_name = lambda s: str((':' in s) and s.split(':')[1] or s)

        REVERSE_TYPE_MAP = dict([(v,k) for k,v in TYPE_MAP.items()])

        def fetch(url):
            "Fetch a document from a URL, save it locally if cache enabled"
            import os, hashlib
            # make md5 hash of the url for caching...
            filename = "%s.xml" % hashlib.md5(url).hexdigest()
            if isinstance(cache, basestring):
                filename = os.path.join(cache, filename)
            if cache and os.path.exists(filename):
                if debug: print "Reading file %s" % (filename, )
                f = open(filename, "r")
                xml = f.read()
                f.close()
            else:
                if debug: print "Fetching url %s" % (url, )
                f = urllib.urlopen(url)
                xml = f.read()
                if cache:
                    if debug: print "Writing file %s" % (filename, )
                    f = open(filename, "w")
                    f.write(xml)
                    f.close()
            return xml

        # Open uri and read xml:
        xml = fetch(url)
        # Parse WSDL XML:
        wsdl = SimpleXMLElement(xml, namespace=wsdl_uri)

        # detect soap prefix and uri (xmlns attributes of <definitions>)
        xsd_ns = None
        soap_uris = {}
        for k, v in wsdl[:]:
            if v in soap_ns and k.startswith("xmlns:"):
                soap_uris[get_local_name(k)] = v
            if v== xsd_uri and k.startswith("xmlns:"):
                xsd_ns = get_local_name(k)

        # Extract useful data:
        self.namespace = wsdl['targetNamespace']
        self.documentation = unicode(wsdl('documentation', error=False) or '')

        services = {}
        bindings = {}           # binding_name: binding
        operations = {}         # operation_name: operation
        port_type_bindings = {} # port_type_name: binding
        messages = {}           # message: element
        elements = {}           # element: type def

        for service in wsdl.service:
            service_name=service['name']
            if not service_name:
                continue # empty service?
            if debug: print "Processing service", service_name
            serv = services.setdefault(service_name, {'ports': {}})
            serv['documentation']=service['documentation'] or ''
            for port in service.port:
                binding_name = get_local_name(port['binding'])
                address = port('address', ns=soap_uris.values(), error=False)
                location = address and address['location'] or None
                soap_uri = address and soap_uris.get(address.get_prefix())
                soap_ver = soap_uri and soap_ns.get(soap_uri)
                bindings[binding_name] = {'service_name': service_name,
                    'location': location,
                    'soap_uri': soap_uri, 'soap_ver': soap_ver,
                    }
                serv['ports'][port['name']] = bindings[binding_name]

        for binding in wsdl.binding:
            binding_name = binding['name']
            if debug: print "Processing binding", service_name
            soap_binding = binding('binding', ns=soap_uris.values(), error=False)
            transport = soap_binding and soap_binding['transport'] or None
            port_type_name = get_local_name(binding['type'])
            bindings[binding_name].update({
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
                action = op and op['soapAction']
                d = operations.setdefault(op_name, {})
                bindings[binding_name]['operations'][op_name] = d
                d.update({'name': op_name})
                #if action: #TODO: separe operation_binding from operation
                if action:
                    d["action"] = action
        
        #TODO: cleanup element/schema/types parsing:
        def process_element(element_name, node):
            "Parse and define simple element types"
            if debug: print "Processing element", element_name
            for tag in node:
                if tag.get_local_name() in ("annotation", "documentation"):
                    continue
                elif tag.get_local_name() in ('element', 'restriction'):
                    if debug: print element_name,"has not children!",tag
                    children = tag # element "alias"?
                    alias = True
                elif tag.children():
                    children = tag.children()
                    alias = False
                else:
                    if debug: print element_name,"has not children!",tag
                    continue #TODO: abstract?
                d = OrderedDict()                    
                for e in children:
                    t = e['type']
                    if not t:
                        t = e['base'] # complexContent (extension)!
                    if not t:
                        t = 'anyType' # no type given!
                    t = t.split(":")







|

















|







333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
                action = op and op['soapAction']
                d = operations.setdefault(op_name, {})
                bindings[binding_name]['operations'][op_name] = d
                d.update({'name': op_name})
                #if action: #TODO: separe operation_binding from operation
                if action:
                    d["action"] = action

        #TODO: cleanup element/schema/types parsing:
        def process_element(element_name, node):
            "Parse and define simple element types"
            if debug: print "Processing element", element_name
            for tag in node:
                if tag.get_local_name() in ("annotation", "documentation"):
                    continue
                elif tag.get_local_name() in ('element', 'restriction'):
                    if debug: print element_name,"has not children!",tag
                    children = tag # element "alias"?
                    alias = True
                elif tag.children():
                    children = tag.children()
                    alias = False
                else:
                    if debug: print element_name,"has not children!",tag
                    continue #TODO: abstract?
                d = OrderedDict()
                for e in children:
                    t = e['type']
                    if not t:
                        t = e['base'] # complexContent (extension)!
                    if not t:
                        t = 'anyType' # no type given!
                    t = t.split(":")
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
                        d.array = True
                    if e is not None and e.get_local_name() == 'extension' and e.children():
                        # extend base element:
                        process_element(element_name, e.children())
                elements.setdefault(element_name, OrderedDict()).update(d)

        # check axis2 namespace at schema types attributes
        self.namespace = dict(wsdl.types("schema", ns=xsd_uri)[:]).get('targetNamespace', self.namespace) 

        imported_schemas = {}

        def preprocess_schema(schema):
            "Find schema elements and complex types"
            for element in schema.children():
                if element.get_local_name() in ('import', ):







|







387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
                        d.array = True
                    if e is not None and e.get_local_name() == 'extension' and e.children():
                        # extend base element:
                        process_element(element_name, e.children())
                elements.setdefault(element_name, OrderedDict()).update(d)

        # check axis2 namespace at schema types attributes
        self.namespace = dict(wsdl.types("schema", ns=xsd_uri)[:]).get('targetNamespace', self.namespace)

        imported_schemas = {}

        def preprocess_schema(schema):
            "Find schema elements and complex types"
            for element in schema.children():
                if element.get_local_name() in ('import', ):
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
                            if debug: print "Replacing ", k , " = ", v[None]
                            elements[k] = v[None]
                            #break
                if isinstance(v, list):
                    for n in v: # recurse list
                        postprocess_element(n)

                        
        # process current wsdl schema:
        for schema in wsdl.types("schema", ns=xsd_uri): 
            preprocess_schema(schema)                

        postprocess_element(elements)

        for message in wsdl.message:
            if debug: print "Processing message", message['name']
            part = message('part', error=False)
            element = {}
            if part:
                element_name = part['element']
                if not element_name:
                    element_name = part['type'] # some uses type instead
                element_name = get_local_name(element_name)
                element = {element_name: elements.get(element_name)}
            messages[message['name']] = element
        
        for port_type in wsdl.portType:
            port_type_name = port_type['name']
            if debug: print "Processing port type", port_type_name
            binding = port_type_bindings[port_type_name]

            for operation in port_type.operation:
                op_name = operation['name']
                op = operations[op_name] 
                op['documentation'] = unicode(operation('documentation', error=False) or '')
                if binding['soap_ver']: 
                    #TODO: separe operation_binding from operation (non SOAP?)
                    input = get_local_name(operation.input['message'])
                    output = get_local_name(operation.output['message'])
                    op['input'] = messages[input]
                    op['output'] = messages[output]

        if debug:
            import pprint
            pprint.pprint(services)
        
        return services

def parse_proxy(proxy_str):
    "Parses proxy address user:pass@host:port into a dict suitable for httplib2"
    proxy_dict = {}
    if proxy_str is None:
        return 
    if "@" in proxy_str:
        user_pass, host_port = proxy_str.split("@")
    else:
        user_pass, host_port = "", proxy_str
    if ":" in host_port:
        host, port = host_port.split(":")
        proxy_dict['proxy_host'], proxy_dict['proxy_port'] = host, int(port)
    if ":" in user_pass:
        proxy_dict['proxy_user'], proxy_dict['proxy_pass'] = user_pass.split(":")
    return proxy_dict
    
    
if __name__=="__main__":
    import sys
    
    if '--web2py' in sys.argv:
        # test local sample webservice exposed by web2py
        from client import SoapClient
        if not '--wsdl' in sys.argv:
            client = SoapClient(
                location = "http://127.0.0.1:8000/webservices/sample/call/soap",
                action = 'http://127.0.0.1:8000/webservices/sample/call/soap', # SOAPAction
                namespace = "http://127.0.0.1:8000/webservices/sample/call/soap", 
                soap_ns='soap', trace = True, ns = False, exceptions=True)
        else:
            client = SoapClient(wsdl="http://127.0.0.1:8000/webservices/sample/call/soap?WSDL",trace=True)
        response = client.Dummy()
        print 'dummy', response
        response = client.Echo(value='hola')
        print 'echo', repr(response)







|

|
|














|







|

|









|






|










|
|


|







|







451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
                            if debug: print "Replacing ", k , " = ", v[None]
                            elements[k] = v[None]
                            #break
                if isinstance(v, list):
                    for n in v: # recurse list
                        postprocess_element(n)


        # process current wsdl schema:
        for schema in wsdl.types("schema", ns=xsd_uri):
            preprocess_schema(schema)

        postprocess_element(elements)

        for message in wsdl.message:
            if debug: print "Processing message", message['name']
            part = message('part', error=False)
            element = {}
            if part:
                element_name = part['element']
                if not element_name:
                    element_name = part['type'] # some uses type instead
                element_name = get_local_name(element_name)
                element = {element_name: elements.get(element_name)}
            messages[message['name']] = element

        for port_type in wsdl.portType:
            port_type_name = port_type['name']
            if debug: print "Processing port type", port_type_name
            binding = port_type_bindings[port_type_name]

            for operation in port_type.operation:
                op_name = operation['name']
                op = operations[op_name]
                op['documentation'] = unicode(operation('documentation', error=False) or '')
                if binding['soap_ver']:
                    #TODO: separe operation_binding from operation (non SOAP?)
                    input = get_local_name(operation.input['message'])
                    output = get_local_name(operation.output['message'])
                    op['input'] = messages[input]
                    op['output'] = messages[output]

        if debug:
            import pprint
            pprint.pprint(services)

        return services

def parse_proxy(proxy_str):
    "Parses proxy address user:pass@host:port into a dict suitable for httplib2"
    proxy_dict = {}
    if proxy_str is None:
        return
    if "@" in proxy_str:
        user_pass, host_port = proxy_str.split("@")
    else:
        user_pass, host_port = "", proxy_str
    if ":" in host_port:
        host, port = host_port.split(":")
        proxy_dict['proxy_host'], proxy_dict['proxy_port'] = host, int(port)
    if ":" in user_pass:
        proxy_dict['proxy_user'], proxy_dict['proxy_pass'] = user_pass.split(":")
    return proxy_dict


if __name__=="__main__":
    import sys

    if '--web2py' in sys.argv:
        # test local sample webservice exposed by web2py
        from client import SoapClient
        if not '--wsdl' in sys.argv:
            client = SoapClient(
                location = "http://127.0.0.1:8000/webservices/sample/call/soap",
                action = 'http://127.0.0.1:8000/webservices/sample/call/soap', # SOAPAction
                namespace = "http://127.0.0.1:8000/webservices/sample/call/soap",
                soap_ns='soap', trace = True, ns = False, exceptions=True)
        else:
            client = SoapClient(wsdl="http://127.0.0.1:8000/webservices/sample/call/soap?WSDL",trace=True)
        response = client.Dummy()
        print 'dummy', response
        response = client.Echo(value='hola')
        print 'echo', repr(response)
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575

    if '--raw' in sys.argv:
        # raw (unmarshalled parameter) local sample webservice exposed by web2py
        from client import SoapClient
        client = SoapClient(
            location = "http://127.0.0.1:8000/webservices/sample/call/soap",
            action = 'http://127.0.0.1:8000/webservices/sample/call/soap', # SOAPAction
            namespace = "http://127.0.0.1:8000/webservices/sample/call/soap", 
            soap_ns='soap', trace = True, ns = False)
        params = SimpleXMLElement("""<?xml version="1.0" encoding="UTF-8"?><AddIntegers><a>3</a><b>2</b></AddIntegers>""") # manully convert returned type
        response = client.call('AddIntegers',params)
        result = response.AddResult 
        print int(result) # manully convert returned type
            
    if '--ctg' in sys.argv:
        # test AFIP Agriculture webservice
        client = SoapClient(
            location = "https://fwshomo.afip.gov.ar/wsctg/services/CTGService",
            action = 'http://impl.service.wsctg.afip.gov.ar/CTGService/', # SOAPAction
            namespace = "http://impl.service.wsctg.afip.gov.ar/CTGService/",
            trace = True,
            ns = True)
        response = client.dummy()
        result = response.dummyResponse
        print str(result.appserver)
        print str(result.dbserver)
        print str(result.authserver)
    
    if '--wsfe' in sys.argv:
        # Demo & Test (AFIP Electronic Invoice):
        ta_file = open("TA.xml")
        try:
            ta_string = ta_file.read()   # read access ticket (wsaa.py)
        finally:
            ta_file.close()







|



|

|













|







541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575

    if '--raw' in sys.argv:
        # raw (unmarshalled parameter) local sample webservice exposed by web2py
        from client import SoapClient
        client = SoapClient(
            location = "http://127.0.0.1:8000/webservices/sample/call/soap",
            action = 'http://127.0.0.1:8000/webservices/sample/call/soap', # SOAPAction
            namespace = "http://127.0.0.1:8000/webservices/sample/call/soap",
            soap_ns='soap', trace = True, ns = False)
        params = SimpleXMLElement("""<?xml version="1.0" encoding="UTF-8"?><AddIntegers><a>3</a><b>2</b></AddIntegers>""") # manully convert returned type
        response = client.call('AddIntegers',params)
        result = response.AddResult
        print int(result) # manully convert returned type

    if '--ctg' in sys.argv:
        # test AFIP Agriculture webservice
        client = SoapClient(
            location = "https://fwshomo.afip.gov.ar/wsctg/services/CTGService",
            action = 'http://impl.service.wsctg.afip.gov.ar/CTGService/', # SOAPAction
            namespace = "http://impl.service.wsctg.afip.gov.ar/CTGService/",
            trace = True,
            ns = True)
        response = client.dummy()
        result = response.dummyResponse
        print str(result.appserver)
        print str(result.dbserver)
        print str(result.authserver)

    if '--wsfe' in sys.argv:
        # Demo & Test (AFIP Electronic Invoice):
        ta_file = open("TA.xml")
        try:
            ta_string = ta_file.read()   # read access ticket (wsaa.py)
        finally:
            ta_file.close()
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
            argAuth= {"Token": token, "Sign": sign, "cuit":long(cuit)}
        )
        if int(results.FERecuperaQTYRequestResult.RError.percode) != 0:
            print "Percode: %s" % results.FERecuperaQTYRequestResult.RError.percode
            print "MSGerror: %s" % results.FERecuperaQTYRequestResult.RError.perrmsg
        else:
            print int(results.FERecuperaQTYRequestResult.qty.value)
    
    if '--feriados' in sys.argv:
        # Demo & Test: Argentina Holidays (Ministerio del Interior):
        # this webservice seems disabled
        from datetime import datetime, timedelta
        client = SoapClient(
            location = "http://webservices.mininterior.gov.ar/Feriados/Service.svc",
            action = 'http://tempuri.org/IMyService/', # SOAPAction







|







588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
            argAuth= {"Token": token, "Sign": sign, "cuit":long(cuit)}
        )
        if int(results.FERecuperaQTYRequestResult.RError.percode) != 0:
            print "Percode: %s" % results.FERecuperaQTYRequestResult.RError.percode
            print "MSGerror: %s" % results.FERecuperaQTYRequestResult.RError.perrmsg
        else:
            print int(results.FERecuperaQTYRequestResult.qty.value)

    if '--feriados' in sys.argv:
        # Demo & Test: Argentina Holidays (Ministerio del Interior):
        # this webservice seems disabled
        from datetime import datetime, timedelta
        client = SoapClient(
            location = "http://webservices.mininterior.gov.ar/Feriados/Service.svc",
            action = 'http://tempuri.org/IMyService/', # SOAPAction
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
        finally:
            ta_file.close()
        ta = SimpleXMLElement(ta_string)
        token = str(ta.credentials.token)
        sign = str(ta.credentials.sign)
        response = client.FEXGetCMP(
            Auth={"Token": token, "Sign": sign, "Cuit": 20267565393},
            Cmp={"Tipo_cbte": 19, "Punto_vta": 1, "Cbte_nro": 1}) 
        result = response['FEXGetCMPResult']
        if False: print result
        if 'FEXErr' in result:
            print "FEXError:", result['FEXErr']['ErrCode'], result['FEXErr']['ErrCode'] 
        cbt = result['FEXResultGet']
        print cbt['Cae']
        FEX_event = result['FEXEvents']
        print FEX_event['EventCode'], FEX_event['EventMsg']

    if '--wsdl-ctg' in sys.argv:
        client = SoapClient(wsdl='https://fwshomo.afip.gov.ar/wsctg/services/CTGService?wsdl',







|



|







633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
        finally:
            ta_file.close()
        ta = SimpleXMLElement(ta_string)
        token = str(ta.credentials.token)
        sign = str(ta.credentials.sign)
        response = client.FEXGetCMP(
            Auth={"Token": token, "Sign": sign, "Cuit": 20267565393},
            Cmp={"Tipo_cbte": 19, "Punto_vta": 1, "Cbte_nro": 1})
        result = response['FEXGetCMPResult']
        if False: print result
        if 'FEXErr' in result:
            print "FEXError:", result['FEXErr']['ErrCode'], result['FEXErr']['ErrCode']
        cbt = result['FEXResultGet']
        print cbt['Cae']
        FEX_event = result['FEXEvents']
        print FEX_event['EventCode'], FEX_event['EventMsg']

    if '--wsdl-ctg' in sys.argv:
        client = SoapClient(wsdl='https://fwshomo.afip.gov.ar/wsctg/services/CTGService?wsdl',
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688

        sign = str(ta.credentials.sign)
        print client.help("obtenerProvincias")
        response = client.obtenerProvincias(auth={"token":token, "sign":sign, "cuitRepresentado":20267565393})
        print "response=",response
        for ret in response:
            print ret['return']['codigoProvincia'], ret['return']['descripcionProvincia'].encode("latin1")
        prueba = dict(numeroCartaDePorte=512345678, codigoEspecie=23,
                cuitRemitenteComercial=20267565393, cuitDestino=20267565393, cuitDestinatario=20267565393, 
                codigoLocalidadOrigen=3058, codigoLocalidadDestino=3059, 
                codigoCosecha='0910', pesoNetoCarga=1000, cantHoras=1, 
                patenteVehiculo='CZO985', cuitTransportista=20267565393,
                numeroCTG="43816783", transaccion='10000001681', observaciones='',
            )

        response = client.solicitarCTG( 
            auth={"token": token, "sign": sign, "cuitRepresentado": 20267565393},
            solicitarCTGRequest= prueba)

        print response['return']['numeroCTG']

    ##print parse_proxy(None)
    ##print parse_proxy("host:1234")
    ##print parse_proxy("user:pass@host:1234")
    ##sys.exit(0) 








|
|
|




|








|
>
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
        sign = str(ta.credentials.sign)
        print client.help("obtenerProvincias")
        response = client.obtenerProvincias(auth={"token":token, "sign":sign, "cuitRepresentado":20267565393})
        print "response=",response
        for ret in response:
            print ret['return']['codigoProvincia'], ret['return']['descripcionProvincia'].encode("latin1")
        prueba = dict(numeroCartaDePorte=512345678, codigoEspecie=23,
                cuitRemitenteComercial=20267565393, cuitDestino=20267565393, cuitDestinatario=20267565393,
                codigoLocalidadOrigen=3058, codigoLocalidadDestino=3059,
                codigoCosecha='0910', pesoNetoCarga=1000, cantHoras=1,
                patenteVehiculo='CZO985', cuitTransportista=20267565393,
                numeroCTG="43816783", transaccion='10000001681', observaciones='',
            )

        response = client.solicitarCTG(
            auth={"token": token, "sign": sign, "cuitRepresentado": 20267565393},
            solicitarCTGRequest= prueba)

        print response['return']['numeroCTG']

    ##print parse_proxy(None)
    ##print parse_proxy("host:1234")
    ##print parse_proxy("user:pass@host:1234")
    ##sys.exit(0)

Modified gluon/contrib/pysimplesoap/server.py from [7ef2196ac7] to [eec0dc1e9f].
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
from simplexml import SimpleXMLElement, TYPE_MAP, DateTime, Date, Decimal

DEBUG = False


class SoapDispatcher(object):
    "Simple Dispatcher for SOAP Server"
    
    def __init__(self, name, documentation='', action='', location='', 
                 namespace=None, prefix=False, 
                 soap_uri="http://schemas.xmlsoap.org/soap/envelope/", 
                 soap_ns='soap',
                 **kwargs):
        self.methods = {}
        self.name = name
        self.documentation = documentation
        self.action = action # base SoapAction
        self.location = location
        self.namespace = namespace # targetNamespace
        self.prefix = prefix
        self.soap_ns = soap_ns
        self.soap_uri = soap_uri
    
    def register_function(self, name, fn, returns=None, args=None, doc=None):
        self.methods[name] = fn, returns, args, doc or getattr(fn,"__doc__","")
        
    def dispatch(self, xml, action=None):
        "Receive and proccess SOAP call"
        # default values:
        prefix = self.prefix
        ret = fault = None
        soap_ns, soap_uri = self.soap_ns, self.soap_uri
        soap_fault_code = 'VersionMismatch'

        try:
            request = SimpleXMLElement(xml, namespace=self.namespace)

            # detect soap prefix and uri (xmlns attributes of Envelope)
            for k, v in request[:]:
                if v in ("http://schemas.xmlsoap.org/soap/envelope/",
                                  "http://www.w3.org/2003/05/soap-env",):
                    soap_ns = request.attributes()[k].localName
                    soap_uri = request.attributes()[k].value
            
            soap_fault_code = 'Client'
            
            # parse request message and get local method            
            method = request('Body', ns=soap_uri).children()(0)
            if action:
                # method name = action 
                name = action[len(self.action)+1:-1]
                prefix = self.prefix
            if not action or not name:
                # method name = input message name
                name = method.get_local_name()
                prefix = method.get_prefix()

            if DEBUG: print "dispatch method", name
            function, returns_types, args_types, doc = self.methods[name]
        
            # de-serialize parameters (if type definitions given)
            if args_types:
                args = method.children().unmarshall(args_types)
            elif args_types is None:
                args = {'request':method} # send raw request
            else:
                args = {} # no parameters
 
            soap_fault_code = 'Server'
            # execute function
            ret = function(**args)
            if DEBUG: print ret

        except Exception, e:
            import sys
            etype, evalue, etb = sys.exc_info()
            if DEBUG: 
                import traceback
                detail = ''.join(traceback.format_exception(etype, evalue, etb))
                detail += '\n\nXML REQUEST\n\n' + xml
            else:
                detail = None
            fault = {'faultcode': "%s.%s" % (soap_fault_code, etype.__name__), 
                     'faultstring': unicode(evalue), 
                     'detail': detail}

        # build response message
        if not prefix:
            xml = """<%(soap_ns)s:Envelope xmlns:%(soap_ns)s="%(soap_uri)s"/>"""  
        else:
            xml = """<%(soap_ns)s:Envelope xmlns:%(soap_ns)s="%(soap_uri)s"
                       xmlns:%(prefix)s="%(namespace)s"/>"""  
            
        xml = xml % {'namespace': self.namespace, 'prefix': prefix,
                     'soap_ns': soap_ns, 'soap_uri': soap_uri}

        response = SimpleXMLElement(xml, namespace=self.namespace,
                                    prefix=prefix)
    
        response['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
        response['xmlns:xsd'] = "http://www.w3.org/2001/XMLSchema"

        body = response.add_child("%s:Body" % soap_ns, ns=False)
        if fault:
            # generate a Soap Fault (with the python exception)
            body.marshall("%s:Fault" % soap_ns, fault, ns=False)







|
|
|
|











|


|

















|

|
|


|









|







|








|





|
|




|


|
|





|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
from simplexml import SimpleXMLElement, TYPE_MAP, DateTime, Date, Decimal

DEBUG = False


class SoapDispatcher(object):
    "Simple Dispatcher for SOAP Server"

    def __init__(self, name, documentation='', action='', location='',
                 namespace=None, prefix=False,
                 soap_uri="http://schemas.xmlsoap.org/soap/envelope/",
                 soap_ns='soap',
                 **kwargs):
        self.methods = {}
        self.name = name
        self.documentation = documentation
        self.action = action # base SoapAction
        self.location = location
        self.namespace = namespace # targetNamespace
        self.prefix = prefix
        self.soap_ns = soap_ns
        self.soap_uri = soap_uri

    def register_function(self, name, fn, returns=None, args=None, doc=None):
        self.methods[name] = fn, returns, args, doc or getattr(fn,"__doc__","")

    def dispatch(self, xml, action=None):
        "Receive and proccess SOAP call"
        # default values:
        prefix = self.prefix
        ret = fault = None
        soap_ns, soap_uri = self.soap_ns, self.soap_uri
        soap_fault_code = 'VersionMismatch'

        try:
            request = SimpleXMLElement(xml, namespace=self.namespace)

            # detect soap prefix and uri (xmlns attributes of Envelope)
            for k, v in request[:]:
                if v in ("http://schemas.xmlsoap.org/soap/envelope/",
                                  "http://www.w3.org/2003/05/soap-env",):
                    soap_ns = request.attributes()[k].localName
                    soap_uri = request.attributes()[k].value

            soap_fault_code = 'Client'

            # parse request message and get local method
            method = request('Body', ns=soap_uri).children()(0)
            if action:
                # method name = action
                name = action[len(self.action)+1:-1]
                prefix = self.prefix
            if not action or not name:
                # method name = input message name
                name = method.get_local_name()
                prefix = method.get_prefix()

            if DEBUG: print "dispatch method", name
            function, returns_types, args_types, doc = self.methods[name]

            # de-serialize parameters (if type definitions given)
            if args_types:
                args = method.children().unmarshall(args_types)
            elif args_types is None:
                args = {'request':method} # send raw request
            else:
                args = {} # no parameters

            soap_fault_code = 'Server'
            # execute function
            ret = function(**args)
            if DEBUG: print ret

        except Exception, e:
            import sys
            etype, evalue, etb = sys.exc_info()
            if DEBUG:
                import traceback
                detail = ''.join(traceback.format_exception(etype, evalue, etb))
                detail += '\n\nXML REQUEST\n\n' + xml
            else:
                detail = None
            fault = {'faultcode': "%s.%s" % (soap_fault_code, etype.__name__),
                     'faultstring': unicode(evalue),
                     'detail': detail}

        # build response message
        if not prefix:
            xml = """<%(soap_ns)s:Envelope xmlns:%(soap_ns)s="%(soap_uri)s"/>"""
        else:
            xml = """<%(soap_ns)s:Envelope xmlns:%(soap_ns)s="%(soap_uri)s"
                       xmlns:%(prefix)s="%(namespace)s"/>"""

        xml = xml % {'namespace': self.namespace, 'prefix': prefix,
                     'soap_ns': soap_ns, 'soap_uri': soap_uri}

        response = SimpleXMLElement(xml, namespace=self.namespace,
                                    prefix=prefix)

        response['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
        response['xmlns:xsd'] = "http://www.w3.org/2001/XMLSchema"

        body = response.add_child("%s:Body" % soap_ns, ns=False)
        if fault:
            # generate a Soap Fault (with the python exception)
            body.marshall("%s:Fault" % soap_ns, fault, ns=False)
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

        return response.as_xml()

    # Introspection functions:

    def list_methods(self):
        "Return a list of aregistered operations"
        return [(method, doc) for method, (function, returns, args, doc) in self.methods.items()] 

    def help(self, method=None):
        "Generate sample request and response messages"
        (function, returns, args, doc) = self.methods[method]
        xml = """
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body><%(method)s xmlns="%(namespace)s"/></soap:Body>







|







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

        return response.as_xml()

    # Introspection functions:

    def list_methods(self):
        "Return a list of aregistered operations"
        return [(method, doc) for method, (function, returns, args, doc) in self.methods.items()]

    def help(self, method=None):
        "Generate sample request and response messages"
        (function, returns, args, doc) = self.methods[method]
        xml = """
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body><%(method)s xmlns="%(namespace)s"/></soap:Body>
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

        return request.as_xml(pretty=True), response.as_xml(pretty=True), doc


    def wsdl(self):
        "Generate Web Service Description v1.1"
        xml = """<?xml version="1.0"?>
<wsdl:definitions name="%(name)s" 
          targetNamespace="%(namespace)s"
          xmlns:tns="%(namespace)s"
          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">%(documentation)s</wsdl:documentation>

    <wsdl:types>
       <xsd:schema targetNamespace="%(namespace)s"
              elementFormDefault="qualified"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       </xsd:schema>
    </wsdl:types>

</wsdl:definitions>
""" % {'namespace': self.namespace, 'name': self.name, 'documentation': self.documentation}
        wsdl = SimpleXMLElement(xml)

        for method, (function, returns, args, doc) in self.methods.items():
            # create elements:
                
            def parse_element(name, values, array=False, complex=False):
                if not complex:
                    element = wsdl('wsdl:types')('xsd:schema').add_child('xsd:element')
                    complex = element.add_child("xsd:complexType")
                else:
                    complex = wsdl('wsdl:types')('xsd:schema').add_child('xsd:complexType')
                    element = complex







|




















|







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216

        return request.as_xml(pretty=True), response.as_xml(pretty=True), doc


    def wsdl(self):
        "Generate Web Service Description v1.1"
        xml = """<?xml version="1.0"?>
<wsdl:definitions name="%(name)s"
          targetNamespace="%(namespace)s"
          xmlns:tns="%(namespace)s"
          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">%(documentation)s</wsdl:documentation>

    <wsdl:types>
       <xsd:schema targetNamespace="%(namespace)s"
              elementFormDefault="qualified"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       </xsd:schema>
    </wsdl:types>

</wsdl:definitions>
""" % {'namespace': self.namespace, 'name': self.name, 'documentation': self.documentation}
        wsdl = SimpleXMLElement(xml)

        for method, (function, returns, args, doc) in self.methods.items():
            # create elements:

            def parse_element(name, values, array=False, complex=False):
                if not complex:
                    element = wsdl('wsdl:types')('xsd:schema').add_child('xsd:element')
                    complex = element.add_child("xsd:complexType")
                else:
                    complex = wsdl('wsdl:types')('xsd:schema').add_child('xsd:complexType')
                    element = complex
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
                    elif isinstance(v, list):
                        n="ArrayOf%s%s" % (name, k)
                        l = []
                        for d in v:
                            l.extend(d.items())
                        parse_element(n, l, array=True, complex=True)
                        t = "tns:%s" % n
                    elif isinstance(v, dict): 
                        n="%s%s" % (name, k)
                        parse_element(n, v.items(), complex=True)
                        t = "tns:%s" % n
                    e.add_attribute('type', t)
            
            parse_element("%s" % method, args and args.items())
            parse_element("%sResponse" % method, returns and returns.items())

            # create messages:
            for m,e in ('Input',''), ('Output','Response'):
                message = wsdl.add_child('wsdl:message')
                message['name'] = "%s%s" % (method, m)
                part = message.add_child("wsdl:part")
                part[:] = {'name': 'parameters', 
                           'element': 'tns:%s%s' % (method,e)}

        # create ports
        portType = wsdl.add_child('wsdl:portType')
        portType['name'] = "%sPortType" % self.name
        for method, (function, returns, args, doc) in self.methods.items():
            op = portType.add_child('wsdl:operation')







|




|








|







237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
                    elif isinstance(v, list):
                        n="ArrayOf%s%s" % (name, k)
                        l = []
                        for d in v:
                            l.extend(d.items())
                        parse_element(n, l, array=True, complex=True)
                        t = "tns:%s" % n
                    elif isinstance(v, dict):
                        n="%s%s" % (name, k)
                        parse_element(n, v.items(), complex=True)
                        t = "tns:%s" % n
                    e.add_attribute('type', t)

            parse_element("%s" % method, args and args.items())
            parse_element("%sResponse" % method, returns and returns.items())

            # create messages:
            for m,e in ('Input',''), ('Output','Response'):
                message = wsdl.add_child('wsdl:message')
                message['name'] = "%s%s" % (method, m)
                part = message.add_child("wsdl:part")
                part[:] = {'name': 'parameters',
                           'element': 'tns:%s%s' % (method,e)}

        # create ports
        portType = wsdl.add_child('wsdl:portType')
        portType['name'] = "%sPortType" % self.name
        for method, (function, returns, args, doc) in self.methods.items():
            op = portType.add_child('wsdl:operation')
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
        service.add_child('wsdl:documentation', text=self.documentation)
        port=service.add_child('wsdl:port')
        port["name"] = "%s" % self.name
        port["binding"] = "tns:%sBinding" % self.name
        soapaddress = port.add_child('soap:address')
        soapaddress["location"] = self.location
        return wsdl.as_xml(pretty=True)
    

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class SOAPHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        "User viewable help information and wsdl"
        args = self.path[1:].split("?")
        print "serving", args
        if self.path != "/" and args[0] not in self.server.dispatcher.methods.keys():
            self.send_error(404, "Method not found: %s" % args[0])
        else:
            if self.path == "/":
                # return wsdl if no method supplied
                response = self.server.dispatcher.wsdl()
            else:
                # return supplied method help (?request or ?response messages)
                req, res, doc = self.server.dispatcher.help(args[0])
                if len(args)==1 or args[1]=="request":
                    response = req
                else:
                    response = res                
            self.send_response(200)
            self.send_header("Content-type", "text/xml")
            self.end_headers()
            self.wfile.write(response)

    def do_POST(self):
        "SOAP POST gateway"







|



















|







298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
        service.add_child('wsdl:documentation', text=self.documentation)
        port=service.add_child('wsdl:port')
        port["name"] = "%s" % self.name
        port["binding"] = "tns:%sBinding" % self.name
        soapaddress = port.add_child('soap:address')
        soapaddress["location"] = self.location
        return wsdl.as_xml(pretty=True)


from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class SOAPHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        "User viewable help information and wsdl"
        args = self.path[1:].split("?")
        print "serving", args
        if self.path != "/" and args[0] not in self.server.dispatcher.methods.keys():
            self.send_error(404, "Method not found: %s" % args[0])
        else:
            if self.path == "/":
                # return wsdl if no method supplied
                response = self.server.dispatcher.wsdl()
            else:
                # return supplied method help (?request or ?response messages)
                req, res, doc = self.server.dispatcher.help(args[0])
                if len(args)==1 or args[1]=="request":
                    response = req
                else:
                    response = res
            self.send_response(200)
            self.send_header("Content-type", "text/xml")
            self.end_headers()
            self.wfile.write(response)

    def do_POST(self):
        "SOAP POST gateway"
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
        name = "PySimpleSoapSample",
        location = "http://localhost:8008/",
        action = 'http://localhost:8008/', # SOAPAction
        namespace = "http://example.com/pysimplesoapsamle/", prefix="ns0",
        documentation = 'Example soap service using PySimpleSoap',
        trace = True,
        ns = True)
    
    def adder(p,c, dt=None):
        "Add several values"
        print c[0]['d'],c[1]['d'],
        import datetime
        dt = dt + datetime.timedelta(365)
        return {'ab': p['a']+p['b'], 'dd': c[0]['d']+c[1]['d'], 'dt': dt}

    def dummy(in0):
        "Just return input"
        return in0

    def echo(request):
        "Copy request->response (generic, any type)"
        return request.value

    dispatcher.register_function('Adder', adder,
        returns={'AddResult': {'ab': int, 'dd': str } }, 
        args={'p': {'a': int,'b': int}, 'dt': Date, 'c': [{'d': Decimal}]})

    dispatcher.register_function('Dummy', dummy,
        returns={'out0': str}, 
        args={'in0': str})

    dispatcher.register_function('Echo', echo)

    if '--local' in sys.argv:

        wsdl=dispatcher.wsdl()
        print wsdl
        testfile = open("C:/test.wsdl","w")
        try:
            testfile.write(wsdl)
        finally:
            testfile.close()
        # dummy local test (clasic soap dialect)
        xml = """<?xml version="1.0" encoding="UTF-8"?> 
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
       <soap:Body>
         <Adder xmlns="http://example.com/sample.wsdl">
           <p><a>1</a><b>2</b></p><c><d>5000000.1</d><d>.2</d></c><dt>20100724</dt>
        </Adder>
       </soap:Body>
    </soap:Envelope>"""







|
















|



|














|







345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
        name = "PySimpleSoapSample",
        location = "http://localhost:8008/",
        action = 'http://localhost:8008/', # SOAPAction
        namespace = "http://example.com/pysimplesoapsamle/", prefix="ns0",
        documentation = 'Example soap service using PySimpleSoap',
        trace = True,
        ns = True)

    def adder(p,c, dt=None):
        "Add several values"
        print c[0]['d'],c[1]['d'],
        import datetime
        dt = dt + datetime.timedelta(365)
        return {'ab': p['a']+p['b'], 'dd': c[0]['d']+c[1]['d'], 'dt': dt}

    def dummy(in0):
        "Just return input"
        return in0

    def echo(request):
        "Copy request->response (generic, any type)"
        return request.value

    dispatcher.register_function('Adder', adder,
        returns={'AddResult': {'ab': int, 'dd': str } },
        args={'p': {'a': int,'b': int}, 'dt': Date, 'c': [{'d': Decimal}]})

    dispatcher.register_function('Dummy', dummy,
        returns={'out0': str},
        args={'in0': str})

    dispatcher.register_function('Echo', echo)

    if '--local' in sys.argv:

        wsdl=dispatcher.wsdl()
        print wsdl
        testfile = open("C:/test.wsdl","w")
        try:
            testfile.write(wsdl)
        finally:
            testfile.close()
        # dummy local test (clasic soap dialect)
        xml = """<?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
       <soap:Body>
         <Adder xmlns="http://example.com/sample.wsdl">
           <p><a>1</a><b>2</b></p><c><d>5000000.1</d><d>.2</d></c><dt>20100724</dt>
        </Adder>
       </soap:Body>
    </soap:Envelope>"""
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454

      </pys:Adder>
   </soapenv:Body>
</soapenv:Envelope>
    """
        print dispatcher.dispatch(xml)

        # echo local test (generic soap service)
        xml = """<?xml version="1.0" encoding="UTF-8"?> 
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
         <Echo xmlns="http://example.com/sample.wsdl">
           <value xsi:type="xsd:string">Hello world</value>
        </Echo>
       </soap:Body>
    </soap:Envelope>"""

        print dispatcher.dispatch(xml)


        for method, doc in dispatcher.list_methods():
            request, response, doc = dispatcher.help(method)
            ##print request
            ##print response
            
    if '--serve' in sys.argv:
        print "Starting server..."
        httpd = HTTPServer(("", 8008), SOAPHandler)
        httpd.dispatcher = dispatcher
        httpd.serve_forever()

    if '--consume' in sys.argv:
        from client import SoapClient
        client = SoapClient(
            location = "http://localhost:8008/",
            action = 'http://localhost:8008/', # SOAPAction
            namespace = "http://example.com/sample.wsdl", 
            soap_ns='soap',
            trace = True,
            ns = False)
        response = client.Adder(p={'a':1,'b':2},dt='20100724',c=[{'d':'1.20'},{'d':'2.01'}])
        result = response.AddResult
        print int(result.ab)
        print str(result.dd)










|

















|











|









>
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
      </pys:Adder>
   </soapenv:Body>
</soapenv:Envelope>
    """
        print dispatcher.dispatch(xml)

        # echo local test (generic soap service)
        xml = """<?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
         <Echo xmlns="http://example.com/sample.wsdl">
           <value xsi:type="xsd:string">Hello world</value>
        </Echo>
       </soap:Body>
    </soap:Envelope>"""

        print dispatcher.dispatch(xml)


        for method, doc in dispatcher.list_methods():
            request, response, doc = dispatcher.help(method)
            ##print request
            ##print response

    if '--serve' in sys.argv:
        print "Starting server..."
        httpd = HTTPServer(("", 8008), SOAPHandler)
        httpd.dispatcher = dispatcher
        httpd.serve_forever()

    if '--consume' in sys.argv:
        from client import SoapClient
        client = SoapClient(
            location = "http://localhost:8008/",
            action = 'http://localhost:8008/', # SOAPAction
            namespace = "http://example.com/sample.wsdl",
            soap_ns='soap',
            trace = True,
            ns = False)
        response = client.Adder(p={'a':1,'b':2},dt='20100724',c=[{'d':'1.20'},{'d':'2.01'}])
        result = response.AddResult
        print int(result.ab)
        print str(result.dd)



Modified gluon/contrib/pysimplesoap/simplexml.py from [dad238090a] to [8fc01ec0e6].
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
__author__ = "Mariano Reingart (reingart@gmail.com)"
__copyright__ = "Copyright (C) 2008/009 Mariano Reingart"
__license__ = "LGPL 3.0"
__version__ = "1.02c"

import xml.dom.minidom
from decimal import Decimal
import datetime 
import time

DEBUG = False

# Functions to serialize/unserialize special immutable types:
datetime_u = lambda s: datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S")
datetime_m = lambda dt: dt.isoformat('T')







|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
__author__ = "Mariano Reingart (reingart@gmail.com)"
__copyright__ = "Copyright (C) 2008/009 Mariano Reingart"
__license__ = "LGPL 3.0"
__version__ = "1.02c"

import xml.dom.minidom
from decimal import Decimal
import datetime
import time

DEBUG = False

# Functions to serialize/unserialize special immutable types:
datetime_u = lambda s: datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S")
datetime_m = lambda dt: dt.isoformat('T')
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Alias():
    def __init__(self, py_type, xml_type):
        self.py_type, self.xml_type = py_type, xml_type
    def __call__(self, value):
        return self.py_type(value)
    def __repr__(self):
        return "<alias '%s' for '%s'>" % (self.xml_type, self.py_type)
        
byte = Alias(str,'byte')
short = Alias(int,'short')
double = Alias(float,'double')
integer = Alias(long,'integer')
DateTime = datetime.datetime
Date = datetime.date
Time = datetime.time

# Define convertion function (python type): xml schema type
TYPE_MAP = {str:'string',unicode:'string',
            bool:'boolean', short:'short', byte:'byte',
            int:'int', long:'long', integer:'integer', 
            float:'float', double:'double',
            Decimal:'decimal',
            datetime.datetime:'dateTime', datetime.date:'date',
            }
TYPE_MARSHAL_FN = {datetime.datetime:datetime_m, datetime.date:date_m,}
TYPE_UNMARSHAL_FN = {datetime.datetime:datetime_u, datetime.date:date_u,
                     bool:bool_u,







|











|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Alias():
    def __init__(self, py_type, xml_type):
        self.py_type, self.xml_type = py_type, xml_type
    def __call__(self, value):
        return self.py_type(value)
    def __repr__(self):
        return "<alias '%s' for '%s'>" % (self.xml_type, self.py_type)

byte = Alias(str,'byte')
short = Alias(int,'short')
double = Alias(float,'double')
integer = Alias(long,'integer')
DateTime = datetime.datetime
Date = datetime.date
Time = datetime.time

# Define convertion function (python type): xml schema type
TYPE_MAP = {str:'string',unicode:'string',
            bool:'boolean', short:'short', byte:'byte',
            int:'int', long:'long', integer:'integer',
            float:'float', double:'double',
            Decimal:'decimal',
            datetime.datetime:'dateTime', datetime.date:'date',
            }
TYPE_MARSHAL_FN = {datetime.datetime:datetime_m, datetime.date:date_m,}
TYPE_UNMARSHAL_FN = {datetime.datetime:datetime_u, datetime.date:date_u,
                     bool:bool_u,
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
        if self.array and False:
            s = "[%s]" % s
        return s


class SimpleXMLElement(object):
    "Simple XML manipulation (simil PHP)"
    
    def __init__(self, text = None, elements = None, document = None, namespace = None, prefix=None):
        self.__ns = namespace
        self.__prefix = prefix
        if text:
            try:
                self.__document = xml.dom.minidom.parseString(text)
            except:
                if DEBUG: print text
                raise
            self.__elements = [self.__document.documentElement]
        else:
            self.__elements = elements
            self.__document = document
    
    def add_child(self,name,text=None,ns=True):
        "Adding a child tag to a node"
        if not ns or not self.__ns:
            if DEBUG: print "adding %s" % (name)
            element = self.__document.createElement(name)
        else:
            if DEBUG: print "adding %s ns %s %s" % (name, self.__ns,ns)







|













|







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
        if self.array and False:
            s = "[%s]" % s
        return s


class SimpleXMLElement(object):
    "Simple XML manipulation (simil PHP)"

    def __init__(self, text = None, elements = None, document = None, namespace = None, prefix=None):
        self.__ns = namespace
        self.__prefix = prefix
        if text:
            try:
                self.__document = xml.dom.minidom.parseString(text)
            except:
                if DEBUG: print text
                raise
            self.__elements = [self.__document.documentElement]
        else:
            self.__elements = elements
            self.__document = document

    def add_child(self,name,text=None,ns=True):
        "Adding a child tag to a node"
        if not ns or not self.__ns:
            if DEBUG: print "adding %s" % (name)
            element = self.__document.createElement(name)
        else:
            if DEBUG: print "adding %s ns %s %s" % (name, self.__ns,ns)
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
                element.appendChild(self.__document.createTextNode(str(text)))
        self._element.appendChild(element)
        return SimpleXMLElement(
                    elements=[element],
                    document=self.__document,
                    namespace=self.__ns,
                    prefix=self.__prefix)
    
    def __setattr__(self, tag, text):
        "Add text child tag node (short form)"
        if tag.startswith("_"):
            object.__setattr__(self, tag, text)
        else:
            if DEBUG: print "__setattr__(%s,%s)" % (tag, text)
            self.add_child(tag,text)







|







136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
                element.appendChild(self.__document.createTextNode(str(text)))
        self._element.appendChild(element)
        return SimpleXMLElement(
                    elements=[element],
                    document=self.__document,
                    namespace=self.__ns,
                    prefix=self.__prefix)

    def __setattr__(self, tag, text):
        "Add text child tag node (short form)"
        if tag.startswith("_"):
            object.__setattr__(self, tag, text)
        else:
            if DEBUG: print "__setattr__(%s,%s)" % (tag, text)
            self.add_child(tag,text)
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    def attributes(self):
        "Return a dict of attributes for this tag"
        #TODO: use slice syntax [:]?
        return self._element.attributes

    def __getitem__(self, item):
        "Return xml tag attribute value or a slice of attributes (iter)"
        if DEBUG: print "__getitem__(%s)" % item 
        if isinstance(item,basestring):
            if self._element.hasAttribute(item):
                return self._element.attributes[item].value
        elif isinstance(item, slice):
            # return a list with name:values
            return self._element.attributes.items()[item]
        else:
            # return element by index (position)
            element = self.__elements[item]
            return SimpleXMLElement(
                    elements=[element],
                    document=self.__document,
                    namespace=self.__ns,
                    prefix=self.__prefix)
            
    def add_attribute(self, name, value):
        "Set an attribute value from a string"
        self._element.setAttribute(name, value)
 
    def __setitem__(self, item, value):
        "Set an attribute value"
        if isinstance(item,basestring):
            self.add_attribute(item, value)
        elif isinstance(item, slice):
            # set multiple attributes at once
            for k, v in value.items():







|














|



|







185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    def attributes(self):
        "Return a dict of attributes for this tag"
        #TODO: use slice syntax [:]?
        return self._element.attributes

    def __getitem__(self, item):
        "Return xml tag attribute value or a slice of attributes (iter)"
        if DEBUG: print "__getitem__(%s)" % item
        if isinstance(item,basestring):
            if self._element.hasAttribute(item):
                return self._element.attributes[item].value
        elif isinstance(item, slice):
            # return a list with name:values
            return self._element.attributes.items()[item]
        else:
            # return element by index (position)
            element = self.__elements[item]
            return SimpleXMLElement(
                    elements=[element],
                    document=self.__document,
                    namespace=self.__ns,
                    prefix=self.__prefix)

    def add_attribute(self, name, value):
        "Set an attribute value from a string"
        self._element.setAttribute(name, value)

    def __setitem__(self, item, value):
        "Set an attribute value"
        if isinstance(item,basestring):
            self.add_attribute(item, value)
        elif isinstance(item, slice):
            # set multiple attributes at once
            for k, v in value.items():
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
            if isinstance(tag, int):
                # return tag by index
                elements=[self.__elements[tag]]
            if ns and not elements:
                for ns_uri in isinstance(ns, (tuple, list)) and ns or (ns, ):
                    if DEBUG: print "searching %s by ns=%s" % (tag,ns_uri)
                    elements = self._element.getElementsByTagNameNS(ns_uri, tag)
                    if elements: 
                        break
            if self.__ns and not elements:
                if DEBUG: print "searching %s by ns=%s" % (tag, self.__ns)
                elements = self._element.getElementsByTagNameNS(self.__ns, tag)
            if not elements:
                if DEBUG: print "searching %s " % (tag)
                elements = self._element.getElementsByTagName(tag)







|







231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
            if isinstance(tag, int):
                # return tag by index
                elements=[self.__elements[tag]]
            if ns and not elements:
                for ns_uri in isinstance(ns, (tuple, list)) and ns or (ns, ):
                    if DEBUG: print "searching %s by ns=%s" % (tag,ns_uri)
                    elements = self._element.getElementsByTagNameNS(ns_uri, tag)
                    if elements:
                        break
            if self.__ns and not elements:
                if DEBUG: print "searching %s by ns=%s" % (tag, self.__ns)
                elements = self._element.getElementsByTagNameNS(self.__ns, tag)
            if not elements:
                if DEBUG: print "searching %s " % (tag)
                elements = self._element.getElementsByTagName(tag)
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
                prefix=self.__prefix)
        except AttributeError, e:
            raise AttributeError("Tag not found: %s (%s)" % (tag, str(e)))

    def __getattr__(self, tag):
        "Shortcut for __call__"
        return self.__call__(tag)
        
    def __iter__(self):
        "Iterate over xml tags at this level"
        try:
            for __element in self.__elements:
                yield SimpleXMLElement(
                    elements=[__element],
                    document=self.__document,
                    namespace=self.__ns,
                    prefix=self.__prefix)
        except:
            raise

    def __dir__(self):
        "List xml children tags names"
        return [node.tagName for node 
                in self._element.childNodes
                if node.nodeType != node.TEXT_NODE]

    def children(self):
        "Return xml children tags element"
        elements=[__element for __element in self._element.childNodes
                          if __element.nodeType == __element.ELEMENT_NODE]
        if not elements:
            return None
            #raise IndexError("Tag %s has no children" % self._element.tagName)
        return SimpleXMLElement(
                elements=elements,
                document=self.__document,
                namespace=self.__ns,
                prefix=self.__prefix)

    def __len__(self):
        "Return elements count"
        return len(self.__elements)
        
    def __contains__( self, item):
        "Search for a tag name in this element or child nodes"
        return self._element.getElementsByTagName(item)
    
    def __unicode__(self):
        "Returns the unicode text nodes of the current element"
        if self._element.childNodes:
            rc = u""
            for node in self._element.childNodes:
                if node.nodeType == node.TEXT_NODE:
                    rc = rc + node.data
            return rc
        return ''
    
    def __str__(self):
        "Returns the str text nodes of the current element"
        return unicode(self).encode("utf8","ignore")

    def __int__(self):
        "Returns the integer value of the current element"
        return int(self.__str__())

    def __float__(self):
        "Returns the float value of the current element"
        try:
            return float(self.__str__())
        except:
            raise IndexError(self._element.toxml())    
    
    _element = property(lambda self: self.__elements[0])

    def unmarshall(self, types):
        "Convert to python values the current serialized xml element"
        # types is a dict of {tag name: convertion function}
        # example: types={'p': {'a': int,'b': int}, 'c': [{'d':str}]}
        #   expected xml: <p><a>1</a><b>2</b></p><c><d>hola</d><d>chau</d>







|














|



















|



|









|













|
|







256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
                prefix=self.__prefix)
        except AttributeError, e:
            raise AttributeError("Tag not found: %s (%s)" % (tag, str(e)))

    def __getattr__(self, tag):
        "Shortcut for __call__"
        return self.__call__(tag)

    def __iter__(self):
        "Iterate over xml tags at this level"
        try:
            for __element in self.__elements:
                yield SimpleXMLElement(
                    elements=[__element],
                    document=self.__document,
                    namespace=self.__ns,
                    prefix=self.__prefix)
        except:
            raise

    def __dir__(self):
        "List xml children tags names"
        return [node.tagName for node
                in self._element.childNodes
                if node.nodeType != node.TEXT_NODE]

    def children(self):
        "Return xml children tags element"
        elements=[__element for __element in self._element.childNodes
                          if __element.nodeType == __element.ELEMENT_NODE]
        if not elements:
            return None
            #raise IndexError("Tag %s has no children" % self._element.tagName)
        return SimpleXMLElement(
                elements=elements,
                document=self.__document,
                namespace=self.__ns,
                prefix=self.__prefix)

    def __len__(self):
        "Return elements count"
        return len(self.__elements)

    def __contains__( self, item):
        "Search for a tag name in this element or child nodes"
        return self._element.getElementsByTagName(item)

    def __unicode__(self):
        "Returns the unicode text nodes of the current element"
        if self._element.childNodes:
            rc = u""
            for node in self._element.childNodes:
                if node.nodeType == node.TEXT_NODE:
                    rc = rc + node.data
            return rc
        return ''

    def __str__(self):
        "Returns the str text nodes of the current element"
        return unicode(self).encode("utf8","ignore")

    def __int__(self):
        "Returns the integer value of the current element"
        return int(self.__str__())

    def __float__(self):
        "Returns the float value of the current element"
        try:
            return float(self.__str__())
        except:
            raise IndexError(self._element.toxml())

    _element = property(lambda self: self.__elements[0])

    def unmarshall(self, types):
        "Convert to python values the current serialized xml element"
        # types is a dict of {tag name: convertion function}
        # example: types={'p': {'a': int,'b': int}, 'c': [{'d':str}]}
        #   expected xml: <p><a>1</a><b>2</b></p><c><d>hola</d><d>chau</d>
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
                value = children and children.unmarshall(fn)
            else:
                if fn is None: # xsd:anyType not unmarshalled
                    value = node
                elif str(node) or fn == str:
                    try:
                        # get special desserialization function (if any)
                        fn = TYPE_UNMARSHAL_FN.get(fn,fn) 
                        value = fn(unicode(node))
                    except (ValueError, TypeError), e:
                        raise ValueError("Tag: %s: %s" % (name, unicode(e)))
                else:
                    value = None
            d[name] = value
        return d







|







350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
                value = children and children.unmarshall(fn)
            else:
                if fn is None: # xsd:anyType not unmarshalled
                    value = node
                elif str(node) or fn == str:
                    try:
                        # get special desserialization function (if any)
                        fn = TYPE_UNMARSHAL_FN.get(fn,fn)
                        value = fn(unicode(node))
                    except (ValueError, TypeError), e:
                        raise ValueError("Tag: %s: %s" % (name, unicode(e)))
                else:
                    value = None
            d[name] = value
        return d
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415

                child.marshall(name,t, False, add_comments=add_comments, ns=ns)
        elif isinstance(value, basestring): # do not convert strings or unicodes
            self.add_child(name,value,ns=ns)
        elif value is None: # sent a empty tag?
            self.add_child(name,ns=ns)
        elif value in TYPE_MAP.keys():
            # add commented placeholders for simple tipes (for examples/help only)
            child = self.add_child(name,ns=ns) 
            child.add_comment(TYPE_MAP[value])
        else: # the rest of object types are converted to string 
            # get special serialization function (if any)
            fn = TYPE_MARSHAL_FN.get(type(value),str)
            self.add_child(name,fn(value),ns=ns) 

    def import_node(self, other):
        x = self.__document.importNode(other._element, True)  # deep copy
        self._element.appendChild(x)


if __name__ == "__main__":
    span = SimpleXMLElement('<span><a href="python.org.ar">pyar</a><prueba><i>1</i><float>1.5</float></prueba></span>')
    assert str(span.a)==str(span('a'))==str(span.a(0))=="pyar"
    assert span.a['href']=="python.org.ar"
    assert int(span.prueba.i)==1 and float(span.prueba.float)==1.5
    span1 = SimpleXMLElement('<span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a></span>')
    assert [str(a) for a in span1.a()] == ['google', 'yahoo', 'hotmail']
    span1.add_child('a','altavista')
    span1.b = "ex msn"
    d = {'href':'http://www.bing.com/', 'alt': 'Bing'} 
    span1.b[:] = d
    assert sorted([(k,v) for k,v in span1.b[:]]) == sorted(d.items())
    print span1.as_xml()
    assert 'b' in span1
    span.import_node(span1)
    print span.as_xml()








|

|


|















|






>
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
                child.marshall(name,t, False, add_comments=add_comments, ns=ns)
        elif isinstance(value, basestring): # do not convert strings or unicodes
            self.add_child(name,value,ns=ns)
        elif value is None: # sent a empty tag?
            self.add_child(name,ns=ns)
        elif value in TYPE_MAP.keys():
            # add commented placeholders for simple tipes (for examples/help only)
            child = self.add_child(name,ns=ns)
            child.add_comment(TYPE_MAP[value])
        else: # the rest of object types are converted to string
            # get special serialization function (if any)
            fn = TYPE_MARSHAL_FN.get(type(value),str)
            self.add_child(name,fn(value),ns=ns)

    def import_node(self, other):
        x = self.__document.importNode(other._element, True)  # deep copy
        self._element.appendChild(x)


if __name__ == "__main__":
    span = SimpleXMLElement('<span><a href="python.org.ar">pyar</a><prueba><i>1</i><float>1.5</float></prueba></span>')
    assert str(span.a)==str(span('a'))==str(span.a(0))=="pyar"
    assert span.a['href']=="python.org.ar"
    assert int(span.prueba.i)==1 and float(span.prueba.float)==1.5
    span1 = SimpleXMLElement('<span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a></span>')
    assert [str(a) for a in span1.a()] == ['google', 'yahoo', 'hotmail']
    span1.add_child('a','altavista')
    span1.b = "ex msn"
    d = {'href':'http://www.bing.com/', 'alt': 'Bing'}
    span1.b[:] = d
    assert sorted([(k,v) for k,v in span1.b[:]]) == sorted(d.items())
    print span1.as_xml()
    assert 'b' in span1
    span.import_node(span1)
    print span.as_xml()

Modified gluon/contrib/rss2.py from [16f1766766] to [e94fb7221b].
582
583
584
585
586
587
588

589
               guid=Guid('http://www.web2py.com/'),
               pubDate=datetime.datetime(2007, 11, 14, 10, 30))])
    return dumps(rss)


if __name__ == '__main__':
    print test()









>

582
583
584
585
586
587
588
589
590
               guid=Guid('http://www.web2py.com/'),
               pubDate=datetime.datetime(2007, 11, 14, 10, 30))])
    return dumps(rss)


if __name__ == '__main__':
    print test()


Modified gluon/contrib/shell.py from [cee4aa579b] to [eb2ebe95bd].
260
261
262
263
264
265
266

267
    finally:
        sys.modules['__main__'] = old_main
    return output.getvalue()

if __name__=='__main__':
    history=History()
    while True: print run(history, raw_input('>>> ')).rstrip()









>

260
261
262
263
264
265
266
267
268
    finally:
        sys.modules['__main__'] = old_main
    return output.getvalue()

if __name__=='__main__':
    history=History()
    while True: print run(history, raw_input('>>> ')).rstrip()


Modified gluon/contrib/simplejson/__init__.py from [85545ee92e] to [19ad7e29d6].
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
    import decoder as dec
    import encoder as enc
    import scanner as scan
    c_make_encoder = _import_c_make_encoder()
    if enabled:
        dec.scanstring = dec.c_scanstring or dec.py_scanstring
        enc.c_make_encoder = c_make_encoder
        enc.encode_basestring_ascii = (enc.c_encode_basestring_ascii or 
            enc.py_encode_basestring_ascii)
        scan.make_scanner = scan.c_make_scanner or scan.py_make_scanner
    else:
        dec.scanstring = dec.py_scanstring
        enc.c_make_encoder = None
        enc.encode_basestring_ascii = enc.py_encode_basestring_ascii
        scan.make_scanner = scan.py_make_scanner







|







407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
    import decoder as dec
    import encoder as enc
    import scanner as scan
    c_make_encoder = _import_c_make_encoder()
    if enabled:
        dec.scanstring = dec.c_scanstring or dec.py_scanstring
        enc.c_make_encoder = c_make_encoder
        enc.encode_basestring_ascii = (enc.c_encode_basestring_ascii or
            enc.py_encode_basestring_ascii)
        scan.make_scanner = scan.c_make_scanner or scan.py_make_scanner
    else:
        dec.scanstring = dec.py_scanstring
        enc.c_make_encoder = None
        enc.encode_basestring_ascii = enc.py_encode_basestring_ascii
        scan.make_scanner = scan.py_make_scanner
433
434
435
436
437
438
439

       check_circular=True,
       allow_nan=True,
       indent=None,
       separators=None,
       encoding='utf-8',
       default=None,
   )








>
433
434
435
436
437
438
439
440
       check_circular=True,
       allow_nan=True,
       indent=None,
       separators=None,
       encoding='utf-8',
       default=None,
   )

Modified gluon/contrib/simplejson/decoder.py from [c0be9ced86] to [40f329f3c5].
416
417
418
419
420
421
422


        """
        try:
            obj, end = self.scan_once(s, idx)
        except StopIteration:
            raise JSONDecodeError("No JSON object could be decoded", s, idx)
        return obj, end








>
416
417
418
419
420
421
422
423

        """
        try:
            obj, end = self.scan_once(s, idx)
        except StopIteration:
            raise JSONDecodeError("No JSON object could be decoded", s, idx)
        return obj, end

Modified gluon/contrib/simplejson/encoder.py from [f221e2871e] to [42e8d5e8d4].
496
497
498
499
500
501
502

            o = _default(o)
            for chunk in _iterencode(o, _current_indent_level):
                yield chunk
            if markers is not None:
                del markers[markerid]

    return _iterencode








>
496
497
498
499
500
501
502
503
            o = _default(o)
            for chunk in _iterencode(o, _current_indent_level):
                yield chunk
            if markers is not None:
                del markers[markerid]

    return _iterencode

Modified gluon/contrib/simplejson/ordered_dict.py from [a551f0ccc4] to [8c94ff18c0].
113
114
115
116
117
118
119

        if isinstance(other, OrderedDict):
            return len(self)==len(other) and \
                   all(p==q for p, q in  zip(self.items(), other.items()))
        return dict.__eq__(self, other)

    def __ne__(self, other):
        return not self == other








>
113
114
115
116
117
118
119
120
        if isinstance(other, OrderedDict):
            return len(self)==len(other) and \
                   all(p==q for p, q in  zip(self.items(), other.items()))
        return dict.__eq__(self, other)

    def __ne__(self, other):
        return not self == other

Modified gluon/contrib/simplejson/scanner.py from [cc67bf7550] to [d8f46e6a6a].
72
73
74
75
76
77
78

            return _scan_once(string, idx)
        finally:
            memo.clear()

    return scan_once

make_scanner = c_make_scanner or py_make_scanner








>
72
73
74
75
76
77
78
79
            return _scan_once(string, idx)
        finally:
            memo.clear()

    return scan_once

make_scanner = c_make_scanner or py_make_scanner

Modified gluon/contrib/simplejson/tool.py from [db7eaed84c] to [b47035ef9b].
36
37
38
39
40
41
42

        outfile.write('\n')
    finally:
        infile.close()
        outfile.close()

if __name__ == '__main__':
    main()








>
36
37
38
39
40
41
42
43
        outfile.write('\n')
    finally:
        infile.close()
        outfile.close()

if __name__ == '__main__':
    main()

Added gluon/contrib/simplejsonrpc.py version [c62b500ebf].
Modified gluon/contrib/sms_utils.py from [91ca572846] to [8d65436de3].
106
107
108
109
110
111
112

113
    """
    import re
    if number[0]=='+1': number=number[1:]
    elif number[0]=='+': number=number[3:]
    elif number[:2]=='00': number=number[3:]
    number=re.sub('[^\d]','',number)
    return number+SMSCODES[provider]









>

106
107
108
109
110
111
112
113
114
    """
    import re
    if number[0]=='+1': number=number[1:]
    elif number[0]=='+': number=number[3:]
    elif number[:2]=='00': number=number[3:]
    number=re.sub('[^\d]','',number)
    return number+SMSCODES[provider]


Modified gluon/contrib/spreadsheet.py from [c2702b5142] to [92270cc749].
256
257
258
259
260
261
262

263

if __name__ == '__main__':
    s = Sheet(0, 0)
    s.cell('a', value="2")
    s.cell('b', value="=sin(a)")
    s.cell('c', value="=cos(a)**2+b*b")
    print s['c'].computed_value









>

256
257
258
259
260
261
262
263
264

if __name__ == '__main__':
    s = Sheet(0, 0)
    s.cell('a', value="2")
    s.cell('b', value="=sin(a)")
    s.cell('c', value="=cos(a)**2+b*b")
    print s['c'].computed_value


Modified gluon/contrib/taskbar_widget.py from [72bc51f407] to [3d91432adc].
237
238
239
240
241
242
243

244
        RESTART = 3
        QUIT = 4

    class EnumServerState:

        RUNNING = 0
        STOPPED = 1









>

237
238
239
240
241
242
243
244
245
        RESTART = 3
        QUIT = 4

    class EnumServerState:

        RUNNING = 0
        STOPPED = 1


Modified gluon/contrib/user_agent_parser.py from [bbbb0c1942] to [0c846c8b37].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""
Extract client information from http user agent
The module does not try to detect all capabilities of browser in current form (it can easily be extended though).
Aim is
    * fast
    * very easy to extend
    * reliable enough for practical purposes
    * and assist python web apps to detect clients.
    
Taken from http://pypi.python.org/pypi/httpagentparser (MIT license)
Modified my Ross Peoples for web2py to better support iPhone and iPad.
"""
import sys
from storage import Storage

class DetectorsHub(dict):








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""
Extract client information from http user agent
The module does not try to detect all capabilities of browser in current form (it can easily be extended though).
Aim is
    * fast
    * very easy to extend
    * reliable enough for practical purposes
    * and assist python web apps to detect clients.

Taken from http://pypi.python.org/pypi/httpagentparser (MIT license)
Modified my Ross Peoples for web2py to better support iPhone and iPad.
"""
import sys
from storage import Storage

class DetectorsHub(dict):
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73




74
75
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    name = "" # "to perform match in DetectorsHub object"
    info_type = "override me"
    result_key = "override me"
    order = 10 # 0 is highest
    look_for = "string to look for"
    skip_if_found = [] # strings if present stop processin
    can_register = False

    prefs = Storage() # dict(info_type = [name1, name2], ..)
    version_splitters = ["/", " "]
    _suggested_detectors = None

    def __init__(self):
        if not self.name:
            self.name = self.__class__.__name__
        self.can_register = (self.__class__.__dict__.get('can_register', True))

    def detect(self, agent, result):
        if agent and self.checkWords(agent):
            result[self.info_type] = Storage(name=self.name)




            version = self.getVersion(agent)
            if version:
                result[self.info_type].version = version

            return True
        return False

    def checkWords(self, agent):
        for w in self.skip_if_found:
            if w in agent:
                return False
        if self.look_for:
            return True
        return False

    def getVersion(self, agent):
        # -> version string /None
        vs = self.version_splitters
        return agent.split(self.look_for + vs[0])[-1].split(vs[1])[0].strip()







>












>
>
>
>



>







|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    name = "" # "to perform match in DetectorsHub object"
    info_type = "override me"
    result_key = "override me"
    order = 10 # 0 is highest
    look_for = "string to look for"
    skip_if_found = [] # strings if present stop processin
    can_register = False
    is_mobile = False
    prefs = Storage() # dict(info_type = [name1, name2], ..)
    version_splitters = ["/", " "]
    _suggested_detectors = None

    def __init__(self):
        if not self.name:
            self.name = self.__class__.__name__
        self.can_register = (self.__class__.__dict__.get('can_register', True))

    def detect(self, agent, result):
        if agent and self.checkWords(agent):
            result[self.info_type] = Storage(name=self.name)
            result[self.info_type].is_mobile = self.is_mobile
            if not result.is_mobile:
                result.is_mobile = result[self.info_type].is_mobile
                
            version = self.getVersion(agent)
            if version:
                result[self.info_type].version = version
            
            return True
        return False

    def checkWords(self, agent):
        for w in self.skip_if_found:
            if w in agent:
                return False
        if self.look_for in agent:
            return True
        return False

    def getVersion(self, agent):
        # -> version string /None
        vs = self.version_splitters
        return agent.split(self.look_for + vs[0])[-1].split(vs[1])[0].strip()
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
            return True

    def getVersion(self, agent):
        if "Version/" in agent:
            return agent.split('Version/')[-1].split(' ')[0].strip()
        else:
            # Mobile Safari
            return agent.split('Safari ')[-1].split(' ')[0].strip() 


class Linux(OS):
    look_for = 'Linux'
    prefs = Storage(browser=["Firefox"], 
                    dist=["Ubuntu", "Android"], flavor=None)

    def getVersion(self, agent):
        pass


class Macintosh(OS):







|




|







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
            return True

    def getVersion(self, agent):
        if "Version/" in agent:
            return agent.split('Version/')[-1].split(' ')[0].strip()
        else:
            # Mobile Safari
            return agent.split('Safari ')[-1].split(' ')[0].strip()


class Linux(OS):
    look_for = 'Linux'
    prefs = Storage(browser=["Firefox"],
                    dist=["Ubuntu", "Android"], flavor=None)

    def getVersion(self, agent):
        pass


class Macintosh(OS):
230
231
232
233
234
235
236

237
238
239
240
241
242
243

244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
    prefs = Storage(browser=['Chrome'])
    def getVersion(self, agent):
        vs = self.version_splitters
        return agent.split(self.look_for+vs[0])[-1].split(vs[1])[1].strip()[:-1]

class Android(Dist):
    look_for = 'Android'


    def getVersion(self, agent):
        return agent.split('Android')[-1].split(';')[0].strip()


class iPhone(Dist):
    look_for = 'iPhone'


    def getVersion(self, agent):
        version_end_chars = ['like', ';', ')']
        part = agent.split('CPU OS')[-1].strip()
        for c in version_end_chars:
            if c in part:
                version = 'iOS ' + part.split(c)[0].strip()
                break
        return version.replace('_', '.')
        
class iPad(Dist):
    look_for = 'iPad'


    def getVersion(self, agent):
        version_end_chars = ['like', ';', ')']
        part = agent.split('CPU OS')[-1].strip()
        for c in version_end_chars:
            if c in part:
                version = 'iOS ' + part.split(c)[0].strip()







>







>









|


>







236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    prefs = Storage(browser=['Chrome'])
    def getVersion(self, agent):
        vs = self.version_splitters
        return agent.split(self.look_for+vs[0])[-1].split(vs[1])[1].strip()[:-1]

class Android(Dist):
    look_for = 'Android'
    is_mobile = True

    def getVersion(self, agent):
        return agent.split('Android')[-1].split(';')[0].strip()


class iPhone(Dist):
    look_for = 'iPhone'
    is_mobile = True

    def getVersion(self, agent):
        version_end_chars = ['like', ';', ')']
        part = agent.split('CPU OS')[-1].strip()
        for c in version_end_chars:
            if c in part:
                version = 'iOS ' + part.split(c)[0].strip()
                break
        return version.replace('_', '.')

class iPad(Dist):
    look_for = 'iPad'
    is_mobile = True

    def getVersion(self, agent):
        version_end_chars = ['like', ';', ')']
        part = agent.split('CPU OS')[-1].strip()
        for c in version_end_chars:
            if c in part:
                version = 'iOS ' + part.split(c)[0].strip()
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293


294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
339
            _d_prefs = prefs.get(info_type, [])
            detectors = detectorshub.reorderByPrefs(detectors, _d_prefs)
            if "detector" in locals():
                detector._suggested_detectors = detectors
        else:
            detectors = _suggested_detectors
        for detector in detectors:
            print "detector name: ", detector.name
            if detector.detect(agent, result):
                prefs = detector.prefs
                _suggested_detectors = detector._suggested_detectors
                break
    return result


class Result(Storage):
    def __missing__(self, k):
        return ""




def detect(agent):
    result = Result()
    _suggested_detectors = []
    for info_type in detectorshub:
        detectors = _suggested_detectors or detectorshub[info_type]
        for detector in detectors:
            if detector.detect(agent, result):
                if detector.prefs and not detector._suggested_detectors:
                    _suggested_detectors = detectorshub.reorderByPrefs(
                        detectors, detector.prefs.get(info_type))
                    detector._suggested_detectors = _suggested_detectors
                    break
    return result


def simple_detect(agent):
    """
    -> (os, browser) # tuple of strings
    """
    result = detect(agent)
    os_list = []
    if 'flavor' in result: os_list.append(result['flavor']['name'])
    if 'dist' in result: os_list.append(result['dist']['name'])
    if 'os' in result: os_list.append(result['os']['name'])

    os = os_list and " ".join(os_list) or "Unknown OS"
    os_version = os_list and (result['flavor'] and result['flavor'].get(
            'version')) or (result['dist'] and result['dist'].get('version')) \
            or (result['os'] and result['os'].get('version')) or ""
    browser = 'browser' in result and result['browser']['name'] \
        or 'Unknown Browser'
    browser_version = 'browser' in result \
        and result['browser'].get('version') or ""
    if browser_version:
        browser = " ".join((browser, browser_version))
    if os_version:
        os = " ".join((os, os_version))

    return os, browser


if __name__ == '__main__':
    import time
    import unittest

    data = (







|











>
>














|



|








|
|
|








>
|







284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
            _d_prefs = prefs.get(info_type, [])
            detectors = detectorshub.reorderByPrefs(detectors, _d_prefs)
            if "detector" in locals():
                detector._suggested_detectors = detectors
        else:
            detectors = _suggested_detectors
        for detector in detectors:
            # print "detector name: ", detector.name
            if detector.detect(agent, result):
                prefs = detector.prefs
                _suggested_detectors = detector._suggested_detectors
                break
    return result


class Result(Storage):
    def __missing__(self, k):
        return ""

"""
THIS VERSION OF DETECT CAUSES IndexErrors.

def detect(agent):
    result = Result()
    _suggested_detectors = []
    for info_type in detectorshub:
        detectors = _suggested_detectors or detectorshub[info_type]
        for detector in detectors:
            if detector.detect(agent, result):
                if detector.prefs and not detector._suggested_detectors:
                    _suggested_detectors = detectorshub.reorderByPrefs(
                        detectors, detector.prefs.get(info_type))
                    detector._suggested_detectors = _suggested_detectors
                    break
    return result
"""

def simple_detect(agent):
    """
    -> (os, browser, is_mobile) # tuple of strings
    """
    result = detect(agent)
    os_list = []
    if 'flavor' in result: os_list.append(result['flavor']['name'])
    if 'dist' in result: os_list.append(result['dist']['name'])
    if 'os' in result: os_list.append(result['os']['name'])

    os = os_list and " ".join(os_list) or "Unknown OS"
    os_version = os_list and ('flavor' in result and result['flavor'] and result['flavor'].get(
            'version')) or ('dist' in result and result['dist'] and result['dist'].get('version')) \
            or ('os' in result and result['os'] and result['os'].get('version')) or ""
    browser = 'browser' in result and result['browser']['name'] \
        or 'Unknown Browser'
    browser_version = 'browser' in result \
        and result['browser'].get('version') or ""
    if browser_version:
        browser = " ".join((browser, browser_version))
    if os_version:
        os = " ".join((os, os_version))
    #is_mobile = ('dist' in result and result.dist.is_mobile) or ('os' in result and result.os.is_mobile) or False
    return os, browser, result.is_mobile


if __name__ == '__main__':
    import time
    import unittest

    data = (
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
        ("Opera/9.80 (X11; Linux i686; U; en) Presto/2.9.168 Version/11.50",
         ("Linux", "Opera 9.80"),
         {"os": {"name": "Linux"}, "browser": {"name": "Opera", "version": "9.80"}},),
        ("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060127 Netscape/8.1",
         ("Windows NT 5.1", "Netscape 8.1"),
         {'os': {'name': 'Windows', 'version': 'NT 5.1'}, 'browser': {'name': 'Netscape', 'version': '8.1'}},),
        )
    
    class TestHAP(unittest.TestCase):
        def setUp(self):
            self.harass_repeat = 1000
            self.data = data

        def test_simple_detect(self):
            for agent, simple_res, res in data:







|







373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
        ("Opera/9.80 (X11; Linux i686; U; en) Presto/2.9.168 Version/11.50",
         ("Linux", "Opera 9.80"),
         {"os": {"name": "Linux"}, "browser": {"name": "Opera", "version": "9.80"}},),
        ("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060127 Netscape/8.1",
         ("Windows NT 5.1", "Netscape 8.1"),
         {'os': {'name': 'Windows', 'version': 'NT 5.1'}, 'browser': {'name': 'Netscape', 'version': '8.1'}},),
        )

    class TestHAP(unittest.TestCase):
        def setUp(self):
            self.harass_repeat = 1000
            self.data = data

        def test_simple_detect(self):
            for agent, simple_res, res in data:
388
389
390
391
392
393
394














            print "\nTime taken for %s detecttions: %s" \
                % (no_of_tests, time_taken)
            print "Time taken for single detecttion: ", \
                time_taken / (len(self.data) * self.harass_repeat)

    unittest.main()






















>
>
>
>
>
>
>
>
>
>
>
>
>
>
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
            print "\nTime taken for %s detecttions: %s" \
                % (no_of_tests, time_taken)
            print "Time taken for single detecttion: ", \
                time_taken / (len(self.data) * self.harass_repeat)

    unittest.main()


class mobilize(object): 

    def __init__(self, func): 
        self.func = func 

    def __call__(self):
        from gluon import current 
        user_agent = current.request.user_agent()
        if user_agent.is_mobile: 
            items = current.response.view.split('.')
            items.insert(-1,'mobile')
            current.response.view = '.'.join(items)
        return self.func() 
Modified gluon/custom_import.py from [9bbb533900] to [d331c61dda].
62
63
64
65
66
67
68
69

70
71
72
73



74
75
76
77
78
79
80

    def begin(self):
        """
        Many imports can be made for a single import statement. This method
        help the management of this aspect.
        """

    def __call__(self, name, globals={}, locals={}, fromlist=[], level=-1):

        """
        The import method itself.
        """
        return _STANDARD_PYTHON_IMPORTER(name, globals, locals, fromlist,



                                         level)

    def end(self):
        """
        Needed for clean up.
        """








|
>



|
>
>
>







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

    def begin(self):
        """
        Many imports can be made for a single import statement. This method
        help the management of this aspect.
        """

    def __call__(self, name, globals=None, locals=None,
		 fromlist=None, level=-1):
        """
        The import method itself.
        """
        return _STANDARD_PYTHON_IMPORTER(name,
					 globals,
					 locals,
					 fromlist,
                                         level)

    def end(self):
        """
        Needed for clean up.
        """

93
94
95
96
97
98
99
100

101
102
103
104




105
106
107
108
109
110
111
112
        # Avoid reloading cause by file modifications of reload:
        self._tl = threading.local()
        self._tl._modules_loaded = None

    def begin(self):
        self._tl._modules_loaded = set()

    def __call__(self, name, globals={}, locals={}, fromlist=[], level=-1):

        """
        The import method itself.
        """





        call_begin_end = self._tl._modules_loaded == None
        if call_begin_end:
            self.begin()

	try:
            self._tl.globals = globals
            self._tl.locals = locals
            self._tl.level = level







|
>




>
>
>
>
|







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
        # Avoid reloading cause by file modifications of reload:
        self._tl = threading.local()
        self._tl._modules_loaded = None

    def begin(self):
        self._tl._modules_loaded = set()

    def __call__(self, name, globals=None, locals=None,
		 fromlist=None, level=-1):
        """
        The import method itself.
        """

	globals = globals or {}
	locals = locals or {}
	fromlist = fromlist or []

        call_begin_end = self._tl._modules_loaded is None
        if call_begin_end:
            self.begin()

	try:
            self._tl.globals = globals
            self._tl.locals = locals
            self._tl.level = level
238
239
240
241
242
243
244
245

246
247
248
249




250
251
252
253
254
255
256
        """

        if file_path.startswith(self.__web2py_path_os_path_sep):
            file_path = file_path[self.__web2py_path_os_path_sep_len:]
            return self.__RE_APP_DIR.match(file_path)
        return False

    def __call__(self, name, globals={}, locals={}, fromlist=[], level=-1):

        """
        The import method itself.
        """





        self.begin()
        #try:
        # if not relative and not from applications:
        if not name.startswith(".") and level <= 0 \
                    and not name.startswith("applications.") \
                    and isinstance(globals, dict):
            # Get the name of the file do the import







|
>




>
>
>
>







247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
        """

        if file_path.startswith(self.__web2py_path_os_path_sep):
            file_path = file_path[self.__web2py_path_os_path_sep_len:]
            return self.__RE_APP_DIR.match(file_path)
        return False

    def __call__(self, name, globals=None, locals=None,
		 fromlist=None, level=-1):
        """
        The import method itself.
        """

	globals = globals or {}
	locals = locals or {}
	fromlist = fromlist or []

        self.begin()
        #try:
        # if not relative and not from applications:
        if not name.startswith(".") and level <= 0 \
                    and not name.startswith("applications.") \
                    and isinstance(globals, dict):
            # Get the name of the file do the import
304
305
306
307
308
309
310
311


            prefix += "." + name
        return result

class _Web2pyDateTrackerImporter(_Web2pyImporter, _DateTrackerImporter):
    """
    Like _Web2pyImporter but using a _DateTrackerImporter.
    """











>
>
318
319
320
321
322
323
324
325
326
327
            prefix += "." + name
        return result

class _Web2pyDateTrackerImporter(_Web2pyImporter, _DateTrackerImporter):
    """
    Like _Web2pyImporter but using a _DateTrackerImporter.
    """



Added gluon/custom_import.pyc version [df735202af].
Modified gluon/dal.py from [e194d94214] to [2094d355b9].
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
'db2://DSN=dsn;UID=user;PWD=pass'
'firebird://username:password@hostname/database'
'firebird_embedded://username:password@c://path'
'informix://user:password@server:3050/database'
'informixu://user:password@server:3050/database' # unicode informix
'google:datastore' # for google app engine datastore
'google:sql' # for google app engine with sql (mysql compatible)
'teradata://DSN=dsn;UID=user;PWD=pass' # experimental 

For more info:
help(DAL)
help(Field)
"""

###################################################################################
# this file orly exposes DAL and Field
###################################################################################

__all__ = ['DAL', 'Field']
MAXCHARLENGTH = 512
INFINITY = 2**15 # not quite but reasonable default max char length






import re
import sys
import locale
import os
import types
import cPickle







|











|
|
>
>
>
>
>







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
'db2://DSN=dsn;UID=user;PWD=pass'
'firebird://username:password@hostname/database'
'firebird_embedded://username:password@c://path'
'informix://user:password@server:3050/database'
'informixu://user:password@server:3050/database' # unicode informix
'google:datastore' # for google app engine datastore
'google:sql' # for google app engine with sql (mysql compatible)
'teradata://DSN=dsn;UID=user;PWD=pass' # experimental

For more info:
help(DAL)
help(Field)
"""

###################################################################################
# this file orly exposes DAL and Field
###################################################################################

__all__ = ['DAL', 'Field']

MAXCHARLENGTH = 2**15 # not quite but reasonable default max char length
DEFAULTLENGTH = {'string':512,
                 'password':512,
                 'upload':512,
                 'text':2**15,
                 'blob':2**31}

import re
import sys
import locale
import os
import types
import cPickle
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
sql_locker = threading.RLock()
thread = threading.local()

# internal representation of tables with field
#  <table>.<field>, tables and fields may only be [a-zA-Z0-0_]

regex_dbname = re.compile('^(\w+)(\:\w+)*')
table_field = re.compile('^[\w_]+\.[\w_]+$')
regex_content = re.compile('(?P<table>[\w\-]+)\.(?P<field>[\w\-]+)\.(?P<uuidkey>[\w\-]+)\.(?P<name>\w+)\.\w+$')
regex_cleanup_fn = re.compile('[\'"\s;]+')
string_unpack=re.compile('(?<!\|)\|(?!\|)')
regex_python_keywords = re.compile('^(and|del|from|not|while|as|elif|global|or|with|assert|else|if|pass|yield|break|except|import|print|class|exec|in|raise|continue|finally|is|return|def|for|lambda|try)$')










|







189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
sql_locker = threading.RLock()
thread = threading.local()

# internal representation of tables with field
#  <table>.<field>, tables and fields may only be [a-zA-Z0-0_]

regex_dbname = re.compile('^(\w+)(\:\w+)*')
table_field = re.compile('^([\w_]+)\.([\w_]+)$')
regex_content = re.compile('(?P<table>[\w\-]+)\.(?P<field>[\w\-]+)\.(?P<uuidkey>[\w\-]+)\.(?P<name>\w+)\.\w+$')
regex_cleanup_fn = re.compile('[\'"\s;]+')
string_unpack=re.compile('(?<!\|)\|(?!\|)')
regex_python_keywords = re.compile('^(and|del|from|not|while|as|elif|global|or|with|assert|else|if|pass|yield|break|except|import|print|class|exec|in|raise|continue|finally|is|return|def|for|lambda|try)$')



226
227
228
229
230
231
232

233
234
235
236
237
238
239
        import contrib.pymysql as pymysql
        drivers.append('pymysql')
    except ImportError:
        logger.debug('no pymysql driver')

    try:
        import psycopg2

        drivers.append('PostgreSQL')
    except ImportError:
        logger.debug('no psycopg2 driver')

    try:
        import cx_Oracle
        drivers.append('Oracle')







>







231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
        import contrib.pymysql as pymysql
        drivers.append('pymysql')
    except ImportError:
        logger.debug('no pymysql driver')

    try:
        import psycopg2
        from psycopg2.extensions import adapt as psycopg2_adapt
        drivers.append('PostgreSQL')
    except ImportError:
        logger.debug('no psycopg2 driver')

    try:
        import cx_Oracle
        drivers.append('Oracle')
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

    try:
        import informixdb
        drivers.append('Informix')
        logger.warning('Informix support is experimental')
    except ImportError:
        logger.debug('no informixdb driver')
        
    try:
        import sapdb
        drivers.append('SAPDB')
        logger.warning('SAPDB support is experimental')
    except ImportError:
        logger.debug('no sapdb driver')








|







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

    try:
        import informixdb
        drivers.append('Informix')
        logger.warning('Informix support is experimental')
    except ImportError:
        logger.debug('no informixdb driver')

    try:
        import sapdb
        drivers.append('SAPDB')
        logger.warning('SAPDB support is experimental')
    except ImportError:
        logger.debug('no sapdb driver')

306
307
308
309
310
311
312





313
314
315
316
317
318
319

    try:
        import pymongo
        drivers.append('mongoDB')
    except:
        logger.debug('no mongoDB driver')







if 'google' in drivers:

    is_jdbc = False

    class GAEDecimalProperty(gae.Property):
        """







>
>
>
>
>







312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

    try:
        import pymongo
        drivers.append('mongoDB')
    except:
        logger.debug('no mongoDB driver')

def OR(a,b):
    return a|b

def AND(a,b):
    return a&b

if 'google' in drivers:

    is_jdbc = False

    class GAEDecimalProperty(gae.Property):
        """
352
353
354
355
356
357
358

359
360
361
362
363
364
365
###################################################################################
# class that handles connection pooling (all adapters derived form this one)
###################################################################################

class ConnectionPool(object):

    pools = {}


    @staticmethod
    def set_folder(folder):
        thread.folder = folder

    # ## this allows gluon to commit/rollback all dbs in this thread








>







363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
###################################################################################
# class that handles connection pooling (all adapters derived form this one)
###################################################################################

class ConnectionPool(object):

    pools = {}
    check_active_connection = True

    @staticmethod
    def set_folder(folder):
        thread.folder = folder

    # ## this allows gluon to commit/rollback all dbs in this thread

391
392
393
394
395
396
397
398






399
400

401
402

403
404
405
406
407
408







409
410
411


412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
        else:
            self.folder = thread.folder = ''

        # Creating the folder if it does not exist
        if False and self.folder and not os.path.exists(self.folder):
            os.mkdir(self.folder)

    def pool_connection(self, f):






        if not self.pool_size:
            self.connection = f()

        else:
            uri = self.uri

            sql_locker.acquire()
            if not uri in ConnectionPool.pools:
                ConnectionPool.pools[uri] = []
            if ConnectionPool.pools[uri]:
                self.connection = ConnectionPool.pools[uri].pop()
                sql_locker.release()







            else:
                sql_locker.release()
                self.connection = f()


        if not hasattr(thread,'instances'):
            thread.instances = []
        thread.instances.append(self)


###################################################################################
# this is a generic adapter that does nothing; all others are derived form this one
###################################################################################

class BaseAdapter(ConnectionPool):

    driver = None
    maxcharlength = INFINITY
    commit_on_alter_table = False
    support_distributed_transaction = False
    uploads_in_blob = False
    types = {
        'boolean': 'CHAR(1)',
        'string': 'CHAR(%(length)s)',
        'text': 'TEXT',







|
>
>
>
>
>
>


>


>
|
|
|
|
|
|
>
>
>
>
>
>
>
|
|
|
>
>












|







403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
        else:
            self.folder = thread.folder = ''

        # Creating the folder if it does not exist
        if False and self.folder and not os.path.exists(self.folder):
            os.mkdir(self.folder)

    def pool_connection(self, f, cursor=True):
        """
        this function defines: self.connection and self.cursor (iff cursor is True)
        if self.pool_size>0 it will try pull the connection from the pool
        if the connection is not active (closed by db server) it will loop
        if not self.pool_size or no active connections in pool makes a new one
        """
        if not self.pool_size:
            self.connection = f()
            self.cursor = cursor and self.connection.cursor()
        else:
            uri = self.uri
            while True:
                sql_locker.acquire()
                if not uri in ConnectionPool.pools:
                    ConnectionPool.pools[uri] = []                    
                if ConnectionPool.pools[uri]:
                    self.connection = ConnectionPool.pools[uri].pop()
                    sql_locker.release()
                    self.cursor = cursor and self.connection.cursor()
                    try:
                        if self.cursor and self.check_active_connection:
                            self.execute('SELECT 1;')
                        break
                    except:
                        pass
                else:
                    sql_locker.release()
                    self.connection = f()
                    self.cursor = cursor and self.connection.cursor()
                    break
        if not hasattr(thread,'instances'):
            thread.instances = []
        thread.instances.append(self)


###################################################################################
# this is a generic adapter that does nothing; all others are derived form this one
###################################################################################

class BaseAdapter(ConnectionPool):

    driver = None
    maxcharlength = MAXCHARLENGTH
    commit_on_alter_table = False
    support_distributed_transaction = False
    uploads_in_blob = False
    types = {
        'boolean': 'CHAR(1)',
        'string': 'CHAR(%(length)s)',
        'text': 'TEXT',
441
442
443
444
445
446
447



448
449
450



451
452
453
454
455
456
457
        'id': 'INTEGER PRIMARY KEY AUTOINCREMENT',
        'reference': 'INTEGER REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
        'list:integer': 'TEXT',
        'list:string': 'TEXT',
        'list:reference': 'TEXT',
        }




    def integrity_error(self):
        return self.driver.IntegrityError




    def file_exists(self, filename):
        """
        to be used ONLY for files that on GAE may not be on filesystem
        """
        return os.path.exists(filename)

    def file_open(self, filename, mode='rb', lock=True):







>
>
>



>
>
>







470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
        'id': 'INTEGER PRIMARY KEY AUTOINCREMENT',
        'reference': 'INTEGER REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
        'list:integer': 'TEXT',
        'list:string': 'TEXT',
        'list:reference': 'TEXT',
        }

    def adapt(self,obj):
        return "'%s'" % obj.replace("'", "''")

    def integrity_error(self):
        return self.driver.IntegrityError

    def operational_error(self):
        return self.driver.OperationalError

    def file_exists(self, filename):
        """
        to be used ONLY for files that on GAE may not be on filesystem
        """
        return os.path.exists(filename)

    def file_open(self, filename, mode='rb', lock=True):
794
795
796
797
798
799
800




801
802



803
804
805
806
807
808
809

    def RANDOM(self):
        return 'Random()'

    def NOT_NULL(self,default,field_type):
        return 'NOT NULL DEFAULT %s' % self.represent(default,field_type)





    def COALESCE_ZERO(self,first):
        return 'COALESCE(%s,0)' % self.expand(first)




    def ALLOW_NULL(self):
        return ''

    def SUBSTRING(self,field,parameters):
        return 'SUBSTR(%s,%s,%s)' % (self.expand(field), parameters[0], parameters[1])








>
>
>
>


>
>
>







829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851

    def RANDOM(self):
        return 'Random()'

    def NOT_NULL(self,default,field_type):
        return 'NOT NULL DEFAULT %s' % self.represent(default,field_type)

    def COALESCE(self,first,second):
        expressions = [self.expand(first)]+[self.expand(e) for e in second]
        return 'COALESCE(%s)' % ','.join(expressions)

    def COALESCE_ZERO(self,first):
        return 'COALESCE(%s,0)' % self.expand(first)

    def RAW(self,first):
        return first

    def ALLOW_NULL(self):
        return ''

    def SUBSTRING(self,field,parameters):
        return 'SUBSTR(%s,%s,%s)' % (self.expand(field), parameters[0], parameters[1])

864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
    def OR(self,first,second):
        return '(%s OR %s)' % (self.expand(first),self.expand(second))

    def BELONGS(self,first,second):
        if isinstance(second,str):
            return '(%s IN (%s))' % (self.expand(first),second[:-1])
        elif second==[] or second==():
            return '(0)'
        items =','.join(self.expand(item,first.type) for item in second)
        return '(%s IN (%s))' % (self.expand(first),items)

    def LIKE(self,first,second):
        return '(%s LIKE %s)' % (self.expand(first),self.expand(second,'string'))

    def STARTSWITH(self,first,second):







|







906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
    def OR(self,first,second):
        return '(%s OR %s)' % (self.expand(first),self.expand(second))

    def BELONGS(self,first,second):
        if isinstance(second,str):
            return '(%s IN (%s))' % (self.expand(first),second[:-1])
        elif second==[] or second==():
            return '(1=0)'
        items =','.join(self.expand(item,first.type) for item in second)
        return '(%s IN (%s))' % (self.expand(first),items)

    def LIKE(self,first,second):
        return '(%s LIKE %s)' % (self.expand(first),self.expand(second,'string'))

    def STARTSWITH(self,first,second):
941
942
943
944
945
946
947


948
949
950
951
952
953
954
955
956
        if isinstance(expression,Field):
            return str(expression)
        elif isinstance(expression, (Expression, Query)):
            if not expression.second is None:
                return expression.op(expression.first, expression.second)
            elif not expression.first is None:
                return expression.op(expression.first)


            else:
                return expression.op()
        elif field_type:
            return self.represent(expression,field_type)
        elif isinstance(expression,(list,tuple)):
            return ','.join([self.represent(item,field_type) for item in expression])
        else:
            return str(expression)








>
>

|







983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
        if isinstance(expression,Field):
            return str(expression)
        elif isinstance(expression, (Expression, Query)):
            if not expression.second is None:
                return expression.op(expression.first, expression.second)
            elif not expression.first is None:
                return expression.op(expression.first)
            elif not isinstance(expression.op,str):
                return expression.op()
            else:
                return '(%s)' % expression.op
        elif field_type:
            return self.represent(expression,field_type)
        elif isinstance(expression,(list,tuple)):
            return ','.join([self.represent(item,field_type) for item in expression])
        else:
            return str(expression)

994
995
996
997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016

1017
1018
1019
1020
1021
1022
1023
                self.execute(query)
            table._db.commit()
            logfile.write('success!\n')
        finally:
            logfile.close()

    def _update(self,tablename,query,fields):

        if query:
            sql_w = ' WHERE ' + self.expand(query)
        else:
            sql_w = ''
        sql_v = ','.join(['%s=%s' % (field.name, self.expand(value,field.type)) for (field,value) in fields])
        return 'UPDATE %s SET %s%s;' % (tablename, sql_v, sql_w)

    def update(self,tablename,query,fields):
        sql = self._update(tablename,query,fields)
        self.execute(sql)
        try:
            return self.cursor.rowcount
        except:
            return None

    def _delete(self,tablename, query):

        if query:
            sql_w = ' WHERE ' + self.expand(query)
        else:
            sql_w = ''
        return 'DELETE FROM %s%s;' % (tablename, sql_w)

    def delete(self,tablename,query):







>
















>







1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
                self.execute(query)
            table._db.commit()
            logfile.write('success!\n')
        finally:
            logfile.close()

    def _update(self,tablename,query,fields):
        query = self.filter_tenant(query,[tablename])
        if query:
            sql_w = ' WHERE ' + self.expand(query)
        else:
            sql_w = ''
        sql_v = ','.join(['%s=%s' % (field.name, self.expand(value,field.type)) for (field,value) in fields])
        return 'UPDATE %s SET %s%s;' % (tablename, sql_v, sql_w)

    def update(self,tablename,query,fields):
        sql = self._update(tablename,query,fields)
        self.execute(sql)
        try:
            return self.cursor.rowcount
        except:
            return None

    def _delete(self,tablename, query):
        query = self.filter_tenant(query,[tablename])
        if query:
            sql_w = ' WHERE ' + self.expand(query)
        else:
            sql_w = ''
        return 'DELETE FROM %s%s;' % (tablename, sql_w)

    def delete(self,tablename,query):
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
            rows = list(rows)
        limitby = attributes.get('limitby',None) or (0,)
        rows = self.rowslice(rows,limitby[0],None)
        return self.parse(rows,self._colnames)

    def _count(self,query,distinct=None):
        tablenames = self.tables(query)

        if query:
            sql_w = ' WHERE ' + self.expand(query)
        else:
            sql_w = ''
        sql_t = ','.join(tablenames)
        if distinct:
            if isinstance(distinct,(list,tuple)):
                distinct = xorify(distinct)
            sql_d = self.expand(distinct)
            return 'SELECT count(DISTINCT %s) FROM %s%s' % (sql_d, sql_t, sql_w)
        return 'SELECT count(*) FROM %s%s' % (sql_t, sql_w)

    def count(self,query,distinct=None):
        self.execute(self._count(query,distinct))
        return self.cursor.fetchone()[0]


    def tables(self,query):
        tables = set()
        if isinstance(query, Field):
            tables.add(query.tablename)
        elif isinstance(query, (Expression, Query)):
            if query.first!=None:
                tables = tables.union(self.tables(query.first))
            if query.second!=None:
                tables = tables.union(self.tables(query.second))
        return list(tables)

    def commit(self):
        return self.connection.commit()

    def rollback(self):







>









|
|











|

|







1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
            rows = list(rows)
        limitby = attributes.get('limitby',None) or (0,)
        rows = self.rowslice(rows,limitby[0],None)
        return self.parse(rows,self._colnames)

    def _count(self,query,distinct=None):
        tablenames = self.tables(query)
        query = self.filter_tenant(query,tablenames)
        if query:
            sql_w = ' WHERE ' + self.expand(query)
        else:
            sql_w = ''
        sql_t = ','.join(tablenames)
        if distinct:
            if isinstance(distinct,(list,tuple)):
                distinct = xorify(distinct)
            sql_d = self.expand(distinct)
            return 'SELECT count(DISTINCT %s) FROM %s%s;' % (sql_d, sql_t, sql_w)
        return 'SELECT count(*) FROM %s%s;' % (sql_t, sql_w)

    def count(self,query,distinct=None):
        self.execute(self._count(query,distinct))
        return self.cursor.fetchone()[0]


    def tables(self,query):
        tables = set()
        if isinstance(query, Field):
            tables.add(query.tablename)
        elif isinstance(query, (Expression, Query)):
            if not query.first is None:
                tables = tables.union(self.tables(query.first))
            if not query.second is None:
                tables = tables.union(self.tables(query.second))
        return list(tables)

    def commit(self):
        return self.connection.commit()

    def rollback(self):
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
        if isinstance(obj, (list, tuple)):
            obj = bar_encode(obj)
        if obj is None:
            return 'NULL'
        if obj == '' and not fieldtype[:2] in ['st', 'te', 'pa', 'up']:
            return 'NULL'
        r = self.represent_exceptions(obj,fieldtype)
        if r != None:
            return r
        if fieldtype == 'boolean':
            if obj and not str(obj)[:1].upper() in ['F', '0']:
                return "'T'"
            else:
                return "'F'"
        if fieldtype == 'id' or fieldtype == 'integer':







|







1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
        if isinstance(obj, (list, tuple)):
            obj = bar_encode(obj)
        if obj is None:
            return 'NULL'
        if obj == '' and not fieldtype[:2] in ['st', 'te', 'pa', 'up']:
            return 'NULL'
        r = self.represent_exceptions(obj,fieldtype)
        if not r is None:
            return r
        if fieldtype == 'boolean':
            if obj and not str(obj)[:1].upper() in ['F', '0']:
                return "'T'"
            else:
                return "'F'"
        if fieldtype == 'id' or fieldtype == 'integer':
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
                obj = str(obj)
        if not isinstance(obj,str):
            obj = str(obj)
        try:
            obj.decode(self.db_codec)
        except:
            obj = obj.decode('latin1').encode(self.db_codec)
        return "'%s'" % obj.replace("'", "''")

    def represent_exceptions(self, obj, fieldtype):
        return None

    def lastrowid(self,table):
        return None








|







1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
                obj = str(obj)
        if not isinstance(obj,str):
            obj = str(obj)
        try:
            obj.decode(self.db_codec)
        except:
            obj = obj.decode('latin1').encode(self.db_codec)
        return self.adapt(obj)

    def represent_exceptions(self, obj, fieldtype):
        return None

    def lastrowid(self,table):
        return None

1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459

1460

1461

1462












1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476




1477
1478
1479
1480
1481
1482
1483
1484
                if field_type == 'id':
                    id = colset[field.name]
                    colset.update_record = lambda _ = (colset, table, id), **a: update_record(_, a)
                    colset.delete_record = lambda t = table, i = id: t._db(t._id==i).delete()
                    for (referee_table, referee_name) in \
                            table._referenced_by:
                        s = db[referee_table][referee_name]
                        if not referee_table in colset:
                            # for backward compatibility
                            colset[referee_table] = Set(db, s == id)
                        ### add new feature?
                        ### colset[referee_table+'_by_'+refree_name] = Set(db, s == id)
                    colset['id'] = id
            new_rows.append(new_row)

        rowsobj = Rows(db, new_rows, colnames, rawrows=rows)

        for tablename in virtualtables:

            for item in db[tablename].virtualfields:












                try:
                    rowsobj = rowsobj.setvirtualfields(**{tablename:item})
                except KeyError:
                    # to avoid breaking virtualfields when partial select
                    pass
        return rowsobj

    def filter_tenant(self,query,tablenames):
        fieldname = self.db._request_tenant
        for tablename in tablenames:
            table = self.db[tablename]
            if fieldname in table:
                default = table[fieldname].default
                if default!=None:




                    query = query&(table[fieldname]==default)
        return query

###################################################################################
# List of all the available adapters, they all extend BaseAdapter
###################################################################################

class SQLiteAdapter(BaseAdapter):







|
|
|
<
|


>

>

>
|
>
>
>
>
>
>
>
>
>
>
>
>













|
>
>
>
>
|







1493
1494
1495
1496
1497
1498
1499
1500
1501
1502

1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
                if field_type == 'id':
                    id = colset[field.name]
                    colset.update_record = lambda _ = (colset, table, id), **a: update_record(_, a)
                    colset.delete_record = lambda t = table, i = id: t._db(t._id==i).delete()
                    for (referee_table, referee_name) in \
                            table._referenced_by:
                        s = db[referee_table][referee_name]
                        referee_link = db._referee_name and \
                            db._referee_name % dict(table=referee_table,field=referee_name)
                        if referee_link and not referee_link in colset:

                            colset[referee_link] = Set(db, s == id)
                    colset['id'] = id
            new_rows.append(new_row)

        rowsobj = Rows(db, new_rows, colnames, rawrows=rows)

        for tablename in virtualtables:
            ### new style virtual fields
            table = db[tablename]
            fields_virtual = [(f,v) for (f,v) in table.items() if isinstance(v,FieldVirtual)]
            fields_lazy = [(f,v) for (f,v) in table.items() if isinstance(v,FieldLazy)]
            if fields_virtual or fields_lazy:
                for row in rowsobj.records:
                    box = row[tablename]
                    for f,v in fields_virtual:
                        box[f] = v.f(row)
                    for f,v in fields_lazy:
                        box[f] = (v.handler or VirtualCommand)(v.f,row)

            ### old style virtual fields
            for item in table.virtualfields:
                try:
                    rowsobj = rowsobj.setvirtualfields(**{tablename:item})
                except KeyError:
                    # to avoid breaking virtualfields when partial select
                    pass
        return rowsobj

    def filter_tenant(self,query,tablenames):
        fieldname = self.db._request_tenant
        for tablename in tablenames:
            table = self.db[tablename]
            if fieldname in table:
                default = table[fieldname].default
                if not default is None:
                    newquery = table[fieldname]==default
                    if query is None:
                        query = newquery
                    else:
                        query = query&newquery
        return query

###################################################################################
# List of all the available adapters, they all extend BaseAdapter
###################################################################################

class SQLiteAdapter(BaseAdapter):
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525


1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
            (i, j) = table[lookup]
            return int(s[i:j])
        except:
            return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "sqlite"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        path_encoding = sys.getfilesystemencoding() or locale.getdefaultlocale()[1] or 'utf8'
        if uri.startswith('sqlite:memory'):
            dbpath = ':memory:'
        else:
            dbpath = uri.split('://')[1]
            if dbpath[0] != '/':
                dbpath = os.path.join(self.folder.decode(path_encoding).encode('utf8'),dbpath)
        if not 'check_same_thread' in driver_args:
            driver_args['check_same_thread'] = False


        def connect(dbpath=dbpath, driver_args=driver_args):
            return self.driver.Connection(dbpath, **driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()
        self.connection.create_function('web2py_extract', 2, SQLiteAdapter.web2py_extract)

    def _truncate(self,table,mode = ''):
        tablename = table._tablename
        return ['DELETE FROM %s;' % tablename,
                "DELETE FROM sqlite_sequence WHERE name='%s';" % tablename]

    def lastrowid(self,table):
        return self.cursor.lastrowid


class JDBCSQLiteAdapter(SQLiteAdapter):

    driver = globals().get('zxJDBC',None)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "sqlite"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        path_encoding = sys.getfilesystemencoding() or locale.getdefaultlocale()[1] or 'utf8'
        if uri.startswith('sqlite:memory'):
            dbpath = ':memory:'
        else:
            dbpath = uri.split('://')[1]
            if dbpath[0] != '/':
                dbpath = os.path.join(self.folder.decode(path_encoding).encode('utf8'),dbpath)
        def connect(dbpath=dbpath,driver_args=driver_args):
            return self.driver.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath),**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()
        # FIXME http://www.zentus.com/sqlitejdbc/custom_functions.html for UDFs
        # self.connection.create_function('web2py_extract', 2, SQLiteAdapter.web2py_extract)

    def execute(self,a):
        return self.log_execute(a[:-1])


class MySQLAdapter(BaseAdapter):

    driver = globals().get('pymysql',None)
    maxcharlength = 255
    commit_on_alter_table = True







|
















>
>



<

















|
















<
<



|
|







1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595

1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629


1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
            (i, j) = table[lookup]
            return int(s[i:j])
        except:
            return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "sqlite"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        path_encoding = sys.getfilesystemencoding() or locale.getdefaultlocale()[1] or 'utf8'
        if uri.startswith('sqlite:memory'):
            dbpath = ':memory:'
        else:
            dbpath = uri.split('://')[1]
            if dbpath[0] != '/':
                dbpath = os.path.join(self.folder.decode(path_encoding).encode('utf8'),dbpath)
        if not 'check_same_thread' in driver_args:
            driver_args['check_same_thread'] = False
        if not 'detect_types' in driver_args:
            driver_args['detect_types'] = self.driver.PARSE_DECLTYPES
        def connect(dbpath=dbpath, driver_args=driver_args):
            return self.driver.Connection(dbpath, **driver_args)
        self.pool_connection(connect)

        self.connection.create_function('web2py_extract', 2, SQLiteAdapter.web2py_extract)

    def _truncate(self,table,mode = ''):
        tablename = table._tablename
        return ['DELETE FROM %s;' % tablename,
                "DELETE FROM sqlite_sequence WHERE name='%s';" % tablename]

    def lastrowid(self,table):
        return self.cursor.lastrowid


class JDBCSQLiteAdapter(SQLiteAdapter):

    driver = globals().get('zxJDBC',None)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "sqlite"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        path_encoding = sys.getfilesystemencoding() or locale.getdefaultlocale()[1] or 'utf8'
        if uri.startswith('sqlite:memory'):
            dbpath = ':memory:'
        else:
            dbpath = uri.split('://')[1]
            if dbpath[0] != '/':
                dbpath = os.path.join(self.folder.decode(path_encoding).encode('utf8'),dbpath)
        def connect(dbpath=dbpath,driver_args=driver_args):
            return self.driver.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath),**driver_args)


        # FIXME http://www.zentus.com/sqlitejdbc/custom_functions.html for UDFs
        # self.connection.create_function('web2py_extract', 2, SQLiteAdapter.web2py_extract)

    def execute(self,a):        
        return self.log_execute(a)


class MySQLAdapter(BaseAdapter):

    driver = globals().get('pymysql',None)
    maxcharlength = 255
    commit_on_alter_table = True
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
        self.execute("XA ROLLBACK;")

    def concat_add(self,table):
        return '; ALTER TABLE %s ADD ' % table

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "mysql"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|







1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
        self.execute("XA ROLLBACK;")

    def concat_add(self,table):
        return '; ALTER TABLE %s ADD ' % table

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "mysql"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
                                passwd=credential_decoder(password),
                                host=host,
                                port=port,
                                charset=charset))
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()
        self.execute('SET FOREIGN_KEY_CHECKS=1;')
        self.execute("SET sql_mode='NO_BACKSLASH_ESCAPES';")

    def lastrowid(self,table):
        self.execute('select last_insert_id();')
        return int(self.cursor.fetchone()[0])


class PostgreSQLAdapter(BaseAdapter):

    driver = globals().get('psycopg2',None)

    support_distributed_transaction = True
    types = {







<






<







1720
1721
1722
1723
1724
1725
1726

1727
1728
1729
1730
1731
1732

1733
1734
1735
1736
1737
1738
1739
                                passwd=credential_decoder(password),
                                host=host,
                                port=port,
                                charset=charset))
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)

        self.execute('SET FOREIGN_KEY_CHECKS=1;')
        self.execute("SET sql_mode='NO_BACKSLASH_ESCAPES';")

    def lastrowid(self,table):
        self.execute('select last_insert_id();')
        return int(self.cursor.fetchone()[0])


class PostgreSQLAdapter(BaseAdapter):

    driver = globals().get('psycopg2',None)

    support_distributed_transaction = True
    types = {
1690
1691
1692
1693
1694
1695
1696



1697
1698
1699
1700
1701
1702
1703
        'id': 'SERIAL PRIMARY KEY',
        'reference': 'INTEGER REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
        'list:integer': 'TEXT',
        'list:string': 'TEXT',
        'list:reference': 'TEXT',
        }




    def sequence_name(self,table):
        return '%s_id_Seq' % table

    def RANDOM(self):
        return 'RANDOM()'

    def distributed_transaction_begin(self,key):







>
>
>







1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
        'id': 'SERIAL PRIMARY KEY',
        'reference': 'INTEGER REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s',
        'list:integer': 'TEXT',
        'list:string': 'TEXT',
        'list:reference': 'TEXT',
        }

    def adapt(self,obj):
        return psycopg2_adapt(obj).getquoted()

    def sequence_name(self,table):
        return '%s_id_Seq' % table

    def RANDOM(self):
        return 'RANDOM()'

    def distributed_transaction_begin(self,key):
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
        # self.execute('CREATE SEQUENCE %s;' % table._sequence_name)
        # self.execute("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT NEXTVAL('%s');" \
        #              % (table._tablename, table._fieldname, table._sequence_name))
        self.execute(query)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "postgres"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|







1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
        # self.execute('CREATE SEQUENCE %s;' % table._sequence_name)
        # self.execute("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT NEXTVAL('%s');" \
        #              % (table._tablename, table._fieldname, table._sequence_name))
        self.execute(query)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "postgres"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
            msg = ("dbname='%s' user='%s' host='%s'"
                   "port=%s password='%s'") \
                   % (db, user, host, port, password)
        def connect(msg=msg,driver_args=driver_args):
            return self.driver.connect(msg,**driver_args)
        self.pool_connection(connect)
        self.connection.set_client_encoding('UTF8')
        self.cursor = self.connection.cursor()
        self.execute('BEGIN;')
        self.execute("SET CLIENT_ENCODING TO 'UNICODE';")
        self.execute("SET standard_conforming_strings=on;")

    def lastrowid(self,table):
        self.execute("select currval('%s')" % table._sequence_name)
        return int(self.cursor.fetchone()[0])

    def LIKE(self,first,second):







<
<
<







1820
1821
1822
1823
1824
1825
1826



1827
1828
1829
1830
1831
1832
1833
            msg = ("dbname='%s' user='%s' host='%s'"
                   "port=%s password='%s'") \
                   % (db, user, host, port, password)
        def connect(msg=msg,driver_args=driver_args):
            return self.driver.connect(msg,**driver_args)
        self.pool_connection(connect)
        self.connection.set_client_encoding('UTF8')



        self.execute("SET standard_conforming_strings=on;")

    def lastrowid(self,table):
        self.execute("select currval('%s')" % table._sequence_name)
        return int(self.cursor.fetchone()[0])

    def LIKE(self,first,second):
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
            key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
        return '(%s ILIKE %s)' % (self.expand(first),self.expand(key,'string'))

class JDBCPostgreSQLAdapter(PostgreSQLAdapter):

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "postgres"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|







1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
            key = '%|'+str(second).replace('|','||').replace('%','%%')+'|%'
        return '(%s ILIKE %s)' % (self.expand(first),self.expand(key,'string'))

class JDBCPostgreSQLAdapter(PostgreSQLAdapter):

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "postgres"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
            raise SyntaxError, 'Database name required'
        port = m.group('port') or '5432'
        msg = ('jdbc:postgresql://%s:%s/%s' % (host, port, db), user, password)
        def connect(msg=msg,driver_args=driver_args):
            return self.driver.connect(*msg,**driver_args)
        self.pool_connection(connect)
        self.connection.set_client_encoding('UTF8')
        self.cursor = self.connection.cursor()
        self.execute('BEGIN;')
        self.execute("SET CLIENT_ENCODING TO 'UNICODE';")


class OracleAdapter(BaseAdapter):

    driver = globals().get('cx_Oracle',None)







<







1876
1877
1878
1879
1880
1881
1882

1883
1884
1885
1886
1887
1888
1889
            raise SyntaxError, 'Database name required'
        port = m.group('port') or '5432'
        msg = ('jdbc:postgresql://%s:%s/%s' % (host, port, db), user, password)
        def connect(msg=msg,driver_args=driver_args):
            return self.driver.connect(*msg,**driver_args)
        self.pool_connection(connect)
        self.connection.set_client_encoding('UTF8')

        self.execute('BEGIN;')
        self.execute("SET CLIENT_ENCODING TO 'UNICODE';")


class OracleAdapter(BaseAdapter):

    driver = globals().get('cx_Oracle',None)
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936


1937
1938
1939
1940
1941
1942
1943
1944
            else:
                obj = str(obj)
            return "to_date('%s','yyyy-mm-dd hh24:mi:ss')" % obj
        return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "oracle"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        uri = uri.split('://')[1]
        if not 'threaded' in driver_args:
            driver_args['threaded']=True
        def connect(uri=uri,driver_args=driver_args):
            return self.driver.connect(uri,**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()
        self.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';")
        self.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS';")
    oracle_fix = re.compile("[^']*('[^']*'[^']*)*\:(?P<clob>CLOB\('([^']+|'')*'\))")

    def execute(self, command):
        args = []
        i = 1
        while True:
            m = self.oracle_fix.match(command)
            if not m:
                break
            command = command[:m.start('clob')] + str(i) + command[m.end('clob'):]
            args.append(m.group('clob')[6:-2].replace("''", "'"))
            i += 1


        return self.log_execute(command[:-1], args)

    def create_sequence_and_triggers(self, query, table, **args):
        tablename = table._tablename
        sequence_name = table._sequence_name
        trigger_name = table._trigger_name
        self.execute(query)
        self.execute('CREATE SEQUENCE %s START WITH 1 INCREMENT BY 1 NOMAXVALUE;' % sequence_name)







|













<














>
>
|







1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982

1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
            else:
                obj = str(obj)
            return "to_date('%s','yyyy-mm-dd hh24:mi:ss')" % obj
        return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "oracle"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        uri = uri.split('://')[1]
        if not 'threaded' in driver_args:
            driver_args['threaded']=True
        def connect(uri=uri,driver_args=driver_args):
            return self.driver.connect(uri,**driver_args)
        self.pool_connection(connect)

        self.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';")
        self.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS';")
    oracle_fix = re.compile("[^']*('[^']*'[^']*)*\:(?P<clob>CLOB\('([^']+|'')*'\))")

    def execute(self, command):
        args = []
        i = 1
        while True:
            m = self.oracle_fix.match(command)
            if not m:
                break
            command = command[:m.start('clob')] + str(i) + command[m.end('clob'):]
            args.append(m.group('clob')[6:-2].replace("''", "'"))
            i += 1
        if command[-1:]==';':
            command = command[:-1]
        return self.log_execute(command, args)

    def create_sequence_and_triggers(self, query, table, **args):
        tablename = table._tablename
        sequence_name = table._sequence_name
        trigger_name = table._trigger_name
        self.execute(query)
        self.execute('CREATE SEQUENCE %s START WITH 1 INCREMENT BY 1 NOMAXVALUE;' % sequence_name)
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
            urlargs = ';'.join(['%s=%s' % (ak, av) for (ak, av) in argsdict.items()])
            cnxn = 'SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s;%s' \
                % (host, port, db, user, password, urlargs)
        def connect(cnxn=cnxn,driver_args=driver_args):
            return self.driver.connect(cnxn,**driver_args)
        if not fake_connect:
            self.pool_connection(connect)
            self.cursor = self.connection.cursor()

    def lastrowid(self,table):
        #self.execute('SELECT @@IDENTITY;')
        self.execute('SELECT SCOPE_IDENTITY();')
        return int(self.cursor.fetchone()[0])

    def integrity_error_class(self):







<







2124
2125
2126
2127
2128
2129
2130

2131
2132
2133
2134
2135
2136
2137
            urlargs = ';'.join(['%s=%s' % (ak, av) for (ak, av) in argsdict.items()])
            cnxn = 'SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s;%s' \
                % (host, port, db, user, password, urlargs)
        def connect(cnxn=cnxn,driver_args=driver_args):
            return self.driver.connect(cnxn,**driver_args)
        if not fake_connect:
            self.pool_connection(connect)


    def lastrowid(self,table):
        #self.execute('SELECT @@IDENTITY;')
        self.execute('SELECT SCOPE_IDENTITY();')
        return int(self.cursor.fetchone()[0])

    def integrity_error_class(self):
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182

    def _truncate(self,table,mode = ''):
        return ['DELETE FROM %s;' % table._tablename,
                'SET GENERATOR %s TO 0;' % table._sequence_name]

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "firebird"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|







2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243

    def _truncate(self,table,mode = ''):
        return ['DELETE FROM %s;' % table._tablename,
                'SET GENERATOR %s TO 0;' % table._sequence_name]

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "firebird"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
                                   charset = charset))
        if adapter_args.has_key('driver_name'):
            if adapter_args['driver_name'] == 'kinterbasdb':
                self.driver = kinterbasdb
            elif adapter_args['driver_name'] == 'firebirdsql':
                self.driver = firebirdsql
        else:
            self.driver = kinterbasdb        
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()

    def create_sequence_and_triggers(self, query, table, **args):
        tablename = table._tablename
        sequence_name = table._sequence_name
        trigger_name = table._trigger_name
        self.execute(query)
        self.execute('create generator %s;' % sequence_name)
        self.execute('set generator %s to 0;' % sequence_name)
        self.execute('create trigger %s for %s active before insert position 0 as\nbegin\nif(new.id is null) then\nbegin\nnew.id = gen_id(%s, 1);\nend\nend;' % (trigger_name, tablename, sequence_name))

    def lastrowid(self,table):
        sequence_name = table._sequence_name
        self.execute('SELECT gen_id(%s, 0) FROM rdb$database' % sequence_name)
        return int(self.cursor.fetchone()[0])


class FireBirdEmbeddedAdapter(FireBirdAdapter):

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "firebird"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|



<




















|







2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275

2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
                                   charset = charset))
        if adapter_args.has_key('driver_name'):
            if adapter_args['driver_name'] == 'kinterbasdb':
                self.driver = kinterbasdb
            elif adapter_args['driver_name'] == 'firebirdsql':
                self.driver = firebirdsql
        else:
            self.driver = kinterbasdb
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)


    def create_sequence_and_triggers(self, query, table, **args):
        tablename = table._tablename
        sequence_name = table._sequence_name
        trigger_name = table._trigger_name
        self.execute(query)
        self.execute('create generator %s;' % sequence_name)
        self.execute('set generator %s to 0;' % sequence_name)
        self.execute('create trigger %s for %s active before insert position 0 as\nbegin\nif(new.id is null) then\nbegin\nnew.id = gen_id(%s, 1);\nend\nend;' % (trigger_name, tablename, sequence_name))

    def lastrowid(self,table):
        sequence_name = table._sequence_name
        self.execute('SELECT gen_id(%s, 0) FROM rdb$database' % sequence_name)
        return int(self.cursor.fetchone()[0])


class FireBirdEmbeddedAdapter(FireBirdAdapter):

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "firebird"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
        #    return kinterbasdb.connect(**driver_args)
        if adapter_args.has_key('driver_name'):
            if adapter_args['driver_name'] == 'kinterbasdb':
                self.driver = kinterbasdb
            elif adapter_args['driver_name'] == 'firebirdsql':
                self.driver = firebirdsql
        else:
            self.driver = kinterbasdb        
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()


class InformixAdapter(BaseAdapter):

    driver = globals().get('informixdb',None)

    types = {







|



<







2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338

2339
2340
2341
2342
2343
2344
2345
        #    return kinterbasdb.connect(**driver_args)
        if adapter_args.has_key('driver_name'):
            if adapter_args['driver_name'] == 'kinterbasdb':
                self.driver = kinterbasdb
            elif adapter_args['driver_name'] == 'firebirdsql':
                self.driver = firebirdsql
        else:
            self.driver = kinterbasdb
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)



class InformixAdapter(BaseAdapter):

    driver = globals().get('informixdb',None)

    types = {
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
            else:
                obj = str(obj)
            return "to_date('%s','yyyy-mm-dd hh24:mi:ss')" % obj
        return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "informix"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|







2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
            else:
                obj = str(obj)
            return "to_date('%s','yyyy-mm-dd hh24:mi:ss')" % obj
        return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "informix"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
        user = credential_decoder(user)
        password = credential_decoder(password)
        dsn = '%s@%s' % (db,host)
        driver_args.update(dict(user=user,password=password,autocommit=True))
        def connect(dsn=dsn,driver_args=driver_args):
            return self.driver.connect(dsn,**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()

    def execute(self,command):
        if command[-1:]==';':
            command = command[:-1]
        return self.log_execute(command)

    def lastrowid(self,table):







<







2430
2431
2432
2433
2434
2435
2436

2437
2438
2439
2440
2441
2442
2443
        user = credential_decoder(user)
        password = credential_decoder(password)
        dsn = '%s@%s' % (db,host)
        driver_args.update(dict(user=user,password=password,autocommit=True))
        def connect(dsn=dsn,driver_args=driver_args):
            return self.driver.connect(dsn,**driver_args)
        self.pool_connection(connect)


    def execute(self,command):
        if command[-1:]==';':
            command = command[:-1]
        return self.log_execute(command)

    def lastrowid(self,table):
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
            elif isinstance(obj, datetime.date):
                obj = obj.isoformat()[:10]+'-00.00.00'
            return "'%s'" % obj
        return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "db2"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        cnxn = uri.split('://', 1)[1]
        def connect(cnxn=cnxn,driver_args=driver_args):
            return self.driver.connect(cnxn,**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()

    def execute(self,command):
        if command[-1:]==';':
            command = command[:-1]
        return self.log_execute(command)

    def lastrowid(self,table):







|











<







2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513

2514
2515
2516
2517
2518
2519
2520
            elif isinstance(obj, datetime.date):
                obj = obj.isoformat()[:10]+'-00.00.00'
            return "'%s'" % obj
        return None

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "db2"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        cnxn = uri.split('://', 1)[1]
        def connect(cnxn=cnxn,driver_args=driver_args):
            return self.driver.connect(cnxn,**driver_args)
        self.pool_connection(connect)


    def execute(self,command):
        if command[-1:]==';':
            command = command[:-1]
        return self.log_execute(command)

    def lastrowid(self,table):
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
        'list:string': 'CLOB',
        'list:reference': 'CLOB',
        }


    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "teradata"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        cnxn = uri.split('://', 1)[1]
        def connect(cnxn=cnxn,driver_args=driver_args):
            return self.driver.connect(cnxn,**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()


INGRES_SEQNAME='ii***lineitemsequence' # NOTE invalid database object name
                                       # (ANSI-SQL wants this form of name
                                       # to be a delimited identifier)

class IngresAdapter(BaseAdapter):







|











<







2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570

2571
2572
2573
2574
2575
2576
2577
        'list:string': 'CLOB',
        'list:reference': 'CLOB',
        }


    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "teradata"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
        cnxn = uri.split('://', 1)[1]
        def connect(cnxn=cnxn,driver_args=driver_args):
            return self.driver.connect(cnxn,**driver_args)
        self.pool_connection(connect)



INGRES_SEQNAME='ii***lineitemsequence' # NOTE invalid database object name
                                       # (ANSI-SQL wants this form of name
                                       # to be a delimited identifier)

class IngresAdapter(BaseAdapter):
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
            if lmin:
                # Requires Ingres 9.2+
                sql_o += ' OFFSET %d' % (lmin, )
        return 'SELECT %s %s FROM %s%s%s;' % (sql_s, sql_f, sql_t, sql_w, sql_o)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "ingres"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|







2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
            if lmin:
                # Requires Ingres 9.2+
                sql_o += ' OFFSET %d' % (lmin, )
        return 'SELECT %s %s FROM %s%s%s;' % (sql_s, sql_f, sql_t, sql_w, sql_o)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "ingres"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
        driver_args.update(dict(database=database_name,
                                   vnode=vnode,
                                   servertype=servertype,
                                   trace=trace))
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()

    def create_sequence_and_triggers(self, query, table, **args):
        # post create table auto inc code (if needed)
        # modify table to btree for performance....
        # Older Ingres releases could use rule/trigger like Oracle above.
        if hasattr(table,'_primarykey'):
            modify_tbl_sql = 'modify %s to btree unique on %s' % \







<







2639
2640
2641
2642
2643
2644
2645

2646
2647
2648
2649
2650
2651
2652
        driver_args.update(dict(database=database_name,
                                   vnode=vnode,
                                   servertype=servertype,
                                   trace=trace))
        def connect(driver_args=driver_args):
            return self.driver.connect(**driver_args)
        self.pool_connection(connect)


    def create_sequence_and_triggers(self, query, table, **args):
        # post create table auto inc code (if needed)
        # modify table to btree for performance....
        # Older Ingres releases could use rule/trigger like Oracle above.
        if hasattr(table,'_primarykey'):
            modify_tbl_sql = 'modify %s to btree unique on %s' % \
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
        self.execute('CREATE SEQUENCE %s;' % table._sequence_name)
        self.execute("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT NEXTVAL('%s');" \
                         % (table._tablename, table._id.name, table._sequence_name))
        self.execute(query)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.dbengine = "sapdb"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()







|







2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
        self.execute('CREATE SEQUENCE %s;' % table._sequence_name)
        self.execute("ALTER TABLE %s ALTER COLUMN %s SET DEFAULT NEXTVAL('%s');" \
                         % (table._tablename, table._id.name, table._sequence_name))
        self.execute(query)

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.dbengine = "sapdb"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.find_or_make_work_folder()
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
        if not db:
            raise SyntaxError, 'Database name required'
        def connect(user=user,password=password,database=db,
                    host=host,driver_args=driver_args):
            return self.driver.Connection(user,password,database,
                                          host,**driver_args)
        self.pool_connection(connect)
        # self.connection.set_client_encoding('UTF8')
        self.cursor = self.connection.cursor()

    def lastrowid(self,table):
        self.execute("select %s.NEXTVAL from dual" % table._sequence_name)
        return int(self.cursor.fetchone()[0])

class CubridAdapter(MySQLAdapter):








<
<







2764
2765
2766
2767
2768
2769
2770


2771
2772
2773
2774
2775
2776
2777
        if not db:
            raise SyntaxError, 'Database name required'
        def connect(user=user,password=password,database=db,
                    host=host,driver_args=driver_args):
            return self.driver.Connection(user,password,database,
                                          host,**driver_args)
        self.pool_connection(connect)



    def lastrowid(self,table):
        self.execute("select %s.NEXTVAL from dual" % table._sequence_name)
        return int(self.cursor.fetchone()[0])

class CubridAdapter(MySQLAdapter):

2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771



2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784

2785
2786
2787
2788
2789
2790
2791
        port = int(m.group('port') or '30000')
        charset = m.group('charset') or 'utf8'
        user=credential_decoder(user),
        passwd=credential_decoder(password),
        def connect(host,port,db,user,passwd,driver_args=driver_args):
            return self.driver.connect(host,port,db,user,passwd,**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()
        self.execute('SET FOREIGN_KEY_CHECKS=1;')
        self.execute("SET sql_mode='NO_BACKSLASH_ESCAPES';")


######## GAE MySQL ##########

class DatabaseStoredFile:

    web2py_filesystem = False




    def __init__(self,db,filename,mode):
        if db._adapter.dbengine != 'mysql':
            raise RuntimeError, "only MySQL can store metadata .table files in database for now"
        self.db = db
        self.filename = filename
        self.mode = mode
        if not self.web2py_filesystem:
            self.db.executesql("CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(512), content LONGTEXT, PRIMARY KEY(path) ) ENGINE=InnoDB;")
            DatabaseStoredFile.web2py_filesystem = True
        self.p=0
        self.data = ''
        if mode in ('r','rw','a'):
            query = "SELECT content FROM web2py_filesystem WHERE path='%s'" % filename

            rows = self.db.executesql(query)
            if rows:
                self.data = rows[0][0]
            elif os.path.exists(filename):
                datafile = open(filename, 'r')
                try:
                    self.data = datafile.read()







<










>
>
>












|
>







2807
2808
2809
2810
2811
2812
2813

2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
        port = int(m.group('port') or '30000')
        charset = m.group('charset') or 'utf8'
        user=credential_decoder(user),
        passwd=credential_decoder(password),
        def connect(host,port,db,user,passwd,driver_args=driver_args):
            return self.driver.connect(host,port,db,user,passwd,**driver_args)
        self.pool_connection(connect)

        self.execute('SET FOREIGN_KEY_CHECKS=1;')
        self.execute("SET sql_mode='NO_BACKSLASH_ESCAPES';")


######## GAE MySQL ##########

class DatabaseStoredFile:

    web2py_filesystem = False

    def escape(self,obj):
        return self.db._adapter.esacpe(obj)    

    def __init__(self,db,filename,mode):
        if db._adapter.dbengine != 'mysql':
            raise RuntimeError, "only MySQL can store metadata .table files in database for now"
        self.db = db
        self.filename = filename
        self.mode = mode
        if not self.web2py_filesystem:
            self.db.executesql("CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(512), content LONGTEXT, PRIMARY KEY(path) ) ENGINE=InnoDB;")
            DatabaseStoredFile.web2py_filesystem = True
        self.p=0
        self.data = ''
        if mode in ('r','rw','a'):
            query = "SELECT content FROM web2py_filesystem WHERE path='%s'" \
                % filename
            rows = self.db.executesql(query)
            if rows:
                self.data = rows[0][0]
            elif os.path.exists(filename):
                datafile = open(filename, 'r')
                try:
                    self.data = datafile.read()
2807
2808
2809
2810
2811
2812
2813
2814

2815
2816
2817
2818
2819
2820
2821
2822
2823
2824

2825
2826
2827
2828
2829
2830
2831
            data, self.p = self.data[self.p:], len(self.data)
        return data

    def write(self,data):
        self.data += data

    def close(self):
        self.db.executesql("DELETE FROM web2py_filesystem WHERE path='%s'" % self.filename)

        query = "INSERT INTO web2py_filesystem(path,content) VALUES ('%s','%s')" % \
            (self.filename, self.data.replace("'","''"))
        self.db.executesql(query)
        self.db.commit()

    @staticmethod
    def exists(db,filename):
        if os.path.exists(filename):
            return True
        query = "SELECT path FROM web2py_filesystem WHERE path='%s'" % filename

        if db.executesql(query):
            return True
        return False


class UseDatabaseStoredFile:








|
>
|
|







|
>







2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
            data, self.p = self.data[self.p:], len(self.data)
        return data

    def write(self,data):
        self.data += data

    def close(self):
        self.db.executesql("DELETE FROM web2py_filesystem WHERE path=%s" \
                               % self.adapt(self.filename))
        query = "INSERT INTO web2py_filesystem(path,content) VALUES (%s,%s)"\
            % (self.adapt(self.filename), self.adapt(self.data))
        self.db.executesql(query)
        self.db.commit()

    @staticmethod
    def exists(db,filename):
        if os.path.exists(filename):
            return True
        query = "SELECT path FROM web2py_filesystem WHERE path=%s" \
            % self.adapt(filename)
        if db.executesql(query):
            return True
        return False


class UseDatabaseStoredFile:

2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867

2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
    def file_delete(self,filename):
        query = "DELETE FROM web2py_filesystem WHERE path='%s'" % filename
        self.db.executesql(query)
        self.db.commit()

class GoogleSQLAdapter(UseDatabaseStoredFile,MySQLAdapter):

    def __init__(self, db, uri='google:sql://realm:domain/database', pool_size=0,
                 folder=None, db_codec='UTF-8', check_reserved=None,
                 migrate=True, fake_migrate=False,
                 credential_decoder = lambda x:x, driver_args={},
                    adapter_args={}):

        self.db = db
        self.dbengine = "mysql"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.folder = folder or '$HOME/'+thread.folder.split('/applications/',1)[1]

        m = re.compile('^(?P<instance>.*)/(?P<db>.*)$').match(self.uri[len('google:sql://'):])
        if not m:
            raise SyntaxError, "Invalid URI string in SQLDB: %s" % self._uri
        instance = credential_decoder(m.group('instance'))
        db = credential_decoder(m.group('db'))
        driver_args['instance'] = instance

        if not migrate:
            driver_args['database'] = db
        def connect(driver_args=driver_args):
            return rdbms.connect(**driver_args)
        self.pool_connection(connect)
        self.cursor = self.connection.cursor()
        if migrate:
            # self.execute('DROP DATABASE %s' % db)
            self.execute('CREATE DATABASE IF NOT EXISTS %s' % db)
            self.execute('USE %s' % db)
        self.execute("SET FOREIGN_KEY_CHECKS=1;")
        self.execute("SET sql_mode='NO_BACKSLASH_ESCAPES';")

class NoSQLAdapter(BaseAdapter):







|
|
<

|















>
|




<
|







2899
2900
2901
2902
2903
2904
2905
2906
2907

2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930

2931
2932
2933
2934
2935
2936
2937
2938
    def file_delete(self,filename):
        query = "DELETE FROM web2py_filesystem WHERE path='%s'" % filename
        self.db.executesql(query)
        self.db.commit()

class GoogleSQLAdapter(UseDatabaseStoredFile,MySQLAdapter):

    def __init__(self, db, uri='google:sql://realm:domain/database',
                 pool_size=0, folder=None, db_codec='UTF-8',

                 credential_decoder = lambda x:x, driver_args={},
                 adapter_args={}):

        self.db = db
        self.dbengine = "mysql"
        self.uri = uri
        self.pool_size = pool_size
        self.folder = folder
        self.db_codec = db_codec
        self.folder = folder or '$HOME/'+thread.folder.split('/applications/',1)[1]

        m = re.compile('^(?P<instance>.*)/(?P<db>.*)$').match(self.uri[len('google:sql://'):])
        if not m:
            raise SyntaxError, "Invalid URI string in SQLDB: %s" % self._uri
        instance = credential_decoder(m.group('instance'))
        db = credential_decoder(m.group('db'))
        driver_args['instance'] = instance
        createdb = adapter_args.get('createdb',True)
        if not createdb:
            driver_args['database'] = db
        def connect(driver_args=driver_args):
            return rdbms.connect(**driver_args)
        self.pool_connection(connect)

        if createdb:
            # self.execute('DROP DATABASE %s' % db)
            self.execute('CREATE DATABASE IF NOT EXISTS %s' % db)
            self.execute('USE %s' % db)
        self.execute("SET FOREIGN_KEY_CHECKS=1;")
        self.execute("SET sql_mode='NO_BACKSLASH_ESCAPES';")

class NoSQLAdapter(BaseAdapter):
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
        if fieldtype.startswith('list:'):
            if not obj:
                obj = []
            if not isinstance(obj, (list, tuple)):
                obj = [obj]
        if obj == '' and  not fieldtype[:2] in ['st','te','pa','up']:
            return None
        if obj != None:
            if isinstance(obj, list) and not fieldtype.startswith('list'):
                obj = [self.represent(o, fieldtype) for o in obj]
            elif fieldtype in ('integer','id'):
                obj = long(obj)
            elif fieldtype == 'double':
                obj = float(obj)
            elif fieldtype.startswith('reference'):







|







2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
        if fieldtype.startswith('list:'):
            if not obj:
                obj = []
            if not isinstance(obj, (list, tuple)):
                obj = [obj]
        if obj == '' and  not fieldtype[:2] in ['st','te','pa','up']:
            return None
        if not obj is None:
            if isinstance(obj, list) and not fieldtype.startswith('list'):
                obj = [self.represent(o, fieldtype) for o in obj]
            elif fieldtype in ('integer','id'):
                obj = long(obj)
            elif fieldtype == 'double':
                obj = float(obj)
            elif fieldtype.startswith('reference'):
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056

    def file_exists(self, filename): pass
    def file_open(self, filename, mode='rb', lock=True): pass
    def file_close(self, fileobj, unlock=True): pass

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.types.update({
                'boolean': gae.BooleanProperty,
                'string': (lambda: gae.StringProperty(multiline=True)),
                'text': gae.TextProperty,
                'password': gae.StringProperty,
                'blob': gae.BlobProperty,
                'upload': gae.StringProperty,







|







3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113

    def file_exists(self, filename): pass
    def file_open(self, filename, mode='rb', lock=True): pass
    def file_close(self, fileobj, unlock=True): pass

    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.types.update({
                'boolean': gae.BooleanProperty,
                'string': (lambda: gae.StringProperty(multiline=True)),
                'text': gae.TextProperty,
                'password': gae.StringProperty,
                'blob': gae.BlobProperty,
                'upload': gae.StringProperty,
3224
3225
3226
3227
3228
3229
3230
3231


3232
3233
3234
3235
3236
3237
3238
            raise SyntaxError, "Not suported %s" % first.op.__name__
        first.op = nop
        return self.expand(first)

    def truncate(self,table,mode):
        self.db(table._id > 0).delete()

    def select_raw(self,query,fields=[],attributes={}):


        new_fields = []
        for item in fields:
            if isinstance(item,SQLALL):
                new_fields += item.table
            else:
                new_fields.append(item)
        fields = new_fields







|
>
>







3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
            raise SyntaxError, "Not suported %s" % first.op.__name__
        first.op = nop
        return self.expand(first)

    def truncate(self,table,mode):
        self.db(table._id > 0).delete()

    def select_raw(self,query,fields=None,attributes=None):
        fields = fields or []
        attributes = attributes or {}
        new_fields = []
        for item in fields:
            if isinstance(item,SQLALL):
                new_fields += item.table
            else:
                new_fields.append(item)
        fields = new_fields
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
        if fieldtype=='id':
            return repr(str(int(value)))
        return repr(not isinstance(value,unicode) and value or value.encode('utf8'))

    def __init__(self,db,uri='couchdb://127.0.0.1:5984',
                 pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.uri = uri
        self.dbengine = 'couchdb'
        self.folder = folder
        db['_lastsql'] = ''
        self.db_codec = 'UTF-8'
        self.pool_size = pool_size

        url='http://'+uri[10:]
        def connect(url=url,driver_args=driver_args):
            return couchdb.Server(url,**driver_args)
        self.pool_connection(connect)

    def create_table(self, table, migrate=True, fake_migrate=False, polymodel=None):
        if migrate:
            try:
                self.connection.create(table._tablename)
            except:
                pass







|











|







3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
        if fieldtype=='id':
            return repr(str(int(value)))
        return repr(not isinstance(value,unicode) and value or value.encode('utf8'))

    def __init__(self,db,uri='couchdb://127.0.0.1:5984',
                 pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.uri = uri
        self.dbengine = 'couchdb'
        self.folder = folder
        db['_lastsql'] = ''
        self.db_codec = 'UTF-8'
        self.pool_size = pool_size

        url='http://'+uri[10:]
        def connect(url=url,driver_args=driver_args):
            return couchdb.Server(url,**driver_args)
        self.pool_connection(connect,cursor=False)

    def create_table(self, table, migrate=True, fake_migrate=False, polymodel=None):
        if migrate:
            try:
                self.connection.create(table._tablename)
            except:
                pass
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
                'list:integer': list,
                'list:reference': list,
        }

    def __init__(self,db,uri='mongodb://127.0.0.1:5984/db',
                 pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}):
        self.db = db
        self.uri = uri
        self.dbengine = 'mongodb'
        self.folder = folder
        db['_lastsql'] = ''
        self.db_codec = 'UTF-8'
        self.pool_size = pool_size

        m = re.compile('^(?P<host>[^\:/]+)(\:(?P<port>[0-9]+))?/(?P<db>.+)$').match(self._uri[10:])
        if not m:
            raise SyntaxError, "Invalid URI string in DAL: %s" % self._uri
        host = m.group('host')
        if not host:
            raise SyntaxError, 'mongodb: host name required'
        dbname = m.group('db')
        if not dbname:
            raise SyntaxError, 'mongodb: db name required'
        port = m.group('port') or 27017
        driver_args.update(dict(host=host,port=port))
        def connect(dbname=dbname,driver_args=driver_args):
            return pymongo.Connection(**driver_args)[dbname]
        self.pool_connection(connect)

    def insert(self,table,fields):
        ctable = self.connection[table._tablename]
        values = dict((k,self.represent(v,table[k].type)) for k,v in fields)
        ctable.insert(values)
        return uuid2int(id)








|








|

|










|







3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
                'list:integer': list,
                'list:reference': list,
        }

    def __init__(self,db,uri='mongodb://127.0.0.1:5984/db',
                 pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                 adapter_args={}):
        self.db = db
        self.uri = uri
        self.dbengine = 'mongodb'
        self.folder = folder
        db['_lastsql'] = ''
        self.db_codec = 'UTF-8'
        self.pool_size = pool_size

        m = re.compile('^(?P<host>[^\:/]+)(\:(?P<port>[0-9]+))?/(?P<db>.+)$').match(self.uri[10:])
        if not m:
            raise SyntaxError, "Invalid URI string in DAL: %s" % self.uri
        host = m.group('host')
        if not host:
            raise SyntaxError, 'mongodb: host name required'
        dbname = m.group('db')
        if not dbname:
            raise SyntaxError, 'mongodb: db name required'
        port = m.group('port') or 27017
        driver_args.update(dict(host=host,port=port))
        def connect(dbname=dbname,driver_args=driver_args):
            return pymongo.Connection(**driver_args)[dbname]
        self.pool_connection(connect,cursor=False)

    def insert(self,table,fields):
        ctable = self.connection[table._tablename]
        values = dict((k,self.represent(v,table[k].type)) for k,v in fields)
        ctable.insert(values)
        return uuid2int(id)

3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
        requires.append(validators.IS_TIME())
    elif field_type == 'datetime':
        requires.append(validators.IS_DATETIME())
    elif field.db and field_type.startswith('reference') and \
            field_type.find('.') < 0 and \
            field_type[10:] in field.db.tables:
        referenced = field.db[field_type[10:]]
        def repr_ref(id, r=referenced, f=ff): return f(r, id)
        field.represent = field.represent or repr_ref
        if hasattr(referenced, '_format') and referenced._format:
            requires = validators.IS_IN_DB(field.db,referenced._id,
                                           referenced._format)
            if field.unique:
                requires._and = validators.IS_NOT_IN_DB(field.db,field)
            if field.tablename == field_type[10:]:
                return validators.IS_EMPTY_OR(requires)
            return requires
    elif field.db and field_type.startswith('list:reference') and \
            field_type.find('.') < 0 and \
            field_type[15:] in field.db.tables:
        referenced = field.db[field_type[15:]]
        def list_ref_repr(ids, r=referenced, f=ff):
            if not ids:
                return None
            refs = r._db(r._id.belongs(ids)).select(r._id)
            return (refs and ', '.join(str(f(r,ref.id)) for ref in refs) or '')
        field.represent = field.represent or list_ref_repr
        if hasattr(referenced, '_format') and referenced._format:
            requires = validators.IS_IN_DB(field.db,referenced._id,
                                           referenced._format,multiple=True)
        else:
            requires = validators.IS_IN_DB(field.db,referenced._id,
                                           multiple=True)
        if field.unique:
            requires._and = validators.IS_NOT_IN_DB(field.db,field)
        return requires
    elif field_type.startswith('list:'):
        def repr_list(values): return', '.join(str(v) for v in (values or []))
        field.represent = field.represent or repr_list
    if field.unique:
        requires.insert(0,validators.IS_NOT_IN_DB(field.db,field))
    sff = ['in', 'do', 'da', 'ti', 'de', 'bo']
    if field.notnull and not field_type[:2] in sff:
        requires.insert(0, validators.IS_NOT_EMPTY())
    elif not field.notnull and field_type[:2] in sff and requires:







|













|















|







3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
        requires.append(validators.IS_TIME())
    elif field_type == 'datetime':
        requires.append(validators.IS_DATETIME())
    elif field.db and field_type.startswith('reference') and \
            field_type.find('.') < 0 and \
            field_type[10:] in field.db.tables:
        referenced = field.db[field_type[10:]]
        def repr_ref(id, row=None, r=referenced, f=ff): return f(r, id)
        field.represent = field.represent or repr_ref
        if hasattr(referenced, '_format') and referenced._format:
            requires = validators.IS_IN_DB(field.db,referenced._id,
                                           referenced._format)
            if field.unique:
                requires._and = validators.IS_NOT_IN_DB(field.db,field)
            if field.tablename == field_type[10:]:
                return validators.IS_EMPTY_OR(requires)
            return requires
    elif field.db and field_type.startswith('list:reference') and \
            field_type.find('.') < 0 and \
            field_type[15:] in field.db.tables:
        referenced = field.db[field_type[15:]]
        def list_ref_repr(ids, row=None, r=referenced, f=ff):
            if not ids:
                return None
            refs = r._db(r._id.belongs(ids)).select(r._id)
            return (refs and ', '.join(str(f(r,ref.id)) for ref in refs) or '')
        field.represent = field.represent or list_ref_repr
        if hasattr(referenced, '_format') and referenced._format:
            requires = validators.IS_IN_DB(field.db,referenced._id,
                                           referenced._format,multiple=True)
        else:
            requires = validators.IS_IN_DB(field.db,referenced._id,
                                           multiple=True)
        if field.unique:
            requires._and = validators.IS_NOT_IN_DB(field.db,field)
        return requires
    elif field_type.startswith('list:'):
        def repr_list(values,row=None): return', '.join(str(v) for v in (values or []))
        field.represent = field.represent or repr_list
    if field.unique:
        requires.insert(0,validators.IS_NOT_IN_DB(field.db,field))
    sff = ['in', 'do', 'da', 'ti', 'de', 'bo']
    if field.notnull and not field_type[:2] in sff:
        requires.insert(0, validators.IS_NOT_EMPTY())
    elif not field.notnull and field_type[:2] in sff and requires:
3768
3769
3770
3771
3772
3773
3774

3775
3776





3777
3778
3779
3780
3781
3782
3783
    """
    a dictionary that lets you do d['a'] as well as d.a
    this is only used to store a Row
    """

    def __getitem__(self, key):
        key=str(key)

        if key in self.get('_extra',{}):
            return self._extra[key]





        return dict.__getitem__(self, key)

    def __call__(self,key):
        return self.__getitem__(key)

    def __setitem__(self, key, value):
        dict.__setitem__(self, str(key), value)







>


>
>
>
>
>







3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
    """
    a dictionary that lets you do d['a'] as well as d.a
    this is only used to store a Row
    """

    def __getitem__(self, key):
        key=str(key)
        m = table_field.match(key)
        if key in self.get('_extra',{}):
            return self._extra[key]
        elif m:
            try:
                return dict.__getitem__(self, m.group(1))[m.group(2)]
            except (KeyError,TypeError):
                key = m.group(2)
        return dict.__getitem__(self, key)

    def __call__(self,key):
        return self.__getitem__(key)

    def __setitem__(self, key, value):
        dict.__setitem__(self, str(key), value)
3841
3842
3843
3844
3845
3846
3847









































































































3848
3849
3850
3851
3852
3853
3854
# database and should for RDBMs and some NoSQL databases
################################################################################

class SQLCallableList(list):
    def __call__(self):
        return copy.copy(self)











































































































class DAL(dict):

    """
    an instance of this class represents a database connection

    Example::







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
# database and should for RDBMs and some NoSQL databases
################################################################################

class SQLCallableList(list):
    def __call__(self):
        return copy.copy(self)

def smart_query(fields,text):
    if not isinstance(fields,(list,tuple)):
        fields = [fields]
    new_fields = []
    for field in fields:
        if isinstance(field,Field):
            new_fields.append(field)
        elif isinstance(field,Table):
            for ofield in field:
                new_fields.append(ofield)
        else:
            raise RuntimeError, "fields must be a list of fields"
    field_map = {}
    for field in fields:
        n = field.name.lower()
        if not n in field_map: 
            field_map[n] = field
        n = str(field).lower()
        if not n in field_map:
            field_map[n] = field
    re_constants = re.compile('(\"[^\"]*?\")|(\'[^\']*?\')')
    constants = {}
    i = 0 
    while True:
        m = re_constants.search(text)
        if not m: break
        text = text[:m.start()]+('#%i' % i)+text[m.end():] 
        constants[str(i)] = m.group()[1:-1]
        i+=1
    text = re.sub('\s+',' ',text).lower()
    for a,b in [('&','and'),
                ('|','or'),
                ('~','not'),
                ('==','=='),
                ('<','<'),
                ('>','>'),
                ('<=','<='),
                ('>=','>='),
                ('<>','!='),
                ('=<','<='),
                ('=>','>='),
                ('=','=='),
                (' less or equal than ','<='),
                (' greater or equal than ','>='),
                (' equal or less than ','<='),
                (' equal or greater than ','>='),
                (' less or equal ','<='),
                (' greater or equal ','>='),
                (' equal or less ','<='),
                (' equal or greater ','>='),
                (' not equal to ','!='),
                (' not equal ','!='),
                (' equal to ','=='),
                (' equal ','=='),
                (' equals ','!='),
                (' less than ','<'),
                (' greater than ','>'),
                (' starts with ','startswith'),
                (' ends with ','endswith'),
                (' is ','==')]:            
        if a[0]==' ':
            text = text.replace(' is'+a,' %s ' % b)
        text = text.replace(a,' %s ' % b)
    text = re.sub('\s+',' ',text).lower()
    query = field = neg = op = logic = None
    for item in text.split():
        if field is None:
            if item == 'not':
                neg = True
            elif not neg and not logic and item in ('and','or'):
                logic = item
            elif item in field_map:
                field = field_map[item]                
            else:
                raise RuntimeError, "Invalid syntax"
        elif not field is None and op is None:
            op = item
        elif not op is None:
            if item.startswith('#'):
                if not item[1:] in constants:
                    raise RuntimeError, "Invalid syntax"
                value = constants[item[1:]]
            else:
                value = item
                if op == '==': op = 'like'
            if op == '==': new_query = field==value
            elif op == '<': new_query = field<value
            elif op == '>': new_query = field>value                
            elif op == '<=': new_query = field<=value
            elif op == '>=': new_query = field>=value                
            elif op == 'contains': new_query = field.contains(value)
            elif op == 'like': new_query = field.like(value)
            elif op == 'startswith': new_query = field.startswith(value)
            elif op == 'endswith': new_query = field.endswith(value)
            else: raise RuntimeError, "Invalid operation"
            if neg: new_query = ~new_query                
            if query is None:
                query = new_query
            elif logic == 'and':
                query &= new_query
            elif logic == 'or':
                query |= new_query                
            field = op = neg = logic = None
    return query


class DAL(dict):

    """
    an instance of this class represents a database connection

    Example::
3900
3901
3902
3903
3904
3905
3906
3907

3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
            raise RuntimeError, 'failure to commit distributed transaction'
        else:
            for (i, db) in instances:
                db._adapter.commit_prepared(keys[i])
        return


    def __init__(self, uri='sqlite://dummy.db', pool_size=0, folder=None,

                 db_codec='UTF-8', check_reserved=None,
                 migrate=True, fake_migrate=False,
                 migrate_enabled=True, fake_migrate_all=False,
                 decode_credentials=False, driver_args=None,
                 adapter_args={}, attempts=5, auto_import=False):
        """
        Creates a new Database Abstraction Layer instance.

        Keyword arguments:

        :uri: string that contains information for connecting to a database.
               (default: 'sqlite://dummy.db')







|
>




|







4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
            raise RuntimeError, 'failure to commit distributed transaction'
        else:
            for (i, db) in instances:
                db._adapter.commit_prepared(keys[i])
        return


    def __init__(self, uri='sqlite://dummy.db',
                 pool_size=0, folder=None,
                 db_codec='UTF-8', check_reserved=None,
                 migrate=True, fake_migrate=False,
                 migrate_enabled=True, fake_migrate_all=False,
                 decode_credentials=False, driver_args=None,
                 adapter_args=None, attempts=5, auto_import=False):
        """
        Creates a new Database Abstraction Layer instance.

        Keyword arguments:

        :uri: string that contains information for connecting to a database.
               (default: 'sqlite://dummy.db')
3946
3947
3948
3949
3950
3951
3952

3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967

3968


3969
3970
3971
3972
3973
3974
3975
        self._pool_size = pool_size
        self._db_codec = db_codec
        self._lastsql = ''
        self._timings = []
        self._pending_references = {}
        self._request_tenant = 'request_tenant'
        self._common_fields = []

        if not str(attempts).isdigit() or attempts < 0:
            attempts = 5
        if uri:
            uris = isinstance(uri,(list,tuple)) and uri or [uri]
            error = ''
            connected = False
            for k in range(attempts):
                for uri in uris:
                    try:
                        if is_jdbc and not uri.startswith('jdbc:'):
                            uri = 'jdbc:'+uri
                        self._dbname = regex_dbname.match(uri).group()
                        if not self._dbname in ADAPTERS:
                            raise SyntaxError, "Error in URI '%s' or database not supported" % self._dbname
                        # notice that driver args or {} else driver_args defaults to {} global, not correct

                        args = (self,uri,pool_size,folder,db_codec,credential_decoder,driver_args or {}, adapter_args)


                        self._adapter = ADAPTERS[self._dbname](*args)
                        connected = True
                        break
                    except SyntaxError:
                        raise
                    except Exception, error:
                        sys.stderr.write('DEBUG_c: Exception %r' % ((Exception, error,),))







>














|
>
|
>
>







4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
        self._pool_size = pool_size
        self._db_codec = db_codec
        self._lastsql = ''
        self._timings = []
        self._pending_references = {}
        self._request_tenant = 'request_tenant'
        self._common_fields = []
        self._referee_name = '%(table)s'
        if not str(attempts).isdigit() or attempts < 0:
            attempts = 5
        if uri:
            uris = isinstance(uri,(list,tuple)) and uri or [uri]
            error = ''
            connected = False
            for k in range(attempts):
                for uri in uris:
                    try:
                        if is_jdbc and not uri.startswith('jdbc:'):
                            uri = 'jdbc:'+uri
                        self._dbname = regex_dbname.match(uri).group()
                        if not self._dbname in ADAPTERS:
                            raise SyntaxError, "Error in URI '%s' or database not supported" % self._dbname
                        # notice that driver args or {} else driver_args
                        # defaults to {} global, not correct
                        args = (self,uri,pool_size,folder,
                                db_codec, credential_decoder,
                                driver_args or {}, adapter_args or {})
                        self._adapter = ADAPTERS[self._dbname](*args)
                        connected = True
                        break
                    except SyntaxError:
                        raise
                    except Exception, error:
                        sys.stderr.write('DEBUG_c: Exception %r' % ((Exception, error,),))
4264
4265
4266
4267
4268
4269
4270
4271

4272

4273

4274


4275
4276
4277
4278
4279
4280
4281
            if key not in [
                    'migrate',
                    'primarykey',
                    'fake_migrate',
                    'format',
                    'trigger_name',
                    'sequence_name',
                    'polymodel']:

                raise SyntaxError, 'invalid table "%s" attribute: %s' % (tablename, key)

        migrate = self._migrate_enabled and args.get('migrate',self._migrate)

        fake_migrate = self._fake_migrate_all or args.get('fake_migrate',self._fake_migrate)


        format = args.get('format',None)
        trigger_name = args.get('trigger_name', None)
        sequence_name = args.get('sequence_name', None)
        primarykey=args.get('primarykey',None)
        polymodel=args.get('polymodel',None)
        if not isinstance(tablename,str):
            raise SyntaxError, "missing table name"







|
>
|
>
|
>
|
>
>







4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
            if key not in [
                    'migrate',
                    'primarykey',
                    'fake_migrate',
                    'format',
                    'trigger_name',
                    'sequence_name',
                    'polymodel',
                    'table_class']:
                raise SyntaxError, 'invalid table "%s" attribute: %s' \
                    % (tablename, key)
        migrate = self._migrate_enabled and args.get('migrate',
                                                     self._migrate)
        fake_migrate = self._fake_migrate_all or args.get('fake_migrate',
                                                          self._fake_migrate)
        table_class = args.get('table_class',Table)
        format = args.get('format',None)
        trigger_name = args.get('trigger_name', None)
        sequence_name = args.get('sequence_name', None)
        primarykey=args.get('primarykey',None)
        polymodel=args.get('polymodel',None)
        if not isinstance(tablename,str):
            raise SyntaxError, "missing table name"
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
            raise SyntaxError, 'table already defined: %s' % tablename
        elif self.check_reserved:
            self.check_reserved_keyword(tablename)

        if self._common_fields:
            fields = [f for f in fields] + [f for f in self._common_fields]

        t = self[tablename] = Table(self, tablename, *fields,
                                    **dict(primarykey=primarykey,
                                    trigger_name=trigger_name,
                                    sequence_name=sequence_name))
        # db magic
        if self._uri in (None,'None'):
            return t

        t._create_references()

        if migrate or self._adapter.dbengine=='google:datastore':







|
|
|
|







4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
            raise SyntaxError, 'table already defined: %s' % tablename
        elif self.check_reserved:
            self.check_reserved_keyword(tablename)

        if self._common_fields:
            fields = [f for f in fields] + [f for f in self._common_fields]

        t = self[tablename] = table_class(self, tablename, *fields,
                                          **dict(primarykey=primarykey,
                                                 trigger_name=trigger_name,
                                                 sequence_name=sequence_name))
        # db magic
        if self._uri in (None,'None'):
            return t

        t._create_references()

        if migrate or self._adapter.dbengine=='google:datastore':
4335
4336
4337
4338
4339
4340
4341



4342
4343
4344
4345
4346
4347
4348
            raise SyntaxError, \
                'Object %s exists and cannot be redefined' % key
        self[key] = value

    def __repr__(self):
        return '<DAL ' + dict.__repr__(self) + '>'




    def __call__(self, query=None):
        if isinstance(query,Table):
            query = query._id>0
        elif isinstance(query,Field):
            query = query!=None
        return Set(self, query)








>
>
>







4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
            raise SyntaxError, \
                'Object %s exists and cannot be redefined' % key
        self[key] = value

    def __repr__(self):
        return '<DAL ' + dict.__repr__(self) + '>'

    def smart_query(self,fields,text):
        return Set(self, smart_query(fields,text))

    def __call__(self, query=None):
        if isinstance(query,Table):
            query = query._id>0
        elif isinstance(query,Field):
            query = query!=None
        return Set(self, query)

4405
4406
4407
4408
4409
4410
4411
4412
4413

4414
4415
4416
4417
4418
4419
4420
    def export_to_csv_file(self, ofile, *args, **kwargs):
        for table in self.tables:
            ofile.write('TABLE %s\r\n' % table)
            self(self[table]._id > 0).select().export_to_csv_file(ofile, *args, **kwargs)
            ofile.write('\r\n\r\n')
        ofile.write('END')

    def import_from_csv_file(self, ifile, id_map={}, null='<NULL>',
                             unique='uuid', *args, **kwargs):

        for line in ifile:
            line = line.strip()
            if not line:
                continue
            elif line == 'END':
                return
            elif not line.startswith('TABLE ') or not line[6:] in self.tables:







|

>







4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
    def export_to_csv_file(self, ofile, *args, **kwargs):
        for table in self.tables:
            ofile.write('TABLE %s\r\n' % table)
            self(self[table]._id > 0).select().export_to_csv_file(ofile, *args, **kwargs)
            ofile.write('\r\n\r\n')
        ofile.write('END')

    def import_from_csv_file(self, ifile, id_map=None, null='<NULL>',
                             unique='uuid', *args, **kwargs):
        if id_map is None: id_map={}
        for line in ifile:
            line = line.strip()
            if not line:
                continue
            elif line == 'END':
                return
            elif not line.startswith('TABLE ') or not line[6:] in self.tables:
4450
4451
4452
4453
4454
4455
4456



4457
4458
4459
4460
4461
4462
4463

    def __getattr__(self, key):
        if key == 'id':
            return int(self)
        self.__allocate()
        return self._record.get(key, None)




    def __setattr__(self, key, value):
        if key.startswith('_'):
            int.__setattr__(self, key, value)
            return
        self.__allocate()
        self._record[key] =  value








>
>
>







4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650

    def __getattr__(self, key):
        if key == 'id':
            return int(self)
        self.__allocate()
        return self._record.get(key, None)

    def get(self, key):
        return self.__getattr__(key)

    def __setattr__(self, key, value):
        if key.startswith('_'):
            int.__setattr__(self, key, value)
            return
        self.__allocate()
        self._record[key] =  value

4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
        primarykey = args.get('primarykey', None)
        fieldnames,newfields=set(),[]
        if primarykey:
            if not isinstance(primarykey,list):
                raise SyntaxError, \
                    "primarykey must be a list of fields from table '%s'" \
                    % tablename
            self._primarykey = primarykey            
        elif not [f for f in fields if isinstance(f,Field) and f.type=='id']:
            field = Field('id', 'id')
            newfields.append(field)
            fieldnames.add('id')
            self._id = field
        for field in fields:
            if not isinstance(field, (Field, Table)):







|







4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
        primarykey = args.get('primarykey', None)
        fieldnames,newfields=set(),[]
        if primarykey:
            if not isinstance(primarykey,list):
                raise SyntaxError, \
                    "primarykey must be a list of fields from table '%s'" \
                    % tablename
            self._primarykey = primarykey
        elif not [f for f in fields if isinstance(f,Field) and f.type=='id']:
            field = Field('id', 'id')
            newfields.append(field)
            fieldnames.add('id')
            self._id = field
        for field in fields:
            if not isinstance(field, (Field, Table)):
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606



4607
4608
4609
4610
4611
4612
4613
            for field in fields:
                if isinstance(field, Field) and field.type == 'upload'\
                        and field.uploadfield is True:
                    tmp = field.uploadfield = '%s_blob' % field.name
                    fields.append(self._db.Field(tmp, 'blob', default=''))

        lower_fieldnames = set()
        reserved = dir(Table) + ['fields'] 
        for field in fields:
            if db and db.check_reserved:
                db.check_reserved_keyword(field.name)
            elif field.name in reserved:
                raise SyntaxError, "field name %s not allowed" % field.name

            if field.name.lower() in lower_fieldnames:
                raise SyntaxError, "duplicate field %s in table %s" \
                    % (field.name, tablename)
            else:
                lower_fieldnames.add(field.name.lower())

            self.fields.append(field.name)
            self[field.name] = field
            if field.type == 'id':
                self['id'] = field
            field.tablename = field._tablename = tablename
            field.table = field._table = self
            field.db = field._db = self._db
            if self._db and field.type!='text' and \
                    self._db._adapter.maxcharlength < field.length:
                field.length = self._db._adapter.maxcharlength
            if field.requires == DEFAULT:
                field.requires = sqlhtml_validators(field)
        self.ALL = SQLALL(self)

        if hasattr(self,'_primarykey'):
            for k in self._primarykey:
                if k not in self.fields:
                    raise SyntaxError, \
                        "primarykey must be a list of fields from table '%s " % tablename
                else:
                    self[k].notnull = True




    def _validate(self,**vars):
        errors = Row()
        for key,value in vars.items():
            value,error = self[key].validate(value)
            if error:
                errors[key] = error
        return errors







|



















|














>
>
>







4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
            for field in fields:
                if isinstance(field, Field) and field.type == 'upload'\
                        and field.uploadfield is True:
                    tmp = field.uploadfield = '%s_blob' % field.name
                    fields.append(self._db.Field(tmp, 'blob', default=''))

        lower_fieldnames = set()
        reserved = dir(Table) + ['fields']
        for field in fields:
            if db and db.check_reserved:
                db.check_reserved_keyword(field.name)
            elif field.name in reserved:
                raise SyntaxError, "field name %s not allowed" % field.name

            if field.name.lower() in lower_fieldnames:
                raise SyntaxError, "duplicate field %s in table %s" \
                    % (field.name, tablename)
            else:
                lower_fieldnames.add(field.name.lower())

            self.fields.append(field.name)
            self[field.name] = field
            if field.type == 'id':
                self['id'] = field
            field.tablename = field._tablename = tablename
            field.table = field._table = self
            field.db = field._db = self._db
            if self._db and not field.type in ('text','blob') and \
                    self._db._adapter.maxcharlength < field.length:
                field.length = self._db._adapter.maxcharlength
            if field.requires == DEFAULT:
                field.requires = sqlhtml_validators(field)
        self.ALL = SQLALL(self)

        if hasattr(self,'_primarykey'):
            for k in self._primarykey:
                if k not in self.fields:
                    raise SyntaxError, \
                        "primarykey must be a list of fields from table '%s " % tablename
                else:
                    self[k].notnull = True

    def update(self,*args,**kwargs):
        raise RuntimeError, "Syntax Not Supported"

    def _validate(self,**vars):
        errors = Row()
        for key,value in vars.items():
            value,error = self[key].validate(value)
            if error:
                errors[key] = error
        return errors
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
                if name != 'id':
                    raise SyntaxError, 'Field %s does not belong to the table' % name
            else:
                new_fields.append((self[name],fields[name]))
                new_fields_names.append(name)
        for ofield in self:
            if not ofield.name in new_fields_names:
                if not update and ofield.default!=None:
                    new_fields.append((ofield,ofield.default))
                elif update and ofield.update!=None:
                    new_fields.append((ofield,ofield.update))
        for ofield in self:
            if not ofield.name in new_fields_names and ofield.compute:
                try:
                    new_fields.append((ofield,ofield.compute(Row(fields))))
                except KeyError:
                    pass







|

|







4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
                if name != 'id':
                    raise SyntaxError, 'Field %s does not belong to the table' % name
            else:
                new_fields.append((self[name],fields[name]))
                new_fields_names.append(name)
        for ofield in self:
            if not ofield.name in new_fields_names:
                if not update and not ofield.default is None:
                    new_fields.append((ofield,ofield.default))
                elif update and not ofield.update is None:
                    new_fields.append((ofield,ofield.update))
        for ofield in self:
            if not ofield.name in new_fields_names and ofield.compute:
                try:
                    new_fields.append((ofield,ofield.compute(Row(fields))))
                except KeyError:
                    pass
4843
4844
4845
4846
4847
4848
4849

4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
        colnames = None
        if isinstance(id_map, dict):
            if not self._tablename in id_map:
                id_map[self._tablename] = {}
            id_map_self = id_map[self._tablename]

        def fix(field, value, id_map):

            if value == null:
                value = None
            elif field.type=='blob':
                value = base64.b64decode(value)
            elif field.type=='double':
                if not value.strip():
                    value = None
                else:
                    value = float(value)
            elif field.type=='integer':
                if not value.strip():
                    value = None
                else:
                    value = int(value)
            elif field.type.startswith('list:string'):
                value = bar_decode_string(value)
            elif field.type.startswith('list:reference'):
                ref_table = field.type[10:].strip()
                value = [id_map[ref_table][int(v)] \
                             for v in bar_decode_string(value)]
            elif field.type.startswith('list:'):
                value = bar_decode_integer(value)
            elif id_map and field.type.startswith('reference'):
                try:
                    value = id_map[field.type[9:].strip()][value]







>
















|
|







5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
        colnames = None
        if isinstance(id_map, dict):
            if not self._tablename in id_map:
                id_map[self._tablename] = {}
            id_map_self = id_map[self._tablename]

        def fix(field, value, id_map):
            list_reference_s='list:reference'
            if value == null:
                value = None
            elif field.type=='blob':
                value = base64.b64decode(value)
            elif field.type=='double':
                if not value.strip():
                    value = None
                else:
                    value = float(value)
            elif field.type=='integer':
                if not value.strip():
                    value = None
                else:
                    value = int(value)
            elif field.type.startswith('list:string'):
                value = bar_decode_string(value)
            elif field.type.startswith(list_reference_s):
                ref_table = field.type[len(list_reference_s):].strip()
                value = [id_map[ref_table][int(v)] \
                             for v in bar_decode_string(value)]
            elif field.type.startswith('list:'):
                value = bar_decode_integer(value)
            elif id_map and field.type.startswith('reference'):
                try:
                    value = id_map[field.type[9:].strip()][value]
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
                    record = self._db(query).select().first()
                    if record:
                        record.update_record(**dict(items))
                        new_id = record[self._id.name]
                    else:
                        new_id = self.insert(**dict(items))
                if id_map and cid != []:
                    id_map_self[line[cid]] = new_id

    def with_alias(self, alias):
        return self._db._adapter.alias(self,alias)

    def on(self, query):
        return Expression(self._db,self._db._adapter.ON,self,query)








|







5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
                    record = self._db(query).select().first()
                    if record:
                        record.update_record(**dict(items))
                        new_id = record[self._id.name]
                    else:
                        new_id = self.insert(**dict(items))
                if id_map and cid != []:
                    id_map_self[int(line[cid])] = new_id

    def with_alias(self, alias):
        return self._db._adapter.alias(self,alias)

    def on(self, query):
        return Expression(self._db,self._db._adapter.ON,self,query)

4972
4973
4974
4975
4976
4977
4978



4979
4980
4981
4982
4983
4984
4985
4986
4987

    def hour(self):
        return Expression(self.db, self.db._adapter.EXTRACT, self, 'hour', 'integer')

    def minutes(self):
        return Expression(self.db, self.db._adapter.EXTRACT, self, 'minute', 'integer')




    def coalesce_zero(self):
            return Expression(self.db, self.db._adapter.COALESCE_ZERO, self, None, self.type)

    def seconds(self):
        return Expression(self.db, self.db._adapter.EXTRACT, self, 'second', 'integer')

    def __getslice__(self, start, stop):
        if start < 0:
            pos0 = '(%s - %d)' % (self.len(), abs(start) - 1)







>
>
>

|







5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181

    def hour(self):
        return Expression(self.db, self.db._adapter.EXTRACT, self, 'hour', 'integer')

    def minutes(self):
        return Expression(self.db, self.db._adapter.EXTRACT, self, 'minute', 'integer')

    def coalesce(self,*others):
        return Expression(self.db, self.db._adapter.COALESCE, self, others, self.type)

    def coalesce_zero(self):
        return Expression(self.db, self.db._adapter.COALESCE_ZERO, self, None, self.type)

    def seconds(self):
        return Expression(self.db, self.db._adapter.EXTRACT, self, 'second', 'integer')

    def __getslice__(self, start, stop):
        if start < 0:
            pos0 = '(%s - %d)' % (self.len(), abs(start) - 1)
5062
5063
5064
5065
5066
5067
5068
5069



5070
5071
5072
5073
5074
5075
5076
        return Query(self.db, self.db._adapter.STARTSWITH, self, value)

    def endswith(self, value):
        if not self.type in ('string', 'text'):
            raise SyntaxError, "endswith used with incompatible field type"
        return Query(self.db, self.db._adapter.ENDSWITH, self, value)

    def contains(self, value):



        if not self.type in ('string', 'text') and not self.type.startswith('list:'):
            raise SyntaxError, "contains used with incompatible field type"
        return Query(self.db, self.db._adapter.CONTAINS, self, value)

    def with_alias(self,alias):
        return Expression(self.db,self.db._adapter.AS,self,alias,self.type)








|
>
>
>







5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
        return Query(self.db, self.db._adapter.STARTSWITH, self, value)

    def endswith(self, value):
        if not self.type in ('string', 'text'):
            raise SyntaxError, "endswith used with incompatible field type"
        return Query(self.db, self.db._adapter.ENDSWITH, self, value)

    def contains(self, value, all=False):
        if isinstance(value,(list,tuple)):
            subqueries = [self.contains(str(v).strip()) for v in value if str(v).strip()]
            return reduce(all and AND or OR, subqueries)
        if not self.type in ('string', 'text') and not self.type.startswith('list:'):
            raise SyntaxError, "contains used with incompatible field type"
        return Query(self.db, self.db._adapter.CONTAINS, self, value)

    def with_alias(self,alias):
        return Expression(self.db,self.db._adapter.AS,self,alias,self.type)

5128
5129
5130
5131
5132
5133
5134



5135






5136



5137
5138
5139
5140
5141
5142
5143

    def __getitem__(self, i):
        return None

    def __str__(self):
        return self._class











class Field(Expression):




    """
    an instance of this class represents a database field

    example::

        a = Field(name, 'string', length=32, default=None, required=False,







>
>
>

>
>
>
>
>
>

>
>
>







5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352

    def __getitem__(self, i):
        return None

    def __str__(self):
        return self._class

class FieldVirtual(object):
    def __init__(self,f):
        self.f = f

class FieldLazy(object):
    def __init__(self,f,handler=None):
        self.f = f
        self.handler = handler


class Field(Expression):

    Virtual = FieldVirtual
    Lazy = FieldLazy

    """
    an instance of this class represents a database field

    example::

        a = Field(name, 'string', length=32, default=None, required=False,
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
        required=False,
        requires=DEFAULT,
        ondelete='CASCADE',
        notnull=False,
        unique=False,
        uploadfield=True,
        widget=None,
        label=None,
        comment=None,
        writable=True,
        readable=True,
        update=None,
        authorize=None,
        autodelete=False,
        represent=None,







|







5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
        required=False,
        requires=DEFAULT,
        ondelete='CASCADE',
        notnull=False,
        unique=False,
        uploadfield=True,
        widget=None,
        label=DEFAULT,
        comment=None,
        writable=True,
        readable=True,
        update=None,
        authorize=None,
        autodelete=False,
        represent=None,
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230



5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
        self.name = fieldname = cleanup(fieldname)
        if hasattr(Table,fieldname) or fieldname[0] == '_' or \
                regex_python_keywords.match(fieldname):
            raise SyntaxError, 'Field: invalid field name: %s' % fieldname
        if isinstance(type, Table):
            type = 'reference ' + type._tablename
        self.type = type  # 'string', 'integer'
        self.length = (length is None) and MAXCHARLENGTH or length
        if default==DEFAULT:
            self.default = update or None
        else:
            self.default = default
        self.required = required  # is this field required
        self.ondelete = ondelete.upper()  # this is for reference fields only
        self.notnull = notnull
        self.unique = unique
        self.uploadfield = uploadfield
        self.uploadfolder = uploadfolder
        self.uploadseparate = uploadseparate
        self.widget = widget



        self.label = label or ' '.join(item.capitalize() for item in fieldname.split('_'))
        self.comment = comment
        self.writable = writable
        self.readable = readable
        self.update = update
        self.authorize = authorize
        self.autodelete = autodelete
        if not represent and type in ('list:integer','list:string'):
            represent=lambda x: ', '.join(str(y) for y in x or [])
        self.represent = represent
        self.compute = compute
        self.isattachment = True
        self.custom_store = custom_store
        self.custom_retrieve = custom_retrieve
        self.custom_delete = custom_delete
        if self.label is None:







|












>
>
>
|







|







5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
        self.name = fieldname = cleanup(fieldname)
        if hasattr(Table,fieldname) or fieldname[0] == '_' or \
                regex_python_keywords.match(fieldname):
            raise SyntaxError, 'Field: invalid field name: %s' % fieldname
        if isinstance(type, Table):
            type = 'reference ' + type._tablename
        self.type = type  # 'string', 'integer'
        self.length = (length is None) and DEFAULTLENGTH.get(type,512) or length
        if default==DEFAULT:
            self.default = update or None
        else:
            self.default = default
        self.required = required  # is this field required
        self.ondelete = ondelete.upper()  # this is for reference fields only
        self.notnull = notnull
        self.unique = unique
        self.uploadfield = uploadfield
        self.uploadfolder = uploadfolder
        self.uploadseparate = uploadseparate
        self.widget = widget
        if label == DEFAULT:
            self.label = ' '.join(i.capitalize() for i in fieldname.split('_'))
        else:
            self.label = label or ''
        self.comment = comment
        self.writable = writable
        self.readable = readable
        self.update = update
        self.authorize = authorize
        self.autodelete = autodelete
        if not represent and type in ('list:integer','list:string'):
            represent=lambda x,r=None: ', '.join(str(y) for y in x or [])
        self.represent = represent
        self.compute = compute
        self.isattachment = True
        self.custom_store = custom_store
        self.custom_retrieve = custom_retrieve
        self.custom_delete = custom_delete
        if self.label is None:
5367
5368
5369
5370
5371
5372
5373


5374
5375
5376
5377
5378
5379
5380
    def __str__(self):
        try:
            return '%s.%s' % (self.tablename, self.name)
        except:
            return '<no table>.%s' % self.name




class Query(object):

    """
    a query object necessary to define a set.
    it can be stored or can be passed to DAL.__call__() to obtain a Set

    Example::







>
>







5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
    def __str__(self):
        try:
            return '%s.%s' % (self.tablename, self.name)
        except:
            return '<no table>.%s' % self.name


def raw(s): return Expression(None,s)

class Query(object):

    """
    a query object necessary to define a set.
    it can be stored or can be passed to DAL.__call__() to obtain a Set

    Example::
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
    def __init__(
        self,
        db,
        op,
        first=None,
        second=None,
        ):
        self.db = db
        self.op = op
        self.first = first
        self.second = second

    def __str__(self):
        return self.db._adapter.expand(self)








|







5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
    def __init__(
        self,
        db,
        op,
        first=None,
        second=None,
        ):
        self.db = self._db = db
        self.op = op
        self.first = first
        self.second = second

    def __str__(self):
        return self.db._adapter.expand(self)

5445
5446
5447
5448
5449
5450
5451


5452
5453
5454
5455
5456
5457
5458
        self.db = db
        self._db = db # for backward compatibility
        self.query = query

    def __call__(self, query):
        if isinstance(query,Table):
            query = query._id>0


        elif isinstance(query,Field):
            query = query!=None
        if self.query:
            return Set(self.db, self.query & query)
        else:
            return Set(self.db, query)








>
>







5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
        self.db = db
        self._db = db # for backward compatibility
        self.query = query

    def __call__(self, query):
        if isinstance(query,Table):
            query = query._id>0
        elif isinstance(query,str):
            query = raw(query)
        elif isinstance(query,Field):
            query = query!=None
        if self.query:
            return Set(self.db, self.query & query)
        else:
            return Set(self.db, query)

5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
    def update(self, **update_fields):
        tablename = self.db._adapter.get_table(self.query)
        fields = self.db[tablename]._listify(update_fields,update=True)
        if not fields:
            raise SyntaxError, "No fields to update"
        self.delete_uploaded_files(update_fields)
        return self.db._adapter.update(tablename,self.query,fields)
    
    def validate_and_update(self, **update_fields):
        tablename = self.db._adapter.get_table(self.query)
        response = Row()
        response.errors = self.db[tablename]._validate(**update_fields) 
        fields = self.db[tablename]._listify(update_fields,update=True)
        if not fields:
            raise SyntaxError, "No fields to update"
        self.delete_uploaded_files(update_fields)
        if not response.errors:
            response.updated = self.db._adapter.update(tablename,self.query,fields)
        else:







|



|







5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
    def update(self, **update_fields):
        tablename = self.db._adapter.get_table(self.query)
        fields = self.db[tablename]._listify(update_fields,update=True)
        if not fields:
            raise SyntaxError, "No fields to update"
        self.delete_uploaded_files(update_fields)
        return self.db._adapter.update(tablename,self.query,fields)

    def validate_and_update(self, **update_fields):
        tablename = self.db._adapter.get_table(self.query)
        response = Row()
        response.errors = self.db[tablename]._validate(**update_fields)
        fields = self.db[tablename]._listify(update_fields,update=True)
        if not fields:
            raise SyntaxError, "No fields to update"
        self.delete_uploaded_files(update_fields)
        if not response.errors:
            response.updated = self.db._adapter.update(tablename,self.query,fields)
        else:
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552











5553
5554
5555
5556
5557
5558
5559
                    uploadfolder = field.uploadfolder
                    if not uploadfolder:
                        uploadfolder = os.path.join(self.db._adapter.folder, '..', 'uploads')
                    if field.uploadseparate:
                        items = oldname.split('.')
                        uploadfolder = os.path.join(uploadfolder,
                                                    "%s.%s" % (items[0], items[1]),
                                                    items[2][:2])                
                    oldpath = os.path.join(uploadfolder, oldname)
                    if os.path.exists(oldpath):
                        os.unlink(oldpath)

def update_record(pack, a={}):
    (colset, table, id) = pack
    b = a or dict(colset)
    c = dict([(k,v) for (k,v) in b.items() if k in table.fields and table[k].type!='id'])
    table._db(table._id==id).update(**c)
    for (k, v) in c.items():
        colset[k] = v













class Rows(object):

    """
    A wrapper for the return value of a select. It basically represents a table.
    It has an iterator and each row is represented as a dictionary.
    """







|




|







>
>
>
>
>
>
>
>
>
>
>







5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
                    uploadfolder = field.uploadfolder
                    if not uploadfolder:
                        uploadfolder = os.path.join(self.db._adapter.folder, '..', 'uploads')
                    if field.uploadseparate:
                        items = oldname.split('.')
                        uploadfolder = os.path.join(uploadfolder,
                                                    "%s.%s" % (items[0], items[1]),
                                                    items[2][:2])
                    oldpath = os.path.join(uploadfolder, oldname)
                    if os.path.exists(oldpath):
                        os.unlink(oldpath)

def update_record(pack, a=None):
    (colset, table, id) = pack
    b = a or dict(colset)
    c = dict([(k,v) for (k,v) in b.items() if k in table.fields and table[k].type!='id'])
    table._db(table._id==id).update(**c)
    for (k, v) in c.items():
        colset[k] = v

class VirtualCommand(object):
    def __init__(self,method,row):
        self.method=method
        #self.instance=instance
        self.row=row
    def __call__(self,*args,**kwargs):
        return self.method(self.row,*args,**kwargs)

def lazy_virtualfield(f):
    f.__lazy__ = True
    return f

class Rows(object):

    """
    A wrapper for the return value of a select. It basically represents a table.
    It has an iterator and each row is represented as a dictionary.
    """
5571
5572
5573
5574
5575
5576
5577

















5578
5579
5580
5581
5582
5583
5584
5585
5586
5587

5588
5589
5590
5591





5592
5593
5594
5595
5596
5597
5598
        self.db = db
        self.records = records
        self.colnames = colnames
        self.compact = compact
        self.response = rawrows

    def setvirtualfields(self,**keyed_virtualfields):

















        if not keyed_virtualfields:
            return self
        for row in self.records:
            for (tablename,virtualfields) in keyed_virtualfields.items():
                attributes = dir(virtualfields)
                virtualfields.__dict__.update(row)
                if not tablename in row:
                    box = row[tablename] = Row()
                else:
                    box = row[tablename]

                for attribute in attributes:
                    if attribute[0] != '_':
                        method = getattr(virtualfields,attribute)
                        if hasattr(method,'im_func') and method.im_func.func_code.co_argcount:





                            box[attribute]=method()
        return self

    def __and__(self,other):
        if self.colnames!=other.colnames: raise Exception, 'Cannot & incompatible Rows objects'
        records = self.records+other.records
        return Rows(self.db,records,self.colnames)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





<




>



|
>
>
>
>
>







5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826

5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
        self.db = db
        self.records = records
        self.colnames = colnames
        self.compact = compact
        self.response = rawrows

    def setvirtualfields(self,**keyed_virtualfields):
        """
        db.define_table('x',Field('number','integer'))
        if db(db.x).isempty(): [db.x.insert(number=i) for i in range(10)]

        from gluon.dal import lazy_virtualfield

        class MyVirtualFields(object):
            # normal virtual field (backward compatible, discouraged)
            def normal_shift(self): return self.x.number+1
            # lazy virtual field (because of @staticmethod)
            @lazy_virtualfield
            def lazy_shift(instance,row,delta=4): return row.x.number+delta
        db.x.virtualfields.append(MyVirtualFields())

        for row in db(db.x).select():
            print row.number, row.normal_shift, row.lazy_shift(delta=7)
        """
        if not keyed_virtualfields:
            return self
        for row in self.records:
            for (tablename,virtualfields) in keyed_virtualfields.items():
                attributes = dir(virtualfields)

                if not tablename in row:
                    box = row[tablename] = Row()
                else:
                    box = row[tablename]
                updated = False
                for attribute in attributes:
                    if attribute[0] != '_':
                        method = getattr(virtualfields,attribute)
                        if hasattr(method,'__lazy__'):
                            box[attribute]=VirtualCommand(method,row)
                        elif type(method)==types.MethodType:
                            if not updated:
                                virtualfields.__dict__.update(row)
                                updated = True
                            box[attribute]=method()
        return self

    def __and__(self,other):
        if self.colnames!=other.colnames: raise Exception, 'Cannot & incompatible Rows objects'
        records = self.records+other.records
        return Rows(self.db,records,self.colnames)
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
                else:
                    (t, f) = col.split('.')
                    field = self.db[t][f]
                    if isinstance(record.get(t, None), (Row,dict)):
                        value = record[t][f]
                    else:
                        value = record[f]
                    if field.type=='blob' and value!=None:
                        value = base64.b64encode(value)
                    elif represent and field.represent:
                        value = field.represent(value)
                    row.append(none_exception(value))
            writer.writerow(row)

    def xml(self):







|







6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
                else:
                    (t, f) = col.split('.')
                    field = self.db[t][f]
                    if isinstance(record.get(t, None), (Row,dict)):
                        value = record[t][f]
                    else:
                        value = record[f]
                    if field.type=='blob' and not value is None:
                        value = base64.b64encode(value)
                    elif represent and field.represent:
                        value = field.represent(value)
                    row.append(none_exception(value))
            writer.writerow(row)

    def xml(self):
5804
5805
5806
5807
5808
5809
5810

5811
5812

5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
        if not mode in ['object', 'array']:
            raise SyntaxError, 'Invalid JSON serialization mode: %s' % mode

        def inner_loop(record, col):
            (t, f) = col.split('.')
            res = None
            if not table_field.match(col):

                res = record._extra[col]
            else:

                if isinstance(record.get(t, None), Row):
                    res = record[t][f]
                else:
                    res = record[f]
            if mode == 'object':
                return (f, res)
            else:
                return res

        if mode == 'object':
            items = [dict([inner_loop(record, col) for col in
                     self.colnames]) for record in self]
        else:







>


>





|







6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
        if not mode in ['object', 'array']:
            raise SyntaxError, 'Invalid JSON serialization mode: %s' % mode

        def inner_loop(record, col):
            (t, f) = col.split('.')
            res = None
            if not table_field.match(col):
                key = col
                res = record._extra[col]
            else:
                key = f
                if isinstance(record.get(t, None), Row):
                    res = record[t][f]
                else:
                    res = record[f]
            if mode == 'object':
                return (key, res)
            else:
                return res

        if mode == 'object':
            items = [dict([inner_loop(record, col) for col in
                     self.colnames]) for record in self]
        else:
6054
6055
6056
6057
6058
6059
6060


6061
6062
6063
################################################################################
# run tests
################################################################################

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












>
>



6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
################################################################################
# run tests
################################################################################

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





Added gluon/dal.pyc version [20a5258c74].
Modified gluon/debug.py from [48b9d6a75a] to [08ba1f60b0].
76
77
78
79
80
81
82


83
84
85
    while True:
        data = pipe_out.read()
        if data is None:
            break
        result.append(data)
    logger.info("DEBUG: result %s" % repr(result))
    return ''.join(result)












>
>



76
77
78
79
80
81
82
83
84
85
86
87
    while True:
        data = pipe_out.read()
        if data is None:
            break
        result.append(data)
    logger.info("DEBUG: result %s" % repr(result))
    return ''.join(result)





Modified gluon/decoder.py from [b310fed651] to [b88475c376].
68
69
70
71
72
73
74


75
                    encoding=rest[:rest.find(quote_char)]

    return encoding

def decoder(buffer):
    encoding = autoDetectXMLEncoding(buffer)
    return buffer.decode(encoding).encode('utf8')










>
>

68
69
70
71
72
73
74
75
76
77
                    encoding=rest[:rest.find(quote_char)]

    return encoding

def decoder(buffer):
    encoding = autoDetectXMLEncoding(buffer)
    return buffer.decode(encoding).encode('utf8')



Added gluon/decoder.pyc version [7da62cc626].
Modified gluon/fileutils.py from [e355481567] to [5c9401ac89].
9
10
11
12
13
14
15

16
17
18
19
20
21

22
23
24
25
26
27
28

import storage
import os
import re
import tarfile
import glob
import time

from http import HTTP
from gzip import open as gzopen
from settings import global_settings


__all__ = [

    'read_file',
    'write_file',
    'readlines_file',
    'up',
    'abspath',
    'mktree',
    'listdir',







>






>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

import storage
import os
import re
import tarfile
import glob
import time
import datetime
from http import HTTP
from gzip import open as gzopen
from settings import global_settings


__all__ = [
    'parse_version',
    'read_file',
    'write_file',
    'readlines_file',
    'up',
    'abspath',
    'mktree',
    'listdir',
36
37
38
39
40
41
42








43
44
45
46
47
48
49
    'w2p_pack',
    'w2p_unpack',
    'w2p_pack_plugin',
    'w2p_unpack_plugin',
    'fix_newlines',
    'make_fake_file_like_object',
    ]









def read_file(filename, mode='r'):
    "returns content from filename, making sure to close the file explicitly on exit."
    f = open(filename, mode)
    try:
        return f.read()
    finally:







>
>
>
>
>
>
>
>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    'w2p_pack',
    'w2p_unpack',
    'w2p_pack_plugin',
    'w2p_unpack_plugin',
    'fix_newlines',
    'make_fake_file_like_object',
    ]

def parse_version(version = "Version 1.99.0 (2011-09-19 08:23:26)"):
    re_version = re.compile('[^\d]+ (\d+)\.(\d+)\.(\d+)\s*\((?P<datetime>.+?)\)\s*(?P<type>[a-z]+)?')
    m = re_version.match(version)
    a,b,c = int(m.group(1)),int(m.group(2)),int(m.group(3)),
    s = m.group('type') or 'dev'
    d = datetime.datetime.strptime(m.group('datetime'),'%Y-%m-%d %H:%M:%S')
    return (a,b,c,d,s)

def read_file(filename, mode='r'):
    "returns content from filename, making sure to close the file explicitly on exit."
    f = open(filename, mode)
    try:
        return f.read()
    finally:
380
381
382
383
384
385
386
387


def make_fake_file_like_object():
    class LogFile(object):
        def write(self, value):
            pass
        def close(self):
            pass
    return LogFile()











>
>
390
391
392
393
394
395
396
397
398
399
def make_fake_file_like_object():
    class LogFile(object):
        def write(self, value):
            pass
        def close(self):
            pass
    return LogFile()



Added gluon/fileutils.pyc version [f01ef6af2e].
Modified gluon/globals.py from [60a5318a8f] to [831ab2321b].
70
71
72
73
74
75
76
77
78

79
80
81

82
83
84
85
86
87
88
        self.get_vars = Storage()
        self.post_vars = Storage()
        self.vars = Storage()
        self.folder = None
        self.application = None
        self.function = None
        self.args = List()
        self.extension = None
        self.now = datetime.datetime.now()

        self.is_restful = False
        self.is_https = False
        self.is_local = False


    def compute_uuid(self):
        self.uuid = '%s/%s.%s.%s' % (
            self.application,
            self.client.replace(':', '_'),
            self.now.strftime('%Y-%m-%d.%H-%M-%S'),
            web2py_uuid())







|

>



>







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
        self.get_vars = Storage()
        self.post_vars = Storage()
        self.vars = Storage()
        self.folder = None
        self.application = None
        self.function = None
        self.args = List()
        self.extension = 'html'
        self.now = datetime.datetime.now()
        self.utcnow = datetime.datetime.utcnow()
        self.is_restful = False
        self.is_https = False
        self.is_local = False
        self.global_settings = settings.global_settings

    def compute_uuid(self):
        self.uuid = '%s/%s.%s.%s' % (
            self.application,
            self.client.replace(':', '_'),
            self.now.strftime('%Y-%m-%d.%H-%M-%S'),
            web2py_uuid())
98
99
100
101
102
103
104


105
106
107
108
109
110
111
    def restful(self):
        def wrapper(action,self=self):
            def f(_action=action,_self=self,*a,**b):
                self.is_restful = True
                method = _self.env.request_method
                if len(_self.args) and '.' in _self.args[-1]:
                    _self.args[-1],_self.extension = _self.args[-1].rsplit('.',1)


                if not method in ['GET','POST','DELETE','PUT']:
                    raise HTTP(400,"invalid method")
                rest_action = _action().get(method,None)
                if not rest_action:
                    raise HTTP(400,"method not supported")
                try:
                    return rest_action(*_self.args,**_self.vars)







>
>







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    def restful(self):
        def wrapper(action,self=self):
            def f(_action=action,_self=self,*a,**b):
                self.is_restful = True
                method = _self.env.request_method
                if len(_self.args) and '.' in _self.args[-1]:
                    _self.args[-1],_self.extension = _self.args[-1].rsplit('.',1)
                    current.response.headers['Content-Type'] = \
                        contenttype(_self.extension.lower())
                if not method in ['GET','POST','DELETE','PUT']:
                    raise HTTP(400,"invalid method")
                rest_action = _action().get(method,None)
                if not rest_action:
                    raise HTTP(400,"method not supported")
                try:
                    return rest_action(*_self.args,**_self.vars)
178
179
180
181
182
183
184

















185
186
187
188
189
190
191
            self.body.close()
            (self.body, self.view) = (obody, oview)
        else:
            run_view_in(self._view_environment)
            page = self.body.getvalue()
        return page


















    def stream(
        self,
        stream,
        chunk_size = DEFAULT_CHUNK_SIZE,
        request=None,
        ):
        """







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
            self.body.close()
            (self.body, self.view) = (obody, oview)
        else:
            run_view_in(self._view_environment)
            page = self.body.getvalue()
        return page

    def include_meta(self):
        s = ''
        for key,value in (self.meta or {}).items():
            s += '<meta name="%s" content="%s" />' % (key,xmlescape(value))
        self.write(s,escape=False)

    def include_files(self):
        s = ''
        for k,f in enumerate(self.files or []):
            if not f in self.files[:k]:
                filename = f.lower().split('?')[0]
                if filename.endswith('.css'):
                    s += '<link href="%s" rel="stylesheet" type="text/css" />' % f
                elif filename.endswith('.js'):
                    s += '<script src="%s" type="text/javascript"></script>' % f
        self.write(s,escape=False)
    
    def stream(
        self,
        stream,
        chunk_size = DEFAULT_CHUNK_SIZE,
        request=None,
        ):
        """
Added gluon/globals.pyc version [3c7f502a11].
Modified gluon/highlight.py from [3472f01bc9] to [20997e491b].
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    Do syntax highlighting.
    """

    def __init__(
        self,
        mode,
        link=None,
        styles={},
        ):
        """
        Initialise highlighter:
            mode = language (PYTHON, WEB2PY,C, CPP, HTML, HTML_PLAIN)
        """

        mode = mode.upper()
        if link and link[-1] != '/':
            link = link + '/'
        self.link = link
        self.styles = styles
        self.output = []
        self.span_style = None







|





|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    Do syntax highlighting.
    """

    def __init__(
        self,
        mode,
        link=None,
        styles=None,
        ):
        """
        Initialise highlighter:
            mode = language (PYTHON, WEB2PY,C, CPP, HTML, HTML_PLAIN)
        """
        styles = styles or {}
        mode = mode.upper()
        if link and link[-1] != '/':
            link = link + '/'
        self.link = link
        self.styles = styles
        self.output = []
        self.span_style = None
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
            ('KEYWORD',
             re.compile(r'(def|class|break|continue|del|exec|finally|pass|'
              + r'print|raise|return|try|except|global|assert|lambda|'
              + r'yield|for|while|if|elif|else|and|in|is|not|or|import|'
              + r'from|True|False)(?![a-zA-Z0-9_])'),
             'color:#185369; font-weight: bold'),
            ('WEB2PY',
             re.compile(r'(request|response|session|cache|redirect|local_import|HTTP|TR|XML|URL|BEAUTIFY|A|BODY|BR|B|CAT|CENTER|CODE|DIV|EM|EMBED|FIELDSET|LEGEND|FORM|H1|H2|H3|H4|H5|H6|IFRAME|HEAD|HR|HTML|I|IMG|INPUT|LABEL|LI|LINK|MARKMIN|MENU|META|OBJECT|OL|ON|OPTION|P|PRE|SCRIPT|SELECT|SPAN|STYLE|TABLE|THEAD|TBODY|TFOOT|TAG|TD|TEXTAREA|TH|TITLE|TT|T|UL|XHTML|IS_SLUG|IS_STRONG|IS_LOWER|IS_UPPER|IS_ALPHANUMERIC|IS_DATETIME|IS_DATETIME_IN_RANGE|IS_DATE|IS_DATE_IN_RANGE|IS_DECIMAL_IN_RANGE|IS_EMAIL|IS_EXPR|IS_FLOAT_IN_RANGE|IS_IMAGE|IS_INT_IN_RANGE|IS_IN_SET|IS_IPV4|IS_LIST_OF|IS_LENGTH|IS_MATCH|IS_EQUAL_TO|IS_EMPTY_OR|IS_NULL_OR|IS_NOT_EMPTY|IS_TIME|IS_UPLOAD_FILENAME|IS_URL|CLEANUP|CRYPT|IS_IN_DB|IS_NOT_IN_DB|DAL|Field|SQLFORM|SQLTABLE|xmlescape|embed64)(?![a-zA-Z0-9_])'
             ), 'link:%(link)s;text-decoration:None;color:#FF5C1F;'),
            ('MAGIC', re.compile(r'self|None'),
             'color:#185369; font-weight: bold'),
            ('MULTILINESTRING', re.compile(r'r?u?(\'\'\'|""")'),
             'color: #FF9966'),
            ('STRING', re.compile(r'r?u?\'(.*?)(?<!\\)\'|"(.*?)(?<!\\)"'
             ), 'color: #FF9966'),







|







162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
            ('KEYWORD',
             re.compile(r'(def|class|break|continue|del|exec|finally|pass|'
              + r'print|raise|return|try|except|global|assert|lambda|'
              + r'yield|for|while|if|elif|else|and|in|is|not|or|import|'
              + r'from|True|False)(?![a-zA-Z0-9_])'),
             'color:#185369; font-weight: bold'),
            ('WEB2PY',
             re.compile(r'(request|response|session|cache|redirect|local_import|HTTP|TR|XML|URL|BEAUTIFY|A|BODY|BR|B|CAT|CENTER|CODE|COL|COLGROUP|DIV|EM|EMBED|FIELDSET|LEGEND|FORM|H1|H2|H3|H4|H5|H6|IFRAME|HEAD|HR|HTML|I|IMG|INPUT|LABEL|LI|LINK|MARKMIN|MENU|META|OBJECT|OL|ON|OPTION|P|PRE|SCRIPT|SELECT|SPAN|STYLE|TABLE|THEAD|TBODY|TFOOT|TAG|TD|TEXTAREA|TH|TITLE|TT|T|UL|XHTML|IS_SLUG|IS_STRONG|IS_LOWER|IS_UPPER|IS_ALPHANUMERIC|IS_DATETIME|IS_DATETIME_IN_RANGE|IS_DATE|IS_DATE_IN_RANGE|IS_DECIMAL_IN_RANGE|IS_EMAIL|IS_EXPR|IS_FLOAT_IN_RANGE|IS_IMAGE|IS_INT_IN_RANGE|IS_IN_SET|IS_IPV4|IS_LIST_OF|IS_LENGTH|IS_MATCH|IS_EQUAL_TO|IS_EMPTY_OR|IS_NULL_OR|IS_NOT_EMPTY|IS_TIME|IS_UPLOAD_FILENAME|IS_URL|CLEANUP|CRYPT|IS_IN_DB|IS_NOT_IN_DB|DAL|Field|SQLFORM|SQLTABLE|xmlescape|embed64)(?![a-zA-Z0-9_])'
             ), 'link:%(link)s;text-decoration:None;color:#FF5C1F;'),
            ('MAGIC', re.compile(r'self|None'),
             'color:#185369; font-weight: bold'),
            ('MULTILINESTRING', re.compile(r'r?u?(\'\'\'|""")'),
             'color: #FF9966'),
            ('STRING', re.compile(r'r?u?\'(.*?)(?<!\\)\'|"(.*?)(?<!\\)"'
             ), 'color: #FF9966'),
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259


260
261
262
263
264
265
266
                                Highlighter.all_styles[mode][0](self,
                                    token, match, style
                                     % dict(link=self.link))
                        else:
                            new_mode = \
                                Highlighter.all_styles[mode][0](self,
                                    token, match, style)
                        if new_mode != None:
                            mode = new_mode
                        i += max(1, len(match.group()))
                        break
            else:
                self.change_style(None, None)
                self.output.append(data[i])
                i += 1
        self.change_style(None, None)
        return ''.join(self.output).expandtabs(4)

    def change_style(self, token, style):
        """
        Generate output to change from existing style to another style only.
        """

        if token in self.styles:
            style = self.styles[token]
        if self.span_style != style:
            if style != 'Keep':
                if self.span_style != None:
                    self.output.append('</span>')
                if style != None:
                    self.output.append('<span style="%s">' % style)
                self.span_style = style


def highlight(
    code,
    language,
    link='/examples/globals/vars/',
    counter=1,
    styles={},
    highlight_line=None,
    attributes={},
    ):


    if not 'CODE' in styles:
        code_style = """
        font-size: 11px;
        font-family: Bitstream Vera Sans Mono,monospace;
        background-color: transparent;
        margin: 0;
        padding: 5px;







|



















|

|









|

|

>
>







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
                                Highlighter.all_styles[mode][0](self,
                                    token, match, style
                                     % dict(link=self.link))
                        else:
                            new_mode = \
                                Highlighter.all_styles[mode][0](self,
                                    token, match, style)
                        if not new_mode is None:
                            mode = new_mode
                        i += max(1, len(match.group()))
                        break
            else:
                self.change_style(None, None)
                self.output.append(data[i])
                i += 1
        self.change_style(None, None)
        return ''.join(self.output).expandtabs(4)

    def change_style(self, token, style):
        """
        Generate output to change from existing style to another style only.
        """

        if token in self.styles:
            style = self.styles[token]
        if self.span_style != style:
            if style != 'Keep':
                if not self.span_style is None:
                    self.output.append('</span>')
                if not style is None:
                    self.output.append('<span style="%s">' % style)
                self.span_style = style


def highlight(
    code,
    language,
    link='/examples/globals/vars/',
    counter=1,
    styles=None,
    highlight_line=None,
    attributes=None,
    ):
    styles = styles or {}
    attributes = attributes or {}
    if not 'CODE' in styles:
        code_style = """
        font-size: 11px;
        font-family: Bitstream Vera Sans Mono,monospace;
        background-color: transparent;
        margin: 0;
        padding: 5px;
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334


            linenumbers[lineno] = '<div style="%s">%s</div>' % (linehighlight_style, linenumbers[lineno])

    code = '<br/>'.join(lines)
    numbers = '<br/>'.join(linenumbers)

    items = attributes.items()
    fa = ' '.join([key[1:].lower() for (key, value) in items if key[:1]
                   == '_' and value == None] + ['%s="%s"'
                   % (key[1:].lower(), str(value).replace('"', "'"))
                  for (key, value) in attributes.items() if key[:1]
                   == '_' and value])
    if fa:
        fa = ' ' + fa
    return '<table%s><tr valign="top"><td style="width:40px; text-align: right;"><pre style="%s">%s</pre></td><td><pre style="%s">%s</pre></td></tr></table>'\
         % (fa, linenumbers_style, numbers, code_style, code)


if __name__ == '__main__':
    import sys
    argfp = open(sys.argv[1])
    data = argfp.read()
    argfp.close()
    print '<html><body>' + highlight(data, sys.argv[2])\
         + '</body></html>'










|

















>
>
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
            linenumbers[lineno] = '<div style="%s">%s</div>' % (linehighlight_style, linenumbers[lineno])

    code = '<br/>'.join(lines)
    numbers = '<br/>'.join(linenumbers)

    items = attributes.items()
    fa = ' '.join([key[1:].lower() for (key, value) in items if key[:1]
                   == '_' and value is None] + ['%s="%s"'
                   % (key[1:].lower(), str(value).replace('"', "'"))
                  for (key, value) in attributes.items() if key[:1]
                   == '_' and value])
    if fa:
        fa = ' ' + fa
    return '<table%s><tr valign="top"><td style="width:40px; text-align: right;"><pre style="%s">%s</pre></td><td><pre style="%s">%s</pre></td></tr></table>'\
         % (fa, linenumbers_style, numbers, code_style, code)


if __name__ == '__main__':
    import sys
    argfp = open(sys.argv[1])
    data = argfp.read()
    argfp.close()
    print '<html><body>' + highlight(data, sys.argv[2])\
         + '</body></html>'



Added gluon/highlight.pyc version [7e17a5f9fa].
Modified gluon/html.py from [a67293b7f5] to [87e3a1e282].
42
43
44
45
46
47
48


49
50
51
52
53
54
55
    'BEAUTIFY',
    'BODY',
    'BR',
    'BUTTON',
    'CENTER',
    'CAT',
    'CODE',


    'DIV',
    'EM',
    'EMBED',
    'FIELDSET',
    'FORM',
    'H1',
    'H2',







>
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    'BEAUTIFY',
    'BODY',
    'BR',
    'BUTTON',
    'CENTER',
    'CAT',
    'CODE',
    'COL',
    'COLGROUP',
    'DIV',
    'EM',
    'EMBED',
    'FIELDSET',
    'FORM',
    'H1',
    'H2',
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


def URL(
    a=None,
    c=None,
    f=None,
    r=None,
    args=[],
    vars={},
    anchor='',
    extension=None,
    env=None,
    hmac_key=None,
    hash_vars=True,
    salt=None,
    user_signature=None,
    scheme=None,
    host=None,
    port=None,

    ):
    """
    generate a URL

    example::

        >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'],







|
|










>







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


def URL(
    a=None,
    c=None,
    f=None,
    r=None,
    args=None,
    vars=None,
    anchor='',
    extension=None,
    env=None,
    hmac_key=None,
    hash_vars=True,
    salt=None,
    user_signature=None,
    scheme=None,
    host=None,
    port=None,
    encode_embedded_slash=False,
    ):
    """
    generate a URL

    example::

        >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'],
161
162
163
164
165
166
167
168






169
170
171
172
173
174
175
        '/a/c/f/x/y/z?p=3&p=1&q=2#1'

        >>> str(URL(a='a', c='c', f='f', anchor='1+2'))
        '/a/c/f#1%2B2'

        >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'],
        ...     vars={'p':(1,3), 'q':2}, anchor='1', hmac_key='key'))
        '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=5d06bb8a4a6093dd325da2ee591c35c61afbd3c6#1'







    generates a url '/a/c/f' corresponding to application a, controller c
    and function f. If r=request is passed, a, c, f are set, respectively,
    to r.application, r.controller, r.function.

    The more typical usage is:








|
>
>
>
>
>
>







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
        '/a/c/f/x/y/z?p=3&p=1&q=2#1'

        >>> str(URL(a='a', c='c', f='f', anchor='1+2'))
        '/a/c/f#1%2B2'

        >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'],
        ...     vars={'p':(1,3), 'q':2}, anchor='1', hmac_key='key'))
        '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f#1'

        >>> str(URL(a='a', c='c', f='f', args=['w/x', 'y/z']))
        '/a/c/f/w/x/y/z'

        >>> str(URL(a='a', c='c', f='f', args=['w/x', 'y/z'], encode_embedded_slash=True))
        '/a/c/f/w%2Fx/y%2Fz'

    generates a url '/a/c/f' corresponding to application a, controller c
    and function f. If r=request is passed, a, c, f are set, respectively,
    to r.application, r.controller, r.function.

    The more typical usage is:

230
231
232
233
234
235
236





237



238
239
240
241
242
243
244
    function2 = '%s.%s' % (function,extension or 'html')

    if not (application and controller and function):
        raise SyntaxError, 'not enough information to build the url'

    if not isinstance(args, (list, tuple)):
        args = [args]





    other = args and urllib.quote('/' + '/'.join([str(x) for x in args])) or ''



    if other.endswith('/'):
        other += '/'    # add trailing slash to make last trailing empty arg explicit

    if vars.has_key('_signature'): vars.pop('_signature')
    list_vars = []
    for (key, vals) in sorted(vars.items()):
        if not isinstance(vals, (list, tuple)):







>
>
>
>
>
|
>
>
>







239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
    function2 = '%s.%s' % (function,extension or 'html')

    if not (application and controller and function):
        raise SyntaxError, 'not enough information to build the url'

    if not isinstance(args, (list, tuple)):
        args = [args]

    if args:
        if encode_embedded_slash:
            other = '/' + '/'.join([urllib.quote(str(x), '') for x in args])
        else:
            other = args and urllib.quote('/' + '/'.join([str(x) for x in args]))
    else:
        other = ''

    if other.endswith('/'):
        other += '/'    # add trailing slash to make last trailing empty arg explicit

    if vars.has_key('_signature'): vars.pop('_signature')
    list_vars = []
    for (key, vals) in sorted(vars.items()):
        if not isinstance(vals, (list, tuple)):
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
            if hash_vars and not isinstance(hash_vars, (list, tuple)):
                hash_vars = [hash_vars]
            h_vars = [(k, v) for (k, v) in list_vars if k in hash_vars]

        # re-assembling the same way during hash authentication
        message = h_args + '?' + urllib.urlencode(sorted(h_vars))

        sig = hmac_hash(message,hmac_key,salt=salt)
        # add the signature into vars
        list_vars.append(('_signature', sig))

    if list_vars:
        other += '?%s' % urllib.urlencode(list_vars)
    if anchor:
        other += '#' + urllib.quote(str(anchor))







|







283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
            if hash_vars and not isinstance(hash_vars, (list, tuple)):
                hash_vars = [hash_vars]
            h_vars = [(k, v) for (k, v) in list_vars if k in hash_vars]

        # re-assembling the same way during hash authentication
        message = h_args + '?' + urllib.urlencode(sorted(h_vars))

        sig = hmac_hash(message, hmac_key, digest_alg='sha1', salt=salt)
        # add the signature into vars
        list_vars.append(('_signature', sig))

    if list_vars:
        other += '?%s' % urllib.urlencode(list_vars)
    if anchor:
        other += '#' + urllib.quote(str(anchor))
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
    do not call directly. Use instead:

    URL.verify(hmac_key='...')

    the key has to match the one used to generate the URL.

        >>> r = Storage()
        >>> gv = Storage(p=(1,3),q=2,_signature='5d06bb8a4a6093dd325da2ee591c35c61afbd3c6')
        >>> r.update(dict(application='a', controller='c', function='f'))
        >>> r['args'] = ['x', 'y', 'z']
        >>> r['get_vars'] = gv
        >>> verifyURL(r, 'key')
        True
        >>> verifyURL(r, 'kay')
        False
        >>> r.get_vars.p = (3, 1)







|
|







320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
    do not call directly. Use instead:

    URL.verify(hmac_key='...')

    the key has to match the one used to generate the URL.

        >>> r = Storage()
        >>> gv = Storage(p=(1,3),q=2,_signature='a32530f0d0caa80964bb92aad2bedf8a4486a31f')
        >>> r.update(dict(application='a', controller='c', function='f', extension='html'))
        >>> r['args'] = ['x', 'y', 'z']
        >>> r['get_vars'] = gv
        >>> verifyURL(r, 'key')
        True
        >>> verifyURL(r, 'kay')
        False
        >>> r.get_vars.p = (3, 1)
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
        except:
            # user has removed one of our vars! Immediate fail
            return False
    # build the full message string with both args & vars
    message = h_args + '?' + urllib.urlencode(sorted(h_vars))

    # hash with the hmac_key provided
    sig = hmac_hash(message,str(hmac_key),salt=salt)

    # put _signature back in get_vars just in case a second call to URL.verify is performed
    # (otherwise it'll immediately return false)
    request.get_vars['_signature'] = original_sig

    # return whether or not the signature in the request matched the one we just generated
    # (I.E. was the message the same as the one we originally signed)







|







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
        except:
            # user has removed one of our vars! Immediate fail
            return False
    # build the full message string with both args & vars
    message = h_args + '?' + urllib.urlencode(sorted(h_vars))

    # hash with the hmac_key provided
    sig = hmac_hash(message, str(hmac_key), digest_alg='sha1', salt=salt)

    # put _signature back in get_vars just in case a second call to URL.verify is performed
    # (otherwise it'll immediately return false)
    request.get_vars['_signature'] = original_sig

    # return whether or not the signature in the request matched the one we just generated
    # (I.E. was the message the same as the one we originally signed)
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
        kargs['first_only'] = True
        sibs = self.siblings(*args, **kargs)
        if not sibs:
            return None
        return sibs[0]

class CAT(DIV):
    
    tag = ''

def TAG_unpickler(data):
    return cPickle.loads(data)

def TAG_pickler(data):
    d = DIV()







|







1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
        kargs['first_only'] = True
        sibs = self.siblings(*args, **kargs)
        if not sibs:
            return None
        return sibs[0]

class CAT(DIV):

    tag = ''

def TAG_unpickler(data):
    return cPickle.loads(data)

def TAG_pickler(data):
    d = DIV()
1273
1274
1275
1276
1277
1278
1279








1280



1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298


class A(DIV):

    tag = 'a'

    def xml(self):








        if self['callback']:



            self['_onclick']="ajax('%s',[],'%s');return false;" % \
                (self['callback'],self['target'] or '')
            self['_href'] = self['_href'] or '#null'
        elif self['cid']:
            self['_onclick']='web2py_component("%s","%s");return false;' % \
                (self['_href'],self['cid'])
        return DIV.xml(self)


class BUTTON(DIV):
    
    tag = 'button'


class EM(DIV):

    tag = 'em'








>
>
>
>
>
>
>
>
|
>
>
>
|
|








|







1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326


class A(DIV):

    tag = 'a'

    def xml(self):
        if self['delete']:
            d = "jQuery(this).closest('%s').remove();" % self['delete']
        else:
            d = ''
        if self['component']:
            self['_onclick']="web2py_component('%s','%s');%sreturn false;" % \
                (self['component'],self['target'] or '',d)
            self['_href'] = self['_href'] or '#null'
        elif self['callback']:
            if d:
                self['_onclick']="if(confirm(w2p_ajax_confirm_message||'Are you sure you want o delete this object?')){ajax('%s',[],'%s');%s};return false;" % (self['callback'],self['target'] or '',d)
            else:
                self['_onclick']="ajax('%s',[],'%s');%sreturn false;" % \
                    (self['callback'],self['target'] or '',d)
            self['_href'] = self['_href'] or '#null'
        elif self['cid']:
            self['_onclick']='web2py_component("%s","%s");return false;' % \
                (self['_href'],self['cid'])
        return DIV.xml(self)


class BUTTON(DIV):

    tag = 'button'


class EM(DIV):

    tag = 'em'

1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
                self['value'] = self['_value'] == value
        requires = self['requires']
        if requires:
            if not isinstance(requires, (list, tuple)):
                requires = [requires]
            for validator in requires:
                (value, errors) = validator(value)
                if errors != None:
                    self.vars[name] = value
                    self.errors[name] = errors
                    break
        if not name in self.errors:
            self.vars[name] = value
            return True
        return False

    def _postprocessing(self):
        t = self['_type']
        if not t:
            t = self['_type'] = 'text'
        t = t.lower()
        value = self['value']
        if self['_value'] == None:
            _value = None
        else:
            _value = str(self['_value'])
        if t == 'checkbox':
            if not _value:
                _value = self['_value'] = 'on'
            if not value:
                value = []
            elif value is True:
                value = [_value]
            elif not isinstance(value,(list,tuple)):
                value = str(value).split('|')
            self['_checked'] = _value in value and 'checked' or None
        elif t == 'radio':
            if str(value) == str(_value):
                self['_checked'] = 'checked'
            else:
                self['_checked'] = None
        elif t == 'text' or t == 'hidden':
            if value != None:
                self['_value'] = value
            else:
                self['value'] = _value

    def xml(self):
        name = self.attributes.get('_name', None)
        if name and hasattr(self, 'errors') \
                and self.errors.get(name, None) \
                and self['hideerror'] != True:
            return DIV.xml(self) + DIV(self.errors[name], _class='error',







|














|



|









|





|
|

|







1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
                self['value'] = self['_value'] == value
        requires = self['requires']
        if requires:
            if not isinstance(requires, (list, tuple)):
                requires = [requires]
            for validator in requires:
                (value, errors) = validator(value)
                if not errors is None:
                    self.vars[name] = value
                    self.errors[name] = errors
                    break
        if not name in self.errors:
            self.vars[name] = value
            return True
        return False

    def _postprocessing(self):
        t = self['_type']
        if not t:
            t = self['_type'] = 'text'
        t = t.lower()
        value = self['value']
        if self['_value'] is None:
            _value = None
        else:
            _value = str(self['_value'])
        if t == 'checkbox' and not '_checked' in self.attributes:
            if not _value:
                _value = self['_value'] = 'on'
            if not value:
                value = []
            elif value is True:
                value = [_value]
            elif not isinstance(value,(list,tuple)):
                value = str(value).split('|')
            self['_checked'] = _value in value and 'checked' or None
        elif t == 'radio' and not '_checked' in self.attributes:
            if str(value) == str(_value):
                self['_checked'] = 'checked'
            else:
                self['_checked'] = None
        elif t == 'text' or t == 'hidden':
            if value is None:
                self['value'] = _value
            else:
                self['_value'] = value

    def xml(self):
        name = self.attributes.get('_name', None)
        if name and hasattr(self, 'errors') \
                and self.errors.get(name, None) \
                and self['hideerror'] != True:
            return DIV.xml(self) + DIV(self.errors[name], _class='error',
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
    tag = 'textarea'

    def _postprocessing(self):
        if not '_rows' in self.attributes:
            self['_rows'] = 10
        if not '_cols' in self.attributes:
            self['_cols'] = 40
        if self['value'] != None:
            self.components = [self['value']]
        elif self.components:
            self['value'] = self.components[0]


class OPTION(DIV):








|







1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
    tag = 'textarea'

    def _postprocessing(self):
        if not '_rows' in self.attributes:
            self['_rows'] = 10
        if not '_cols' in self.attributes:
            self['_cols'] = 40
        if not self['value'] is None:
            self.components = [self['value']]
        elif self.components:
            self['value'] = self.components[0]


class OPTION(DIV):

1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
            if isinstance(c, OPTGROUP):
                component_list.append(c.components)
            else:
                component_list.append([c])
        options = itertools.chain(*component_list)

        value = self['value']
        if value != None:
            if not self['_multiple']:
                for c in options: # my patch
                    if value and str(c['_value'])==str(value):
                        c['_selected'] = 'selected'
                    else:
                        c['_selected'] = None
            else:







|







1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
            if isinstance(c, OPTGROUP):
                component_list.append(c.components)
            else:
                component_list.append([c])
        options = itertools.chain(*component_list)

        value = self['value']
        if not value is None:
            if not self['_multiple']:
                for c in options: # my patch
                    if value and str(c['_value'])==str(value):
                        c['_selected'] = 'selected'
                    else:
                        c['_selected'] = None
            else:
1723
1724
1725
1726
1727
1728
1729

1730
1731
1732
1733
1734
1735
1736
1737
1738

1739



1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
    tag = 'form'

    def __init__(self, *components, **attributes):
        DIV.__init__(self, *components,  **attributes)
        self.vars = Storage()
        self.errors = Storage()
        self.latest = Storage()


    def accepts(
        self,
        vars,
        session=None,
        formname='default',
        keepvalues=False,
        onvalidation=None,
        hideerror=False,

        ):



        if vars.__class__.__name__ == 'Request':
            vars=vars.post_vars
        self.errors.clear()
        self.request_vars = Storage()
        self.request_vars.update(vars)
        self.session = session
        self.formname = formname
        self.keepvalues = keepvalues

        # if this tag is a form and we are in accepting mode (status=True)
        # check formname and formkey








>



|





>

>
>
>
|
|


|







1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
    tag = 'form'

    def __init__(self, *components, **attributes):
        DIV.__init__(self, *components,  **attributes)
        self.vars = Storage()
        self.errors = Storage()
        self.latest = Storage()
        self.accepted = None # none for not submitted

    def accepts(
        self,
        request_vars,
        session=None,
        formname='default',
        keepvalues=False,
        onvalidation=None,
        hideerror=False,
        **kwargs
        ):
        """
        kwargs is not used but allows to specify the same interface for FROM and SQLFORM
        """
        if request_vars.__class__.__name__ == 'Request':
            request_vars=request_vars.post_vars
        self.errors.clear()
        self.request_vars = Storage()
        self.request_vars.update(request_vars)
        self.session = session
        self.formname = formname
        self.keepvalues = keepvalues

        # if this tag is a form and we are in accepting mode (status=True)
        # check formname and formkey

1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789

1790
1791
1792
1793
1794
1795
1796
        status = self._traverse(status,hideerror)
        if onvalidation:
            if isinstance(onvalidation, dict):
                onsuccess = onvalidation.get('onsuccess', None)
                onfailure = onvalidation.get('onfailure', None)
                if onsuccess and status:
                    onsuccess(self)
                if onfailure and vars and not status:
                    onfailure(self)
                    status = len(self.errors) == 0
            elif status:
                if isinstance(onvalidation, (list, tuple)):
                    [f(self) for f in onvalidation]
                else:
                    onvalidation(self)
        if self.errors:
            status = False
        if session != None:
            if hasattr(self,'record_hash'):
                formkey = self.record_hash
            else:
                formkey = web2py_uuid()
            self.formkey = session['_formkey[%s]' % formname] = formkey
        if status and not keepvalues:
            self._traverse(False,hideerror)

        return status

    def _postprocessing(self):
        if not '_action' in self.attributes:
            self['_action'] = ''
        if not '_method' in self.attributes:
            self['_method'] = 'post'







|









|







>







1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
        status = self._traverse(status,hideerror)
        if onvalidation:
            if isinstance(onvalidation, dict):
                onsuccess = onvalidation.get('onsuccess', None)
                onfailure = onvalidation.get('onfailure', None)
                if onsuccess and status:
                    onsuccess(self)
                if onfailure and request_vars and not status:
                    onfailure(self)
                    status = len(self.errors) == 0
            elif status:
                if isinstance(onvalidation, (list, tuple)):
                    [f(self) for f in onvalidation]
                else:
                    onvalidation(self)
        if self.errors:
            status = False
        if not session is None:
            if hasattr(self,'record_hash'):
                formkey = self.record_hash
            else:
                formkey = web2py_uuid()
            self.formkey = session['_formkey[%s]' % formname] = formkey
        if status and not keepvalues:
            self._traverse(False,hideerror)
        self.accepted = status
        return status

    def _postprocessing(self):
        if not '_action' in self.attributes:
            self['_action'] = ''
        if not '_method' in self.attributes:
            self['_method'] = 'post'
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856


1857
1858
1859
1860


1861



1862
1863
1864





1865
1866
1867



1868
1869
1870







1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
    def xml(self):
        newform = FORM(*self.components, **self.attributes)
        hidden_fields = self.hidden_fields()
        if hidden_fields.components:
            newform.append(hidden_fields)
        return DIV.xml(newform)

    def validate(self, 
                 values=None,
                 session=None, 
                 formname='default',
                 keepvalues=False,
                 onvalidation=None,
                 hideerror=False,
                 onsuccess='flash',
                 onfailure='flash',
                 message_onsuccess=None, 
                 message_onfailure=None, 
                 ):
        """
        This function validates the form, 
        you can use it instead of directly form.accepts.

        Usage:
        In controller

        def action():
            form=FORM(INPUT(_name=\"test\", requires=IS_NOT_EMPTY()))
            form.validate() #you can pass some args here - see below
            return dict(form=form)

        This can receive a bunch of arguments        

        onsuccess = 'flash' - will show message_onsuccess in response.flash
                    None - will do nothing
                    can be a function (lambda form: pass)
        onfailure = 'flash' - will show message_onfailure in response.flash
                    None - will do nothing
                    can be a function (lambda form: pass)

        values = values to test the validation - dictionary, response.vars, session or other - Default to (request.vars, session)
        message_onsuccess
        message_onfailure


        """
        from gluon import current
        if not session: session = current.session
        if not values: values = current.request.post_vars


         



        message_onsuccess = message_onsuccess or current.T("Success!")
        message_onfailure = message_onfailure or \
            current.T("Errors in form, please check it out.")






        if self.accepts(values, session):
            if onsuccess == 'flash':



                current.response.flash = message_onsuccess
            elif callable(onsuccess):
                onsuccess(self)







            return True
        elif self.errors:
            if onfailure == 'flash':
                current.response.flash = message_onfailure
            elif callable(onfailure):
                onfailure(self)
            return False

    def process(self, values=None, session=None, **args):
        """
        Perform the .validate() method but returns the form

        Usage in controllers:
        # directly on return
        def action():
            #some code here







|
<
<
<
<
<
<
<
<
<
<
<

|










|







<
<


>
>

|
<
|
>
>
|
>
>
>
|
|
|
>
>
>
>
>

|

>
>
>
|


>
>
>
>
>
>
>








|







1848
1849
1850
1851
1852
1853
1854
1855











1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875


1876
1877
1878
1879
1880
1881

1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
    def xml(self):
        newform = FORM(*self.components, **self.attributes)
        hidden_fields = self.hidden_fields()
        if hidden_fields.components:
            newform.append(hidden_fields)
        return DIV.xml(newform)

    def validate(self,**kwargs):











        """
        This function validates the form,
        you can use it instead of directly form.accepts.

        Usage:
        In controller

        def action():
            form=FORM(INPUT(_name=\"test\", requires=IS_NOT_EMPTY()))
            form.validate() #you can pass some args here - see below
            return dict(form=form)

        This can receive a bunch of arguments

        onsuccess = 'flash' - will show message_onsuccess in response.flash
                    None - will do nothing
                    can be a function (lambda form: pass)
        onfailure = 'flash' - will show message_onfailure in response.flash
                    None - will do nothing
                    can be a function (lambda form: pass)


        message_onsuccess
        message_onfailure
        next      = where to redirect in case of success
        any other kwargs will be passed for form.accepts(...)
        """
        from gluon import current, redirect

        kwargs['request_vars'] = kwargs.get('request_vars',current.request.post_vars)
        kwargs['session'] = kwargs.get('session',current.session)
        kwargs['dbio'] = kwargs.get('dbio',False) # necessary for SQLHTML forms

        onsuccess = kwargs.get('onsuccess','flash')
        onfailure = kwargs.get('onfailure','flash')
        message_onsuccess = kwargs.get('message_onsuccess',
                                       current.T("Success!"))
        message_onfailure = kwargs.get('message_onfailure',
                                       current.T("Errors in form, please check it out."))
        next = kwargs.get('next',None)
        for key in ('message_onsuccess','message_onfailure','onsuccess',
                    'onfailure','next'):
            if key in kwargs:
                del kwargs[key]

        if self.accepts(**kwargs):
            if onsuccess == 'flash':
                if next:
                    current.session.flash = message_onsuccess
                else:
                    current.response.flash = message_onsuccess
            elif callable(onsuccess):
                onsuccess(self)
            if next:
                if self.vars.id:
                    next = next.replace('[id]',str(self.vars.id))
                    next = next % self.vars
                    if not next.startswith('/'):
                        next = URL(next)
                redirect(next)
            return True
        elif self.errors:
            if onfailure == 'flash':
                current.response.flash = message_onfailure
            elif callable(onfailure):
                onfailure(self)
            return False

    def process(self, **kwargs):
        """
        Perform the .validate() method but returns the form

        Usage in controllers:
        # directly on return
        def action():
            #some code here
1899
1900
1901
1902
1903
1904
1905
1906

1907
1908
1909
1910
1911
1912
1913
1914
        def my_callback(status, msg):
           response.flash = "Success! "+msg if status else "Errors occured"

        # after argument can be 'flash' to response.flash messages
        # or a function name to use as callback or None to do nothing.
        def action():
            return dict(form=SQLFORM(db.table).process(onsuccess=my_callback)
        """ 

        self.validate(values=values, session=session, **args)
        return self


class BEAUTIFY(DIV):

    """
    example::







|
>
|







1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
        def my_callback(status, msg):
           response.flash = "Success! "+msg if status else "Errors occured"

        # after argument can be 'flash' to response.flash messages
        # or a function name to use as callback or None to do nothing.
        def action():
            return dict(form=SQLFORM(db.table).process(onsuccess=my_callback)
        """
        kwargs['dbio'] = kwargs.get('dbio',True) # necessary for SQLHTML forms
        self.validate(**kwargs)
        return self


class BEAUTIFY(DIV):

    """
    example::
2160
2161
2162
2163
2164
2165
2166
2167

2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182

2183
2184
2185
2186
2187
2188
2189
            try:
                parent_tagname=self.parent.tag
                self.parent = self.parent.parent
            except:
                raise RuntimeError, "unable to balance tag %s" % tagname
            if parent_tagname[:len(tagname)]==tagname: break

def markdown_serializer(text,tag=None,attr={}):

    if tag is None: return re.sub('\s+',' ',text)
    if tag=='br': return '\n\n'
    if tag=='h1': return '#'+text+'\n\n'
    if tag=='h2': return '#'*2+text+'\n\n'
    if tag=='h3': return '#'*3+text+'\n\n'
    if tag=='h4': return '#'*4+text+'\n\n'
    if tag=='p': return text+'\n\n'
    if tag=='b' or tag=='strong': return '**%s**' % text
    if tag=='em' or tag=='i': return '*%s*' % text
    if tag=='tt' or tag=='code': return '`%s`' % text
    if tag=='a': return '[%s](%s)' % (text,attr.get('_href',''))
    if tag=='img': return '![%s](%s)' % (attr.get('_alt',''),attr.get('_src',''))
    return text

def markmin_serializer(text,tag=None,attr={}):

    # if tag is None: return re.sub('\s+',' ',text)
    if tag=='br': return '\n\n'
    if tag=='h1': return '# '+text+'\n\n'
    if tag=='h2': return '#'*2+' '+text+'\n\n'
    if tag=='h3': return '#'*3+' '+text+'\n\n'
    if tag=='h4': return '#'*4+' '+text+'\n\n'
    if tag=='p': return text+'\n\n'







|
>














|
>







2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
            try:
                parent_tagname=self.parent.tag
                self.parent = self.parent.parent
            except:
                raise RuntimeError, "unable to balance tag %s" % tagname
            if parent_tagname[:len(tagname)]==tagname: break

def markdown_serializer(text,tag=None,attr=None):
    attr = attr or {}
    if tag is None: return re.sub('\s+',' ',text)
    if tag=='br': return '\n\n'
    if tag=='h1': return '#'+text+'\n\n'
    if tag=='h2': return '#'*2+text+'\n\n'
    if tag=='h3': return '#'*3+text+'\n\n'
    if tag=='h4': return '#'*4+text+'\n\n'
    if tag=='p': return text+'\n\n'
    if tag=='b' or tag=='strong': return '**%s**' % text
    if tag=='em' or tag=='i': return '*%s*' % text
    if tag=='tt' or tag=='code': return '`%s`' % text
    if tag=='a': return '[%s](%s)' % (text,attr.get('_href',''))
    if tag=='img': return '![%s](%s)' % (attr.get('_alt',''),attr.get('_src',''))
    return text

def markmin_serializer(text,tag=None,attr=None):
    attr = attr or {}
    # if tag is None: return re.sub('\s+',' ',text)
    if tag=='br': return '\n\n'
    if tag=='h1': return '# '+text+'\n\n'
    if tag=='h2': return '#'*2+' '+text+'\n\n'
    if tag=='h3': return '#'*3+' '+text+'\n\n'
    if tag=='h4': return '#'*4+' '+text+'\n\n'
    if tag=='p': return text+'\n\n'
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
    return text


class MARKMIN(XmlComponent):
    """
    For documentation: http://web2py.com/examples/static/markmin.html
    """
    def __init__(self, text, extra={}, allowed={}, sep='p'):
        self.text = text
        self.extra = extra
        self.allowed = allowed
        self.sep = sep

    def xml(self):
        """
        calls the gluon.contrib.markmin render function to convert the wiki syntax
        """
        return render(self.text,extra=self.extra,allowed=self.allowed,sep=self.sep)







|

|
|







2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
    return text


class MARKMIN(XmlComponent):
    """
    For documentation: http://web2py.com/examples/static/markmin.html
    """
    def __init__(self, text, extra=None, allowed=None, sep='p'):
        self.text = text
        self.extra = extra or {}
        self.allowed = allowed or {}
        self.sep = sep

    def xml(self):
        """
        calls the gluon.contrib.markmin render function to convert the wiki syntax
        """
        return render(self.text,extra=self.extra,allowed=self.allowed,sep=self.sep)
2232
2233
2234
2235
2236
2237
2238
2239


        """
        return [self.text]


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











>
>
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
        """
        return [self.text]


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



Added gluon/html.pyc version [8f42eff40f].
Modified gluon/http.py from [4537bde179] to [d702443dbf].
116
117
118
119
120
121
122


123
124
125
126


127

    def __str__(self):
        "stringify me"
        return self.message


def redirect(location, how=303):


    location = location.replace('\r', '%0D').replace('\n', '%0A')
    raise HTTP(how,
               'You are being redirected <a href="%s">here</a>' % location,
               Location=location)










>
>




>
>

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

    def __str__(self):
        "stringify me"
        return self.message


def redirect(location, how=303):
    if not location:
        return
    location = location.replace('\r', '%0D').replace('\n', '%0A')
    raise HTTP(how,
               'You are being redirected <a href="%s">here</a>' % location,
               Location=location)



Added gluon/http.pyc version [c8d52a9b33].
Modified gluon/import_all.py from [91c08d2cb3] to [39dc019a12].
103
104
105
106
107
108
109


110
    except:
        # Raise an exception if the current module is a dependency
        if module in alert_dependency:
            msg = "Missing dependency: %(module)s\n" % locals()
            msg += "Try the following command: "
            msg += "easy_install-%(python_version)s -U %(module)s" % locals()
            raise ImportError, msg










>
>

103
104
105
106
107
108
109
110
111
112
    except:
        # Raise an exception if the current module is a dependency
        if module in alert_dependency:
            msg = "Missing dependency: %(module)s\n" % locals()
            msg += "Try the following command: "
            msg += "easy_install-%(python_version)s -U %(module)s" % locals()
            raise ImportError, msg



Modified gluon/languages.py from [1245d246fd] to [03ebceec94].
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
        self.language_file = None
        self.http_accept_language = request.env.http_accept_language
        self.requested_languages = self.force(self.http_accept_language)
        self.lazy = True
        self.otherTs = {}

    def get_possible_languages(self):
        possible_languages = self.current_languages
        file_ending = re.compile("\.py$")
        for langfile in os.listdir(os.path.join(self.folder,'languages')):
            if file_ending.search(langfile):
                possible_languages.append(file_ending.sub('',langfile))
        return possible_languages

    def set_current_languages(self, *languages):
        if len(languages) == 1 and isinstance(languages[0], (tuple, list)):
            languages = languages[0]
        self.current_languages = languages
        self.force(self.http_accept_language)

    def force(self, *languages):
        if not languages or languages[0] == None:
            languages = []
        if len(languages) == 1 and isinstance(languages[0], (str, unicode)):
            languages = languages[0]
        if languages:
            if isinstance(languages, (str, unicode)):
                accept_languages = languages.split(';')
                languages = []







|













|







206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
        self.language_file = None
        self.http_accept_language = request.env.http_accept_language
        self.requested_languages = self.force(self.http_accept_language)
        self.lazy = True
        self.otherTs = {}

    def get_possible_languages(self):
        possible_languages = [lang for lang in self.current_languages]
        file_ending = re.compile("\.py$")
        for langfile in os.listdir(os.path.join(self.folder,'languages')):
            if file_ending.search(langfile):
                possible_languages.append(file_ending.sub('',langfile))
        return possible_languages

    def set_current_languages(self, *languages):
        if len(languages) == 1 and isinstance(languages[0], (tuple, list)):
            languages = languages[0]
        self.current_languages = languages
        self.force(self.http_accept_language)

    def force(self, *languages):
        if not languages or languages[0] is None:
            languages = []
        if len(languages) == 1 and isinstance(languages[0], (str, unicode)):
            languages = languages[0]
        if languages:
            if isinstance(languages, (str, unicode)):
                accept_languages = languages.split(';')
                languages = []
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
                    self.language_file = filename
                    self.t = read_dict(filename)
                    return languages
        self.language_file = None
        self.t = {}  # ## no language by default
        return languages

    def __call__(self, message, symbols={},language=None):
        if not language:
            if self.lazy:
                return lazyT(message, symbols, self)
            else:
                return self.translate(message, symbols)
        else:
            try:







|







246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
                    self.language_file = filename
                    self.t = read_dict(filename)
                    return languages
        self.language_file = None
        self.t = {}  # ## no language by default
        return languages

    def __call__(self, message, symbols={}, language=None):
        if not language:
            if self.lazy:
                return lazyT(message, symbols, self)
            else:
                return self.translate(message, symbols)
        else:
            try:
273
274
275
276
277
278
279



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
        T(' hello world ') -> ' hello world '
        T(' hello world ## token') -> 'hello world'
        T('hello ## world ## token') -> 'hello ## world'

        the ## notation is ignored in multiline strings and strings that
        start with ##. this is to allow markmin syntax to be translated
        """



        if not message.startswith('#') and not '\n' in message:
            tokens = message.rsplit('##', 1)
        else:
            # this allows markmin syntax in translations
            tokens = [message]
        if len(tokens) == 2:
            tokens[0] = tokens[0].strip()
            message = tokens[0] + '##' + tokens[1].strip()
        mt = self.t.get(message, None)
        if mt == None:
            self.t[message] = mt = tokens[0]
            if self.language_file and not is_gae:
                write_dict(self.language_file, self.t)
        if symbols or symbols == 0:
            return mt % symbols
        return mt








>
>
>









|







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
        T(' hello world ') -> ' hello world '
        T(' hello world ## token') -> 'hello world'
        T('hello ## world ## token') -> 'hello ## world'

        the ## notation is ignored in multiline strings and strings that
        start with ##. this is to allow markmin syntax to be translated
        """
        #for some reason languages.py gets executed before gaehandler.py
        # is able to set web2py_runtime_gae, so re-check here
        is_gae = settings.global_settings.web2py_runtime_gae
        if not message.startswith('#') and not '\n' in message:
            tokens = message.rsplit('##', 1)
        else:
            # this allows markmin syntax in translations
            tokens = [message]
        if len(tokens) == 2:
            tokens[0] = tokens[0].strip()
            message = tokens[0] + '##' + tokens[1].strip()
        mt = self.t.get(message, None)
        if mt is None:
            self.t[message] = mt = tokens[0]
            if self.language_file and not is_gae:
                write_dict(self.language_file, self.t)
        if symbols or symbols == 0:
            return mt % symbols
        return mt

340
341
342
343
344
345
346
347
348


    for language in listdir(path, '^\w+(\-\w+)?\.py$'):
        findT(application_path, language[:-3])


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













>
>
343
344
345
346
347
348
349
350
351
352
353
    for language in listdir(path, '^\w+(\-\w+)?\.py$'):
        findT(application_path, language[:-3])


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




Added gluon/languages.pyc version [cc4448c9de].
Modified gluon/main.py from [a23025057a] to [414838077d].
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import datetime
import signal
import socket
import tempfile
import random
import string
import platform
from fileutils import abspath, write_file
from settings import global_settings
from admin import add_path_first, create_missing_folders, create_missing_app_folders
from globals import current

from custom_import import custom_import_install
from contrib.simplejson import dumps








|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import datetime
import signal
import socket
import tempfile
import random
import string
import platform
from fileutils import abspath, write_file, parse_version
from settings import global_settings
from admin import add_path_first, create_missing_folders, create_missing_app_folders
from globals import current

from custom_import import custom_import_install
from contrib.simplejson import dumps

99
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
# Security Checks: validate URL and session_id here,
# accept_language is validated in languages

# pattern used to validate client address
regex_client = re.compile('[\w\-:]+(\.[\w\-]+)*\.?')  # ## to account for IPV6

version_info = open(abspath('VERSION', gluon=True), 'r')
web2py_version = version_info.read()
version_info.close()


try:
    import rocket
except:
    if not global_settings.web2py_runtime_gae:
        logger.warn('unable to import Rocket')








|

>







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Security Checks: validate URL and session_id here,
# accept_language is validated in languages

# pattern used to validate client address
regex_client = re.compile('[\w\-:]+(\.[\w\-]+)*\.?')  # ## to account for IPV6

version_info = open(abspath('VERSION', gluon=True), 'r')
web2py_version = parse_version(version_info.read().strip())
version_info.close()
global_settings.web2py_version = web2py_version

try:
    import rocket
except:
    if not global_settings.web2py_runtime_gae:
        logger.warn('unable to import Rocket')

414
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429
430
431
432
433
434
                # ##################################################

                if not os.path.exists(request.folder):
                    if request.application == rewrite.thread.routes.default_application and request.application != 'welcome':
                        request.application = 'welcome'
                        redirect(Url(r=request))
                    elif rewrite.thread.routes.error_handler:
                        redirect(Url(rewrite.thread.routes.error_handler['application'],

                                     rewrite.thread.routes.error_handler['controller'],
                                     rewrite.thread.routes.error_handler['function'],
                                     args=request.application))
                    else:
                        raise HTTP(404,
                                   rewrite.thread.routes.error_message % 'invalid request',
                                   web2py_error='invalid application')
                request.url = Url(r=request, args=request.args,
                                       extension=request.raw_extension)

                # ##################################################
                # build missing folders
                # ##################################################







|
>
|
|


|
|







415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
                # ##################################################

                if not os.path.exists(request.folder):
                    if request.application == rewrite.thread.routes.default_application and request.application != 'welcome':
                        request.application = 'welcome'
                        redirect(Url(r=request))
                    elif rewrite.thread.routes.error_handler:
                        _handler = rewrite.thread.routes.error_handler
                        redirect(Url(_handler['application'],
                                     _handler['controller'],
                                     _handler['function'],
                                     args=request.application))
                    else:
                        raise HTTP(404, rewrite.thread.routes.error_message \
                                       % 'invalid request',
                                   web2py_error='invalid application')
                request.url = Url(r=request, args=request.args,
                                       extension=request.raw_extension)

                # ##################################################
                # build missing folders
                # ##################################################
442
443
444
445
446
447
448
449

450
451
452

453
454
455
456
457
458
459
                parse_get_post_vars(request, environ)

                # ##################################################
                # expose wsgi hooks for convenience
                # ##################################################

                request.wsgi.environ = environ_aux(environ,request)
                request.wsgi.start_response = lambda status='200', headers=[], \

                    exec_info=None, response=response: \
                    start_response_aux(status, headers, exec_info, response)
                request.wsgi.middleware = lambda *a: middleware_aux(request,response,*a)


                # ##################################################
                # load cookies
                # ##################################################

                if request.env.http_cookie:
                    try:







|
>


|
>







444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
                parse_get_post_vars(request, environ)

                # ##################################################
                # expose wsgi hooks for convenience
                # ##################################################

                request.wsgi.environ = environ_aux(environ,request)
                request.wsgi.start_response = \
                    lambda status='200', headers=[], \
                    exec_info=None, response=response: \
                    start_response_aux(status, headers, exec_info, response)
                request.wsgi.middleware = \
                    lambda *a: middleware_aux(request,response,*a)

                # ##################################################
                # load cookies
                # ##################################################

                if request.env.http_cookie:
                    try:
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481

                session.connect(request, response)

                # ##################################################
                # set no-cache headers
                # ##################################################

                response.headers['Content-Type'] = contenttype('.'+request.extension)

                response.headers['Cache-Control'] = \
                    'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
                response.headers['Expires'] = \
                    time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
                response.headers['Pragma'] = 'no-cache'

                # ##################################################







|
>







471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

                session.connect(request, response)

                # ##################################################
                # set no-cache headers
                # ##################################################

                response.headers['Content-Type'] = \
                    contenttype('.'+request.extension)
                response.headers['Cache-Control'] = \
                    'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
                response.headers['Expires'] = \
                    time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
                response.headers['Pragma'] = 'no-cache'

                # ##################################################
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
                ticket = e.log(request) or 'unknown'
                if response._custom_rollback:
                    response._custom_rollback()
                else:
                    BaseAdapter.close_all_instances('rollback')

                http_response = \
                    HTTP(500,
                         rewrite.thread.routes.error_message_ticket % dict(ticket=ticket),
                         web2py_error='ticket %s' % ticket)

        except:

            if request.body:
                request.body.close()








|
|







551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
                ticket = e.log(request) or 'unknown'
                if response._custom_rollback:
                    response._custom_rollback()
                else:
                    BaseAdapter.close_all_instances('rollback')

                http_response = \
                    HTTP(500, rewrite.thread.routes.error_message_ticket % \
                             dict(ticket=ticket),
                         web2py_error='ticket %s' % ticket)

        except:

            if request.body:
                request.body.close()

569
570
571
572
573
574
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
                else:
                    BaseAdapter.close_all_instances('rollback')
            except:
                pass
            e = RestrictedError('Framework', '', '', locals())
            ticket = e.log(request) or 'unrecoverable'
            http_response = \
                HTTP(500,
                     rewrite.thread.routes.error_message_ticket % dict(ticket=ticket),
                     web2py_error='ticket %s' % ticket)

    finally:
        if response and hasattr(response, 'session_file') and response.session_file:

            response.session_file.close()
#         if global_settings.debugging:
#             import gluon.debug
#             gluon.debug.stop_trace()

    session._unlock(response)
    http_response, new_environ = rewrite.try_rewrite_on_error(
        http_response, request, environ, ticket)
    if not http_response:
        return wsgibase(new_environ,responder)
    if global_settings.web2py_crontype == 'soft':
        newcron.softcron(global_settings.applications_parent).start()
    return http_response.to(responder)
    

def save_password(password, port):
    """
    used by main() to save the password in the parameters_port.py file.
    """

    password_file = abspath('parameters_%i.py' % port)







|
|



|
>













|







574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
                else:
                    BaseAdapter.close_all_instances('rollback')
            except:
                pass
            e = RestrictedError('Framework', '', '', locals())
            ticket = e.log(request) or 'unrecoverable'
            http_response = \
                HTTP(500, rewrite.thread.routes.error_message_ticket \
                         % dict(ticket=ticket),
                     web2py_error='ticket %s' % ticket)

    finally:
        if response and hasattr(response, 'session_file') \
                and response.session_file:
            response.session_file.close()
#         if global_settings.debugging:
#             import gluon.debug
#             gluon.debug.stop_trace()

    session._unlock(response)
    http_response, new_environ = rewrite.try_rewrite_on_error(
        http_response, request, environ, ticket)
    if not http_response:
        return wsgibase(new_environ,responder)
    if global_settings.web2py_crontype == 'soft':
        newcron.softcron(global_settings.applications_parent).start()
    return http_response.to(responder)


def save_password(password, port):
    """
    used by main() to save the password in the parameters_port.py file.
    """

    password_file = abspath('parameters_%i.py' % port)
714
715
716
717
718
719
720

721
722
723
724
725
726
727
        port=8000,
        password='',
        pid_filename='httpserver.pid',
        log_filename='httpserver.log',
        profiler_filename=None,
        ssl_certificate=None,
        ssl_private_key=None,

        min_threads=None,
        max_threads=None,
        server_name=None,
        request_queue_size=5,
        timeout=10,
        shutdown_timeout=None, # Rocket does not use a shutdown timeout
        path=None,







>







720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
        port=8000,
        password='',
        pid_filename='httpserver.pid',
        log_filename='httpserver.log',
        profiler_filename=None,
        ssl_certificate=None,
        ssl_private_key=None,
        ssl_ca_certificate=None,
        min_threads=None,
        max_threads=None,
        server_name=None,
        request_queue_size=5,
        timeout=10,
        shutdown_timeout=None, # Rocket does not use a shutdown timeout
        path=None,
765
766
767
768
769
770
771



772
773
774
775
776
777
778
            logger.warning('Python "ssl" module unavailable. SSL is OFF')
        elif not os.path.exists(ssl_certificate):
            logger.warning('unable to open SSL certificate. SSL is OFF')
        elif not os.path.exists(ssl_private_key):
            logger.warning('unable to open SSL private key. SSL is OFF')
        else:
            sock_list.extend([ssl_private_key, ssl_certificate])



            logger.info('SSL is ON')
        app_info = {'wsgi_app': appfactory(wsgibase,
                                           log_filename,
                                           profiler_filename) }

        self.server = rocket.Rocket(interfaces or tuple(sock_list),
                                    method='wsgi',







>
>
>







772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
            logger.warning('Python "ssl" module unavailable. SSL is OFF')
        elif not os.path.exists(ssl_certificate):
            logger.warning('unable to open SSL certificate. SSL is OFF')
        elif not os.path.exists(ssl_private_key):
            logger.warning('unable to open SSL private key. SSL is OFF')
        else:
            sock_list.extend([ssl_private_key, ssl_certificate])
            if ssl_ca_certificate:
                sock_list.append(ssl_ca_certificate)
            
            logger.info('SSL is ON')
        app_info = {'wsgi_app': appfactory(wsgibase,
                                           log_filename,
                                           profiler_filename) }

        self.server = rocket.Rocket(interfaces or tuple(sock_list),
                                    method='wsgi',
803
804
805
806
807
808
809
810


        """
        newcron.stopcron()
        self.server.stop(stoplogging)
        try:
            os.unlink(self.pid_filename)
        except:
            pass











>
>
813
814
815
816
817
818
819
820
821
822
        """
        newcron.stopcron()
        self.server.stop(stoplogging)
        try:
            os.unlink(self.pid_filename)
        except:
            pass



Added gluon/main.pyc version [7db36fceca].
Modified gluon/myregex.py from [a8dd66dbcb] to [9e69d6c53a].
22
23
24
25
26
27
28


29
    flags=re.M)

regex_include = re.compile(\
    '(?P<all>\{\{\s*include\s+[\'"](?P<name>[^\'"]*)[\'"]\s*\}\})')

regex_extend = re.compile(\
    '^\s*(?P<all>\{\{\s*extend\s+[\'"](?P<name>[^\'"]+)[\'"]\s*\}\})',re.MULTILINE)










>
>

22
23
24
25
26
27
28
29
30
31
    flags=re.M)

regex_include = re.compile(\
    '(?P<all>\{\{\s*include\s+[\'"](?P<name>[^\'"]*)[\'"]\s*\}\})')

regex_extend = re.compile(\
    '^\s*(?P<all>\{\{\s*extend\s+[\'"](?P<name>[^\'"]+)[\'"]\s*\}\})',re.MULTILINE)



Added gluon/myregex.pyc version [e888c61100].
Modified gluon/newcron.py from [196ddfcd9f] to [bdd245f2ad].
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
        lock is implemented by writing a pickle (start, stop) in cron.master
        start is time when cron job starts and stop is time when cron completed
        stop == 0 if job started but did not yet complete
        if a cron job started within less than 60 seconds, acquire returns None
        if a cron job started before 60 seconds and did not stop,
        a warning is issue "Stale cron.master detected"
        """
        if portalocker.LOCK_EX == None:
            logger.warning('WEB2PY CRON: Disabled because no file locking')
            return None
        self.master = open(self.path,'rb+')
        try:
            ret = None
            portalocker.lock(self.master,portalocker.LOCK_EX)
            try:







|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
        lock is implemented by writing a pickle (start, stop) in cron.master
        start is time when cron job starts and stop is time when cron completed
        stop == 0 if job started but did not yet complete
        if a cron job started within less than 60 seconds, acquire returns None
        if a cron job started before 60 seconds and did not stop,
        a warning is issue "Stale cron.master detected"
        """
        if portalocker.LOCK_EX is None:
            logger.warning('WEB2PY CRON: Disabled because no file locking')
            return None
        self.master = open(self.path,'rb+')
        try:
            ret = None
            portalocker.lock(self.master,portalocker.LOCK_EX)
            try:
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
                    (proc.returncode, stdoutdata+stderrdata))
        else:
            logger.debug('WEB2PY CRON Call returned success:\n%s' \
                              % stdoutdata)

def crondance(applications_parent, ctype='soft', startup=False):
    apppath = os.path.join(applications_parent,'applications')
    cron_path = os.path.join(apppath,'admin','cron')
    token = Token(cron_path)
    cronmaster = token.acquire(startup=startup)
    if not cronmaster:
        return
    now_s = time.localtime()
    checks=(('min',now_s.tm_min),
            ('hr',now_s.tm_hour),







|







225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
                    (proc.returncode, stdoutdata+stderrdata))
        else:
            logger.debug('WEB2PY CRON Call returned success:\n%s' \
                              % stdoutdata)

def crondance(applications_parent, ctype='soft', startup=False):
    apppath = os.path.join(applications_parent,'applications')
    cron_path = os.path.join(applications_parent)
    token = Token(cron_path)
    cronmaster = token.acquire(startup=startup)
    if not cronmaster:
        return
    now_s = time.localtime()
    checks=(('min',now_s.tm_min),
            ('hr',now_s.tm_hour),
306
307
308
309
310
311
312
313


            try:
                cronlauncher(commands, shell=shell).start()
            except Exception, e:
                logger.warning(
                    'WEB2PY CRON: Execution error for %s: %s' \
                        % (task.get('cmd'), e))
    token.release()











>
>
306
307
308
309
310
311
312
313
314
315
            try:
                cronlauncher(commands, shell=shell).start()
            except Exception, e:
                logger.warning(
                    'WEB2PY CRON: Execution error for %s: %s' \
                        % (task.get('cmd'), e))
    token.release()



Added gluon/newcron.pyc version [ad7a061b21].
Modified gluon/portalocker.py from [65a3d73919] to [91f1b9e40f].
116
117
118
119
120
121
122


123
    timestamp = strftime('%m/%d/%Y %H:%M:%S\n', localtime(time()))
    log.write(timestamp)

    print 'Wrote lines. Hit enter to release lock.'
    dummy = sys.stdin.readline()

    log.close()










>
>

116
117
118
119
120
121
122
123
124
125
    timestamp = strftime('%m/%d/%Y %H:%M:%S\n', localtime(time()))
    log.write(timestamp)

    print 'Wrote lines. Hit enter to release lock.'
    dummy = sys.stdin.readline()

    log.close()



Added gluon/portalocker.pyc version [9f3bbb0a55].
Modified gluon/reserved_sql_keywords.py from [b06be514b4] to [87dbdea57f].
1707
1708
1709
1710
1711
1712
1713


1714
    'ingresu': INGRES,
    'jdbc:sqlite': JDBCSQLITE,
    'jdbc:postgres': JDBCPOSTGRESQL,
    'common': COMMON,
}

ADAPTERS['all'] = reduce(lambda a,b:a.union(b),(x for x in ADAPTERS.values()))










>
>

1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
    'ingresu': INGRES,
    'jdbc:sqlite': JDBCSQLITE,
    'jdbc:postgres': JDBCPOSTGRESQL,
    'common': COMMON,
}

ADAPTERS['all'] = reduce(lambda a,b:a.union(b),(x for x in ADAPTERS.values()))



Modified gluon/restricted.py from [610deece4c] to [4c53576dff].
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
    """

    def __init__(
        self,
        layer='',
        code='',
        output='',
        environment={},
        ):
        """
        layer here is some description of where in the system the exception
        occurred.
        """

        self.layer = layer
        self.code = code
        self.output = output

        if layer:
            try:
                self.traceback = traceback.format_exc()
            except:
                self.traceback = 'no traceback because template parting error'
            try:
                self.snapshot = snapshot(context=10,code=code,environment=environment)

            except:
                self.snapshot = {}
        else:
            self.traceback = '(no error)'
            self.snapshot = {}
        self.environment = environment

    def log(self, request):
        """
        logs the exception.
        """

        try:







|





|



>






|
>





<







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
    """

    def __init__(
        self,
        layer='',
        code='',
        output='',
        environment=None,
        ):
        """
        layer here is some description of where in the system the exception
        occurred.
        """
        if environment is None: environment = {}
        self.layer = layer
        self.code = code
        self.output = output
        self.environment = environment
        if layer:
            try:
                self.traceback = traceback.format_exc()
            except:
                self.traceback = 'no traceback because template parting error'
            try:
                self.snapshot = snapshot(context=10,code=code,
                                         environment=self.environment)
            except:
                self.snapshot = {}
        else:
            self.traceback = '(no error)'
            self.snapshot = {}


    def log(self, request):
        """
        logs the exception.
        """

        try:
173
174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192

def compile2(code,layer):
    """
    The +'\n' is necessary else compile fails when code ends in a comment.
    """
    return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, 'exec')

def restricted(code, environment={}, layer='Unknown'):
    """
    runs code in environment and returns the output. if an exception occurs
    in code it raises a RestrictedError containing the traceback. layer is
    passed to RestrictedError to identify where the error occurred.
    """

    environment['__file__'] = layer
    try:
        if type(code) == types.CodeType:
            ccode = code
        else:
            ccode = compile2(code,layer)
        exec ccode in environment







|





>







174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

def compile2(code,layer):
    """
    The +'\n' is necessary else compile fails when code ends in a comment.
    """
    return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, 'exec')

def restricted(code, environment=None, layer='Unknown'):
    """
    runs code in environment and returns the output. if an exception occurs
    in code it raises a RestrictedError containing the traceback. layer is
    passed to RestrictedError to identify where the error occurred.
    """
    if environment is None: environment = {}
    environment['__file__'] = layer
    try:
        if type(code) == types.CodeType:
            ccode = code
        else:
            ccode = compile2(code,layer)
        exec ccode in environment
279
280
281
282
283
284
285
286



    # add web2py environment variables
    for k,v in environment.items():
        if k in ('request', 'response', 'session'):
            s[k] = BEAUTIFY(v)

    return s











>
>
281
282
283
284
285
286
287
288
289
290

    # add web2py environment variables
    for k,v in environment.items():
        if k in ('request', 'response', 'session'):
            s[k] = BEAUTIFY(v)

    return s



Added gluon/restricted.pyc version [52584fef22].
Modified gluon/rewrite.py from [a3895bf0e7] to [f70728e92c].
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    "return new copy of default base router"
    router = Storage(
        default_application = 'init',
            applications = 'ALL',
        default_controller = 'default',
            controllers = 'DEFAULT',
        default_function = 'index',
            functions = None,
        default_language = None,
            languages = None,
        root_static = ['favicon.ico', 'robots.txt'],
        domains = None,
        exclusive_domain = False,
        map_hyphen = False,
        acfe_match = r'\w+$',              # legal app/ctlr/fcn/ext







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    "return new copy of default base router"
    router = Storage(
        default_application = 'init',
            applications = 'ALL',
        default_controller = 'default',
            controllers = 'DEFAULT',
        default_function = 'index',
            functions = dict(),
        default_language = None,
            languages = None,
        root_static = ['favicon.ico', 'robots.txt'],
        domains = None,
        exclusive_domain = False,
        map_hyphen = False,
        acfe_match = r'\w+$',              # legal app/ctlr/fcn/ext
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391



392





393
394
395
396
397
398
399
        for key in router.keys():
            if key not in ROUTER_KEYS:
                raise SyntaxError, "unknown key '%s' in router '%s'" % (key, app)
        if not router.controllers:
            router.controllers = set()
        elif not isinstance(router.controllers, str):
            router.controllers = set(router.controllers)
        if router.functions:
            router.functions = set(router.functions)
        else:
            router.functions = set()
        if router.languages:
            router.languages = set(router.languages)
        else:
            router.languages = set()
        if app != 'BASE':
            for base_only in ROUTER_BASE_KEYS:
                router.pop(base_only, None)
            if 'domain' in router:
                routers.BASE.domains[router.domain] = app
            if isinstance(router.controllers, str) and router.controllers == 'DEFAULT':
                router.controllers = set()
                if os.path.isdir(abspath('applications', app)):
                    cpath = abspath('applications', app, 'controllers')
                    for cname in os.listdir(cpath):
                        if os.path.isfile(abspath(cpath, cname)) and cname.endswith('.py'):
                            router.controllers.add(cname[:-3])
            if router.controllers:
                router.controllers.add('static')
                router.controllers.add(router.default_controller)
            if router.functions:



                router.functions.add(router.default_function)






    if isinstance(routers.BASE.applications, str) and routers.BASE.applications == 'ALL':
        routers.BASE.applications = list(all_apps)
    if routers.BASE.applications:
        routers.BASE.applications = set(routers.BASE.applications)
    else:
        routers.BASE.applications = set()







<
<
<
<




















>
>
>
|
>
>
>
>
>







361
362
363
364
365
366
367




368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
        for key in router.keys():
            if key not in ROUTER_KEYS:
                raise SyntaxError, "unknown key '%s' in router '%s'" % (key, app)
        if not router.controllers:
            router.controllers = set()
        elif not isinstance(router.controllers, str):
            router.controllers = set(router.controllers)




        if router.languages:
            router.languages = set(router.languages)
        else:
            router.languages = set()
        if app != 'BASE':
            for base_only in ROUTER_BASE_KEYS:
                router.pop(base_only, None)
            if 'domain' in router:
                routers.BASE.domains[router.domain] = app
            if isinstance(router.controllers, str) and router.controllers == 'DEFAULT':
                router.controllers = set()
                if os.path.isdir(abspath('applications', app)):
                    cpath = abspath('applications', app, 'controllers')
                    for cname in os.listdir(cpath):
                        if os.path.isfile(abspath(cpath, cname)) and cname.endswith('.py'):
                            router.controllers.add(cname[:-3])
            if router.controllers:
                router.controllers.add('static')
                router.controllers.add(router.default_controller)
            if router.functions:
                if isinstance(router.functions, (set, tuple, list)):
                    functions = set(router.functions)
                    if isinstance(router.default_function, str):
                        functions.add(router.default_function)  # legacy compatibility
                    router.functions = { router.default_controller: functions }
                for controller in router.functions:
                    router.functions[controller] = set(router.functions[controller])
            else:
                router.functions = dict()

    if isinstance(routers.BASE.applications, str) and routers.BASE.applications == 'ALL':
        routers.BASE.applications = list(all_apps)
    if routers.BASE.applications:
        routers.BASE.applications = set(routers.BASE.applications)
    else:
        routers.BASE.applications = set()
421
422
423
424
425
426
427

428
429


430
431
432
433
434
435
436
437
438
439
    domains = dict()
    if routers.BASE.domains:
        for (domain, app) in [(d.strip(':'), a.strip('/')) for (d, a) in routers.BASE.domains.items()]:
            port = None
            if ':' in domain:
                (domain, port) = domain.split(':')
            ctlr = None

            if '/' in app:
                (app, ctlr) = app.split('/')


            if app not in all_apps and app not in routers:
                raise SyntaxError, "unknown app '%s' in domains" % app
            domains[(domain, port)] = (app, ctlr)
    routers.BASE.domains = domains

def regex_uri(e, regexes, tag, default=None):
    "filter incoming URI against a list of regexes"
    path = e['PATH_INFO']
    host = e.get('HTTP_HOST', 'localhost').lower()
    i = host.find(':')







>

|
>
>


|







425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
    domains = dict()
    if routers.BASE.domains:
        for (domain, app) in [(d.strip(':'), a.strip('/')) for (d, a) in routers.BASE.domains.items()]:
            port = None
            if ':' in domain:
                (domain, port) = domain.split(':')
            ctlr = None
            fcn = None
            if '/' in app:
                (app, ctlr) = app.split('/', 1)
            if ctlr and '/' in ctlr:
                (ctlr, fcn) = ctlr.split('/')
            if app not in all_apps and app not in routers:
                raise SyntaxError, "unknown app '%s' in domains" % app
            domains[(domain, port)] = (app, ctlr, fcn)
    routers.BASE.domains = domains

def regex_uri(e, regexes, tag, default=None):
    "filter incoming URI against a list of regexes"
    path = e['PATH_INFO']
    host = e.get('HTTP_HOST', 'localhost').lower()
    i = host.find(':')
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
        self.application = None
        self.language = None
        self.controller = None
        self.function = None
        self.extension = 'html'

        self.controllers = set()
        self.functions = set()
        self.languages = set()
        self.default_language = None
        self.map_hyphen = False
        self.exclusive_domain = False

        path = self.env['PATH_INFO']
        self.query = self.env.get('QUERY_STRING', None)







|







757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
        self.application = None
        self.language = None
        self.controller = None
        self.function = None
        self.extension = 'html'

        self.controllers = set()
        self.functions = dict()
        self.languages = set()
        self.default_language = None
        self.map_hyphen = False
        self.exclusive_domain = False

        path = self.env['PATH_INFO']
        self.query = self.env.get('QUERY_STRING', None)
806
807
808
809
810
811
812

813
814
815
816
817
818
819

820
821
822
823



824
825
826
827
828
829
830
            self.args = List(self.args[prefixlen:]) # strip the prefix

    def map_app(self):
        "determine application name"
        base = routers.BASE  # base router
        self.domain_application = None
        self.domain_controller = None

        arg0 = self.harg0
        if base.applications and arg0 in base.applications:
            self.application = arg0
        elif (self.host, self.port) in base.domains:
            (self.application, self.domain_controller) = base.domains[(self.host, self.port)]
            self.env['domain_application'] = self.application
            self.env['domain_controller'] = self.domain_controller

        elif (self.host, None) in base.domains:
            (self.application, self.domain_controller) = base.domains[(self.host, None)]
            self.env['domain_application'] = self.application
            self.env['domain_controller'] = self.domain_controller



        elif arg0 and not base.applications:
            self.application = arg0
        else:
            self.application = base.default_application or ''
        self.pop_arg_if(self.application == arg0)

        if not base._acfe_match.match(self.application):







>

<
<
|
|


>

|


>
>
>







813
814
815
816
817
818
819
820
821


822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
            self.args = List(self.args[prefixlen:]) # strip the prefix

    def map_app(self):
        "determine application name"
        base = routers.BASE  # base router
        self.domain_application = None
        self.domain_controller = None
        self.domain_function = None
        arg0 = self.harg0


        if (self.host, self.port) in base.domains:
            (self.application, self.domain_controller, self.domain_function) = base.domains[(self.host, self.port)]
            self.env['domain_application'] = self.application
            self.env['domain_controller'] = self.domain_controller
            self.env['domain_function'] = self.domain_function
        elif (self.host, None) in base.domains:
            (self.application, self.domain_controller, self.domain_function) = base.domains[(self.host, None)]
            self.env['domain_application'] = self.application
            self.env['domain_controller'] = self.domain_controller
            self.env['domain_function'] = self.domain_function
        elif base.applications and arg0 in base.applications:
            self.application = arg0
        elif arg0 and not base.applications:
            self.application = arg0
        else:
            self.application = base.default_application or ''
        self.pop_arg_if(self.application == arg0)

        if not base._acfe_match.match(self.application):
924
925
926
927
928
929
930
931



932



933
934
935
936
937
938
939
                                   'static', file)
        logger.debug("route: static=%s" % static_file)
        return static_file

    def map_function(self):
        "handle function.extension"
        arg0 = self.harg0    # map hyphens
        if not arg0 or self.functions and arg0 not in self.functions and self.controller == self.default_controller:



            self.function = self.router.default_function or ""



            self.pop_arg_if(arg0 and self.function == arg0)
        else:
            func_ext = arg0.split('.')
            if len(func_ext) > 1:
                self.function = func_ext[0]
                self.extension = func_ext[-1]
            else:







|
>
>
>
|
>
>
>







934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
                                   'static', file)
        logger.debug("route: static=%s" % static_file)
        return static_file

    def map_function(self):
        "handle function.extension"
        arg0 = self.harg0    # map hyphens
        functions = self.functions.get(self.controller, set())
        if isinstance(self.router.default_function, dict):
            default_function = self.router.default_function.get(self.controller, None)
        else:
            default_function = self.router.default_function # str or None
        default_function = self.domain_function or default_function
        if not arg0 or functions and arg0 not in functions:
            self.function = default_function or ""
            self.pop_arg_if(arg0 and self.function == arg0)
        else:
            func_ext = arg0.split('.')
            if len(func_ext) > 1:
                self.function = func_ext[0]
                self.extension = func_ext[-1]
            else:
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035



1036
1037
1038
1039
1040
1041
1042
1043
        self.other = other
        self.scheme = scheme
        self.host = host
        self.port = port

        self.applications = routers.BASE.applications
        self.controllers = self.router.controllers
        self.functions = self.router.functions
        self.languages = self.router.languages
        self.default_language = self.router.default_language
        self.exclusive_domain = self.router.exclusive_domain
        self.map_hyphen = self.router.map_hyphen
        self.map_static = self.router.map_static
        self.path_prefix = routers.BASE.path_prefix

        self.domain_application = request and self.request.env.domain_application
        self.domain_controller = request and self.request.env.domain_controller



        self.default_function = self.router.default_function

        if (self.router.exclusive_domain and self.domain_application and self.domain_application != self.application and not self.host):
            raise SyntaxError, 'cross-domain conflict: must specify host'

        lang = request and request.uri_language
        if lang and self.languages and lang in self.languages:
            self.language = lang







|









>
>
>
|







1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
        self.other = other
        self.scheme = scheme
        self.host = host
        self.port = port

        self.applications = routers.BASE.applications
        self.controllers = self.router.controllers
        self.functions = self.router.functions.get(self.controller, set())
        self.languages = self.router.languages
        self.default_language = self.router.default_language
        self.exclusive_domain = self.router.exclusive_domain
        self.map_hyphen = self.router.map_hyphen
        self.map_static = self.router.map_static
        self.path_prefix = routers.BASE.path_prefix

        self.domain_application = request and self.request.env.domain_application
        self.domain_controller = request and self.request.env.domain_controller
        if isinstance(self.router.default_function, dict):
            self.default_function = self.router.default_function.get(self.controller, None)
        else:
            self.default_function = self.router.default_function

        if (self.router.exclusive_domain and self.domain_application and self.domain_application != self.application and not self.host):
            raise SyntaxError, 'cross-domain conflict: must specify host'

        lang = request and request.uri_language
        if lang and self.languages and lang in self.languages:
            self.language = lang
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
    def omit_acf(self):
        "omit what we can of a/c/f"

        router = self.router

        #  Handle the easy no-args case of tail-defaults: /a/c  /a  /
        #
        if not self.args and self.function == router.default_function:
            self.omit_function = True
            if self.controller == router.default_controller:
                self.omit_controller = True
                if self.application == self.default_application:
                    self.omit_application = True

        #  omit default application
        #  (which might be the domain default application)
        #
        default_application = self.domain_application or self.default_application
        if self.application == default_application:
            self.omit_application = True

        #  omit controller if default controller
        #
        default_controller = ((self.application == self.domain_application) and self.domain_controller) or router.default_controller or ''
        if self.controller == default_controller:
            self.omit_controller = True

        #  omit function if default controller/function
        #
        if self.functions and self.function == self.default_function and self.omit_controller:
            self.omit_function = True

        #  prohibit ambiguous cases
        #
        #  because we presume the lang string to be unambiguous, its presence protects application omission
        #
        if self.omit_language:







|



















|

|







1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
    def omit_acf(self):
        "omit what we can of a/c/f"

        router = self.router

        #  Handle the easy no-args case of tail-defaults: /a/c  /a  /
        #
        if not self.args and self.function == self.default_function:
            self.omit_function = True
            if self.controller == router.default_controller:
                self.omit_controller = True
                if self.application == self.default_application:
                    self.omit_application = True

        #  omit default application
        #  (which might be the domain default application)
        #
        default_application = self.domain_application or self.default_application
        if self.application == default_application:
            self.omit_application = True

        #  omit controller if default controller
        #
        default_controller = ((self.application == self.domain_application) and self.domain_controller) or router.default_controller or ''
        if self.controller == default_controller:
            self.omit_controller = True

        #  omit function if possible
        #
        if self.functions and self.function in self.functions and self.function == self.default_function:
            self.omit_function = True

        #  prohibit ambiguous cases
        #
        #  because we presume the lang string to be unambiguous, its presence protects application omission
        #
        if self.omit_language:
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220



    We would also like to be able to strip the default application or application/controller
    from URLs with function/args present, thus:

        /da/c/f/args  => /c/f/args
        /da/dc/f/args => /f/args

    We use [applications] and [controllers] and [functions] to suppress ambiguous omissions.

    We assume that language names do not collide with a/c/f names.
    '''
    map = MapUrlOut(request, env, application, controller, function, args, other, scheme, host, port)
    return map.acf()

def get_effective_router(appname):
    "return a private copy of the effective router for the specified application"
    if not routers or appname not in routers:
        return None
    return Storage(routers[appname])  # return a copy










|












>
>
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241

    We would also like to be able to strip the default application or application/controller
    from URLs with function/args present, thus:

        /da/c/f/args  => /c/f/args
        /da/dc/f/args => /f/args

    We use [applications] and [controllers] and {functions} to suppress ambiguous omissions.

    We assume that language names do not collide with a/c/f names.
    '''
    map = MapUrlOut(request, env, application, controller, function, args, other, scheme, host, port)
    return map.acf()

def get_effective_router(appname):
    "return a private copy of the effective router for the specified application"
    if not routers or appname not in routers:
        return None
    return Storage(routers[appname])  # return a copy



Added gluon/rewrite.pyc version [1f6cf594b7].
Modified gluon/rocket.py from [069a2f3dcb] to [cb29338f3f].
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-

# This file is part of the Rocket Web Server
# Copyright (c) 2010 Timothy Farrell

# Import System Modules
import sys
import errno
import socket
import logging
import platform


# Define Constants
VERSION = '1.2.2'
SERVER_NAME = socket.gethostname()
SERVER_SOFTWARE = 'Rocket %s' % VERSION
HTTP_SERVER_SOFTWARE = '%s Python/%s' % (SERVER_SOFTWARE, sys.version.split(' ')[0])
BUF_SIZE = 16384
SOCKET_TIMEOUT = 1 # in secs
THREAD_STOP_CHECK_INTERVAL = 1 # in secs, How often should threads check for a server stop message?
IS_JYTHON = platform.system() == 'Java' # Handle special cases for Jython



|







>


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# -*- coding: utf-8 -*-

# This file is part of the Rocket Web Server
# Copyright (c) 2011 Timothy Farrell

# Import System Modules
import sys
import errno
import socket
import logging
import platform
import traceback

# Define Constants
VERSION = '1.2.4'
SERVER_NAME = socket.gethostname()
SERVER_SOFTWARE = 'Rocket %s' % VERSION
HTTP_SERVER_SOFTWARE = '%s Python/%s' % (SERVER_SOFTWARE, sys.version.split(' ')[0])
BUF_SIZE = 16384
SOCKET_TIMEOUT = 1 # in secs
THREAD_STOP_CHECK_INTERVAL = 1 # in secs, How often should threads check for a server stop message?
IS_JYTHON = platform.system() == 'Java' # Handle special cases for Jython
83
84
85
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
import time
import socket
try:
    import ssl
    has_ssl = True
except ImportError:
    has_ssl = False

# package imports removed in monolithic build



class Connection(object):
    __slots__ = [
        'setblocking',
        'sendall',
        'shutdown',
        'makefile',
        'fileno',
        'client_addr',
        'client_port',
        'server_port',
        'socket',
        'start_time',
        'ssl',
        'secure'




    ]

    def __init__(self, sock_tuple, port, secure=False):
        self.client_addr, self.client_port = sock_tuple[1]
        self.server_port = port
        self.socket = sock_tuple[0]
        self.start_time = time.time()







>

>
>














|
>
>
>
>







84
85
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
import time
import socket
try:
    import ssl
    has_ssl = True
except ImportError:
    has_ssl = False
# Import Package Modules
# package imports removed in monolithic build
# TODO - This part is still very experimental.
#from .filelike import FileLikeSocket

class Connection(object):
    __slots__ = [
        'setblocking',
        'sendall',
        'shutdown',
        'makefile',
        'fileno',
        'client_addr',
        'client_port',
        'server_port',
        'socket',
        'start_time',
        'ssl',
        'secure',
        'recv',
        'send',
        'read',
        'write'
    ]

    def __init__(self, sock_tuple, port, secure=False):
        self.client_addr, self.client_port = sock_tuple[1]
        self.server_port = port
        self.socket = sock_tuple[0]
        self.start_time = time.time()
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
            self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

        self.socket.settimeout(SOCKET_TIMEOUT)

        self.sendall = self.socket.sendall
        self.shutdown = self.socket.shutdown
        self.fileno = self.socket.fileno



        self.makefile = self.socket.makefile
        self.setblocking = self.socket.setblocking




    def close(self):
        if hasattr(self.socket, '_sock'):
            try:
                self.socket._sock.close()
            except socket.error:
                info = sys.exc_info()
                if info[1].errno != socket.EBADF:
                    raise info[1]
                else:
                    pass
        self.socket.close()


# Monolithic build...end of module: rocket\connection.py










































































































































































































































# Monolithic build...start of module: rocket\listener.py

# Import System Modules
import os
import socket
import logging
import traceback







>
>
>

|
>
>
>







|





>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
            self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

        self.socket.settimeout(SOCKET_TIMEOUT)

        self.sendall = self.socket.sendall
        self.shutdown = self.socket.shutdown
        self.fileno = self.socket.fileno
        self.setblocking = self.socket.setblocking
        self.recv = self.socket.recv
        self.send = self.socket.send
        self.makefile = self.socket.makefile

# FIXME - this is not ready for prime-time yet.
#    def makefile(self, buf_size=BUF_SIZE):
#        return FileLikeSocket(self, buf_size)

    def close(self):
        if hasattr(self.socket, '_sock'):
            try:
                self.socket._sock.close()
            except socket.error:
                info = sys.exc_info()
                if info[1].args[0] != socket.EBADF:
                    raise info[1]
                else:
                    pass
        self.socket.close()


# Monolithic build...end of module: rocket\connection.py
# Monolithic build...start of module: rocket\filelike.py

# Import System Modules
import socket
try:
    from io import StringIO
except ImportError:
    try:
        from cStringIO import StringIO
    except ImportError:
        from StringIO import StringIO
# Import Package Modules
# package imports removed in monolithic build

class FileLikeSocket(object):
    def __init__(self, conn, buf_size=BUF_SIZE):
        self.conn = conn
        self.buf_size = buf_size
        self.buffer = StringIO()
        self.content_length = None

        if self.conn.socket.gettimeout() == 0.0:
            self.read = self.non_blocking_read
        else:
            self.read = self.blocking_read

    def __iter__(self):
        return self

    def recv(self, size):
        while True:
            try:
                return self.conn.recv(size)
            except socket.error:
                exc = sys.exc_info()
                e = exc[1]
                # FIXME - Don't raise socket_errors_nonblocking or socket_error_eintr
                if (e.args[0] not in set()):
                    raise

    def next(self):
        data = self.readline()
        if data == '':
            raise StopIteration
        return data

    def non_blocking_read(self, size=None):
        # Shamelessly adapted from Cherrypy!
        bufr = self.buffer
        bufr.seek(0, 2)
        if size is None:
            while True:
                data = self.recv(self.buf_size)
                if not data:
                    break
                bufr.write(data)

            self.buffer = StringIO()

            return bufr.getvalue()
        else:
            buf_len = self.buffer.tell()
            if buf_len >= size:
                bufr.seek(0)
                data = bufr.read(size)
                self.buffer = StringIO(bufr.read())
                return data

            self.buffer = StringIO()
            while True:
                remaining = size - buf_len
                data = self.recv(remaining)

                if not data:
                    break

                n = len(data)
                if n == size and not buf_len:
                    return data

                if n == remaining:
                    bufr.write(data)
                    del data
                    break

                bufr.write(data)
                buf_len += n
                del data

            return bufr.getvalue()

    def blocking_read(self, length=None):
        if length is None:
            if self.content_length is not None:
                length = self.content_length
            else:
                length = 1

        try:
            data = self.conn.recv(length)
        except:
            data = b('')

        return data

    def readline(self):
        data = b("")
        char = self.read(1)
        while char != b('\n') and char is not b(''):
            line = repr(char)
            data += char
            char = self.read(1)
        data += char
        return data

    def readlines(self, hint="ignored"):
        return list(self)

    def close(self):
        self.conn = None
        self.content_length = None

# Monolithic build...end of module: rocket\filelike.py
# Monolithic build...start of module: rocket\futures.py

# Import System Modules
import time
try:
    from concurrent.futures import Future, ThreadPoolExecutor
    from concurrent.futures.thread import _WorkItem
    has_futures = True
except ImportError:
    has_futures = False

    class Future:
        pass

    class ThreadPoolExecutor:
        pass

    class _WorkItem:
        pass


class WSGIFuture(Future):
    def __init__(self, f_dict, *args, **kwargs):
        Future.__init__(self, *args, **kwargs)

        self.timeout = None

        self._mem_dict = f_dict
        self._lifespan = 30
        self._name = None
        self._start_time = time.time()

    def set_running_or_notify_cancel(self):
        if time.time() - self._start_time >= self._lifespan:
            self.cancel()
        else:
            return super(WSGIFuture, self).set_running_or_notify_cancel()


    def remember(self, name, lifespan=None):
        self._lifespan = lifespan or self._lifespan

        if name in self._mem_dict:
            raise NameError('Cannot remember future by name "%s".  ' % name + \
                            'A future already exists with that name.' )
        self._name = name
        self._mem_dict[name] = self

        return self

    def forget(self):
        if self._name in self._mem_dict and self._mem_dict[self._name] is self:
            del self._mem_dict[self._name]
            self._name = None

class _WorkItem(object):
    def __init__(self, future, fn, args, kwargs):
        self.future = future
        self.fn = fn
        self.args = args
        self.kwargs = kwargs

    def run(self):
        if not self.future.set_running_or_notify_cancel():
            return

        try:
            result = self.fn(*self.args, **self.kwargs)
        except BaseException:
            e = sys.exc_info()[1]
            self.future.set_exception(e)
        else:
            self.future.set_result(result)

class WSGIExecutor(ThreadPoolExecutor):
    multithread = True
    multiprocess = False

    def __init__(self, *args, **kwargs):
        ThreadPoolExecutor.__init__(self, *args, **kwargs)

        self.futures = dict()

    def submit(self, fn, *args, **kwargs):
        if self._shutdown_lock.acquire():
            if self._shutdown:
                self._shutdown_lock.release()
                raise RuntimeError('Cannot schedule new futures after shutdown')

            f = WSGIFuture(self.futures)
            w = _WorkItem(f, fn, args, kwargs)

            self._work_queue.put(w)
            self._adjust_thread_count()
            self._shutdown_lock.release()
            return f
        else:
            return False

class FuturesMiddleware(object):
    "Futures middleware that adds a Futures Executor to the environment"
    def __init__(self, app, threads=5):
        self.app = app
        self.executor = WSGIExecutor(threads)

    def __call__(self, environ, start_response):
        environ["wsgiorg.executor"] = self.executor
        environ["wsgiorg.futures"] = self.executor.futures
        return self.app(environ, start_response)

# Monolithic build...end of module: rocket\futures.py
# Monolithic build...start of module: rocket\listener.py

# Import System Modules
import os
import socket
import logging
import traceback
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
        Thread.__init__(self, *args, **kwargs)

        # Instance variables
        self.active_queue = active_queue
        self.interface = interface
        self.addr = interface[0]
        self.port = interface[1]
        self.secure = len(interface) == 4 and \
                      os.path.exists(interface[2]) and \
                      os.path.exists(interface[3])

        self.ready = False

        # Error Log
        self.err_log = logging.getLogger('Rocket.Errors.Port%i' % self.port)
        self.err_log.addHandler(NullHandler())

        # Build the socket







|
|
|
>







417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
        Thread.__init__(self, *args, **kwargs)

        # Instance variables
        self.active_queue = active_queue
        self.interface = interface
        self.addr = interface[0]
        self.port = interface[1]
        self.secure = len(interface) >= 4
        self.clientcert_req = (len(interface) == 5 and interface[4])

        self.thread = None
        self.ready = False

        # Error Log
        self.err_log = logging.getLogger('Rocket.Errors.Port%i' % self.port)
        self.err_log.addHandler(NullHandler())

        # Build the socket
199
200
201
202
203
204
205






206
207
208
209
210
211
212
                return
            elif not os.path.exists(interface[3]):
                data = (interface[3], interface[0], interface[1])
                self.err_log.error("Cannot find certificate file "
                          "'%s'.  Cannot bind to %s:%s" % data)
                return







        # Set socket options
        try:
            listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        except:
            msg = "Cannot share socket.  Using %s:%i exclusively."
            self.err_log.warning(msg % (self.addr, self.port))








>
>
>
>
>
>







449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
                return
            elif not os.path.exists(interface[3]):
                data = (interface[3], interface[0], interface[1])
                self.err_log.error("Cannot find certificate file "
                          "'%s'.  Cannot bind to %s:%s" % data)
                return

            if self.clientcert_req and not os.path.exists(interface[4]):
                data = (interface[4], interface[0], interface[1])
                self.err_log.error("Cannot find root ca certificate file "
                          "'%s'.  Cannot bind to %s:%s" % data)
                return
            
        # Set socket options
        try:
            listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        except:
            msg = "Cannot share socket.  Using %s:%i exclusively."
            self.err_log.warning(msg % (self.addr, self.port))

234
235
236
237
238
239
240



241
242
243
244


245







246
247
248
249

250
251
252
253
254
255
256
257
258
259



























260
261
262
263
264
265
266

            self.listener = listener

            self.ready = True

    def wrap_socket(self, sock):
        try:



            sock = ssl.wrap_socket(sock,
                                   keyfile = self.interface[2],
                                   certfile = self.interface[3],
                                   server_side = True,


                                   ssl_version = ssl.PROTOCOL_SSLv23)







        except SSLError:
            # Generally this happens when an HTTP request is received on a
            # secure socket. We don't do anything because it will be detected
            # by Worker and dealt with appropriately.

            pass

        return sock


    def run(self):
        if not self.ready:
            self.err_log.warning('Listener started when not ready.')
            return




























        if __debug__:
            self.err_log.debug('Entering main loop.')
        while True:
            try:
                sock, addr = self.listener.accept()

                if self.secure:







>
>
>
|
|
|
|
>
>
|
>
>
>
>
>
>
>




>




<
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

            self.listener = listener

            self.ready = True

    def wrap_socket(self, sock):
        try:
            if self.clientcert_req:
                ca_certs = self.interface[4]
                cert_reqs = ssl.CERT_OPTIONAL
                sock = ssl.wrap_socket(sock,
                                       keyfile = self.interface[2],
                                       certfile = self.interface[3],
                                       server_side = True,
                                       cert_reqs = cert_reqs,
                                       ca_certs = ca_certs,
                                       ssl_version = ssl.PROTOCOL_SSLv23)
            else:
                sock = ssl.wrap_socket(sock,
                                       keyfile = self.interface[2],
                                       certfile = self.interface[3],
                                       server_side = True,
                                       ssl_version = ssl.PROTOCOL_SSLv23)

        except SSLError:
            # Generally this happens when an HTTP request is received on a
            # secure socket. We don't do anything because it will be detected
            # by Worker and dealt with appropriately.
            self.err_log.error('SSL Error: %s' % traceback.format_exc())
            pass

        return sock


    def start(self):
        if not self.ready:
            self.err_log.warning('Listener started when not ready.')
            return

        if self.thread is not None and self.thread.isAlive():
            self.err_log.warning('Listener already running.')
            return

        self.thread = Thread(target=self.listen, name="Port" + str(self.port))

        self.thread.start()

    def isAlive(self):
        if self.thread is None:
            return False

        return self.thread.isAlive()

    def join(self):
        if self.thread is None:
            return

        self.ready = False

        self.thread.join()

        del self.thread
        self.thread = None
        self.ready = True

    def listen(self):
        if __debug__:
            self.err_log.debug('Entering main loop.')
        while True:
            try:
                sock, addr = self.listener.accept()

                if self.secure:
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
                if not self.ready:
                    if __debug__:
                        self.err_log.debug('Listener exiting.')
                    return
                else:
                    continue
            except:
                self.err_log.error(str(traceback.format_exc()))

# Monolithic build...end of module: rocket\listener.py
# Monolithic build...start of module: rocket\main.py

# Import System Modules
import sys
import time
import socket
import logging
import traceback

try:
    from queue import Queue
except ImportError:
    from Queue import Queue

# Import Package Modules
# package imports removed in monolithic build







|










|







572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
                if not self.ready:
                    if __debug__:
                        self.err_log.debug('Listener exiting.')
                    return
                else:
                    continue
            except:
                self.err_log.error(traceback.format_exc())

# Monolithic build...end of module: rocket\listener.py
# Monolithic build...start of module: rocket\main.py

# Import System Modules
import sys
import time
import socket
import logging
import traceback
from threading import Lock
try:
    from queue import Queue
except ImportError:
    from Queue import Queue

# Import Package Modules
# package imports removed in monolithic build
320
321
322
323
324
325
326


327
328
329
330
331
332
333
                 min_threads = None,
                 max_threads = None,
                 queue_size = None,
                 timeout = 600,
                 handle_signals = True):

        self.handle_signals = handle_signals



        if not isinstance(interfaces, list):
            self.interfaces = [interfaces]
        else:
            self.interfaces = interfaces

        if min_threads is None:







>
>







615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
                 min_threads = None,
                 max_threads = None,
                 queue_size = None,
                 timeout = 600,
                 handle_signals = True):

        self.handle_signals = handle_signals
        self.startstop_lock = Lock()
        self.timeout = timeout

        if not isinstance(interfaces, list):
            self.interfaces = [interfaces]
        else:
            self.interfaces = interfaces

        if min_threads is None:
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383



384
385
386
387
388
389
390
391
392
393
394
395
396




397
398
399
400
401
402
403
404
405
406
407
408
409
410

411
412


413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

429

430

431
432
433





434
435
436
437
438
439
440
441
442
443
444



445
446











447
448
449
450
451
452
453
454
455
456

        if max_threads and queue_size > max_threads:
            queue_size = max_threads

        if isinstance(app_info, dict):
            app_info['server_software'] = SERVER_SOFTWARE

        monitor_queue = Queue()
        active_queue = Queue()

        self._monitor = Monitor(monitor_queue, active_queue, timeout)

        self._threadpool = ThreadPool(get_method(method),
                                      app_info = app_info,
                                      active_queue=active_queue,
                                      monitor_queue = monitor_queue,
                                      min_threads=min_threads,
                                      max_threads=max_threads)

        # Build our socket listeners
        self.listeners = [Listener(i, queue_size, active_queue) for i in self.interfaces]
        for ndx in range(len(self.listeners)-1, 0, -1):
            if not self.listeners[ndx].ready:
                del self.listeners[ndx]

        if not self.listeners:
            log.critical("No interfaces to listen on...closing.")
            sys.exit(1)

    def _sigterm(self, signum, frame):
        log.info('Received SIGTERM')
        self.stop()

    def _sighup(self, signum, frame):
        log.info('Received SIGHUP')
        self.restart()

    def start(self):
        log.info('Starting %s' % SERVER_SOFTWARE)




        # Set up our shutdown signals
        if self.handle_signals:
            try:
                import signal
                signal.signal(signal.SIGTERM, self._sigterm)
                signal.signal(signal.SIGUSR1, self._sighup)
            except:
                log.debug('This platform does not support signals.')

        # Start our worker threads
        self._threadpool.start()

        # Start our monitor thread




        self._monitor.setDaemon(True)
        self._monitor.start()

        # I know that EXPR and A or B is bad but I'm keeping it for Py2.4
        # compatibility.
        str_extract = lambda l: (l.addr, l.port, l.secure and '*' or '')

        msg = 'Listening on sockets: '
        msg += ', '.join(['%s:%i%s' % str_extract(l) for l in self.listeners])
        log.info(msg)

        for l in self.listeners:
            l.start()


        tp = self._threadpool
        dynamic_resize = tp.dynamic_resize



        while not tp.stop_server:
            try:
                dynamic_resize()
                time.sleep(THREAD_STOP_CHECK_INTERVAL)
            except KeyboardInterrupt:
                # Capture a keyboard interrupt when running from a console
                break
            except:
                if not tp.stop_server:
                    log.error(str(traceback.format_exc()))
                    continue

        return self.stop()

    def stop(self, stoplogging = True):

        log.info("Stopping Server")



        # Stop listeners
        for l in self.listeners:
            l.ready = False





            if l.isAlive():
                l.join()

        # Stop Worker threads
        self._threadpool.stop()

        # Stop Monitor
        self._monitor.stop()
        if self._monitor.isAlive():
            self._monitor.join()




        if stoplogging:
            logging.shutdown()












    def restart(self):
        self.stop(False)
        self.start()

def CherryPyWSGIServer(bind_addr,
                       wsgi_app,
                       numthreads = 10,
                       server_name = None,
                       max = -1,







|
|
<
<



|
|
|
|


|
















|


>
>
>
|
|
|
|
|
|
|
|

|
|

|
>
>
>
>
|
|

|
|
|

|
|
|

|
|

>
|
|
>
>

|

<





|
|




|
>
|
>

>
|
|
|
>
>
>
>
>
|
|

<
<
<
|
|
|
|

>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>


|







641
642
643
644
645
646
647
648
649


650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720

721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748



749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

        if max_threads and queue_size > max_threads:
            queue_size = max_threads

        if isinstance(app_info, dict):
            app_info['server_software'] = SERVER_SOFTWARE

        self.monitor_queue = Queue()
        self.active_queue = Queue()



        self._threadpool = ThreadPool(get_method(method),
                                      app_info = app_info,
                                      active_queue = self.active_queue,
                                      monitor_queue = self.monitor_queue,
                                      min_threads = min_threads,
                                      max_threads = max_threads)

        # Build our socket listeners
        self.listeners = [Listener(i, queue_size, self.active_queue) for i in self.interfaces]
        for ndx in range(len(self.listeners)-1, 0, -1):
            if not self.listeners[ndx].ready:
                del self.listeners[ndx]

        if not self.listeners:
            log.critical("No interfaces to listen on...closing.")
            sys.exit(1)

    def _sigterm(self, signum, frame):
        log.info('Received SIGTERM')
        self.stop()

    def _sighup(self, signum, frame):
        log.info('Received SIGHUP')
        self.restart()

    def start(self, background=False):
        log.info('Starting %s' % SERVER_SOFTWARE)

        self.startstop_lock.acquire()

        try:
            # Set up our shutdown signals
            if self.handle_signals:
                try:
                    import signal
                    signal.signal(signal.SIGTERM, self._sigterm)
                    signal.signal(signal.SIGUSR1, self._sighup)
                except:
                    log.debug('This platform does not support signals.')

            # Start our worker threads
            self._threadpool.start()

            # Start our monitor thread
            self._monitor = Monitor(self.monitor_queue,
                                    self.active_queue,
                                    self.timeout,
                                    self._threadpool)
            self._monitor.setDaemon(True)
            self._monitor.start()

            # I know that EXPR and A or B is bad but I'm keeping it for Py2.4
            # compatibility.
            str_extract = lambda l: (l.addr, l.port, l.secure and '*' or '')

            msg = 'Listening on sockets: '
            msg += ', '.join(['%s:%i%s' % str_extract(l) for l in self.listeners])
            log.info(msg)

            for l in self.listeners:
                l.start()

        finally:
            self.startstop_lock.release()

        if background:
            return

        while self._monitor.isAlive():
            try:

                time.sleep(THREAD_STOP_CHECK_INTERVAL)
            except KeyboardInterrupt:
                # Capture a keyboard interrupt when running from a console
                break
            except:
                if self._monitor.isAlive():
                    log.error(traceback.format_exc())
                    continue

        return self.stop()

    def stop(self, stoplogging = False):
        log.info('Stopping %s' % SERVER_SOFTWARE)

        self.startstop_lock.acquire()

        try:
            # Stop listeners
            for l in self.listeners:
                l.ready = False

            # Encourage a context switch
            time.sleep(0.01)

            for l in self.listeners:
                if l.isAlive():
                    l.join()




            # Stop Monitor
            self._monitor.stop()
            if self._monitor.isAlive():
                self._monitor.join()

            # Stop Worker threads
            self._threadpool.stop()

            if stoplogging:
                logging.shutdown()
                msg = "Calling logging.shutdown() is now the responsibility of \
                       the application developer.  Please update your \
                       applications to no longer call rocket.stop(True)"
                try:
                    import warnings
                    raise warnings.DeprecationWarning(msg)
                except ImportError:
                    raise RuntimeError(msg)

        finally:
            self.startstop_lock.release()

    def restart(self):
        self.stop()
        self.start()

def CherryPyWSGIServer(bind_addr,
                       wsgi_app,
                       numthreads = 10,
                       server_name = None,
                       max = -1,
482
483
484
485
486
487
488

489
490
491
492


493
494
495
496
497
498



499
500
501
502
503
504
505
506
507
508
509




510
511
512
513
514
515

516
517
518
519
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559




560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578






579
580
581
582
583
584
585
class Monitor(Thread):
    # Monitor worker class.

    def __init__(self,
                 monitor_queue,
                 active_queue,
                 timeout,

                 *args,
                 **kwargs):

        Thread.__init__(self, *args, **kwargs)



        # Instance Variables
        self.monitor_queue = monitor_queue
        self.active_queue = active_queue
        self.timeout = timeout




        self.connections = set()
        self.active = False

    def run(self):
        self.name = self.getName()
        self.log = logging.getLogger('Rocket.Monitor')
        self.log.addHandler(NullHandler())

        self.active = True
        conn_list = list()
        list_changed = False





        if __debug__:
            self.log.debug('Entering monitor loop.')

        # Enter thread main loop
        while self.active:

            # Move the queued connections to the selection pool
            while not self.monitor_queue.empty() or not len(self.connections):
                if __debug__:
                    self.log.debug('In "receive timed-out connections" loop.')

                c = self.monitor_queue.get()

                if c is None:
                    # A non-client is a signal to die
                    if __debug__:
                        self.log.debug('Received a death threat.')

                    return

                self.log.debug('Received a timed out connection.')

                if __debug__:
                    assert(c not in self.connections)

                if IS_JYTHON:
                    # Jython requires a socket to be in Non-blocking mode in
                    # order to select on it.
                    c.setblocking(False)

                if __debug__:
                    self.log.debug('Adding connection to monitor list.')

                self.connections.add(c)
                list_changed = True

            # Wait on those connections
            self.log.debug('Blocking on connections')
            if list_changed:
                conn_list = list(self.connections)
                list_changed = False

            try:

                readable = select.select(conn_list,
                                         [],
                                         [],
                                         THREAD_STOP_CHECK_INTERVAL)[0]
            except:
                if self.active:
                    raise
                else:




                    break

            # If we have any readable connections, put them back
            for r in readable:
                if __debug__:
                    self.log.debug('Restoring readable connection')

                if IS_JYTHON:
                    # Jython requires a socket to be in Non-blocking mode in
                    # order to select on it, but the rest of the code requires
                    # that it be in blocking mode.
                    r.setblocking(True)

                r.start_time = time.time()
                self.active_queue.put(r)

                self.connections.remove(r)
                list_changed = True







            # If we have any stale connections, kill them off.
            if self.timeout:
                now = time.time()
                stale = set()
                for c in self.connections:
                    if (now - c.start_time) >= self.timeout:
                        stale.add(c)







>




>
>






>
>
>




<
<
<
<



>
>
>
>






>

|









>
|


















<





>
|
|
|
|
<
<
<

>
>
>
>


|
|
|
|

|
|
|
|
|

|
|

|
|

>
>
>
>
>
>







805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831




832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884
885
886



887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
class Monitor(Thread):
    # Monitor worker class.

    def __init__(self,
                 monitor_queue,
                 active_queue,
                 timeout,
                 threadpool,
                 *args,
                 **kwargs):

        Thread.__init__(self, *args, **kwargs)

        self._threadpool = threadpool

        # Instance Variables
        self.monitor_queue = monitor_queue
        self.active_queue = active_queue
        self.timeout = timeout

        self.log = logging.getLogger('Rocket.Monitor')
        self.log.addHandler(NullHandler())

        self.connections = set()
        self.active = False

    def run(self):




        self.active = True
        conn_list = list()
        list_changed = False

        # We need to make sure the queue is empty before we start
        while not self.monitor_queue.empty():
            self.monitor_queue.get()

        if __debug__:
            self.log.debug('Entering monitor loop.')

        # Enter thread main loop
        while self.active:

            # Move the queued connections to the selection pool
            while not self.monitor_queue.empty():
                if __debug__:
                    self.log.debug('In "receive timed-out connections" loop.')

                c = self.monitor_queue.get()

                if c is None:
                    # A non-client is a signal to die
                    if __debug__:
                        self.log.debug('Received a death threat.')
                    self.stop()
                    break

                self.log.debug('Received a timed out connection.')

                if __debug__:
                    assert(c not in self.connections)

                if IS_JYTHON:
                    # Jython requires a socket to be in Non-blocking mode in
                    # order to select on it.
                    c.setblocking(False)

                if __debug__:
                    self.log.debug('Adding connection to monitor list.')

                self.connections.add(c)
                list_changed = True

            # Wait on those connections

            if list_changed:
                conn_list = list(self.connections)
                list_changed = False

            try:
                if len(conn_list):
                    readable = select.select(conn_list,
                                             [],
                                             [],
                                             THREAD_STOP_CHECK_INTERVAL)[0]



                else:
                    time.sleep(THREAD_STOP_CHECK_INTERVAL)
                    readable = []

                if not self.active:
                    break

                # If we have any readable connections, put them back
                for r in readable:
                    if __debug__:
                        self.log.debug('Restoring readable connection')

                    if IS_JYTHON:
                        # Jython requires a socket to be in Non-blocking mode in
                        # order to select on it, but the rest of the code requires
                        # that it be in blocking mode.
                        r.setblocking(True)

                    r.start_time = time.time()
                    self.active_queue.put(r)

                    self.connections.remove(r)
                    list_changed = True

            except:
                if self.active:
                    raise
                else:
                    break

            # If we have any stale connections, kill them off.
            if self.timeout:
                now = time.time()
                stale = set()
                for c in self.connections:
                    if (now - c.start_time) >= self.timeout:
                        stale.add(c)
593
594
595
596
597
598
599




600
601
602
603
604
605
606
607

608
609
610
611
612
613
614
                    self.connections.remove(c)
                    list_changed = True

                    try:
                        c.close()
                    finally:
                        del c





    def stop(self):
        self.active = False

        if __debug__:
            self.log.debug('Flushing waiting connections')

        for c in self.connections:

            try:
                c.close()
            finally:
                del c

        if __debug__:
            self.log.debug('Flushing queued connections')







>
>
>
>







|
>







931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
                    self.connections.remove(c)
                    list_changed = True

                    try:
                        c.close()
                    finally:
                        del c

            # Dynamically resize the threadpool to adapt to our changing needs.
            self._threadpool.dynamic_resize()


    def stop(self):
        self.active = False

        if __debug__:
            self.log.debug('Flushing waiting connections')

        while self.connections:
            c = self.connections.pop()
            try:
                c.close()
            finally:
                del c

        if __debug__:
            self.log.debug('Flushing queued connections')
630
631
632
633
634
635
636

637
638
639
640
641
642
643
# Monolithic build...end of module: rocket\monitor.py
# Monolithic build...start of module: rocket\threadpool.py

# Import System Modules
import logging
# Import Package Modules
# package imports removed in monolithic build


# Setup Logging
log = logging.getLogger('Rocket.Errors.ThreadPool')
log.addHandler(NullHandler())

class ThreadPool:
    """The ThreadPool class is a container class for all the worker threads. It







>







973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
# Monolithic build...end of module: rocket\monitor.py
# Monolithic build...start of module: rocket\threadpool.py

# Import System Modules
import logging
# Import Package Modules
# package imports removed in monolithic build


# Setup Logging
log = logging.getLogger('Rocket.Errors.ThreadPool')
log.addHandler(NullHandler())

class ThreadPool:
    """The ThreadPool class is a container class for all the worker threads. It
659
660
661
662
663
664
665

666
667
668
669
670
671
672




673
674
675

676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694


695
696
697
698
699
700
701
702






703
704
705


706
707
708
709

710
711
712
713
714
715
716
717
        self.active_queue = active_queue

        self.worker_class = method
        self.min_threads = min_threads
        self.max_threads = max_threads
        self.monitor_queue = monitor_queue
        self.stop_server = False


        # TODO - Optimize this based on some real-world usage data
        self.grow_threshold = int(max_threads/10) + 2

        if not isinstance(app_info, dict):
            app_info = dict()





        app_info.update(max_threads=max_threads,
                        min_threads=min_threads)


        self.app_info = app_info

        self.threads = set()
        for x in range(min_threads):
            worker = self.worker_class(app_info,
                                       self.active_queue,
                                       self.monitor_queue)
            self.threads.add(worker)

    def start(self):
        self.stop_server = False
        if __debug__:
            log.debug("Starting threads.")

        for thread in self.threads:
            thread.setDaemon(True)
            thread.start()

    def stop(self):


        if __debug__:
            log.debug("Stopping threads.")

        self.stop_server = True

        # Prompt the threads to die
        for t in self.threads:
            self.active_queue.put(None)







        # Give them the gun
        for t in self.threads:


            t.kill()

        # Wait until they pull the trigger
        for t in self.threads:

            t.join()

        # Clean up the mess
        self.bring_out_your_dead()

    def bring_out_your_dead(self):
        # Remove dead threads from the pool








>







>
>
>
>



>



<
<
<
<
<






|
|
|


>
>






|
|
>
>
>
>
>
>


|
>
>
|



>
|







1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028





1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
        self.active_queue = active_queue

        self.worker_class = method
        self.min_threads = min_threads
        self.max_threads = max_threads
        self.monitor_queue = monitor_queue
        self.stop_server = False
        self.alive = False

        # TODO - Optimize this based on some real-world usage data
        self.grow_threshold = int(max_threads/10) + 2

        if not isinstance(app_info, dict):
            app_info = dict()

        if has_futures and app_info.get('futures'):
            app_info['executor'] = WSGIExecutor(max([DEFAULTS['MIN_THREADS'],
                                                     2]))

        app_info.update(max_threads=max_threads,
                        min_threads=min_threads)

        self.min_threads = min_threads
        self.app_info = app_info

        self.threads = set()






    def start(self):
        self.stop_server = False
        if __debug__:
            log.debug("Starting threads.")

        self.grow(self.min_threads)

        self.alive = True

    def stop(self):
        self.alive = False

        if __debug__:
            log.debug("Stopping threads.")

        self.stop_server = True

        # Prompt the threads to die
        self.shrink(len(self.threads))

        # Stop futures initially
        if has_futures and self.app_info.get('futures'):
            if __debug__:
                log.debug("Future executor is present.  Python will not "
                          "exit until all jobs have finished.")
            self.app_info['executor'].shutdown(wait=False)

        # Give them the gun
        #active_threads = [t for t in self.threads if t.isAlive()]
        #while active_threads:
        #    t = active_threads.pop()
        #    t.kill()

        # Wait until they pull the trigger
        for t in self.threads:
            if t.isAlive():
                t.join()

        # Clean up the mess
        self.bring_out_your_dead()

    def bring_out_your_dead(self):
        # Remove dead threads from the pool

729
730
731
732
733
734
735

736
737
738
739
740
741
742
743
    def grow(self, amount=None):
        if self.stop_server:
            return

        if not amount:
            amount = self.max_threads


        amount = min([amount, self.max_threads - len(self.threads)])

        if __debug__:
            log.debug("Growing by %i." % amount)

        for x in range(amount):
            worker = self.worker_class(self.app_info,
                                       self.active_queue,







>
|







1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
    def grow(self, amount=None):
        if self.stop_server:
            return

        if not amount:
            amount = self.max_threads

        if self.alive:
            amount = min([amount, self.max_threads - len(self.threads)])

        if __debug__:
            log.debug("Growing by %i." % amount)

        for x in range(amount):
            worker = self.worker_class(self.app_info,
                                       self.active_queue,
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794

# Import System Modules
import re
import sys
import socket
import logging
import traceback
#from wsgiref.headers import Headers
from threading import Thread
from datetime import datetime

try:
    from urllib import unquote
except ImportError:
    from urllib.parse import unquote







|







1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151

# Import System Modules
import re
import sys
import socket
import logging
import traceback
from wsgiref.headers import Headers
from threading import Thread
from datetime import datetime

try:
    from urllib import unquote
except ImportError:
    from urllib.parse import unquote
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
Content-Type: %s

%s
'''
if IS_JYTHON:
    HTTP_METHODS = set(['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT'])

###
# The Headers and FileWrapper classes are ripped straight from the Python
# Standard Library. I've removed some docstrings and integrated my BUF_SIZE.
# See the Python License here: http://docs.python.org/license.html
###

# Regular expression that matches `special' characters in parameters, the
# existance of which force quoting of the parameter value.
import re
_tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')

def _formatparam(param, value=None, quote=1):
    """Convenience function to format and return a key=value pair.

    This will quote the value if needed or if quote is true.
    """
    if value is not None and len(value) > 0:
        if quote or _tspecials.search(value):
            value = value.replace('\\', '\\\\').replace('"', r'\"')
            return '%s="%s"' % (param, value)
        else:
            return '%s=%s' % (param, value)
    else:
        return param

class Headers:
    def __init__(self,headers):
        if type(headers) is not type([]):
            raise TypeError("Headers must be a list of name/value tuples")
        self._headers = headers

    def __len__(self):
        return len(self._headers)

    def __setitem__(self, name, val):
        del self[name]
        self._headers.append((name, val))

    def __delitem__(self,name):
        name = name.lower()
        self._headers[:] = [kv for kv in self._headers if kv[0].lower() != name]

    def __getitem__(self,name):
        return self.get(name)

    def has_key(self, name):
        return self.get(name) is not None

    __contains__ = has_key

    def get_all(self, name):
        name = name.lower()
        return [kv[1] for kv in self._headers if kv[0].lower()==name]

    def get(self,name,default=None):
        name = name.lower()
        for k,v in self._headers:
            if k.lower()==name:
                return v
        return default

    def keys(self):
        return [k for k, v in self._headers]

    def values(self):
        return [v for k, v in self._headers]

    def items(self):
        return self._headers[:]

    def __repr__(self):
        return "Headers(%r)" % self._headers

    def __str__(self):
        return '\r\n'.join(["%s: %s" % kv for kv in self._headers]+['',''])

    def setdefault(self,name,value):
        result = self.get(name)
        if result is None:
            self._headers.append((name,value))
            return value
        else:
            return result


    def add_header(self, _name, _value, **_params):
        parts = []
        if _value is not None:
            parts.append(_value)
        for k, v in _params.items():
            if v is None:
                parts.append(k.replace('_', '-'))
            else:
                parts.append(_formatparam(k.replace('_', '-'), v))
        self._headers.append((_name, "; ".join(parts)))

class FileWrapper:
    """Wrapper to convert file-like objects to iterables"""

    def __init__(self, filelike, blksize=BUF_SIZE):
        self.filelike = filelike
        self.blksize = blksize
        if hasattr(filelike,'close'):
            self.close = filelike.close

    def __getitem__(self,key):
        data = self.filelike.read(self.blksize)
        if data:
            return data
        raise IndexError

    def __iter__(self):
        return self

    def next(self):
        data = self.filelike.read(self.blksize)
        if data:
            return data
        raise StopIteration

class Worker(Thread):
    """The Worker class is a base class responsible for receiving connections
    and (a subclass) will run an application to process the the connection """

    def __init__(self,
                 app_info,
                 active_queue,







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1190
1191
1192
1193
1194
1195
1196
























































































































1197
1198
1199
1200
1201
1202
1203
Content-Type: %s

%s
'''
if IS_JYTHON:
    HTTP_METHODS = set(['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT'])

























































































































class Worker(Thread):
    """The Worker class is a base class responsible for receiving connections
    and (a subclass) will run an application to process the the connection """

    def __init__(self,
                 app_info,
                 active_queue,
974
975
976
977
978
979
980

981
982
983
984
985
986
987
        self.app_info = app_info
        self.active_queue = active_queue
        self.monitor_queue = monitor_queue

        self.size = 0
        self.status = "200 OK"
        self.closeConnection = True


        # Request Log
        self.req_log = logging.getLogger('Rocket.Requests')
        self.req_log.addHandler(NullHandler())

        # Error Log
        self.err_log = logging.getLogger('Rocket.Errors.'+self.getName())







>







1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
        self.app_info = app_info
        self.active_queue = active_queue
        self.monitor_queue = monitor_queue

        self.size = 0
        self.status = "200 OK"
        self.closeConnection = True
        self.request_line = ""

        # Request Log
        self.req_log = logging.getLogger('Rocket.Requests')
        self.req_log.addHandler(NullHandler())

        # Error Log
        self.err_log = logging.getLogger('Rocket.Errors.'+self.getName())
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
        try:
            self.conn.sendall(b(msg))
        except socket.error:
            self.closeConnection = True
            self.err_log.error('Tried to send "%s" to client but received socket'
                           ' error' % status)

    def kill(self):
        if self.isAlive() and hasattr(self, 'conn'):
            try:
                self.conn.shutdown(socket.SHUT_RDWR)
            except socket.error:
                info = sys.exc_info()
                if info[1].args[0] != socket.EBADF:
                    self.err_log.debug('Error on shutdown: '+str(info))

    def read_request_line(self, sock_file):
        self.request_line = ''
        try:
            # Grab the request line
            d = sock_file.readline()
            if PY3K:







|
|
|
|
|
|
|
|







1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
        try:
            self.conn.sendall(b(msg))
        except socket.error:
            self.closeConnection = True
            self.err_log.error('Tried to send "%s" to client but received socket'
                           ' error' % status)

    #def kill(self):
    #    if self.isAlive() and hasattr(self, 'conn'):
    #        try:
    #            self.conn.shutdown(socket.SHUT_RDWR)
    #        except socket.error:
    #            info = sys.exc_info()
    #            if info[1].args[0] != socket.EBADF:
    #                self.err_log.debug('Error on shutdown: '+str(info))

    def read_request_line(self, sock_file):
        self.request_line = ''
        try:
            # Grab the request line
            d = sock_file.readline()
            if PY3K:
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239



1240
1241
1242
1243
1244
1245
1246
                   query_string=query_string,
                   scheme=scheme.lower(),
                   host=host)
        return req


    def read_headers(self, sock_file):

        headers = dict()
        l = sock_file.readline()

        lname = None
        lval = None
        while True:
            if PY3K:
                try:
                    l = str(l, 'ISO-8859-1')
                except UnicodeDecodeError:
                    self.err_log.warning('Client sent invalid header: ' + repr(l))

            if l == '\r\n':
                break

            if l[0] in ' \t' and lname:
                # Some headers take more than one line
                lval += ',' + l.strip()
            else:
                # HTTP header values are latin-1 encoded
                l = l.split(':', 1)
                # HTTP header names are us-ascii encoded

                lname = l[0].strip().upper().replace('-', '_')
                lval = l[-1].strip()
            headers[str(lname)] = str(lval)

            l = sock_file.readline()



        return headers

class SocketTimeout(Exception):
    "Exception for when a socket times out between requests."
    pass

class BadRequest(Exception):







>
|
|

|
|
|
|
|
|
|
|

|
|

|
|
|
|
|
|
|

|
|
|

|
>
>
>







1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
                   query_string=query_string,
                   scheme=scheme.lower(),
                   host=host)
        return req


    def read_headers(self, sock_file):
        try:
            headers = dict()
            l = sock_file.readline()

            lname = None
            lval = None
            while True:
                if PY3K:
                    try:
                        l = str(l, 'ISO-8859-1')
                    except UnicodeDecodeError:
                        self.err_log.warning('Client sent invalid header: ' + repr(l))

                if l == '\r\n':
                    break

                if l[0] in ' \t' and lname:
                    # Some headers take more than one line
                    lval += ',' + l.strip()
                else:
                    # HTTP header values are latin-1 encoded
                    l = l.split(':', 1)
                    # HTTP header names are us-ascii encoded

                    lname = l[0].strip().upper().replace('-', '_')
                    lval = l[-1].strip()
                headers[str(lname)] = str(lval)

                l = sock_file.readline()
        except socket.timeout:
            raise SocketTimeout("Socket timed out before request.")

        return headers

class SocketTimeout(Exception):
    "Exception for when a socket times out between requests."
    pass

class BadRequest(Exception):
1296
1297
1298
1299
1300
1301
1302

1303

1304
1305
1306
1307
1308
1309
































































































































































































1310
1311
1312
1313
1314
1315
1316

1317
1318

1319
1320
1321
1322
1323
1324
1325
        return data

    def readlines(self):
        yield self.readline()

def get_method(method):


    methods = dict(wsgi=WSGIWorker)

    return methods[method.lower()]

# Monolithic build...end of module: rocket\worker.py
# Monolithic build...start of module: rocket\methods\__init__.py

# Monolithic build...end of module: rocket\methods\__init__.py
































































































































































































# Monolithic build...start of module: rocket\methods\wsgi.py

# Import System Modules
import sys
import socket
#from wsgiref.headers import Headers
#from wsgiref.util import FileWrapper

# Import Package Modules
# package imports removed in monolithic build



if PY3K:
    from email.utils import formatdate
else:
    # Caps Utils for Py2.4 compatibility
    from email.Utils import formatdate







>
|
>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|
|
>


>







1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
        return data

    def readlines(self):
        yield self.readline()

def get_method(method):


    methods = dict(wsgi=WSGIWorker,
                   fs=FileSystemWorker)
    return methods[method.lower()]

# Monolithic build...end of module: rocket\worker.py
# Monolithic build...start of module: rocket\methods\__init__.py

# Monolithic build...end of module: rocket\methods\__init__.py
# Monolithic build...start of module: rocket\methods\fs.py

# Import System Modules
import os
import time
import mimetypes
from email.utils import formatdate
from wsgiref.headers import Headers
from wsgiref.util import FileWrapper
# Import Package Modules
# package imports removed in monolithic build


# Define Constants
CHUNK_SIZE = 2**16 # 64 Kilobyte chunks
HEADER_RESPONSE = '''HTTP/1.1 %s\r\n%s'''
INDEX_HEADER = '''\
<html>
<head><title>Directory Index: %(path)s</title>
<style> .parent { margin-bottom: 1em; }</style>
</head>
<body><h1>Directory Index: %(path)s</h1>
<table>
<tr><th>Directories</th></tr>
'''
INDEX_ROW = '''<tr><td><div class="%(cls)s"><a href="/%(link)s">%(name)s</a></div></td></tr>'''
INDEX_FOOTER = '''</table></body></html>\r\n'''

class LimitingFileWrapper(FileWrapper):
    def __init__(self, limit=None, *args, **kwargs):
        self.limit = limit
        FileWrapper.__init__(self, *args, **kwargs)

    def read(self, amt):
        if amt > self.limit:
            amt = self.limit
        self.limit -= amt
        return FileWrapper.read(self, amt)

class FileSystemWorker(Worker):
    def __init__(self, *args, **kwargs):
        """Builds some instance variables that will last the life of the
        thread."""

        Worker.__init__(self, *args, **kwargs)

        self.root = os.path.abspath(self.app_info['document_root'])
        self.display_index = self.app_info['display_index']

    def serve_file(self, filepath, headers):
        filestat = os.stat(filepath)
        self.size = filestat.st_size
        modtime = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
                                time.gmtime(filestat.st_mtime))
        self.headers.add_header('Last-Modified', modtime)
        if headers.get('if_modified_since') == modtime:
            # The browser cache is up-to-date, send a 304.
            self.status = "304 Not Modified"
            self.data = []
            return

        ct = mimetypes.guess_type(filepath)[0]
        self.content_type = ct if ct else 'text/plain'
        try:
            f = open(filepath, 'rb')
            self.headers['Pragma'] = 'cache'
            self.headers['Cache-Control'] = 'private'
            self.headers['Content-Length'] = str(self.size)
            if self.etag:
                self.headers.add_header('Etag', self.etag)
            if self.expires:
                self.headers.add_header('Expires', self.expires)

            try:
                # Implement 206 partial file support.
                start, end = headers['range'].split('-')
                start = 0 if not start.isdigit() else int(start)
                end = self.size if not end.isdigit() else int(end)
                if self.size < end or start < 0:
                    self.status = "214 Unsatisfiable Range Requested"
                    self.data = FileWrapper(f, CHUNK_SIZE)
                else:
                    f.seek(start)
                    self.data = LimitingFileWrapper(f, CHUNK_SIZE, limit=end)
                    self.status = "206 Partial Content"
            except:
                self.data = FileWrapper(f, CHUNK_SIZE)
        except IOError:
            self.status = "403 Forbidden"

    def serve_dir(self, pth, rpth):
        def rel_path(path):
            return os.path.normpath(path[len(self.root):] if path.startswith(self.root) else path)

        if not self.display_index:
            self.status = '404 File Not Found'
            return b('')
        else:
            self.content_type = 'text/html'

            dir_contents = [os.path.join(pth, x) for x in os.listdir(os.path.normpath(pth))]
            dir_contents.sort()

            dirs = [rel_path(x)+'/' for x in dir_contents if os.path.isdir(x)]
            files = [rel_path(x) for x in dir_contents if os.path.isfile(x)]

            self.data = [INDEX_HEADER % dict(path='/'+rpth)]
            if rpth:
                self.data += [INDEX_ROW % dict(name='(parent directory)', cls='dir parent', link='/'.join(rpth[:-1].split('/')[:-1]))]
            self.data += [INDEX_ROW % dict(name=os.path.basename(x[:-1]), link=os.path.join(rpth, os.path.basename(x[:-1])).replace('\\', '/'), cls='dir') for x in dirs]
            self.data += ['<tr><th>Files</th></tr>']
            self.data += [INDEX_ROW % dict(name=os.path.basename(x), link=os.path.join(rpth, os.path.basename(x)).replace('\\', '/'), cls='file') for x in files]
            self.data += [INDEX_FOOTER]
            self.headers['Content-Length'] = self.size = str(sum([len(x) for x in self.data]))
            self.status = '200 OK'

    def run_app(self, conn):
        self.status = "200 OK"
        self.size = 0
        self.expires = None
        self.etag = None
        self.content_type = 'text/plain'
        self.content_length = None

        if __debug__:
            self.err_log.debug('Getting sock_file')

        # Build our file-like object
        sock_file = conn.makefile('rb',BUF_SIZE)
        request = self.read_request_line(sock_file)
        if request['method'].upper() not in ('GET', ):
            self.status = "501 Not Implemented"

        try:
            # Get our file path
            headers = dict([(str(k.lower()), v) for k, v in self.read_headers(sock_file).items()])
            rpath = request.get('path', '').lstrip('/')
            filepath = os.path.join(self.root, rpath)
            filepath = os.path.abspath(filepath)
            if __debug__:
                self.err_log.debug('Request for path: %s' % filepath)

            self.closeConnection = headers.get('connection', 'close').lower() == 'close'
            self.headers = Headers([('Date', formatdate(usegmt=True)),
                                    ('Server', HTTP_SERVER_SOFTWARE),
                                    ('Connection', headers.get('connection', 'close')),
                                   ])

            if not filepath.lower().startswith(self.root.lower()):
                # File must be within our root directory
                self.status = "400 Bad Request"
                self.closeConnection = True
            elif not os.path.exists(filepath):
                self.status = "404 File Not Found"
                self.closeConnection = True
            elif os.path.isdir(filepath):
                self.serve_dir(filepath, rpath)
            elif os.path.isfile(filepath):
                self.serve_file(filepath, headers)
            else:
                # It exists but it's not a file or a directory????
                # What is it then?
                self.status = "501 Not Implemented"
                self.closeConnection = True

            h = self.headers
            statcode, statstr = self.status.split(' ', 1)
            statcode = int(statcode)
            if statcode >= 400:
                h.add_header('Content-Type', self.content_type)
                self.data = [statstr]

            # Build our output headers
            header_data = HEADER_RESPONSE % (self.status, str(h))

            # Send the headers
            if __debug__:
                self.err_log.debug('Sending Headers: %s' % repr(header_data))
            self.conn.sendall(b(header_data))

            for data in self.data:
                self.conn.sendall(b(data))

            if hasattr(self.data, 'close'):
                self.data.close()

        finally:
            if __debug__:
                self.err_log.debug('Finally closing sock_file')
            sock_file.close()

# Monolithic build...end of module: rocket\methods\fs.py
# Monolithic build...start of module: rocket\methods\wsgi.py

# Import System Modules
import sys
import socket
from wsgiref.headers import Headers
from wsgiref.util import FileWrapper

# Import Package Modules
# package imports removed in monolithic build



if PY3K:
    from email.utils import formatdate
else:
    # Caps Utils for Py2.4 compatibility
    from email.Utils import formatdate
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355
1356
1357
1358





1359
1360
1361
1362
1363
1364
1365
            multithreaded = self.app_info.get('max_threads') != 1
        else:
            multithreaded = False
        self.base_environ = dict({'SERVER_SOFTWARE': self.app_info['server_software'],
                                  'wsgi.multithread': multithreaded,
                                  })
        self.base_environ.update(BASE_ENV)

        # Grab our application
        self.app = self.app_info.get('wsgi_app')

        if not hasattr(self.app, "__call__"):
            raise TypeError("The wsgi_app specified (%s) is not a valid WSGI application." % repr(self.app))







    def build_environ(self, sock_file, conn):
        """ Build the execution environment. """
        # Grab the request line
        request = self.read_request_line(sock_file)

        # Copy the Base Environment







>






>
>
>
>
>







1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
            multithreaded = self.app_info.get('max_threads') != 1
        else:
            multithreaded = False
        self.base_environ = dict({'SERVER_SOFTWARE': self.app_info['server_software'],
                                  'wsgi.multithread': multithreaded,
                                  })
        self.base_environ.update(BASE_ENV)

        # Grab our application
        self.app = self.app_info.get('wsgi_app')

        if not hasattr(self.app, "__call__"):
            raise TypeError("The wsgi_app specified (%s) is not a valid WSGI application." % repr(self.app))

        # Enable futures
        if has_futures and self.app_info.get('futures'):
            executor = self.app_info['executor']
            self.base_environ.update({"wsgiorg.executor": executor,
                                      "wsgiorg.futures": executor.futures})

    def build_environ(self, sock_file, conn):
        """ Build the execution environment. """
        # Grab the request line
        request = self.read_request_line(sock_file)

        # Copy the Base Environment
1388
1389
1390
1391
1392
1393
1394








1395
1396
1397
1398
1399
1400
1401
        # Add Dynamic WSGI Variables
        if conn.ssl:
            environ['wsgi.url_scheme'] = 'https'
            environ['HTTPS'] = 'on'
        else:
            environ['wsgi.url_scheme'] = 'http'









        if environ.get('HTTP_TRANSFER_ENCODING', '') == 'chunked':
            environ['wsgi.input'] = ChunkedReader(sock_file)
        else:
            environ['wsgi.input'] = sock_file

        return environ








>
>
>
>
>
>
>
>







1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
        # Add Dynamic WSGI Variables
        if conn.ssl:
            environ['wsgi.url_scheme'] = 'https'
            environ['HTTPS'] = 'on'
        else:
            environ['wsgi.url_scheme'] = 'http'

        if conn.ssl:
            try:
                peercert = conn.socket.getpeercert(binary_form=True)
                environ['SSL_CLIENT_RAW_CERT'] = \
                    peercert and ssl.DER_cert_to_PEM_cert(peercert)
            except Exception,e:
                print e

        if environ.get('HTTP_TRANSFER_ENCODING', '') == 'chunked':
            environ['wsgi.input'] = ChunkedReader(sock_file)
        else:
            environ['wsgi.input'] = sock_file

        return environ

1520
1521
1522
1523
1524
1525
1526



1527
1528
1529
1530
1531
1532
1533
1534
        sections = None
        output = None

        if __debug__:
            self.err_log.debug('Getting sock_file')

        # Build our file-like object



        sock_file = conn.makefile('rb',BUF_SIZE)

        try:
            # Read the headers and build our WSGI environment
            self.environ = environ = self.build_environ(sock_file, conn)

            # Handle 100 Continue
            if environ.get('HTTP_EXPECT', '') == '100-continue':







>
>
>
|







1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
        sections = None
        output = None

        if __debug__:
            self.err_log.debug('Getting sock_file')

        # Build our file-like object
        if PY3K:
            sock_file = conn.makefile(mode='rb', buffering=BUF_SIZE)
        else:
            sock_file = conn.makefile(BUF_SIZE)

        try:
            # Read the headers and build our WSGI environment
            self.environ = environ = self.build_environ(sock_file, conn)

            # Handle 100 Continue
            if environ.get('HTTP_EXPECT', '') == '100-continue':
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
    if static_folder:
        if not static_folder.startswith('/'):
            static_folder = os.path.join(os.getcwd(),static_folder)
        path = os.path.join(static_folder, environ['PATH_INFO'][1:] or 'index.html')
        type = types.get(path.split('.')[-1],'text')
        if os.path.exists(path):
            try:
                pathfile = open(path,'rb')
                try:
                    data = pathfile.read()
                finally:
                    pathfile.close()
                start_response('200 OK', [('Content-Type', type)])
            except IOError:
                start_response('404 NOT FOUND', [])
                data = '404 NOT FOUND'
        else:
            start_response('500 INTERNAL SERVER ERROR', [])
            data = '500 INTERNAL SERVER ERROR'







|
<
<
<
<







2038
2039
2040
2041
2042
2043
2044
2045




2046
2047
2048
2049
2050
2051
2052
    if static_folder:
        if not static_folder.startswith('/'):
            static_folder = os.path.join(os.getcwd(),static_folder)
        path = os.path.join(static_folder, environ['PATH_INFO'][1:] or 'index.html')
        type = types.get(path.split('.')[-1],'text')
        if os.path.exists(path):
            try:
                data = open(path,'rb').read()




                start_response('200 OK', [('Content-Type', type)])
            except IOError:
                start_response('404 NOT FOUND', [])
                data = '404 NOT FOUND'
        else:
            start_response('500 INTERNAL SERVER ERROR', [])
            data = '500 INTERNAL SERVER ERROR'
Added gluon/rocket.pyc version [30fb9fab51].
Modified gluon/sanitizer.py from [a160c3e797] to [393e02e106].
218
219
220
221
222
223
224


225
        'blockquote': ['type'],
        'td': ['colspan'],
        },
             escape=True):
    if not isinstance(text, str): return str(text)
    return XssCleaner(permitted_tags=permitted_tags,
                      allowed_attributes=allowed_attributes).strip(text, escape)










>
>

218
219
220
221
222
223
224
225
226
227
        'blockquote': ['type'],
        'td': ['colspan'],
        },
             escape=True):
    if not isinstance(text, str): return str(text)
    return XssCleaner(permitted_tags=permitted_tags,
                      allowed_attributes=allowed_attributes).strip(text, escape)



Added gluon/sanitizer.pyc version [d789c7453f].
Added gluon/scheduler.py version [b19c6df200].
Modified gluon/serializers.py from [4a4a474858] to [aeb8c6ffcb].
1
2
3
4
5
6
7
8
9
10
11







12
13
14
15
16
17
18
19
20
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
"""
import datetime
from storage import Storage
from html import TAG
from html import xmlescape
from languages import lazyT
import contrib.simplejson as simplejson







import contrib.rss2 as rss2

def custom_json(o):
    if hasattr(o,'custom_json') and callable(o.custom_json):
        return o.custom_json()
    if isinstance(o, (datetime.date,
                      datetime.datetime,
                      datetime.time)):
        return o.isoformat()[:19].replace('T',' ')










|
>
>
>
>
>
>
>
|








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
"""
import datetime
from storage import Storage
from html import TAG
from html import xmlescape
from languages import lazyT
import contrib.rss2 as rss2

try:
    import json as json_parser                      # try stdlib (Python 2.6)
except ImportError:
    try:
        import simplejson as json_parser            # try external module
    except:
        import contrib.simplejson as json_parser    # fallback to pure-Python module

def custom_json(o):
    if hasattr(o,'custom_json') and callable(o.custom_json):
        return o.custom_json()
    if isinstance(o, (datetime.date,
                      datetime.datetime,
                      datetime.time)):
        return o.isoformat()[:19].replace('T',' ')
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


def xml(value, encoding='UTF-8', key='document'):
    return ('<?xml version="1.0" encoding="%s"?>' % encoding) + str(xml_rec(value,key))


def json(value,default=custom_json):
    return simplejson.dumps(value,default=default)


def csv(value):
    return ''


def rss(feed):







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67


def xml(value, encoding='UTF-8', key='document'):
    return ('<?xml version="1.0" encoding="%s"?>' % encoding) + str(xml_rec(value,key))


def json(value,default=custom_json):
    return json_parser.dumps(value,default=default)


def csv(value):
    return ''


def rss(feed):
71
72
73
74
75
76
77
78


                                        description=entry['description'],
                                        pubDate=entry.get('created_on', now)
                                        )\
                                    for entry in feed['entries']
                                    ]
                    )
    return rss2.dumps(rss)











>
>
78
79
80
81
82
83
84
85
86
87
                                        description=entry['description'],
                                        pubDate=entry.get('created_on', now)
                                        )\
                                    for entry in feed['entries']
                                    ]
                    )
    return rss2.dumps(rss)



Added gluon/serializers.pyc version [50c93bfb9c].
Modified gluon/settings.py from [5c78f2495b] to [f43a3ef62c].
1
2
3
4
5
6
7
8
9
10


11
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
"""

from storage import Storage

global_settings = Storage()
settings = global_settings  # legacy compatibility













>
>

1
2
3
4
5
6
7
8
9
10
11
12
13
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
"""

from storage import Storage

global_settings = Storage()
settings = global_settings  # legacy compatibility



Added gluon/settings.pyc version [ee34a24607].
Modified gluon/shell.py from [e6d16bd699] to [20bba43f9c].
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
import sys
import code
import logging
import types
import re
import optparse
import glob

import fileutils
import settings
from utils import web2py_uuid
from compileapp import build_environment, read_pyc, run_models_in
from restricted import RestrictedError
from globals import Request, Response, Session
from storage import Storage
from admin import w2p_unpack



logger = logging.getLogger("web2py")

def exec_environment(
    pyfile='',
    request=None,







|








>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import code
import logging
import types
import re
import optparse
import glob
import traceback
import fileutils
import settings
from utils import web2py_uuid
from compileapp import build_environment, read_pyc, run_models_in
from restricted import RestrictedError
from globals import Request, Response, Session
from storage import Storage
from admin import w2p_unpack
from dal import BaseAdapter


logger = logging.getLogger("web2py")

def exec_environment(
    pyfile='',
    request=None,
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
        Builds a web2py environment and optionally executes a Python
        file into the environment.
        A Storage dictionary containing the resulting environment is returned.
        The working directory must be web2py root -- this is the web2py default.

    """

    if request==None: request = Request()
    if response==None: response = Response()
    if session==None: session = Session()

    if request.folder is None:
        mo = re.match(r'(|.*/)applications/(?P<appname>[^/]+)', pyfile)
        if mo:
            appname = mo.group('appname')
            request.folder = os.path.join('applications', appname)
        else:







|
|
|







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        Builds a web2py environment and optionally executes a Python
        file into the environment.
        A Storage dictionary containing the resulting environment is returned.
        The working directory must be web2py root -- this is the web2py default.

    """

    if request is None: request = Request()
    if response is None: response = Response()
    if session is None: session = Session()

    if request.folder is None:
        mo = re.match(r'(|.*/)applications/(?P<appname>[^/]+)', pyfile)
        if mo:
            appname = mo.group('appname')
            request.folder = os.path.join('applications', appname)
        else:
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160


def run(
    appname,
    plain=False,
    import_models=False,
    startfile=None,
    bpython=False

    ):
    """
    Start interactive shell or run Python script (startfile) in web2py
    controller environment. appname is formatted like:

    a      web2py application name
    a/c    exec the controller c into the application environment







|
>







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162


def run(
    appname,
    plain=False,
    import_models=False,
    startfile=None,
    bpython=False,
    python_code=False
    ):
    """
    Start interactive shell or run Python script (startfile) in web2py
    controller environment. appname is formatted like:

    a      web2py application name
    a/c    exec the controller c into the application environment
198
199
200
201
202
203
204

205
206









207
208
209
210
211
212
213
214
215
216
217
218
219






220

221
222
223
224
225
226
227
228
229
230
231
232

    if f:
        exec ('print %s()' % f, _env)
    elif startfile:
        exec_pythonrc()
        try:
            execfile(startfile, _env)

        except RestrictedError, e:
            print e.traceback









    else:
        if not plain:
            if bpython:
                try:
                    import bpython
                    bpython.embed(locals_=_env)
                    return
                except:
                    logger.warning(
                        'import bpython error; trying ipython...')
            else:
                try:
                    import IPython






                    # following 2 lines fix a problem with IPython; thanks Michael Toomim

                    if '__builtins__' in _env:
                        del _env['__builtins__']
                    shell = IPython.Shell.IPShell(argv=[], user_ns=_env)
                    shell.mainloop()
                    return
                except:
                    logger.warning(
                        'import IPython error; use default python shell')
        try:
            import readline
            import rlcompleter
        except ImportError:







>
|
|
>
>
>
>
>
>
>
>
>













>
>
>
>
>
>
|
>
|
|
|
|
|







200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

    if f:
        exec ('print %s()' % f, _env)
    elif startfile:
        exec_pythonrc()
        try:
            execfile(startfile, _env)
            if import_models: BaseAdapter.close_all_instances('commit')
        except Exception, e:
            print traceback.format_exc()
            if import_models: BaseAdapter.close_all_instances('rollback')
    elif python_code:
        exec_pythonrc()
        try:
            exec(python_code, _env)
            if import_models: BaseAdapter.close_all_instances('commit')
        except Exception, e:
            print traceback.format_exc()
            if import_models: BaseAdapter.close_all_instances('rollback')
    else:
        if not plain:
            if bpython:
                try:
                    import bpython
                    bpython.embed(locals_=_env)
                    return
                except:
                    logger.warning(
                        'import bpython error; trying ipython...')
            else:
                try:
                    import IPython
                    if IPython.__version__ >= '0.11':
                        from IPython.frontend.terminal.embed import InteractiveShellEmbed
                        shell = InteractiveShellEmbed(user_ns=_env)
                        shell()
                        return
                    else:
                        # following 2 lines fix a problem with
                        # IPython; thanks Michael Toomim
                        if '__builtins__' in _env:
                            del _env['__builtins__']
                        shell = IPython.Shell.IPShell(argv=[],user_ns=_env)
                        shell.mainloop()
                        return
                except:
                    logger.warning(
                        'import IPython error; use default python shell')
        try:
            import readline
            import rlcompleter
        except ImportError:
393
394
395
396
397
398
399
400


    else:
        startfile = ''
    run(options.shell, options.plain, startfile=startfile, bpython=options.bpython)


if __name__ == '__main__':
    execute_from_command_line()











>
>
412
413
414
415
416
417
418
419
420
421
    else:
        startfile = ''
    run(options.shell, options.plain, startfile=startfile, bpython=options.bpython)


if __name__ == '__main__':
    execute_from_command_line()



Added gluon/shell.pyc version [cb888418ec].
Modified gluon/sql.py from [8df4f4f856] to [e7fa972eb8].
1
2
3
4
5


6
# this file exists for backward compatibility

__all__ = ['DAL','Field','drivers']

from dal import DAL, Field, Table, Query, Set, Expression, Row, Rows, drivers, BaseAdapter, SQLField, SQLTable, SQLXorable, SQLQuery, SQLSet, SQLRows, SQLStorage, SQLDB, GQLDB, SQLALL, SQLCustomType








>
>

1
2
3
4
5
6
7
8
# this file exists for backward compatibility

__all__ = ['DAL','Field','drivers']

from dal import DAL, Field, Table, Query, Set, Expression, Row, Rows, drivers, BaseAdapter, SQLField, SQLTable, SQLXorable, SQLQuery, SQLSet, SQLRows, SQLStorage, SQLDB, GQLDB, SQLALL, SQLCustomType



Modified gluon/sqlhtml.py from [aa2336d433] to [086b79de71].
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
- SQLFORM: provide a form for a table (with/without record)
- SQLTABLE: provides a table for a set of records
- form_factory: provides a SQLFORM for an non-db backed table

"""

from http import HTTP
from html import XML, SPAN, TAG, A, DIV, UL, LI, TEXTAREA, BR, IMG, SCRIPT
from html import FORM, INPUT, LABEL, OPTION, SELECT
from html import TABLE, THEAD, TBODY, TR, TD, TH
from html import URL as Url
from dal import DAL, Table, Row, CALLABLETYPES
from storage import Storage
from utils import md5_hash
from validators import IS_EMPTY_OR

import urllib
import re
import cStringIO


table_field = re.compile('[\w_]+\.[\w_]+')
widget_class = re.compile('^\w*')

def represent(field,value,record):
    f = field.represent
    if not callable(f):







|


|
|







<







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
- SQLFORM: provide a form for a table (with/without record)
- SQLTABLE: provides a table for a set of records
- form_factory: provides a SQLFORM for an non-db backed table

"""

from http import HTTP
from html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG, SCRIPT
from html import FORM, INPUT, LABEL, OPTION, SELECT
from html import TABLE, THEAD, TBODY, TR, TD, TH
from html import URL
from dal import DAL, Table, Row, CALLABLETYPES, smart_query
from storage import Storage
from utils import md5_hash
from validators import IS_EMPTY_OR

import urllib
import re
import cStringIO


table_field = re.compile('[\w_]+\.[\w_]+')
widget_class = re.compile('^\w*')

def represent(field,value,record):
    f = field.represent
    if not callable(f):
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        generates an INPUT text tag.

        see also: :meth:`FormWidget.widget`
        """

        default = dict(
            _type = 'text',
            value = (value!=None and str(value)) or '',
            )
        attr = StringWidget._attributes(field, default, **attributes)

        return INPUT(**attr)


class IntegerWidget(StringWidget):







|







106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
        generates an INPUT text tag.

        see also: :meth:`FormWidget.widget`
        """

        default = dict(
            _type = 'text',
            value = (not value is None and str(value)) or '',
            )
        attr = StringWidget._attributes(field, default, **attributes)

        return INPUT(**attr)


class IntegerWidget(StringWidget):
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317








318
319
320



321
322
323
324


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368








369
370
371
372
373
374
375
376


377
378
379

380
381
382
383
384
385
386
387
388
389
390
391
    def widget(field, value, **attributes):
        """
        generates a TABLE tag, including INPUT radios (only 1 option allowed)

        see also: :meth:`FormWidget.widget`
        """

        attr = OptionsWidget._attributes(field, {}, **attributes)


        requires = field.requires
        if not isinstance(requires, (list, tuple)):
            requires = [requires]
        if requires:
            if hasattr(requires[0], 'options'):
                options = requires[0].options()
            else:
                raise SyntaxError, 'widget cannot determine options of %s' \
                    % field

        options = [(k, v) for k, v in options if str(v)]
        opts = []
        cols = attributes.get('cols',1)
        totals = len(options)
        mods = totals%cols
        rows = totals/cols
        if mods:
            rows += 1









        for r_index in range(rows):
            tds = []
            for k, v in options[r_index*cols:(r_index+1)*cols]:



                tds.append(TD(INPUT(_type='radio', _name=field.name,
                         requires=attr.get('requires',None),
                         hideerror=True, _value=k,
                         value=value), v))


            opts.append(TR(tds))

        if opts:
            opts[-1][0][0]['hideerror'] = False
        return TABLE(*opts, **attr)


class CheckboxesWidget(OptionsWidget):

    @staticmethod
    def widget(field, value, **attributes):
        """
        generates a TABLE tag, including INPUT checkboxes (multiple allowed)

        see also: :meth:`FormWidget.widget`
        """

        # was values = re.compile('[\w\-:]+').findall(str(value))
        if isinstance(value, (list, tuple)):
            values = [str(v) for v in value]
        else:
            values = [str(value)]

        attr = OptionsWidget._attributes(field, {}, **attributes)


        requires = field.requires
        if not isinstance(requires, (list, tuple)):
            requires = [requires]
        if requires:
            if hasattr(requires[0], 'options'):
                options = requires[0].options()
            else:
                raise SyntaxError, 'widget cannot determine options of %s' \
                    % field

        options = [(k, v) for k, v in options if k != '']
        opts = []
        cols = attributes.get('cols', 1)
        totals = len(options)
        mods = totals % cols
        rows = totals / cols
        if mods:
            rows += 1









        for r_index in range(rows):
            tds = []
            for k, v in options[r_index*cols:(r_index+1)*cols]:
                if k in values:
                    r_value = k
                else:
                    r_value = []
                tds.append(TD(INPUT(_type='checkbox', _name=field.name,


                         requires=attr.get('requires', None),
                         hideerror=True, _value=k,
                         value=r_value), v))

            opts.append(TR(tds))

        if opts:
            opts[-1][0][0]['hideerror'] = False
        return TABLE(*opts, **attr)


class PasswordWidget(FormWidget):

    DEFAULT_PASSWORD_DISPLAY = 8*('*')

    @staticmethod







|
>










<









>
>
>
>
>
>
>
>



>
>
>
|
|
|
|
>
>
|



|


















|
>




















>
>
>
>
>
>
>
>







|
>
>
|
|
|
>
|



|







289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    def widget(field, value, **attributes):
        """
        generates a TABLE tag, including INPUT radios (only 1 option allowed)

        see also: :meth:`FormWidget.widget`
        """

        attr = RadioWidget._attributes(field, {}, **attributes)
        attr['_class'] = attr.get('_class','web2py_radiowidget')

        requires = field.requires
        if not isinstance(requires, (list, tuple)):
            requires = [requires]
        if requires:
            if hasattr(requires[0], 'options'):
                options = requires[0].options()
            else:
                raise SyntaxError, 'widget cannot determine options of %s' \
                    % field

        options = [(k, v) for k, v in options if str(v)]
        opts = []
        cols = attributes.get('cols',1)
        totals = len(options)
        mods = totals%cols
        rows = totals/cols
        if mods:
            rows += 1

        #widget style
        wrappers = dict(
            table=(TABLE,TR,TD),
            ul=(DIV,UL,LI),
            divs=(CAT,DIV,DIV)
            )
        parent, child, inner = wrappers[attributes.get('style','table')]

        for r_index in range(rows):
            tds = []
            for k, v in options[r_index*cols:(r_index+1)*cols]:
                checked={'_checked':'checked'} if k==value else {}
                tds.append(inner(INPUT(_type='radio',
                                       _id='%s%s' % (field.name,k), 
                                       _name=field.name,
                                       requires=attr.get('requires',None),
                                       hideerror=True, _value=k,
                                       value=value,
                                       **checked), 
                                       LABEL(v,_for='%s%s' % (field.name,k))))
            opts.append(child(tds))

        if opts:
            opts[-1][0][0]['hideerror'] = False
        return parent(*opts, **attr)


class CheckboxesWidget(OptionsWidget):

    @staticmethod
    def widget(field, value, **attributes):
        """
        generates a TABLE tag, including INPUT checkboxes (multiple allowed)

        see also: :meth:`FormWidget.widget`
        """

        # was values = re.compile('[\w\-:]+').findall(str(value))
        if isinstance(value, (list, tuple)):
            values = [str(v) for v in value]
        else:
            values = [str(value)]

        attr = CheckboxesWidget._attributes(field, {}, **attributes)
        attr['_class'] = attr.get('_class','web2py_checkboxeswidget')

        requires = field.requires
        if not isinstance(requires, (list, tuple)):
            requires = [requires]
        if requires:
            if hasattr(requires[0], 'options'):
                options = requires[0].options()
            else:
                raise SyntaxError, 'widget cannot determine options of %s' \
                    % field

        options = [(k, v) for k, v in options if k != '']
        opts = []
        cols = attributes.get('cols', 1)
        totals = len(options)
        mods = totals % cols
        rows = totals / cols
        if mods:
            rows += 1

        #widget style
        wrappers = dict(
            table=(TABLE,TR,TD),
            ul=(DIV,UL,LI),
            divs=(CAT,DIV,DIV)
            )
        parent, child, inner = wrappers[attributes.get('style','table')]

        for r_index in range(rows):
            tds = []
            for k, v in options[r_index*cols:(r_index+1)*cols]:
                if k in values:
                    r_value = k
                else:
                    r_value = []
                tds.append(inner(INPUT(_type='checkbox', 
                                       _id='%s%s' % (field.name,k),
                                       _name=field.name,
                                       requires=attr.get('requires', None),
                                       hideerror=True, _value=k,
                                       value=r_value), 
                                       LABEL(v,_for='%s%s' % (field.name,k))))
            opts.append(child(tds))

        if opts:
            opts[-1][0][0]['hideerror'] = False
        return parent(*opts, **attr)


class PasswordWidget(FormWidget):

    DEFAULT_PASSWORD_DISPLAY = 8*('*')

    @staticmethod
432
433
434
435
436
437
438



439
440
441
442
443
444
445
446
447
448
449
450
451

452

453
454
455
456
457
458
459
460
            _type='file',
            )
        attr = UploadWidget._attributes(field, default, **attributes)

        inp = INPUT(**attr)

        if download_url and value:



            url = download_url + '/' + value
            (br, image) = ('', '')
            if UploadWidget.is_image(value):
                br = BR()
                image = IMG(_src = url, _width = UploadWidget.DEFAULT_WIDTH)

            requires = attr["requires"]
            if requires == [] or isinstance(requires, IS_EMPTY_OR):
                inp = DIV(inp, '[',
                          A(UploadWidget.GENERIC_DESCRIPTION, _href = url),
                          '|',
                          INPUT(_type='checkbox',
                                _name=field.name + UploadWidget.ID_DELETE_SUFFIX),

                          UploadWidget.DELETE_FILE,

                          ']', br, image)
            else:
                inp = DIV(inp, '[',
                          A(UploadWidget.GENERIC_DESCRIPTION, _href = url),
                          ']', br, image)
        return inp

    @staticmethod







>
>
>
|











|
>
|
>
|







456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
            _type='file',
            )
        attr = UploadWidget._attributes(field, default, **attributes)

        inp = INPUT(**attr)

        if download_url and value:
            if callable(download_url):
                url = download_url(value)
            else:
                url = download_url + '/' + value
            (br, image) = ('', '')
            if UploadWidget.is_image(value):
                br = BR()
                image = IMG(_src = url, _width = UploadWidget.DEFAULT_WIDTH)

            requires = attr["requires"]
            if requires == [] or isinstance(requires, IS_EMPTY_OR):
                inp = DIV(inp, '[',
                          A(UploadWidget.GENERIC_DESCRIPTION, _href = url),
                          '|',
                          INPUT(_type='checkbox',
                                _name=field.name + UploadWidget.ID_DELETE_SUFFIX,
                                _id=field.name + UploadWidget.ID_DELETE_SUFFIX),
                                LABEL(UploadWidget.DELETE_FILE,
                                     _for=field.name + UploadWidget.ID_DELETE_SUFFIX),
                                ']', br, image)
            else:
                inp = DIV(inp, '[',
                          A(UploadWidget.GENERIC_DESCRIPTION, _href = url),
                          ']', br, image)
        return inp

    @staticmethod
470
471
472
473
474
475
476



477
478
479
480
481
482
483
484
        :param value: the field value
        :param download_url: url for the file download (default = None)
        """

        inp = UploadWidget.GENERIC_DESCRIPTION

        if download_url and value:



            url = download_url + '/' + value
            if UploadWidget.is_image(value):
                inp = IMG(_src = url, _width = UploadWidget.DEFAULT_WIDTH)
            inp = A(inp, _href = url)

        return inp

    @staticmethod







>
>
>
|







499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
        :param value: the field value
        :param download_url: url for the file download (default = None)
        """

        inp = UploadWidget.GENERIC_DESCRIPTION

        if download_url and value:
            if callable(download_url):
                url = download_url(value)
            else:
                url = download_url + '/' + value
            if UploadWidget.is_image(value):
                inp = IMG(_src = url, _width = UploadWidget.DEFAULT_WIDTH)
            inp = A(inp, _href = url)

        return inp

    @staticmethod
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
        self.fields=[field]
        if id_field:
            self.is_reference = True
            self.fields.append(id_field)
        else:
            self.is_reference = False
        if hasattr(request,'application'):
            self.url = Url(r=request, args=request.args)
            self.callback()
        else:
            self.url = request
    def callback(self):
        if self.keyword in self.request.vars:
            field = self.fields[0]
            rows = self.db(field.like(self.request.vars[self.keyword]+'%'))\







|







545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
        self.fields=[field]
        if id_field:
            self.is_reference = True
            self.fields.append(id_field)
        else:
            self.is_reference = False
        if hasattr(request,'application'):
            self.url = URL(args=request.args)
            self.callback()
        else:
            self.url = request
    def callback(self):
        if self.keyword in self.request.vars:
            field = self.fields[0]
            rows = self.db(field.like(self.request.vars[self.keyword]+'%'))\
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
                                                for k,s in enumerate(rows)]).xml())
            else:

                raise HTTP(200,'')
    def __call__(self,field,value,**attributes):
        default = dict(
            _type = 'text',
            value = (value!=None and str(value)) or '',
            )
        attr = StringWidget._attributes(field, default, **attributes)
        div_id = self.keyword+'_div'
        attr['_autocomplete']='off'
        if self.is_reference:
            key2 = self.keyword+'_aux'
            key3 = self.keyword+'_auto'







|







574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
                                                for k,s in enumerate(rows)]).xml())
            else:

                raise HTTP(200,'')
    def __call__(self,field,value,**attributes):
        default = dict(
            _type = 'text',
            value = (not value is None and str(value)) or '',
            )
        attr = StringWidget._attributes(field, default, **attributes)
        div_id = self.keyword+'_div'
        attr['_autocomplete']='off'
        if self.is_reference:
            key2 = self.keyword+'_aux'
            key3 = self.keyword+'_auto'
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
        **attributes
        ):
        """
        SQLFORM(db.table,
               record=None,
               fields=['name'],
               labels={'name': 'Your name'},
               linkto=URL(r=request, f='table/db/')
        """

        self.ignore_rw = ignore_rw
        self.formstyle = formstyle
        nbsp = XML('&nbsp;') # Firefox2 does not display fields with blanks
        FORM.__init__(self, *[], **attributes)
        ofields = fields
        keyed = hasattr(table,'_primarykey')

        # if no fields are provided, build it from the provided table
        # will only use writable or readable fields, unless forced to ignore
        if fields == None:
            fields = [f.name for f in table if (ignore_rw or f.writable or f.readable) and not f.compute]
        self.fields = fields

        # make sure we have an id
        if self.fields[0] != table.fields[0] and \
                isinstance(table,Table) and not keyed:
            self.fields.insert(0, table.fields[0])







|











|







715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
        **attributes
        ):
        """
        SQLFORM(db.table,
               record=None,
               fields=['name'],
               labels={'name': 'Your name'},
               linkto=URL(f='table/db/')
        """

        self.ignore_rw = ignore_rw
        self.formstyle = formstyle
        nbsp = XML('&nbsp;') # Firefox2 does not display fields with blanks
        FORM.__init__(self, *[], **attributes)
        ofields = fields
        keyed = hasattr(table,'_primarykey')

        # if no fields are provided, build it from the provided table
        # will only use writable or readable fields, unless forced to ignore
        if fields is None:
            fields = [f.name for f in table if (ignore_rw or f.writable or f.readable) and not f.compute]
        self.fields = fields

        # make sure we have an id
        if self.fields[0] != table.fields[0] and \
                isinstance(table,Table) and not keyed:
            self.fields.insert(0, table.fields[0])
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
        self.custom.inpval = Storage()
        self.custom.label = Storage()
        self.custom.comment = Storage()
        self.custom.widget = Storage()
        self.custom.linkto = Storage()

        sep = separator or ''
        
        for fieldname in self.fields:
            if fieldname.find('.') >= 0:
                continue

            field = self.table[fieldname]
            comment = None

            if comments:
                comment = col3.get(fieldname, field.comment)
            if comment == None:
                comment = ''
            self.custom.comment[fieldname] = comment

            if labels != None and fieldname in labels:
                label = labels[fieldname]
            else:
                label = field.label
            self.custom.label[fieldname] = label

            field_id = '%s_%s' % (table._tablename, fieldname)

            label = LABEL(label, sep, _for=field_id,
                          _id=field_id+SQLFORM.ID_LABEL_SUFFIX)

            row_id = field_id+SQLFORM.ID_ROW_SUFFIX
            if field.type == 'id':
                self.custom.dspval.id = nbsp
                self.custom.inpval.id = ''
                widget = ''







|









|



|







|







766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
        self.custom.inpval = Storage()
        self.custom.label = Storage()
        self.custom.comment = Storage()
        self.custom.widget = Storage()
        self.custom.linkto = Storage()

        sep = separator or ''

        for fieldname in self.fields:
            if fieldname.find('.') >= 0:
                continue

            field = self.table[fieldname]
            comment = None

            if comments:
                comment = col3.get(fieldname, field.comment)
            if comment is None:
                comment = ''
            self.custom.comment[fieldname] = comment

            if not labels is None and fieldname in labels:
                label = labels[fieldname]
            else:
                label = field.label
            self.custom.label[fieldname] = label

            field_id = '%s_%s' % (table._tablename, fieldname)

            label = LABEL(label, label and sep, _for=field_id,
                          _id=field_id+SQLFORM.ID_LABEL_SUFFIX)

            row_id = field_id+SQLFORM.ID_ROW_SUFFIX
            if field.type == 'id':
                self.custom.dspval.id = nbsp
                self.custom.inpval.id = ''
                widget = ''
1080
1081
1082
1083
1084
1085
1086



1087
1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115

1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
                if hasattr(field, 'widget') and field.widget and fieldname in request_vars:
                    if fieldname in self.vars:
                        value = self.vars[fieldname]
                    elif self.record:
                        value = self.record[fieldname]
                    else:
                        value = self.table[fieldname].default



                    row_id = '%s_%s%s' % (self.table, fieldname, SQLFORM.ID_ROW_SUFFIX)
                    widget = field.widget(field, value)
                    self.field_parent[row_id].components = [ widget ]
                    if not field.type.startswith('list:'):
                        self.field_parent[row_id]._traverse(False, hideerror)
                    self.custom.widget[ fieldname ] = widget

            return ret

        if record_id and str(record_id) != str(self.record_id):
            raise SyntaxError, 'user is tampering with form\'s record_id: ' \
                '%s != %s' % (record_id, self.record_id)

        if record_id and dbio:
            if keyed:
                self.vars.update(record_id)
            else:
                self.vars.id = self.record.id

        if requested_delete and self.custom.deletable:
            if dbio:
                if keyed:
                    qry = reduce(lambda x, y: x & y,
                                 [self.table[k] == record_id[k] for k in self.table._primarykey])
                else:
                    qry = self.table._id == self.record.id
                self.table._db(qry).delete()
            self.errors.clear()
            for component in self.elements('input, select, textarea'):
                component['_disabled'] = True

            return True

        for fieldname in self.fields:
            if not fieldname in self.table.fields:
                continue

            if not self.ignore_rw and not self.table[fieldname].writable:
                ### this happens because FORM has no knowledge of writable
                ### and thinks that a missing boolean field is a None
                if self.table[fieldname].type == 'boolean' and \
                    self.vars.get(fieldname, True) == None:
                    del self.vars[fieldname]
                continue

            field = self.table[fieldname]
            if field.type == 'id':
                continue
            if field.type == 'boolean':
                if self.vars.get(fieldname, False):
                    self.vars[fieldname] = fields[fieldname] = True
                else:
                    self.vars[fieldname] = fields[fieldname] = False
            elif field.type == 'password' and self.record\
                and request_vars.get(fieldname, None) == \
                    PasswordWidget.DEFAULT_PASSWORD_DISPLAY:
                continue  # do not update if password was not changed
            elif field.type == 'upload':
                f = self.vars[fieldname]
                fd = '%s__delete' % fieldname
                if f == '' or f == None:
                    if self.vars.get(fd, False) or not self.record:
                        fields[fieldname] = ''
                    else:
                        fields[fieldname] = self.record[fieldname]
                    self.vars[fieldname] = fields[fieldname]
                    continue
                elif hasattr(f, 'file'):







>
>
>






>






|
<
<
<
|












>










|


















|







1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
                if hasattr(field, 'widget') and field.widget and fieldname in request_vars:
                    if fieldname in self.vars:
                        value = self.vars[fieldname]
                    elif self.record:
                        value = self.record[fieldname]
                    else:
                        value = self.table[fieldname].default
                    if field.type.startswith('list:') and \
                            isinstance(value, str): 
                        value = [value]
                    row_id = '%s_%s%s' % (self.table, fieldname, SQLFORM.ID_ROW_SUFFIX)
                    widget = field.widget(field, value)
                    self.field_parent[row_id].components = [ widget ]
                    if not field.type.startswith('list:'):
                        self.field_parent[row_id]._traverse(False, hideerror)
                    self.custom.widget[ fieldname ] = widget
            self.accepted = ret
            return ret

        if record_id and str(record_id) != str(self.record_id):
            raise SyntaxError, 'user is tampering with form\'s record_id: ' \
                '%s != %s' % (record_id, self.record_id)

        if record_id and dbio and not keyed:



            self.vars.id = self.record.id

        if requested_delete and self.custom.deletable:
            if dbio:
                if keyed:
                    qry = reduce(lambda x, y: x & y,
                                 [self.table[k] == record_id[k] for k in self.table._primarykey])
                else:
                    qry = self.table._id == self.record.id
                self.table._db(qry).delete()
            self.errors.clear()
            for component in self.elements('input, select, textarea'):
                component['_disabled'] = True
            self.accepted = True
            return True

        for fieldname in self.fields:
            if not fieldname in self.table.fields:
                continue

            if not self.ignore_rw and not self.table[fieldname].writable:
                ### this happens because FORM has no knowledge of writable
                ### and thinks that a missing boolean field is a None
                if self.table[fieldname].type == 'boolean' and \
                    self.vars.get(fieldname, True) is None:
                    del self.vars[fieldname]
                continue

            field = self.table[fieldname]
            if field.type == 'id':
                continue
            if field.type == 'boolean':
                if self.vars.get(fieldname, False):
                    self.vars[fieldname] = fields[fieldname] = True
                else:
                    self.vars[fieldname] = fields[fieldname] = False
            elif field.type == 'password' and self.record\
                and request_vars.get(fieldname, None) == \
                    PasswordWidget.DEFAULT_PASSWORD_DISPLAY:
                continue  # do not update if password was not changed
            elif field.type == 'upload':
                f = self.vars[fieldname]
                fd = '%s__delete' % fieldname
                if f == '' or f is None:
                    if self.vars.get(fd, False) or not self.record:
                        fields[fieldname] = ''
                    else:
                        fields[fieldname] = self.record[fieldname]
                    self.vars[fieldname] = fields[fieldname]
                    continue
                elif hasattr(f, 'file'):
1162
1163
1164
1165
1166
1167
1168
1169
1170

1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200

1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223

1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244

































































































































































































































































































































































































































































































































































1245
1246
1247
1248
1249
1250
1251
                if isinstance(field.uploadfield, str):
                    fields[field.uploadfield] = source_file.read()
                # proposed by Hamdy (accept?) do we need fields at this point?
                self.vars[fieldname] = fields[fieldname]
                continue
            elif fieldname in self.vars:
                fields[fieldname] = self.vars[fieldname]
            elif field.default == None and field.type != 'blob':
                self.errors[fieldname] = 'no data'

                return False
            value = fields.get(fieldname,None)
            if field.type == 'list:string':
                if not isinstance(value, (tuple, list)):
                    fields[fieldname] = value and [value] or []
            elif isinstance(field.type,str) and field.type.startswith('list:'):
                if not isinstance(value, list):
                    fields[fieldname] = [safe_int(x) for x in (value and [value] or [])]
            elif field.type == 'integer':
                if value != None:
                    fields[fieldname] = safe_int(value)
            elif field.type.startswith('reference'):
                if value != None and isinstance(self.table, Table) and not keyed:
                    fields[fieldname] = safe_int(value)
            elif field.type == 'double':
                if value != None:
                    fields[fieldname] = safe_float(value)

        for fieldname in self.vars:
            if fieldname != 'id' and fieldname in self.table.fields\
                 and not fieldname in fields and not fieldname\
                 in request_vars:
                fields[fieldname] = self.vars[fieldname]

        if dbio:            
            if 'delete_this_record' in fields:
                # this should never happen but seems to happen to some
                del fields['delete_this_record']
            for field in self.table:
                if not field.name in fields and field.writable==False:

                    if record_id:
                        fields[field.name] = self.record[field.name]
                    elif self.table[field.name].default!=None:
                        fields[field.name] = self.table[field.name].default
            if keyed:
                if reduce(lambda x, y: x and y, record_id.values()): # if record_id
                    if fields:
                        qry = reduce(lambda x, y: x & y,
                            [self.table[k] == self.record[k] for k in self.table._primarykey])
                        self.table._db(qry).update(**fields)
                else:
                    pk = self.table.insert(**fields)
                    if pk:
                        self.vars.update(pk)
                    else:
                        ret = False
            else:
                if record_id:
                    self.vars.id = self.record.id
                    if fields:
                        self.table._db(self.table._id == self.record.id).update(**fields)
                else:
                    self.vars.id = self.table.insert(**fields)

        return ret

    @staticmethod
    def factory(*fields, **attributes):
        """
        generates a SQLFORM for the given fields.

        Internally will build a non-database based data model
        to hold the fields.
        """
        # Define a table name, this way it can be logical to our CSS.
        # And if you switch from using SQLFORM to SQLFORM.factory
        # your same css definitions will still apply.

        table_name = attributes.get('table_name', 'no_table')

        # So it won't interfear with SQLDB.define_table
        if 'table_name' in attributes:
            del attributes['table_name']

        return SQLFORM(DAL(None).define_table(table_name, *fields), **attributes)



































































































































































































































































































































































































































































































































































class SQLTABLE(TABLE):

    """
    given a Rows object, as returned by a db().select(), generates
    an html table with the rows.







|

>









|


|


|








|




|
>


|




















>




















|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
                if isinstance(field.uploadfield, str):
                    fields[field.uploadfield] = source_file.read()
                # proposed by Hamdy (accept?) do we need fields at this point?
                self.vars[fieldname] = fields[fieldname]
                continue
            elif fieldname in self.vars:
                fields[fieldname] = self.vars[fieldname]
            elif field.default is None and field.type != 'blob':
                self.errors[fieldname] = 'no data'
                self.accepted = False
                return False
            value = fields.get(fieldname,None)
            if field.type == 'list:string':
                if not isinstance(value, (tuple, list)):
                    fields[fieldname] = value and [value] or []
            elif isinstance(field.type,str) and field.type.startswith('list:'):
                if not isinstance(value, list):
                    fields[fieldname] = [safe_int(x) for x in (value and [value] or [])]
            elif field.type == 'integer':
                if not value is None:
                    fields[fieldname] = safe_int(value)
            elif field.type.startswith('reference'):
                if not value is None and isinstance(self.table, Table) and not keyed:
                    fields[fieldname] = safe_int(value)
            elif field.type == 'double':
                if not value is None:
                    fields[fieldname] = safe_float(value)

        for fieldname in self.vars:
            if fieldname != 'id' and fieldname in self.table.fields\
                 and not fieldname in fields and not fieldname\
                 in request_vars:
                fields[fieldname] = self.vars[fieldname]

        if dbio:
            if 'delete_this_record' in fields:
                # this should never happen but seems to happen to some
                del fields['delete_this_record']
            for field in self.table:
                if not field.name in fields and field.writable==False \
                        and field.update is None:
                    if record_id:
                        fields[field.name] = self.record[field.name]
                    elif not self.table[field.name].default is None:
                        fields[field.name] = self.table[field.name].default
            if keyed:
                if reduce(lambda x, y: x and y, record_id.values()): # if record_id
                    if fields:
                        qry = reduce(lambda x, y: x & y,
                            [self.table[k] == self.record[k] for k in self.table._primarykey])
                        self.table._db(qry).update(**fields)
                else:
                    pk = self.table.insert(**fields)
                    if pk:
                        self.vars.update(pk)
                    else:
                        ret = False
            else:
                if record_id:
                    self.vars.id = self.record.id
                    if fields:
                        self.table._db(self.table._id == self.record.id).update(**fields)
                else:
                    self.vars.id = self.table.insert(**fields)
        self.accepted = ret
        return ret

    @staticmethod
    def factory(*fields, **attributes):
        """
        generates a SQLFORM for the given fields.

        Internally will build a non-database based data model
        to hold the fields.
        """
        # Define a table name, this way it can be logical to our CSS.
        # And if you switch from using SQLFORM to SQLFORM.factory
        # your same css definitions will still apply.

        table_name = attributes.get('table_name', 'no_table')

        # So it won't interfear with SQLDB.define_table
        if 'table_name' in attributes:
            del attributes['table_name']

        return SQLFORM(DAL(None).define_table(table_name, *fields), 
                       **attributes)

    @staticmethod
    def grid(query,
             fields=None,
             field_id=None,
             left=None,
             headers={},
             columns=None,
             orderby=None,
             searchable=True,
             sortable=True,
             paginate=20,
             deletable=True,
             editable=True,
             details=True,
             selectable=None,
             create=True,
             csv=True,
             links=None,
             upload = '<default>',
             args=[],
             user_signature = True,
             maxtextlengths={},
             maxtextlength=20,
             onvalidation=None,
             oncreate=None,
             onupdate=None, 
             ondelete=None,
             sorter_icons=('[^]','[v]'),
             ui = 'web2py',
             showbuttontext=True,
             _class="web2py_grid",             
             formname='web2py_grid',
            ):

        # jQuery UI ThemeRoller classes (empty if ui is disabled)
        if ui == 'jquery-ui':
            ui = dict(widget='ui-widget',                      
                      header='ui-widget-header',
                      content='ui-widget-content',
                      default='ui-state-default',
                      cornerall='ui-corner-all',
                      cornertop='ui-corner-top',
                      cornerbottom='ui-corner-bottom',
                      button='ui-button-text-icon-primary',
                      buttontext='ui-button-text',
                      buttonadd='ui-icon ui-icon-plusthick',
                      buttonback='ui-icon ui-icon-arrowreturnthick-1-w',
                      buttonexport='ui-icon ui-icon-transferthick-e-w',
                      buttondelete='ui-icon ui-icon-trash',
                      buttonedit='ui-icon ui-icon-pencil',
                      buttontable='ui-icon ui-icon-triangle-1-e',
                      buttonview='ui-icon ui-icon-zoomin',
                      )
        elif ui == 'web2py':
            ui = dict(widget='',                      
                      header='',
                      content='',
                      default='',
                      cornerall='',
                      cornertop='',
                      cornerbottom='',
                      button='button',
                      buttontext='buttontext button',
                      buttonadd='icon plus',
                      buttonback='icon leftarrow',
                      buttonexport='icon downarrow',
                      buttondelete='icon trash',
                      buttonedit='icon pen',
                      buttontable='icon rightarrow',
                      buttonview='icon magnifier',
                      )
        elif not isinstance(ui,dict):
            raise RuntimeError,'SQLFORM.grid ui argument must be a dictionary'

        from gluon import current, redirect
        db = query._db
        T = current.T
        request = current.request
        session = current.session
        response = current.response        
        wenabled = (not user_signature or (session.auth and session.auth.user))
        #create = wenabled and create
        #editable = wenabled and editable
        deletable = wenabled and deletable
        def url(**b):
            b['args'] = args+b.get('args',[])
            b['user_signature'] = user_signature
            return URL(**b)

        def gridbutton(buttonclass='buttonadd',buttontext='Add',buttonurl=url(args=[]),callback=None,delete=None):
            if showbuttontext:
                if callback:
                    return A(SPAN(_class=ui.get(buttonclass,'')), 
                             SPAN(T(buttontext),_title=buttontext,
                                  _class=ui.get('buttontext','')),
                             callback=callback,delete=delete,
                             _class=ui.get('button',''))
                else:
                    return A(SPAN(_class=ui.get(buttonclass,'')), 
                             SPAN(T(buttontext),_title=buttontext,
                                  _class=ui.get('buttontext','')),
                             _href=buttonurl,_class=ui.get('button',''))
            else:
                if callback:
                    return A(SPAN(_class=ui.get(buttonclass,'')),
                             callback=callback,delete=delete,
                             _title=buttontext,_class=ui.get('buttontext',''))
                else:
                    return A(SPAN(_class=ui.get(buttonclass,'')),
                             _href=buttonurl,_title=buttontext,
                             _class=ui.get('buttontext',''))

        dbset = db(query)
        tables = [db[tablename] for tablename in db._adapter.tables(
                dbset.query)]
        if not fields:
            fields = reduce(lambda a,b:a+b,
                            [[field for field in table] for table in tables])
        if not field_id:
            field_id = tables[0]._id
        table = field_id.table
        tablename = table._tablename
        referrer = session.get('_web2py_grid_referrer_'+formname, url())
        def check_authorization():
            if user_signature:
                if not URL.verify(request,user_signature=user_signature):
                    session.flash = T('not authorized')
                    redirect(referrer)
        if upload=='<default>':
            upload = lambda filename: url(args=['download',filename])
            if len(request.args)>1 and request.args[-2]=='download':
                check_authorization()
                stream = response.download(request,db)
                raise HTTP(200,stream,**response.headers)

        def buttons(edit=False,view=False,record=None):
            buttons = DIV(gridbutton('buttonback', 'Back', referrer),
                          _class='form_header row_buttons %(header)s %(cornertop)s' % ui)
            if edit:
                args = ['edit',table._tablename,request.args[-1]]
                buttons.append(gridbutton('buttonedit', 'Edit',
                                          url(args=args)))
            if view:
                args = ['view',table._tablename,request.args[-1]]
                buttons.append(gridbutton('buttonview', 'View',
                                          url(args=args)))
            if record and links:
                for link in links:
                    buttons.append(link(record))
            return buttons
        
        formfooter = DIV(
            _class='form_footer row_buttons %(header)s %(cornerbottom)s' % ui)

        create_form = edit_form = None

        if create and len(request.args)>1 and request.args[-2]=='new':
            check_authorization()
            table = db[request.args[-1]]
            create_form = SQLFORM(
                table,
                _class='web2py_form'
                ).process(next=referrer,
                          onvalidation=onvalidation,
                          onsuccess=oncreate,                          
                          formname=formname)
            res = DIV(buttons(),create_form,formfooter,_class=_class)
            res.create_form = create_form
            res.edit_form = None
            res.update_form = None
            return res
        elif details and len(request.args)>2 and request.args[-3]=='view':
            check_authorization()
            table = db[request.args[-2]]
            record = table(request.args[-1]) or redirect(URL('error'))
            form = SQLFORM(table,record,upload=upload,
                           readonly=True,_class='web2py_form')
            res = DIV(buttons(edit=editable,record=record),form,
                      formfooter,_class=_class)
            res.create_form = None
            res.edit_form = None
            res.update_form = None
            return res
        elif editable and len(request.args)>2 and request.args[-3]=='edit':
            check_authorization()
            table = db[request.args[-2]]
            record = table(request.args[-1]) or redirect(URL('error'))
            edit_form = SQLFORM(table,record,upload=upload,
                                deletable=deletable,
                                _class='web2py_form')
            edit_form.process(formname=formname,
                              onvalidation=onvalidation,
                              onsuccess=onupdate,
                              next=referrer)
            res = DIV(buttons(view=details,record=record),
                      edit_form,formfooter,_class=_class)
            res.create_form = None
            res.edit_form = edit_form
            res.update_form = None
            return res
        elif deletable and len(request.args)>2 and request.args[-3]=='delete':
            check_authorization()
            table = db[request.args[-2]]
            ret = db(table.id==request.args[-1]).delete()
            if ondelete:
                return ondelete(table,request.args[-2],ret)
            return ret
        elif csv and len(request.args)>0 and request.args[-1]=='csv':
            check_authorization()
            response.headers['Content-Type'] = 'text/csv'
            response.headers['Content-Disposition'] = \
                'attachment;filename=rows.csv;'
            raise HTTP(200,str(dbset.select()),
                       **{'Content-Type':'text/csv',
                          'Content-Disposition':'attachment;filename=rows.csv;'})
        elif request.vars.records and not isinstance(
            request.vars.records,list):
            request.vars.records=[request.vars.records]
        elif not request.vars.records:
            request.vars.records=[]
        def OR(a,b): return a|b
        def AND(a,b): return a&b

        session['_web2py_grid_referrer_'+formname] = \
            URL(args=request.args,vars=request.vars,
                user_signature=user_signature)
        console = DIV(_class='web2py_console %(header)s %(cornertop)s' % ui)
        error = None
        search_form = None
        if searchable:
            form = FORM(INPUT(_name='keywords',_value=request.vars.keywords,
                              _id='web2py_keywords'),
                        INPUT(_type='submit',_value=T('Search')),
                        INPUT(_type='submit',_value=T('Clear'),
                              _onclick="jQuery('#web2py_keywords').val('');"),
                        _method="GET",_action=url())
            search_form = form
            console.append(form)
            key = request.vars.get('keywords','').strip()
            if searchable==True:
                subquery = None
                if key and not ' ' in key:
                    SEARCHABLE_TYPES = ('string','text','list:string')
                    parts = [field.contains(key) for field in fields \
                                 if field.type in SEARCHABLE_TYPES]
                else:
                    parts = None
                if parts:
                    subquery = reduce(OR,parts)
                else:
                    try:
                        subquery = smart_query(fields,key)
                    except RuntimeError:
                        subquery = None
                        error = T('Invalid query')
            else:
                subquery = searchable(key,fields)
            if subquery:
                dbset = dbset(subquery)   
        try:
            if left:
                nrows = dbset.select('count(*)',left=left).first()['count(*)']
            else:
                nrows = dbset.count()
        except:
            nrows = 0
            error = T('Unsupported query')
                
        search_actions = DIV(_class='web2py_search_actions')
        if create:
            search_actions.append(gridbutton(
                    buttonclass='buttonadd',
                    buttontext='Add',
                    buttonurl=url(args=['new',tablename])))
        if csv:
            search_actions.append(gridbutton(
                    buttonclass='buttonexport',
                    buttontext='Export',
                    buttonurl=url(args=['csv'])))

        console.append(search_actions)

        message = error or T('%(nrows)s records found' % dict(nrows=nrows))

        console.append(DIV(message,_class='web2py_counter'))

        order = request.vars.order or ''
        if sortable:
            if order and not order=='None':
                if order[:1]=='~':
                    sign, rorder = '~', order[1:]
                else:
                    sign, rorder = '', order
                tablename,fieldname = rorder.split('.',1)
                if sign=='~':
                    orderby=~db[tablename][fieldname]
                else:
                    orderby=db[tablename][fieldname]

        head = TR(_class=ui.get('header',''))
        if selectable:
            head.append(TH(_class=ui.get('default','')))
        for field in fields:
            if columns and not str(field) in columns: continue
            if not field.readable: continue
            key = str(field)
            header = headers.get(str(field),
                                 hasattr(field,'label') and field.label or key)
            if sortable:
                if key == order:
                    key, marker = '~'+order, sorter_icons[0]
                elif key == order[1:]:
                    marker = sorter_icons[1]
                else:
                    marker = ''
                header = A(header,marker,_href=url(vars=dict(
                            keywords=request.vars.keywords or '',
                            order=key)))
            head.append(TH(header, _class=ui.get('default','')))
            
        for link in links or []:
            if isinstance(link,dict): 
                head.append(TH(link['header'], _class=ui.get('default','')))

        head.append(TH(_class=ui.get('default','')))
        
        paginator = UL()
        if paginate and paginate<nrows:
            npages,reminder = divmod(nrows,paginate)
            if reminder: npages+=1
            try: page = int(request.vars.page or 1)-1
            except ValueError: page = 0
            limitby = (paginate*page,paginate*(page+1))
            def self_link(name,p):
                d = dict(page=p+1)
                if order: d['order']=order
                if request.vars.keywords: d['keywords']=request.vars.keywords
                return A(name,_href=url(vars=d))
            if page>0:
                paginator.append(LI(self_link('<<',0)))
            if page>1:
                paginator.append(LI(self_link('<',page-1)))
            pages = range(max(0,page-5),min(page+5,npages-1))
            for p in pages:
                if p == page:
                    paginator.append(LI(A(p+1,_onclick='return false'),
                                        _class='current'))
                else:
                    paginator.append(LI(self_link(p+1,p)))
            if page<npages-2:
                paginator.append(LI(self_link('>',page+1)))
            if page<npages-1:
                paginator.append(LI(self_link('>>',npages-1)))
        else:
            limitby = None
        
        rows = dbset.select(left=left,orderby=orderby,limitby=limitby,*fields)
        if not searchable and not rows: return DIV(T('No records found'))
        if rows:
            htmltable = TABLE(THEAD(head))
            tbody = TBODY()
            numrec=0
            for row in rows:
                if numrec % 2 == 0:
                    classtr = 'even'
                else:
                    classtr = 'odd'
                numrec+=1
                id = row[field_id]
                if len(tables)>1 or row.get('_extra',None):
                    rrow = row[field._tablename]
                else:
                    rrow = row
                tr = TR(_class=classtr)
                if selectable:
                    tr.append(INPUT(_type="checkbox",_name="records",_value=id,
                                    value=request.vars.records))
                for field in fields:
                    if columns and not str(field) in columns: continue
                    if not field.readable: continue
                    if field.type=='blob': continue
                    value = row[field]
                    if field.represent:
                        try:
                            value=field.represent(value,rrow)
                        except KeyError:
                            pass
                    elif field.type=='boolean':
                        value = INPUT(_type="checkbox",_checked = value, 
                                      _disabled=True)
                    elif field.type=='upload':
                        if value:
                            if callable(upload):
                                value = A('File', _href=upload(value))
                            elif upload:
                                value = A('File', 
                                          _href='%s/%s' % (upload, value))
                        else:
                            value = ''
                    elif isinstance(value,str) and len(value)>maxtextlength:
                        value=value[:maxtextlengths.get(str(field),maxtextlength)]+'...'
                    else:
                        value=field.formatter(value)
                    tr.append(TD(value))
                row_buttons = TD(_class='row_buttons')
                for link in links or []:
                    if isinstance(link, dict):
                        tr.append(TD(link['body'](row)))
                    else:
                        row_buttons.append(link(row))
                if details and (not callable(details) or details(row)):
                    row_buttons.append(gridbutton(
                            'buttonview', 'View',
                            url(args=['view',tablename,id])))
                if editable and (not callable(editable) or editable(row)):
                    row_buttons.append(gridbutton(
                            'buttonedit', 'Edit',
                            url(args=['edit',tablename,id])))
                if deletable and (not callable(deletable) or deletable(row)):
                    row_buttons.append(gridbutton(
                            'buttondelete', 'Delete',
                            callback=url(args=['delete',tablename,id]),
                            delete='tr'))
                tr.append(row_buttons)
                tbody.append(tr)
            htmltable.append(tbody)
            if selectable:
                htmltable = FORM(htmltable,INPUT(_type="submit"))
                if htmltable.process(formname=formname).accepted:
                    records = [int(r) for r in htmltable.vars.records or []]
                    selectable(records)
                    redirect(referrer)
        else:
            htmltable = DIV(T('No records found'))
        res = DIV(console,
                  DIV(htmltable,_class="web2py_table"),
                  DIV(paginator,_class=\
                          "web2py_paginator %(header)s %(cornerbottom)s" % ui),
                  _class='%s %s' % (_class, ui.get('widget','')))
        res.create_form = create_form
        res.edit_form = edit_form
        res.search_form = search_form
        return res

    @staticmethod
    def smartgrid(table, constraints=None, links=None,
                  linked_tables=None, user_signature=True,
                  **kwargs):
        """
        @auth.requires_login()
        def index():
            db.define_table('person',Field('name'),format='%(name)s')
            db.define_table('dog',
                Field('name'),Field('owner',db.person),format='%(name)s')
            db.define_table('comment',Field('body'),Field('dog',db.dog))
            if db(db.person).isempty():
                from gluon.contrib.populate import populate
                populate(db.person,300)
                populate(db.dog,300)
                populate(db.comment,1000)
                db.commit()
        form=SQLFORM.smartgrid(db[request.args(0) or 'person']) #***
        return dict(form=form)

        *** builds a complete interface to navigate all tables links 
            to the request.args(0)
            table: pagination, search, view, edit, delete, 
                   children, parent, etc.

        constraints is a dict {'table',query} that limits which 
        records can be accessible
        links is a list of lambda row: A(....) that will add buttons
        linked_tables is a optional list of tablenames of tables to be linked

        """
        from gluon import current, A, URL, DIV, H3, redirect
        request, T = current.request, current.T
        db = table._db
        if links is None: links = []
        if constraints is None: constraints = {}
        breadcrumbs = []
        if request.args(0) != table._tablename:
            request.args=[table._tablename]
        try:
            args = 1
            previous_tablename,previous_fieldname,previous_id = \
                table._tablename,None,None
            while len(request.args)>args:
                key = request.args(args)
                if '.' in key:
                    id = request.args(args+1)
                    tablename,fieldname = key.split('.',1)
                    table = db[tablename]
                    field = table[fieldname]
                    field.default = id
                    referee = field.type[10:]
                    if referee!=previous_tablename:
                        raise HTTP(400)
                    cond = constraints.get(referee,None)
                    if cond:
                        record = db(db[referee].id==id)(cond).select().first()
                    else:
                        record = db[referee](id)
                    if previous_id:
                        if record[previous_fieldname] != int(previous_id):
                            raise HTTP(400)
                    previous_tablename,previous_fieldname,previous_id = \
                        tablename,fieldname,id
                    try:
                        name = db[referee]._format % record
                    except TypeError:
                        name = id
                    breadcrumbs += [A(T(referee),
                                      _href=URL(args=request.args[:args])),' ',
                                    A(name,
                                      _href=URL(args=request.args[:args]+[
                                    'view',referee,id],user_signature=True)),
                                    ' > ']
                    args+=2
                else:
                    break
            if args>1:
                query = (field == id)
                if linked_tables is None or referee in linked_tables:
                    field.represent = lambda id,r=None,referee=referee,rep=field.represent: A(rep(id),_href=URL(args=request.args[:args]+['view',referee,id], user_signature=user_signature))
        except (KeyError,ValueError,TypeError):
            redirect(URL(args=table._tablename))
        if args==1:
            query = table.id>0
        if table._tablename in constraints:
            query = query&constraints[table._tablename]
        for tablename,fieldname in table._referenced_by:
            if linked_tables is None or tablename in linked_tables:
                args0 = tablename+'.'+fieldname
                links.append(lambda row,t=T(tablename),args=args,args0=args0:\
                                 A(SPAN(t),_href=URL(args=request.args[:args]+[args0,row.id])))                
        grid=SQLFORM.grid(query,args=request.args[:args],links=links,
                          user_signature=user_signature,**kwargs)
        if isinstance(grid,DIV):
            breadcrumbs.append(A(T(table._tablename),
                                 _href=URL(args=request.args[:args])))
            grid.insert(0,DIV(H3(*breadcrumbs),_class='web2py_breadcrumbs'))
        return grid


class SQLTABLE(TABLE):

    """
    given a Rows object, as returned by a db().select(), generates
    an html table with the rows.
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339

1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404

    This will link rows[id] to .../sometable/value_of_id


    More advanced linkto example::

        def mylink(field, type, ref):
            return URL(r=request, args=[field])

        rows = db.select(db.sometable.ALL)
        table = SQLTABLE(rows, linkto=mylink)

    This will link rows[id] to
        current_app/current_controlle/current_function/value_of_id
        
    New Implements: 24 June 2011:
    -----------------------------
    
    :param selectid: The id you want to select
    :param renderstyle: Boolean render the style with the table
    
    :param extracolums = [{'label':A('Extra',_href='#'),
                    'class': '', #class name of the header
                    'width':'', #width in pixels or %
                    'content':lambda row, rc: A('Edit',_href='edit/%s'%row.id),                     
                    'selected': False #agregate class selected to this column
                    }]
                    
                    
    :param headers = {'table.id':{'label':'Id',
                           'class':'', #class name of the header
                           'width':'', #width in pixels or %
                           'truncate': 16, #truncate the content to...
                           'selected': False #agregate class selected to this column
                           }, 
               'table.myfield':{'label':'My field',
                                'class':'', #class name of the header
                                'width':'', #width in pixels or %
                                'truncate': 16, #truncate the content to...
                                'selected': False #agregate class selected to this column
                                },
               }
               
    table = SQLTABLE(rows, headers=headers, extracolums=extracolums)


    """

    def __init__(
        self,
        sqlrows,
        linkto=None,
        upload=None,
        orderby=None,
        headers={},
        truncate=16,
        columns=None,        
        th_link='',
        extracolumns=None,
        selectid=None,
        renderstyle=False,
        **attributes
        ):

        TABLE.__init__(self, **attributes)

        self.components = []
        self.attributes = attributes
        self.sqlrows = sqlrows
        (components, row) = (self.components, [])
        if not sqlrows:
            return
        if not columns:
            columns = sqlrows.colnames
        if headers=='fieldname:capitalize':
            headers = {}
            for c in columns:
                headers[c] = ' '.join([w.capitalize() for w in c.split('.')[-1].split('_')])
        elif headers=='labels':
            headers = {}
            for c in columns:
                (t,f) = c.split('.')
                field = sqlrows.db[t][f]
                headers[c] = field.label
        if headers!=None:
            for c in columns:#new implement dict
                if isinstance(headers.get(c, c), dict):
                    coldict = headers.get(c, c)
                    attrcol = dict()
                    if coldict['width']!="":
                        attrcol.update(_width=coldict['width'])
                    if coldict['class']!="":
                        attrcol.update(_class=coldict['class'])
                    row.append(TH(coldict['label'],**attrcol))
                elif orderby:
                    row.append(TH(A(headers.get(c, c),
                                    _href=th_link+'?orderby=' + c)))
                else:
                    row.append(TH(headers.get(c, c)))
                    
            if extracolumns:#new implement dict
                for c in extracolumns:
                    attrcol = dict()
                    if c['width']!="":
                        attrcol.update(_width=c['width'])
                    if c['class']!="":
                        attrcol.update(_class=c['class'])
                    row.append(TH(c['label'],**attrcol))
                    
            components.append(THEAD(TR(*row)))
        

        tbody = []
        for (rc, record) in enumerate(sqlrows):
            row = []
            if rc % 2 == 0:
                _class = 'even'
            else:
                _class = 'odd'
                
            if selectid!=None:#new implement
                if record.id==selectid:
                    _class += ' rowselected'
                    
            for colname in columns:
                if not table_field.match(colname):
                    if "_extra" in record and colname in record._extra:
                        r = record._extra[colname]
                        row.append(TD(r))
                        continue
                    else:







|






|


|


|



|


|
|





|







|













|








>


















|














|








|

|








|
|


|







1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987

    This will link rows[id] to .../sometable/value_of_id


    More advanced linkto example::

        def mylink(field, type, ref):
            return URL(args=[field])

        rows = db.select(db.sometable.ALL)
        table = SQLTABLE(rows, linkto=mylink)

    This will link rows[id] to
        current_app/current_controlle/current_function/value_of_id

    New Implements: 24 June 2011:
    -----------------------------

    :param selectid: The id you want to select
    :param renderstyle: Boolean render the style with the table

    :param extracolums = [{'label':A('Extra',_href='#'),
                    'class': '', #class name of the header
                    'width':'', #width in pixels or %
                    'content':lambda row, rc: A('Edit',_href='edit/%s'%row.id),
                    'selected': False #agregate class selected to this column
                    }]


    :param headers = {'table.id':{'label':'Id',
                           'class':'', #class name of the header
                           'width':'', #width in pixels or %
                           'truncate': 16, #truncate the content to...
                           'selected': False #agregate class selected to this column
                           },
               'table.myfield':{'label':'My field',
                                'class':'', #class name of the header
                                'width':'', #width in pixels or %
                                'truncate': 16, #truncate the content to...
                                'selected': False #agregate class selected to this column
                                },
               }

    table = SQLTABLE(rows, headers=headers, extracolums=extracolums)


    """

    def __init__(
        self,
        sqlrows,
        linkto=None,
        upload=None,
        orderby=None,
        headers={},
        truncate=16,
        columns=None,
        th_link='',
        extracolumns=None,
        selectid=None,
        renderstyle=False,
        **attributes
        ):

        TABLE.__init__(self, **attributes)

        self.components = []
        self.attributes = attributes
        self.sqlrows = sqlrows
        (components, row) = (self.components, [])
        if not sqlrows:
            return
        if not columns:
            columns = sqlrows.colnames
        if headers=='fieldname:capitalize':
            headers = {}
            for c in columns:
                headers[c] = ' '.join([w.capitalize() for w in c.split('.')[-1].split('_')])
        elif headers=='labels':
            headers = {}
            for c in columns:
                (t,f) = c.split('.')
                field = sqlrows.db[t][f]
                headers[c] = field.label
        if not headers is None:
            for c in columns:#new implement dict
                if isinstance(headers.get(c, c), dict):
                    coldict = headers.get(c, c)
                    attrcol = dict()
                    if coldict['width']!="":
                        attrcol.update(_width=coldict['width'])
                    if coldict['class']!="":
                        attrcol.update(_class=coldict['class'])
                    row.append(TH(coldict['label'],**attrcol))
                elif orderby:
                    row.append(TH(A(headers.get(c, c),
                                    _href=th_link+'?orderby=' + c)))
                else:
                    row.append(TH(headers.get(c, c)))

            if extracolumns:#new implement dict
                for c in extracolumns:
                    attrcol = dict()
                    if c['width']!="":
                        attrcol.update(_width=c['width'])
                    if c['class']!="":
                        attrcol.update(_class=c['class'])
                    row.append(TH(c['label'],**attrcol))

            components.append(THEAD(TR(*row)))


        tbody = []
        for (rc, record) in enumerate(sqlrows):
            row = []
            if rc % 2 == 0:
                _class = 'even'
            else:
                _class = 'odd'

            if not selectid is None: #new implement
                if record.id==selectid:
                    _class += ' rowselected'

            for colname in columns:
                if not table_field.match(colname):
                    if "_extra" in record and colname in record._extra:
                        r = record._extra[colname]
                        row.append(TD(r))
                        continue
                    else:
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530


                        r = A('file', _href='%s/%s' % (upload, r))
                    elif r:
                        r = 'file'
                    else:
                        r = ''
                elif field.type in ['string','text']:
                    r = str(field.formatter(r))
                    ur = unicode(r, 'utf8')                    
                    if headers!={}: #new implement dict
                        if isinstance(headers[colname],dict):
                            if isinstance(headers[colname]['truncate'], int) \
                                    and len(ur)>headers[colname]['truncate']:
                                r = ur[:headers[colname]['truncate'] - 3]
                                r = r.encode('utf8') + '...'
                    elif truncate!=None and len(ur) > truncate:
                        r = ur[:truncate - 3].encode('utf8') + '...'
                        
                attrcol = dict()#new implement dict
                if headers!={}:
                    if isinstance(headers[colname],dict):
                        colclass=headers[colname]['class']
                        if headers[colname]['selected']:
                            colclass= str(headers[colname]['class'] + " colselected").strip()
                        if colclass!="":
                            attrcol.update(_class=colclass)
                        
                row.append(TD(r,**attrcol))
                
            if extracolumns:#new implement dict
                for c in extracolumns:
                    attrcol = dict()
                    colclass=c['class']
                    if c['selected']:
                        colclass= str(c['class'] + " colselected").strip()
                    if colclass!="":
                        attrcol.update(_class=colclass)
                    contentfunc = c['content']
                    row.append(TD(contentfunc(record, rc),**attrcol))
                    
            tbody.append(TR(_class=_class, *row))
            
        if renderstyle:
            components.append(STYLE(self.style()))
        
        components.append(TBODY(*tbody))
        
    
    def style(self):
        
        css = '''
        table tbody tr.odd {
            background-color: #DFD;
        }
        table tbody tr.even {
            background-color: #EFE;
        }
        table tbody tr.rowselected {
            background-color: #FDD;
        }
        table tbody tr td.colselected {
            background-color: #FDD;
        }
        table tbody tr:hover {
            background: #DDF;
        }
        '''
        
        return css

form_factory = SQLFORM.factory # for backward compatibility, deprecated











|






|

|








|

|










|

|


|

|
|

|

















|





>
>
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
                        r = A('file', _href='%s/%s' % (upload, r))
                    elif r:
                        r = 'file'
                    else:
                        r = ''
                elif field.type in ['string','text']:
                    r = str(field.formatter(r))
                    ur = unicode(r, 'utf8')
                    if headers!={}: #new implement dict
                        if isinstance(headers[colname],dict):
                            if isinstance(headers[colname]['truncate'], int) \
                                    and len(ur)>headers[colname]['truncate']:
                                r = ur[:headers[colname]['truncate'] - 3]
                                r = r.encode('utf8') + '...'
                    elif not truncate is None and len(ur) > truncate:
                        r = ur[:truncate - 3].encode('utf8') + '...'

                attrcol = dict()#new implement dict
                if headers!={}:
                    if isinstance(headers[colname],dict):
                        colclass=headers[colname]['class']
                        if headers[colname]['selected']:
                            colclass= str(headers[colname]['class'] + " colselected").strip()
                        if colclass!="":
                            attrcol.update(_class=colclass)

                row.append(TD(r,**attrcol))

            if extracolumns:#new implement dict
                for c in extracolumns:
                    attrcol = dict()
                    colclass=c['class']
                    if c['selected']:
                        colclass= str(c['class'] + " colselected").strip()
                    if colclass!="":
                        attrcol.update(_class=colclass)
                    contentfunc = c['content']
                    row.append(TD(contentfunc(record, rc),**attrcol))

            tbody.append(TR(_class=_class, *row))

        if renderstyle:
            components.append(STYLE(self.style()))

        components.append(TBODY(*tbody))


    def style(self):

        css = '''
        table tbody tr.odd {
            background-color: #DFD;
        }
        table tbody tr.even {
            background-color: #EFE;
        }
        table tbody tr.rowselected {
            background-color: #FDD;
        }
        table tbody tr td.colselected {
            background-color: #FDD;
        }
        table tbody tr:hover {
            background: #DDF;
        }
        '''

        return css

form_factory = SQLFORM.factory # for backward compatibility, deprecated




Added gluon/sqlhtml.pyc version [b9c43229a5].
Modified gluon/storage.py from [01254dd1ce] to [e0d0b25798].
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    def __getattr__(self, key):
        if key in self:
            return self[key]
        else:
            return None

    def __setattr__(self, key, value):
        if value == None:
            if key in self:
                del self[key]
        else:
            self[key] = value

    def __delattr__(self, key):
        if key in self:







|







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    def __getattr__(self, key):
        if key in self:
            return self[key]
        else:
            return None

    def __setattr__(self, key, value):
        if value is None:
            if key in self:
                del self[key]
        else:
            self[key] = value

    def __delattr__(self, key):
        if key in self:
217
218
219
220
221
222
223
224


        if isinstance(value, str):
            return str(self['T'](value))
        return value

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











>
>
217
218
219
220
221
222
223
224
225
226
        if isinstance(value, str):
            return str(self['T'](value))
        return value

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



Added gluon/storage.pyc version [a1d5b27c69].
Modified gluon/streamer.py from [10f9ac82a7] to [833f1efd4c].
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
regex_start_range = re.compile('\d+(?=\-)')
regex_stop_range = re.compile('(?<=\-)\d+')

DEFAULT_CHUNK_SIZE = 64*1024

def streamer(stream, chunk_size = DEFAULT_CHUNK_SIZE, bytes = None):
    offset = 0
    while bytes == None or offset < bytes:
        if bytes != None and bytes - offset < chunk_size:
            chunk_size = bytes - offset
        data = stream.read(chunk_size)
        length = len(data)
        if not length:
            break
        else:
            yield data







|
|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
regex_start_range = re.compile('\d+(?=\-)')
regex_stop_range = re.compile('(?<=\-)\d+')

DEFAULT_CHUNK_SIZE = 64*1024

def streamer(stream, chunk_size = DEFAULT_CHUNK_SIZE, bytes = None):
    offset = 0
    while bytes is None or offset < bytes:
        if not bytes is None and bytes - offset < chunk_size:
            chunk_size = bytes - offset
        data = stream.read(chunk_size)
        length = len(data)
        if not length:
            break
        else:
            yield data
102
103
104
105
106
107
108
109


        bytes = None
        status = 200
    if request and request.env.web2py_use_wsgi_file_wrapper:
        wrapped = request.env.wsgi_file_wrapper(stream, chunk_size)
    else:
        wrapped = streamer(stream, chunk_size=chunk_size, bytes=bytes)
    raise HTTP(status, wrapped, **headers)











>
>
102
103
104
105
106
107
108
109
110
111
        bytes = None
        status = 200
    if request and request.env.web2py_use_wsgi_file_wrapper:
        wrapped = request.env.wsgi_file_wrapper(stream, chunk_size)
    else:
        wrapped = streamer(stream, chunk_size=chunk_size, bytes=bytes)
    raise HTTP(status, wrapped, **headers)



Added gluon/streamer.pyc version [59d659d0b5].
Modified gluon/template.py from [851c8388c4] to [428131a179].
924
925
926
927
928
929
930


931
    # Returned the rendered content.
    return context['response'].body.getvalue()


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










>
>

924
925
926
927
928
929
930
931
932
933
    # Returned the rendered content.
    return context['response'].body.getvalue()


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



Added gluon/template.pyc version [892f7ab761].
Modified gluon/tests/test_router.py from [ca0892ab11] to [5e9353a27f].
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
        self.assertEqual(filter_url('http://domain.com/welcome/', app=True), 'welcome')
        self.assertEqual(filter_url('http://domain.com', app=True), 'init')
        self.assertEqual(filter_url('http://domain.com/', app=True), 'init')
        self.assertEqual(filter_url('http://domain.com/abc', app=True), 'init')
        self.assertEqual(filter_url('http://domain1.com/abc', app=True), 'app1')
        self.assertEqual(filter_url('http://www.domain1.com/abc', app=True), 'app1')
        self.assertEqual(filter_url('http://domain2.com/abc', app=True), 'app2')
        self.assertEqual(filter_url('http://domain2.com/admin', app=True), 'admin')

        self.assertEqual(filter_url('http://domain.com/goodapp', app=True), 'goodapp')
        self.assertRaises(HTTP, filter_url, 'http://domain.com/bad!app', app=True)
        try:
            # 2.7+ only
            self.assertRaisesRegexp(HTTP, '400.*invalid application', filter_url, 'http://domain.com/bad!app')
        except AttributeError:







|







336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
        self.assertEqual(filter_url('http://domain.com/welcome/', app=True), 'welcome')
        self.assertEqual(filter_url('http://domain.com', app=True), 'init')
        self.assertEqual(filter_url('http://domain.com/', app=True), 'init')
        self.assertEqual(filter_url('http://domain.com/abc', app=True), 'init')
        self.assertEqual(filter_url('http://domain1.com/abc', app=True), 'app1')
        self.assertEqual(filter_url('http://www.domain1.com/abc', app=True), 'app1')
        self.assertEqual(filter_url('http://domain2.com/abc', app=True), 'app2')
        self.assertEqual(filter_url('http://domain2.com/admin', app=True), 'app2')

        self.assertEqual(filter_url('http://domain.com/goodapp', app=True), 'goodapp')
        self.assertRaises(HTTP, filter_url, 'http://domain.com/bad!app', app=True)
        try:
            # 2.7+ only
            self.assertRaisesRegexp(HTTP, '400.*invalid application', filter_url, 'http://domain.com/bad!app')
        except AttributeError:
371
372
373
374
375
376
377



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
                    "www.domain1.com" : "app1",
                    #  same domain, two ports, to two apps
                    "domain2.com"      : "app2a",
                    "domain2.com:8080" : "app2b",
                    #  two domains, same app, two controllers
                    "domain3a.com" : "app3/c3a",
                    "domain3b.com" : "app3/c3b",



                    #  http vs https
                    "domain6.com:80"  : "app6",
                    "domain6.com:443" : "app6s",
                },
            ),
            app1 =  dict( default_controller = 'c1',  default_function = 'f1',  controllers = ['c1'], exclusive_domain=True, ),
            app2a = dict( default_controller = 'c2a', default_function = 'f2a', controllers = ['c2a'], ),
            app2b = dict( default_controller = 'c2b', default_function = 'f2b', controllers = ['c2b'], ),
            app3 =  dict( controllers = ['c3a', 'c3b'], ),
            app4 =  dict( default_controller = 'c4', controllers = ['c4'], domain = 'domain4.com' ),
            app5 =  dict( default_controller = 'c5', controllers = ['c5'], domain = 'localhost' ),
            app6 =  dict( default_controller = 'c6',  default_function = 'f6',  controllers = ['c6'], ),
            app6s =  dict( default_controller = 'c6s',  default_function = 'f6s',  controllers = ['c6s'], ),
        )

        load(rdict=routers)
        self.assertEqual(filter_url('http://domain1.com/abc'), '/app1/c1/abc')
        self.assertEqual(filter_url('http://domain1.com/c1/abc'), '/app1/c1/abc')
        self.assertEqual(filter_url('http://domain1.com/abc.html'), '/app1/c1/abc')
        self.assertEqual(filter_url('http://domain1.com/abc.css'), '/app1/c1/abc.css')
        self.assertEqual(filter_url('http://domain1.com/index/abc'), "/app1/c1/index ['abc']")

        
        self.assertEqual(filter_url('https://domain1.com/app1/ctr/fcn', domain=('app1',None), out=True), "/ctr/fcn")
        self.assertEqual(filter_url('https://www.domain1.com/app1/ctr/fcn', domain=('app1',None), out=True), "/ctr/fcn")

        self.assertEqual(filter_url('http://domain2.com/abc'), '/app2a/c2a/abc')
        self.assertEqual(filter_url('http://domain2.com:8080/abc'), '/app2b/c2b/abc')








>
>
>









|











>







371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
                    "www.domain1.com" : "app1",
                    #  same domain, two ports, to two apps
                    "domain2.com"      : "app2a",
                    "domain2.com:8080" : "app2b",
                    #  two domains, same app, two controllers
                    "domain3a.com" : "app3/c3a",
                    "domain3b.com" : "app3/c3b",
                    #  two domains, same app & controller, two functions
                    "domain4a.com" : "app4/c4/f4a",
                    "domain4b.com" : "app4/c4/f4b",
                    #  http vs https
                    "domain6.com:80"  : "app6",
                    "domain6.com:443" : "app6s",
                },
            ),
            app1 =  dict( default_controller = 'c1',  default_function = 'f1',  controllers = ['c1'], exclusive_domain=True, ),
            app2a = dict( default_controller = 'c2a', default_function = 'f2a', controllers = ['c2a'], ),
            app2b = dict( default_controller = 'c2b', default_function = 'f2b', controllers = ['c2b'], ),
            app3 =  dict( controllers = ['c3a', 'c3b'], ),
            app4 =  dict( default_controller = 'c4', controllers = ['c4']),
            app5 =  dict( default_controller = 'c5', controllers = ['c5'], domain = 'localhost' ),
            app6 =  dict( default_controller = 'c6',  default_function = 'f6',  controllers = ['c6'], ),
            app6s =  dict( default_controller = 'c6s',  default_function = 'f6s',  controllers = ['c6s'], ),
        )

        load(rdict=routers)
        self.assertEqual(filter_url('http://domain1.com/abc'), '/app1/c1/abc')
        self.assertEqual(filter_url('http://domain1.com/c1/abc'), '/app1/c1/abc')
        self.assertEqual(filter_url('http://domain1.com/abc.html'), '/app1/c1/abc')
        self.assertEqual(filter_url('http://domain1.com/abc.css'), '/app1/c1/abc.css')
        self.assertEqual(filter_url('http://domain1.com/index/abc'), "/app1/c1/index ['abc']")
        self.assertEqual(filter_url('http://domain2.com/app1'), "/app2a/c2a/app1")
        
        self.assertEqual(filter_url('https://domain1.com/app1/ctr/fcn', domain=('app1',None), out=True), "/ctr/fcn")
        self.assertEqual(filter_url('https://www.domain1.com/app1/ctr/fcn', domain=('app1',None), out=True), "/ctr/fcn")

        self.assertEqual(filter_url('http://domain2.com/abc'), '/app2a/c2a/abc')
        self.assertEqual(filter_url('http://domain2.com:8080/abc'), '/app2b/c2b/abc')

416
417
418
419
420
421
422
423
424



425
426
427
428
429
430
431
        self.assertEqual(filter_url('http://domain3a.com/c3b'), '/app3/c3b/index')
        self.assertEqual(filter_url('http://domain3b.com/abc'), '/app3/c3b/abc')

        self.assertEqual(filter_url('http://domain3a.com/app3/c3a/fcn', domain=('app3','c3a'), out=True), "/fcn")
        self.assertEqual(filter_url('http://domain3a.com/app3/c3a/fcn', domain=('app3','c3b'), out=True), "/c3a/fcn")
        self.assertEqual(filter_url('http://domain3a.com/app3/c3a/fcn', domain=('app1',None), out=True), "/app3/c3a/fcn")

        self.assertEqual(filter_url('http://domain4.com/abc'), '/app4/c4/abc')
        self.assertEqual(filter_url('https://domain4.com/app4/c4/fcn', domain=('app4',None), out=True), "/fcn")




        self.assertEqual(filter_url('http://localhost/abc'), '/app5/c5/abc')
        self.assertEqual(filter_url('http:///abc'), '/app5/c5/abc') # test null host => localhost
        self.assertEqual(filter_url('https://localhost/app5/c5/fcn', domain=('app5',None), out=True), "/fcn")

        self.assertEqual(filter_url('http://domain6.com'), '/app6/c6/f6')
        self.assertEqual(filter_url('https://domain6.com'), '/app6s/c6s/f6s')







|
|
>
>
>







420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
        self.assertEqual(filter_url('http://domain3a.com/c3b'), '/app3/c3b/index')
        self.assertEqual(filter_url('http://domain3b.com/abc'), '/app3/c3b/abc')

        self.assertEqual(filter_url('http://domain3a.com/app3/c3a/fcn', domain=('app3','c3a'), out=True), "/fcn")
        self.assertEqual(filter_url('http://domain3a.com/app3/c3a/fcn', domain=('app3','c3b'), out=True), "/c3a/fcn")
        self.assertEqual(filter_url('http://domain3a.com/app3/c3a/fcn', domain=('app1',None), out=True), "/app3/c3a/fcn")

        self.assertEqual(filter_url('http://domain4a.com/abc'), '/app4/c4/abc')
        self.assertEqual(filter_url('https://domain4a.com/app4/c4/fcn', domain=('app4',None), out=True), "/fcn")

        self.assertEqual(filter_url('http://domain4a.com'), '/app4/c4/f4a')
        self.assertEqual(filter_url('http://domain4b.com'), '/app4/c4/f4b')

        self.assertEqual(filter_url('http://localhost/abc'), '/app5/c5/abc')
        self.assertEqual(filter_url('http:///abc'), '/app5/c5/abc') # test null host => localhost
        self.assertEqual(filter_url('https://localhost/app5/c5/fcn', domain=('app5',None), out=True), "/fcn")

        self.assertEqual(filter_url('http://domain6.com'), '/app6/c6/f6')
        self.assertEqual(filter_url('https://domain6.com'), '/app6s/c6s/f6s')
521
522
523
524
525
526
527

528






529
530
531
532
533
534
535


536
537

538
539
540
541
542
543
544


545
546
547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
                default_application = 'app',
            ),
            init = dict(
                controllers = ['default'],
            ),
            app = dict(
                controllers = ['default', 'ctr'],

                functions = ['index', 'user', 'help'],






            ),
            app2 = dict(
                controllers = ['default', 'ctr'],
                functions = ['index', 'user', 'help'],
            ),
        )
        load(rdict=router_functions)


        self.assertEqual(str(URL(a='init', c='default', f='f', args=['arg1'])), "/init/f/arg1")
        self.assertEqual(str(URL(a='init', c='default', f='index', args=['arg1'])), "/init/index/arg1")

        self.assertEqual(str(URL(a='app', c='default', f='index', args=['arg1'])), "/arg1")
        self.assertEqual(str(URL(a='app', c='default', f='user', args=['arg1'])), "/user/arg1")
        self.assertEqual(str(URL(a='app', c='default', f='user', args=['index'])), "/user/index")
        self.assertEqual(str(URL(a='app', c='default', f='index', args=['index'])), "/index/index")
        self.assertEqual(str(URL(a='app', c='default', f='index', args=['init'])), "/index/init")
        self.assertEqual(str(URL(a='app', c='default', f='index', args=['ctr'])), "/index/ctr")
        self.assertEqual(str(URL(a='app', c='ctr', f='index', args=['arg'])), "/ctr/index/arg")



        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['arg1'])), "/app2/arg1")
        self.assertEqual(str(URL(a='app2', c='default', f='user', args=['arg1'])), "/app2/user/arg1")
        self.assertEqual(str(URL(a='app2', c='default', f='user', args=['index'])), "/app2/user/index")
        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['index'])), "/app2/index/index")
        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['init'])), "/app2/index/init")
        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['ctr'])), "/app2/index/ctr")


        self.assertEqual(filter_url('http://d.com/arg'), "/app/default/index ['arg']")
        self.assertEqual(filter_url('http://d.com/user'), "/app/default/user")
        self.assertEqual(filter_url('http://d.com/user/arg'), "/app/default/user ['arg']")
        self.assertEqual(filter_url('http://d.com/ctr'), "/app/ctr/index")
        self.assertEqual(filter_url('http://d.com/ctr/index/arg'), "/app/ctr/index ['arg']")
        self.assertEqual(filter_url('http://d.com/ctr/arg'), "/app/ctr/arg")

        self.assertEqual(filter_url('http://d.com/app2/arg'), "/app2/default/index ['arg']")
        self.assertEqual(filter_url('http://d.com/app2/user'), "/app2/default/user")
        self.assertEqual(filter_url('http://d.com/app2/user/arg'), "/app2/default/user ['arg']")
        self.assertEqual(filter_url('http://d.com/app2/ctr'), "/app2/ctr/index")
        self.assertEqual(filter_url('http://d.com/app2/ctr/index/arg'), "/app2/ctr/index ['arg']")
        self.assertEqual(filter_url('http://d.com/app2/ctr/arg'), "/app2/ctr/arg")







>
|
>
>
>
>
>
>







>
>


>







>
>








>



|
<
|







528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
584
                default_application = 'app',
            ),
            init = dict(
                controllers = ['default'],
            ),
            app = dict(
                controllers = ['default', 'ctr'],
                functions = dict(
                    default=['index', 'user', 'help'],
                    ctr=['ctrf1', 'ctrf2', 'ctrf3'],
                ),
                default_function = dict(
                    default='index',
                    ctr='ctrf1',
                ),
            ),
            app2 = dict(
                controllers = ['default', 'ctr'],
                functions = ['index', 'user', 'help'],
            ),
        )
        load(rdict=router_functions)
        
        # outbound
        self.assertEqual(str(URL(a='init', c='default', f='f', args=['arg1'])), "/init/f/arg1")
        self.assertEqual(str(URL(a='init', c='default', f='index', args=['arg1'])), "/init/index/arg1")
        
        self.assertEqual(str(URL(a='app', c='default', f='index', args=['arg1'])), "/arg1")
        self.assertEqual(str(URL(a='app', c='default', f='user', args=['arg1'])), "/user/arg1")
        self.assertEqual(str(URL(a='app', c='default', f='user', args=['index'])), "/user/index")
        self.assertEqual(str(URL(a='app', c='default', f='index', args=['index'])), "/index/index")
        self.assertEqual(str(URL(a='app', c='default', f='index', args=['init'])), "/index/init")
        self.assertEqual(str(URL(a='app', c='default', f='index', args=['ctr'])), "/index/ctr")
        self.assertEqual(str(URL(a='app', c='ctr', f='index', args=['arg'])), "/ctr/index/arg")
        self.assertEqual(str(URL(a='app', c='ctr', f='ctrf1', args=['arg'])), "/ctr/arg")
        self.assertEqual(str(URL(a='app', c='ctr', f='ctrf1', args=['ctrf2'])), "/ctr/ctrf1/ctrf2")

        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['arg1'])), "/app2/arg1")
        self.assertEqual(str(URL(a='app2', c='default', f='user', args=['arg1'])), "/app2/user/arg1")
        self.assertEqual(str(URL(a='app2', c='default', f='user', args=['index'])), "/app2/user/index")
        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['index'])), "/app2/index/index")
        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['init'])), "/app2/index/init")
        self.assertEqual(str(URL(a='app2', c='default', f='index', args=['ctr'])), "/app2/index/ctr")

        # inbound
        self.assertEqual(filter_url('http://d.com/arg'), "/app/default/index ['arg']")
        self.assertEqual(filter_url('http://d.com/user'), "/app/default/user")
        self.assertEqual(filter_url('http://d.com/user/arg'), "/app/default/user ['arg']")
        self.assertEqual(filter_url('http://d.com/ctr'), "/app/ctr/ctrf1")

        self.assertEqual(filter_url('http://d.com/ctr/arg'), "/app/ctr/ctrf1 ['arg']")

        self.assertEqual(filter_url('http://d.com/app2/arg'), "/app2/default/index ['arg']")
        self.assertEqual(filter_url('http://d.com/app2/user'), "/app2/default/user")
        self.assertEqual(filter_url('http://d.com/app2/user/arg'), "/app2/default/user ['arg']")
        self.assertEqual(filter_url('http://d.com/app2/ctr'), "/app2/ctr/index")
        self.assertEqual(filter_url('http://d.com/app2/ctr/index/arg'), "/app2/ctr/index ['arg']")
        self.assertEqual(filter_url('http://d.com/app2/ctr/arg'), "/app2/ctr/arg")
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
        self.assertEqual(get_effective_router('a1').domains, None)
        self.assertEqual(get_effective_router('a1').default_controller, "default")
        self.assertEqual(get_effective_router('a2').default_application, None)
        self.assertEqual(get_effective_router('a2').default_controller, "c2")
        self.assertEqual(get_effective_router('a1').controllers, set(['c1a', 'c1b', 'default', 'static']))
        self.assertEqual(get_effective_router('a2').controllers, set())
        self.assertEqual(get_effective_router('a3').controllers, set(['c1', 'c2', 'static']))
        self.assertEqual(get_effective_router('a4').functions, set(['f1', 'f2']))
        self.assertEqual(get_effective_router('xx'), None)

    def test_router_error(self):
        '''
        Test rewrite of HTTP errors
        '''
        router_err = dict()







|







710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
        self.assertEqual(get_effective_router('a1').domains, None)
        self.assertEqual(get_effective_router('a1').default_controller, "default")
        self.assertEqual(get_effective_router('a2').default_application, None)
        self.assertEqual(get_effective_router('a2').default_controller, "c2")
        self.assertEqual(get_effective_router('a1').controllers, set(['c1a', 'c1b', 'default', 'static']))
        self.assertEqual(get_effective_router('a2').controllers, set())
        self.assertEqual(get_effective_router('a3').controllers, set(['c1', 'c2', 'static']))
        self.assertEqual(get_effective_router('a4').functions, dict(default=set(['f1', 'f2'])))
        self.assertEqual(get_effective_router('xx'), None)

    def test_router_error(self):
        '''
        Test rewrite of HTTP errors
        '''
        router_err = dict()
Modified gluon/tools.py from [af2a86f800] to [1e8e80315e].
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35







36
37

38

39
40
41
42
43
44
45
import datetime
import thread
import logging
import sys
import os
import re
import time
import copy
import smtplib
import urllib
import urllib2
import Cookie
import cStringIO
from email import MIMEBase, MIMEMultipart, MIMEText, Encoders, Header, message_from_string

from contenttype import contenttype
from storage import Storage, StorageList, Settings, Messages
from utils import web2py_uuid
from gluon import *
from fileutils import read_file


import serializers
import contrib.simplejson as simplejson









__all__ = ['Mail', 'Auth', 'Recaptcha', 'Crud', 'Service', 'PluginManager', 'fetch', 'geocode', 'prettydate']



logger = logging.getLogger("web2py")

DEFAULT = lambda: None

def callback(actions,form,tablename=None):
    if actions:
        if tablename and isinstance(actions,dict):







<










<

>


<

>
>
>
>
>
>
>

|
>

>







12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28

29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import datetime
import thread
import logging
import sys
import os
import re
import time

import smtplib
import urllib
import urllib2
import Cookie
import cStringIO
from email import MIMEBase, MIMEMultipart, MIMEText, Encoders, Header, message_from_string

from contenttype import contenttype
from storage import Storage, StorageList, Settings, Messages
from utils import web2py_uuid

from fileutils import read_file
from gluon import *

import serializers


try:
    import json as json_parser                      # try stdlib (Python 2.6)
except ImportError:
    try:
        import simplejson as json_parser            # try external module
    except:
        import contrib.simplejson as json_parser    # fallback to pure-Python module

__all__ = ['Mail', 'Auth', 'Recaptcha', 'Crud', 'Service', 
           'PluginManager', 'fetch', 'geocode', 'prettydate']

### mind there are two loggers here (logger and crud.settings.logger)!
logger = logging.getLogger("web2py")

DEFAULT = lambda: None

def callback(actions,form,tablename=None):
    if actions:
        if tablename and isinstance(actions,dict):
58
59
60
61
62
63
64









65
66
67
68
69
70
71
    return b

def call_or_redirect(f,*args):
    if callable(f):
        redirect(f(*args))
    else:
        redirect(f)










class Mail(object):
    """
    Class for configuring and sending emails with alternative text / html
    body, multiple attachments and encryption support

    Works with SMTP and Google App Engine.







>
>
>
>
>
>
>
>
>







65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    return b

def call_or_redirect(f,*args):
    if callable(f):
        redirect(f(*args))
    else:
        redirect(f)

def replace_id(url, form):
    if url and not url[0] == '/' and url[:4] != 'http':
        # this is here for backward compatibility
        return URL(url.replace('[id]', str(form.vars.id)))
    elif url:
        # this allows http://..../%(id)s/%(name)s/etc.
        return url % form.vars
    return url

class Mail(object):
    """
    Class for configuring and sending emails with alternative text / html
    body, multiple attachments and encryption support

    Works with SMTP and Google App Engine.
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
            self,
            payload,
            filename=None,
            content_id=None,
            content_type=None,
            encoding='utf-8'):
            if isinstance(payload, str):
                if filename == None:
                    filename = os.path.basename(payload)
                payload = read_file(payload, 'rb')
            else:
                if filename == None:
                    raise Exception('Missing attachment name')
                payload = payload.read()
            filename = filename.encode(encoding)
            if content_type == None:
                content_type = contenttype(filename)
            self.my_filename = filename
            self.my_payload = payload
            MIMEBase.MIMEBase.__init__(self, *content_type.split('/', 1))
            self.set_payload(payload)
            self['Content-Disposition'] = 'attachment; filename="%s"' % filename
            if content_id != None:
                self['Content-Id'] = '<%s>' % content_id.encode(encoding)
            Encoders.encode_base64(self)

    def __init__(self, server=None, sender=None, login=None, tls=True):
        """
        Main Mail object








|



|



|






|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
            self,
            payload,
            filename=None,
            content_id=None,
            content_type=None,
            encoding='utf-8'):
            if isinstance(payload, str):
                if filename is None:
                    filename = os.path.basename(payload)
                payload = read_file(payload, 'rb')
            else:
                if filename is None:
                    raise Exception('Missing attachment name')
                payload = payload.read()
            filename = filename.encode(encoding)
            if content_type is None:
                content_type = contenttype(filename)
            self.my_filename = filename
            self.my_payload = payload
            MIMEBase.MIMEBase.__init__(self, *content_type.split('/', 1))
            self.set_payload(payload)
            self['Content-Disposition'] = 'attachment; filename="%s"' % filename
            if not content_id is None:
                self['Content-Id'] = '<%s>' % content_id.encode(encoding)
            Encoders.encode_base64(self)

    def __init__(self, server=None, sender=None, login=None, tls=True):
        """
        Main Mail object

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
            raise Exception('Target receiver address not specified')
        if cc:
            if not isinstance(cc, (list, tuple)):
                cc = [cc]
        if bcc:
            if not isinstance(bcc, (list, tuple)):
                bcc = [bcc]
        if message == None:
            text = html = None
        elif isinstance(message, (list, tuple)):
            text, html = message
        elif message.strip().startswith('<html') and message.strip().endswith('</html>'):
            text = self.settings.server=='gae' and message or None
            html = message
        else:
            text = message
            html = None
        if text != None or html != None:
            attachment = MIMEMultipart.MIMEMultipart('alternative')
            if text != None:
                if isinstance(text, basestring):
                    text = text.decode(encoding).encode('utf-8')
                else:
                    text = text.read().decode(encoding).encode('utf-8')
                attachment.attach(MIMEText.MIMEText(text,_charset='utf-8'))
            if html != None:
                if isinstance(html, basestring):
                    html = html.decode(encoding).encode('utf-8')
                else:
                    html = html.read().decode(encoding).encode('utf-8')
                attachment.attach(MIMEText.MIMEText(html, 'html',_charset='utf-8'))
            payload_in.attach(attachment)
        if attachments == None:
            pass
        elif isinstance(attachments, (list, tuple)):
            for attachment in attachments:
                payload_in.attach(attachment)
        else:
            payload_in.attach(attachments)








|









|

|





|






|







333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
            raise Exception('Target receiver address not specified')
        if cc:
            if not isinstance(cc, (list, tuple)):
                cc = [cc]
        if bcc:
            if not isinstance(bcc, (list, tuple)):
                bcc = [bcc]
        if message is None:
            text = html = None
        elif isinstance(message, (list, tuple)):
            text, html = message
        elif message.strip().startswith('<html') and message.strip().endswith('</html>'):
            text = self.settings.server=='gae' and message or None
            html = message
        else:
            text = message
            html = None
        if not text is None or not html is None:
            attachment = MIMEMultipart.MIMEMultipart('alternative')
            if not text is None:
                if isinstance(text, basestring):
                    text = text.decode(encoding).encode('utf-8')
                else:
                    text = text.read().decode(encoding).encode('utf-8')
                attachment.attach(MIMEText.MIMEText(text,_charset='utf-8'))
            if not html is None:
                if isinstance(html, basestring):
                    html = html.decode(encoding).encode('utf-8')
                else:
                    html = html.read().decode(encoding).encode('utf-8')
                attachment.attach(MIMEText.MIMEText(html, 'html',_charset='utf-8'))
            payload_in.attach(attachment)
        if attachments is None:
            pass
        elif isinstance(attachments, (list, tuple)):
            for attachment in attachments:
                payload_in.attach(attachment)
        else:
            payload_in.attach(attachments)

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
                if cc:
                    rec.extend(cc)
                if bcc:
                    rec.extend(bcc)
                for addr in rec:
                    c.op_keylist_start(addr,0)
                    r = c.op_keylist_next()
                    if r == None:
                        self.error='No key for [%s]' % addr
                        return False
                    recipients.append(r)
                try:
                    # make the encryption
                    c.op_encrypt(recipients, 1, plain, cipher)
                    cipher.seek(0,0)







|







445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
                if cc:
                    rec.extend(cc)
                if bcc:
                    rec.extend(bcc)
                for addr in rec:
                    c.op_keylist_start(addr,0)
                    r = c.op_keylist_next()
                    if r is None:
                        self.error='No key for [%s]' % addr
                        return False
                    recipients.append(r)
                try:
                    # make the encryption
                    c.op_encrypt(recipients, 1, plain, cipher)
                    cipher.seek(0,0)
544
545
546
547
548
549
550
551
552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
            to.extend(bcc)
        payload['Subject'] = encode_header(subject.decode(encoding))
        payload['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S +0000",
                                        time.gmtime())
        result = {}
        try:
            if self.settings.server == 'logging':
                logger.warn('email not sent\n%s\nFrom: %s\nTo: %s\n\n%s\n%s\n' % \
                                 ('-'*40,self.settings.sender,

                                  ', '.join(to),text or html,'-'*40))
            elif self.settings.server == 'gae':
                xcc = dict()
                if cc:
                    xcc['cc'] = cc
                if bcc:
                    xcc['bcc'] = bcc
                from google.appengine.api import mail
                attachments = attachments and [(a.my_filename,a.my_payload) for a in attachments]
                if attachments:
                    result = mail.send_mail(sender=self.settings.sender, to=origTo,
                                            subject=subject, body=text, html=html,
                                            attachments=attachments, **xcc)
                elif html:
                    result = mail.send_mail(sender=self.settings.sender, to=origTo,
                                            subject=subject, body=text, html=html, **xcc)
                else:
                    result = mail.send_mail(sender=self.settings.sender, to=origTo,
                                            subject=subject, body=text, **xcc)
            else:
                smtp_args = self.settings.server.split(':')
                if self.settings.ssl: 
                    server = smtplib.SMTP_SSL(*smtp_args)
                else: 
                    server = smtplib.SMTP(*smtp_args)
                if self.settings.tls and not self.settings.ssl:                
                    server.ehlo()
                    server.starttls()
                    server.ehlo()
                if self.settings.login != None:
                    server.login(*self.settings.login.split(':',1))
                result = server.sendmail(self.settings.sender, to, payload.as_string())
                server.quit()
        except Exception, e:
            logger.warn('Mail.send failure:%s' % e)
            self.result = result
            self.error = e







|
|
>
|




















|

|

|



|







560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
            to.extend(bcc)
        payload['Subject'] = encode_header(subject.decode(encoding))
        payload['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S +0000",
                                        time.gmtime())
        result = {}
        try:
            if self.settings.server == 'logging':
                logger.warn('email not sent\n%s\nFrom: %s\nTo: %s\nSubject: %s\n\n%s\n%s\n' % \
                                ('-'*40,self.settings.sender,
                                 subject,
                                 ', '.join(to),text or html,'-'*40))
            elif self.settings.server == 'gae':
                xcc = dict()
                if cc:
                    xcc['cc'] = cc
                if bcc:
                    xcc['bcc'] = bcc
                from google.appengine.api import mail
                attachments = attachments and [(a.my_filename,a.my_payload) for a in attachments]
                if attachments:
                    result = mail.send_mail(sender=self.settings.sender, to=origTo,
                                            subject=subject, body=text, html=html,
                                            attachments=attachments, **xcc)
                elif html:
                    result = mail.send_mail(sender=self.settings.sender, to=origTo,
                                            subject=subject, body=text, html=html, **xcc)
                else:
                    result = mail.send_mail(sender=self.settings.sender, to=origTo,
                                            subject=subject, body=text, **xcc)
            else:
                smtp_args = self.settings.server.split(':')
                if self.settings.ssl:
                    server = smtplib.SMTP_SSL(*smtp_args)
                else:
                    server = smtplib.SMTP(*smtp_args)
                if self.settings.tls and not self.settings.ssl:
                    server.ehlo()
                    server.starttls()
                    server.ehlo()
                if not self.settings.login is None:
                    server.login(*self.settings.login.split(':',1))
                result = server.sendmail(self.settings.sender, to, payload.as_string())
                server.quit()
        except Exception, e:
            logger.warn('Mail.send failure:%s' % e)
            self.result = result
            self.error = e
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
        if not self.errors.captcha:
            return XML(captcha).xml()
        else:
            captcha.append(DIV(self.errors['captcha'], _class='error'))
            return XML(captcha).xml()


def addrow(form,a,b,c,style,_id,position=-1):
    if style == "divs":
        form[0].insert(position, DIV(DIV(LABEL(a),_class='w2p_fl'),
                                     DIV(b, _class='w2p_fw'),
                                     DIV(c, _class='w2p_fc'),
                                     _id = _id))
    elif style == "table2cols":
        form[0].insert(position, TR(LABEL(a),''))







|







699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
        if not self.errors.captcha:
            return XML(captcha).xml()
        else:
            captcha.append(DIV(self.errors['captcha'], _class='error'))
            return XML(captcha).xml()


def addrow(form, a, b, c, style, _id, position=-1):
    if style == "divs":
        form[0].insert(position, DIV(DIV(LABEL(a),_class='w2p_fl'),
                                     DIV(b, _class='w2p_fw'),
                                     DIV(c, _class='w2p_fc'),
                                     _id = _id))
    elif style == "table2cols":
        form[0].insert(position, TR(LABEL(a),''))
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
    Authentication Example::

        from contrib.utils import *
        mail=Mail()
        mail.settings.server='smtp.gmail.com:587'
        mail.settings.sender='you@somewhere.com'
        mail.settings.login='username:password'
        auth=Auth(globals(), db)
        auth.settings.mailer=mail
        # auth.settings....=...
        auth.define_tables()
        def authentication():
            return dict(form=auth())

    exposes:







|







737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
    Authentication Example::

        from contrib.utils import *
        mail=Mail()
        mail.settings.server='smtp.gmail.com:587'
        mail.settings.sender='you@somewhere.com'
        mail.settings.login='username:password'
        auth=Auth(db)
        auth.settings.mailer=mail
        # auth.settings....=...
        auth.define_tables()
        def authentication():
            return dict(form=auth())

    exposes:
785
786
787
788
789
790
791











792
793


794
795



796
797
798
799
800
801
802
803



804
805
806
807
808
809
810

        ...

        ### these are messages that can be customized
        ...
    """













    def url(self, f=None, args=[], vars={}):


        return URL(c=self.settings.controller,f=f,args=args,vars=vars)




    def __init__(self, environment=None, db=None,
                 controller='default', cas_provider = None):
        """
        auth=Auth(globals(), db)

        - environment is there for legacy but unused (awful)
        - db has to be the database where to create tables for authentication




        """
        ## next two lines for backward compatibility
        if not db and environment and isinstance(environment,DAL):
            db = environment
        self.db = db
        self.environment = current
        request = current.request







>
>
>
>
>
>
>
>
>
>
>

|
>
>
|

>
>
>
|
|

|



|
>
>
>







802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846

        ...

        ### these are messages that can be customized
        ...
    """

    @staticmethod
    def get_or_create_key(filename=None):
        request = current.request
        if not filename:
            filename = os.path.join(request.folder,'private','auth.key')
        if os.path.exists(filename):
            key = open(filename,'r').read().strip()
        else:
            key = web2py_uuid()
            open(filename,'w').write(key)
        return key

    def url(self, f=None, args=None, vars=None):
        if args is None: args=[]
        if vars is None: vars={}
        return URL(c=self.settings.controller, f=f, args=args, vars=vars)

    def here(self):
        return URL(args=current.request.args,vars=current.request.vars)
 
    def __init__(self, environment=None, db=None, mailer=True,
                 hmac_key=None, controller='default', cas_provider=None):
        """
        auth=Auth(db)

        - environment is there for legacy but unused (awful)
        - db has to be the database where to create tables for authentication
        - mailer=Mail(...) or None (no mailed) or True (make a mailer)
        - hmac_key can be a hmac_key or hmac_key=Auth.get_or_create_key()
        - controller (where is the user action?)
        - cas_provider (delegate authentication to the URL, CAS2)
        """
        ## next two lines for backward compatibility
        if not db and environment and isinstance(environment,DAL):
            db = environment
        self.db = db
        self.environment = current
        request = current.request
818
819
820
821
822
823
824




825
826
827
828

829
830
831
832
833
834
835

836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
                auth.last_visit = request.now
        else:
            self.user = None
            session.auth = None
        settings = self.settings = Settings()

        # ## what happens after login?





        # ## what happens after registration?

        settings.hideerror = False

        settings.cas_domains = [request.env.http_host]
        settings.cas_provider = cas_provider
        settings.extra_fields = {}
        settings.actions_disabled = []
        settings.reset_password_requires_verification = False
        settings.registration_requires_verification = False
        settings.registration_requires_approval = False

        settings.alternate_requires_registration = False
        settings.create_user_groups = True

        settings.controller = controller
        settings.login_url = self.url('user', args='login')
        settings.logged_url = self.url('user', args='profile')
        settings.download_url = self.url('download')
        settings.mailer = None
        settings.login_captcha = None
        settings.register_captcha = None
        settings.retrieve_username_captcha = None
        settings.retrieve_password_captcha = None
        settings.captcha = None
        settings.expiration = 3600            # one hour
        settings.long_expiration = 3600*30*24 # one month







>
>
>
>




>







>







|







854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
                auth.last_visit = request.now
        else:
            self.user = None
            session.auth = None
        settings = self.settings = Settings()

        # ## what happens after login?

        self.next = current.request.vars._next
        if isinstance(self.next,(list,tuple)):
            self.next = self.next[0]

        # ## what happens after registration?

        settings.hideerror = False
        settings.password_min_length = 4
        settings.cas_domains = [request.env.http_host]
        settings.cas_provider = cas_provider
        settings.extra_fields = {}
        settings.actions_disabled = []
        settings.reset_password_requires_verification = False
        settings.registration_requires_verification = False
        settings.registration_requires_approval = False
        settings.login_after_registration = False
        settings.alternate_requires_registration = False
        settings.create_user_groups = True

        settings.controller = controller
        settings.login_url = self.url('user', args='login')
        settings.logged_url = self.url('user', args='profile')
        settings.download_url = self.url('download')
        settings.mailer = (mailer==True) and Mail() or mailer
        settings.login_captcha = None
        settings.register_captcha = None
        settings.retrieve_username_captcha = None
        settings.retrieve_password_captcha = None
        settings.captcha = None
        settings.expiration = 3600            # one hour
        settings.long_expiration = 3600*30*24 # one month
895
896
897
898
899
900
901

902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
        settings.logout_next = self.url('index')
        settings.logout_onlogout = None

        settings.register_next = self.url('index')
        settings.register_onvalidation = []
        settings.register_onaccept = []
        settings.register_fields = None


        settings.verify_email_next = self.url('user', args='login')
        settings.verify_email_onaccept = []

        settings.profile_next = self.url('index')
        settings.profile_onvalidation = []
        settings.profile_onaccept = []
        settings.profile_fields = None
        settings.retrieve_username_next = self.url('index')
        settings.retrieve_password_next = self.url('index')
        settings.request_reset_password_next = self.url('user', args='login')
        settings.reset_password_next = self.url('user', args='login')

        settings.change_password_next = self.url('index')
        settings.change_password_onvalidation = []
        settings.change_password_onaccept = []

        settings.retrieve_password_onvalidation = []
        settings.reset_password_onvalidation = []

        settings.hmac_key = None
        settings.lock_keys = True


        # ## these are messages that can be customized
        messages = self.messages = Messages(current.T)
        messages.login_button = 'Login'
        messages.register_button = 'Register'
        messages.password_reset_button = 'Request reset password'
        messages.password_change_button = 'Change password'







>




















|

<







937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966

967
968
969
970
971
972
973
        settings.logout_next = self.url('index')
        settings.logout_onlogout = None

        settings.register_next = self.url('index')
        settings.register_onvalidation = []
        settings.register_onaccept = []
        settings.register_fields = None
        settings.register_verify_password = True

        settings.verify_email_next = self.url('user', args='login')
        settings.verify_email_onaccept = []

        settings.profile_next = self.url('index')
        settings.profile_onvalidation = []
        settings.profile_onaccept = []
        settings.profile_fields = None
        settings.retrieve_username_next = self.url('index')
        settings.retrieve_password_next = self.url('index')
        settings.request_reset_password_next = self.url('user', args='login')
        settings.reset_password_next = self.url('user', args='login')

        settings.change_password_next = self.url('index')
        settings.change_password_onvalidation = []
        settings.change_password_onaccept = []

        settings.retrieve_password_onvalidation = []
        settings.reset_password_onvalidation = []

        settings.hmac_key = hmac_key
        settings.lock_keys = True


        # ## these are messages that can be customized
        messages = self.messages = Messages(current.T)
        messages.login_button = 'Login'
        messages.register_button = 'Register'
        messages.password_reset_button = 'Request reset password'
        messages.password_change_button = 'Change password'
948
949
950
951
952
953
954


955
956
957
958
959
960
961
962
963
964


965
966
967
968
969
970
971
972
        messages.unable_send_email = 'Unable to send email'
        messages.invalid_login = 'Invalid login'
        messages.invalid_user = 'Invalid user'
        messages.invalid_password = 'Invalid password'
        messages.is_empty = "Cannot be empty"
        messages.mismatched_password = "Password fields don't match"
        messages.verify_email = \


            'Click on the link http://...verify_email/%(key)s to verify your email'
        messages.verify_email_subject = 'Email verification'
        messages.username_sent = 'Your username was emailed to you'
        messages.new_password_sent = 'A new password was emailed to you'
        messages.password_changed = 'Password changed'
        messages.retrieve_username = 'Your username is: %(username)s'
        messages.retrieve_username_subject = 'Username retrieve'
        messages.retrieve_password = 'Your password is: %(password)s'
        messages.retrieve_password_subject = 'Password retrieve'
        messages.reset_password = \


            'Click on the link http://...reset_password/%(key)s to reset your password'
        messages.reset_password_subject = 'Password reset'
        messages.invalid_reset_password = 'Invalid reset password'
        messages.profile_updated = 'Profile updated'
        messages.new_password = 'New password'
        messages.old_password = 'Old password'
        messages.group_description = \
            'Group uniquely assigned to user %(id)s'







>
>
|









>
>
|







990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
        messages.unable_send_email = 'Unable to send email'
        messages.invalid_login = 'Invalid login'
        messages.invalid_user = 'Invalid user'
        messages.invalid_password = 'Invalid password'
        messages.is_empty = "Cannot be empty"
        messages.mismatched_password = "Password fields don't match"
        messages.verify_email = \
            'Click on the link http://' + current.request.env.http_host + \
            URL('default','user',args=['verify_email']) + \
            '/%(key)s to verify your email'
        messages.verify_email_subject = 'Email verification'
        messages.username_sent = 'Your username was emailed to you'
        messages.new_password_sent = 'A new password was emailed to you'
        messages.password_changed = 'Password changed'
        messages.retrieve_username = 'Your username is: %(username)s'
        messages.retrieve_username_subject = 'Username retrieve'
        messages.retrieve_password = 'Your password is: %(password)s'
        messages.retrieve_password_subject = 'Password retrieve'
        messages.reset_password = \
            'Click on the link http://' + current.request.env.http_host + \
            URL('default','user',args=['reset_password']) + \
            '/%(key)s to reset your password'
        messages.reset_password_subject = 'Password reset'
        messages.invalid_reset_password = 'Invalid reset password'
        messages.profile_updated = 'Profile updated'
        messages.new_password = 'New password'
        messages.old_password = 'Old password'
        messages.group_description = \
            'Group uniquely assigned to user %(id)s'
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
        messages.label_reset_password_key = 'Reset Password key'
        messages.label_registration_id = 'Registration identifier'
        messages.label_role = 'Role'
        messages.label_description = 'Description'
        messages.label_user_id = 'User ID'
        messages.label_group_id = 'Group ID'
        messages.label_name = 'Name'
        messages.label_table_name = 'Table name'
        messages.label_record_id = 'Record ID'
        messages.label_time_stamp = 'Timestamp'
        messages.label_client_ip = 'Client IP'
        messages.label_origin = 'Origin'
        messages.label_remember_me = "Remember me (for 30 days)"
        messages['T'] = current.T
        messages.verify_password_comment = 'please input your password again'







|







1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
        messages.label_reset_password_key = 'Reset Password key'
        messages.label_registration_id = 'Registration identifier'
        messages.label_role = 'Role'
        messages.label_description = 'Description'
        messages.label_user_id = 'User ID'
        messages.label_group_id = 'Group ID'
        messages.label_name = 'Name'
        messages.label_table_name = 'Object or table name'
        messages.label_record_id = 'Record ID'
        messages.label_time_stamp = 'Timestamp'
        messages.label_client_ip = 'Client IP'
        messages.label_origin = 'Origin'
        messages.label_remember_me = "Remember me (for 30 days)"
        messages['T'] = current.T
        messages.verify_password_comment = 'please input your password again'
1077
1078
1079
1080
1081
1082
1083
1084

1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
                       'reset_password','request_reset_password',
                       'change_password','profile','groups',
                       'impersonate','not_authorized'):
            return getattr(self,args[0])()
        elif args[0]=='cas' and not self.settings.cas_provider:
            if args(1) == 'login': return self.cas_login(version=2)
            if args(1) == 'validate': return self.cas_validate(version=2)
            if args(1) == 'logout': return self.logout()

        else:
            raise HTTP(404)

    def navbar(self,prefix='Welcome',action=None):
        request = current.request
        T = current.T
        if isinstance(prefix,str):
            prefix = T(prefix)
        if not action:
            action=URL(request.application,request.controller,'user')
        if prefix:







|
>



|







1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
                       'reset_password','request_reset_password',
                       'change_password','profile','groups',
                       'impersonate','not_authorized'):
            return getattr(self,args[0])()
        elif args[0]=='cas' and not self.settings.cas_provider:
            if args(1) == 'login': return self.cas_login(version=2)
            if args(1) == 'validate': return self.cas_validate(version=2)
            if args(1) == 'logout':
                return self.logout(next=request.vars.service or DEFAULT)
        else:
            raise HTTP(404)

    def navbar(self, prefix='Welcome', action=None):
        request = current.request
        T = current.T
        if isinstance(prefix,str):
            prefix = T(prefix)
        if not action:
            action=URL(request.application,request.controller,'user')
        if prefix:
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
        else:
            login=A(T('login'),_href=action+'/login')
            register=A(T('register'),_href=action+'/register')
            retrieve_username=A(T('forgot username?'),
                            _href=action+'/retrieve_username')
            lost_password=A(T('lost password?'),
                            _href=action+'/request_reset_password')
            bar = SPAN('[ ',login,' ]',_class='auth_navbar')

            if not 'register' in self.settings.actions_disabled:
                bar.insert(2, ' | ')
                bar.insert(3, register)
            if 'username' in self.settings.table_user.fields() and \
                    not 'retrieve_username' in self.settings.actions_disabled:
                bar.insert(-1, ' | ')







|







1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
        else:
            login=A(T('login'),_href=action+'/login')
            register=A(T('register'),_href=action+'/register')
            retrieve_username=A(T('forgot username?'),
                            _href=action+'/retrieve_username')
            lost_password=A(T('lost password?'),
                            _href=action+'/request_reset_password')
            bar = SPAN(' [ ',login,' ]',_class='auth_navbar')

            if not 'register' in self.settings.actions_disabled:
                bar.insert(2, ' | ')
                bar.insert(3, register)
            if 'username' in self.settings.table_user.fields() and \
                    not 'retrieve_username' in self.settings.actions_disabled:
                bar.insert(-1, ' | ')
1207
1208
1209
1210
1211
1212
1213
1214


1215
1216
1217
1218
1219
1220
1221
                                                   migrate),
                        fake_migrate=fake_migrate,
                        format='%(first_name)s %(last_name)s (%(id)s)'))
            table.first_name.requires = \
                IS_NOT_EMPTY(error_message=self.messages.is_empty)
            table.last_name.requires = \
                IS_NOT_EMPTY(error_message=self.messages.is_empty)
            table[passfield].requires = [CRYPT(key=settings.hmac_key)]


            table.email.requires = \
                [IS_EMAIL(error_message=self.messages.invalid_email),
                 IS_NOT_IN_DB(db, table.email)]
            table.registration_key.default = ''
        settings.table_user = db[settings.table_user_name]
        if not settings.table_group_name in db.tables:
            table = db.define_table(







|
>
>







1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
                                                   migrate),
                        fake_migrate=fake_migrate,
                        format='%(first_name)s %(last_name)s (%(id)s)'))
            table.first_name.requires = \
                IS_NOT_EMPTY(error_message=self.messages.is_empty)
            table.last_name.requires = \
                IS_NOT_EMPTY(error_message=self.messages.is_empty)
            table[passfield].requires = [
                CRYPT(key=settings.hmac_key,
                      min_length=self.settings.password_min_length)]
            table.email.requires = \
                [IS_EMAIL(error_message=self.messages.invalid_email),
                 IS_NOT_IN_DB(db, table.email)]
            table.registration_key.default = ''
        settings.table_user = db[settings.table_user_name]
        if not settings.table_group_name in db.tables:
            table = db.define_table(
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
                    migrate=self.__get_migrate(
                        settings.table_permission_name, migrate),
                    fake_migrate=fake_migrate))
            table.group_id.requires = IS_IN_DB(db, '%s.id' %
                    settings.table_group_name,
                    '%(role)s (%(id)s)')
            table.name.requires = IS_NOT_EMPTY(error_message=self.messages.is_empty)
            table.table_name.requires = IS_EMPTY_OR(IS_IN_SET(self.db.tables))
            table.record_id.requires = IS_INT_IN_RANGE(0, 10 ** 9)
        settings.table_permission = db[settings.table_permission_name]
        if not settings.table_event_name in db.tables:
            table  = db.define_table(
                settings.table_event_name,
                Field('time_stamp', 'datetime',
                        default=current.request.now,







|







1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
                    migrate=self.__get_migrate(
                        settings.table_permission_name, migrate),
                    fake_migrate=fake_migrate))
            table.group_id.requires = IS_IN_DB(db, '%s.id' %
                    settings.table_group_name,
                    '%(role)s (%(id)s)')
            table.name.requires = IS_NOT_EMPTY(error_message=self.messages.is_empty)
            #table.table_name.requires = IS_EMPTY_OR(IS_IN_SET(self.db.tables))
            table.record_id.requires = IS_INT_IN_RANGE(0, 10 ** 9)
        settings.table_permission = db[settings.table_permission_name]
        if not settings.table_event_name in db.tables:
            table  = db.define_table(
                settings.table_event_name,
                Field('time_stamp', 'datetime',
                        default=current.request.now,
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345

1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
            settings.login_form = CasAuth(
                casversion = 2,
                urlbase = settings.cas_provider,
                actions=['login','validate','logout'],
                maps=maps)


    def log_event(self, description, origin='auth'):
        """
        usage::

            auth.log_event(description='this happened', origin='auth')
        """


        if self.is_logged_in():
            user_id = self.user.id
        else:
            user_id = None  # user unknown

        self.settings.table_event.insert(description=description,
                                         origin=origin, user_id=user_id)

    def get_or_create_user(self, keys):
        """
        Used for alternate login methods:
            If the user exists already then password is updated.
            If the user doesn't yet exist, then they are created.
        """
        table_user = self.settings.table_user
        if 'registration_id' in table_user.fields() and \
                'registration_id' in keys:
            username = 'registration_id'
        elif 'username' in table_user.fields():
            username = 'username'
        elif 'email' in table_user.fields():
            username = 'email'
        else:
            raise SyntaxError, "user must have username or email"
        passfield = self.settings.password_field
        user = self.db(table_user[username] == keys[username]).select().first()
        keys['registration_key']=''
        if user:
            user.update_record(**table_user._filter_fields(keys))
        else:
            if not 'first_name' in keys and 'first_name' in table_user.fields:
                keys['first_name'] = keys[username]







|





|
>
|



>
|


















<







1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419

1420
1421
1422
1423
1424
1425
1426
            settings.login_form = CasAuth(
                casversion = 2,
                urlbase = settings.cas_provider,
                actions=['login','validate','logout'],
                maps=maps)


    def log_event(self, description, vars=None, origin='auth'):
        """
        usage::

            auth.log_event(description='this happened', origin='auth')
        """
        if not description:
            return
        elif self.is_logged_in():
            user_id = self.user.id
        else:
            user_id = None  # user unknown
        vars = vars or {}
        self.settings.table_event.insert(description=description % vars,
                                         origin=origin, user_id=user_id)

    def get_or_create_user(self, keys):
        """
        Used for alternate login methods:
            If the user exists already then password is updated.
            If the user doesn't yet exist, then they are created.
        """
        table_user = self.settings.table_user
        if 'registration_id' in table_user.fields() and \
                'registration_id' in keys:
            username = 'registration_id'
        elif 'username' in table_user.fields():
            username = 'username'
        elif 'email' in table_user.fields():
            username = 'email'
        else:
            raise SyntaxError, "user must have username or email"

        user = self.db(table_user[username] == keys[username]).select().first()
        keys['registration_key']=''
        if user:
            user.update_record(**table_user._filter_fields(keys))
        else:
            if not 'first_name' in keys and 'first_name' in table_user.fields:
                keys['first_name'] = keys[username]
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
            allow_access()
        def cas_onaccept(form, onaccept=onaccept):
            if onaccept!=DEFAULT: onaccept(form)
            allow_access()
        return self.login(next,onvalidation,cas_onaccept,log)


    def cas_validate(self,version=2):
        request = current.request
        db, table = self.db, self.settings.table_cas
        current.response.headers['Content-Type']='text'
        ticket = table(uuid=request.vars.ticket)
        url = request.env.path_info.rsplit('/',1)[0]
        if ticket: # and ticket.created_on>request.now-datetime.timedelta(60):
            user = self.settings.table_user(ticket.user_id)
            fullname = user.first_name+' '+user.last_name
            if version==1:
                raise HTTP(200,'yes\n%s:%s:%s'%(user.id,user.email,fullname))
            # assume version 2
            username = user.get('username',user.email)
            raise HTTP(200,'<?xml version="1.0" encoding="UTF-8"?>\n'+\
                           TAG['cas:serviceResponse'](
                    TAG['cas:authenticationSuccess'](
                        TAG['cas:user'](username),
                        *[TAG['cas:'+field.name](user[field.name]) \
                              for field in self.settings.table_user \
                              if field.readable]),
                    **{'_xmlns:cas':'http://www.yale.edu/tp/cas'}).xml())
        if version==1:
            raise HTTP(200,'no\n')
        # assume version 2
        raise HTTP(200,'<?xml version="1.0" encoding="UTF-8"?>\n'+\
                       TAG['cas:serviceResponse'](
                TAG['cas:authenticationFailure'](
                    'Ticket %s not recognized' % ticket,
                    _code='INVALID TICKET'),







|




<



|











|







1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508

1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
            allow_access()
        def cas_onaccept(form, onaccept=onaccept):
            if onaccept!=DEFAULT: onaccept(form)
            allow_access()
        return self.login(next,onvalidation,cas_onaccept,log)


    def cas_validate(self, version=2):
        request = current.request
        db, table = self.db, self.settings.table_cas
        current.response.headers['Content-Type']='text'
        ticket = table(uuid=request.vars.ticket)

        if ticket: # and ticket.created_on>request.now-datetime.timedelta(60):
            user = self.settings.table_user(ticket.user_id)
            fullname = user.first_name+' '+user.last_name
            if version == 1:
                raise HTTP(200,'yes\n%s:%s:%s'%(user.id,user.email,fullname))
            # assume version 2
            username = user.get('username',user.email)
            raise HTTP(200,'<?xml version="1.0" encoding="UTF-8"?>\n'+\
                           TAG['cas:serviceResponse'](
                    TAG['cas:authenticationSuccess'](
                        TAG['cas:user'](username),
                        *[TAG['cas:'+field.name](user[field.name]) \
                              for field in self.settings.table_user \
                              if field.readable]),
                    **{'_xmlns:cas':'http://www.yale.edu/tp/cas'}).xml())
        if version == 1:
            raise HTTP(200,'no\n')
        # assume version 2
        raise HTTP(200,'<?xml version="1.0" encoding="UTF-8"?>\n'+\
                       TAG['cas:serviceResponse'](
                TAG['cas:authenticationFailure'](
                    'Ticket %s not recognized' % ticket,
                    _code='INVALID TICKET'),
1513
1514
1515
1516
1517
1518
1519










1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
        table_user[username].requires = tmpvalidator

        request = current.request
        response = current.response
        session = current.session

        passfield = self.settings.password_field










        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.login_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.login_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.login_onaccept
        if log == DEFAULT:
            log = self.messages.login_log

        user = None # default

        # do we use our own login form, or from a central source?
        if self.settings.login_form == self:
            form = SQLFORM(
                table_user,
                fields=[username, passfield],
                hidden=dict(_next=next),
                showid=self.settings.showid,
                submit_button=self.messages.login_button,
                delete_label=self.messages.delete_label,
                formstyle=self.settings.formstyle,
                separator=self.settings.label_separator
                )








>
>
>
>
>
>
>
>
>
>

<
<
|














|







1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579


1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
        table_user[username].requires = tmpvalidator

        request = current.request
        response = current.response
        session = current.session

        passfield = self.settings.password_field
        try: table_user[passfield].requires[-1].min_length = 0
        except: pass

        ### use session for federated login
        if self.next:
            session._auth_next = self.next
        elif session._auth_next:
            self.next = session._auth_next
        ### pass

        if next == DEFAULT:


            next = self.next or self.settings.login_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.login_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.login_onaccept
        if log == DEFAULT:
            log = self.messages.login_log

        user = None # default

        # do we use our own login form, or from a central source?
        if self.settings.login_form == self:
            form = SQLFORM(
                table_user,
                fields=[username, passfield],
                hidden = dict(_next=next),
                showid=self.settings.showid,
                submit_button=self.messages.login_button,
                delete_label=self.messages.delete_label,
                formstyle=self.settings.formstyle,
                separator=self.settings.label_separator
                )

1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
                            )),"",
                       self.settings.formstyle,
                       'auth_user_remember__row')

            captcha = self.settings.login_captcha or \
                (self.settings.login_captcha!=False and self.settings.captcha)
            if captcha:
                addrow(form, captcha.label, captcha, captcha.comment, self.settings.formstyle,'captcha__row')

            accepted_form = False

            if form.accepts(request, session,
                            formname='login', dbio=False,
                            onvalidation=onvalidation,
                            hideerror=self.settings.hideerror):

                accepted_form = True
                # check for username in db
                user = self.db(table_user[username] == form.vars[username]).select().first()
                if user:
                    # user in db, check if registration pending or disabled
                    temp_user = user
                    if temp_user.registration_key == 'pending':
                        response.flash = self.messages.registration_pending
                        return form
                    elif temp_user.registration_key in ('disabled','blocked'):
                        response.flash = self.messages.login_disabled
                        return form
                    elif temp_user.registration_key!=None and \
                            temp_user.registration_key.strip():
                        response.flash = \
                            self.messages.registration_verifying
                        return form
                    # try alternate logins 1st as these have the
                    # current version of the password
                    user = None







|
>



















|







1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
                            )),"",
                       self.settings.formstyle,
                       'auth_user_remember__row')

            captcha = self.settings.login_captcha or \
                (self.settings.login_captcha!=False and self.settings.captcha)
            if captcha:
                addrow(form, captcha.label, captcha, captcha.comment, 
                       self.settings.formstyle,'captcha__row')
            accepted_form = False

            if form.accepts(request, session,
                            formname='login', dbio=False,
                            onvalidation=onvalidation,
                            hideerror=self.settings.hideerror):

                accepted_form = True
                # check for username in db
                user = self.db(table_user[username] == form.vars[username]).select().first()
                if user:
                    # user in db, check if registration pending or disabled
                    temp_user = user
                    if temp_user.registration_key == 'pending':
                        response.flash = self.messages.registration_pending
                        return form
                    elif temp_user.registration_key in ('disabled','blocked'):
                        response.flash = self.messages.login_disabled
                        return form
                    elif not temp_user.registration_key is None and \
                            temp_user.registration_key.strip():
                        response.flash = \
                            self.messages.registration_verifying
                        return form
                    # try alternate logins 1st as these have the
                    # current version of the password
                    user = None
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637

1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663

1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679


1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
                                                 request.vars[passfield]):
                                if not self in self.settings.login_methods:
                                    # do not store password in db
                                    form.vars[passfield] = None
                                user = self.get_or_create_user(form.vars)
                                break
                if not user:
                    if self.settings.login_failed_log:
                        self.log_event(self.settings.login_failed_log % request.post_vars)
                    # invalid login
                    session.flash = self.messages.invalid_login
                    redirect(self.url(args=request.args,vars=request.get_vars))

        else:
            # use a central authentication server
            cas = self.settings.login_form
            cas_user = cas.get_user()

            if cas_user:
                cas_user[passfield] = None
                user = self.get_or_create_user(table_user._filter_fields(cas_user))

            elif hasattr(cas,'login_form'):
                return cas.login_form()
            else:
                # we need to pass through login again before going on
                next = self.url('user',args='login',vars=dict(_next=next))
                redirect(cas.login_url(next))


        # process authenticated users
        if user:
            user = Storage(table_user._filter_fields(user, id=True))

            if log:
                self.log_event(log % user)

        # process authenticated users
            # user wants to be logged in for longer
            session.auth = Storage(
                user = user,
                last_visit = request.now,
                expiration = self.settings.long_expiration,
                remember = request.vars.has_key("remember"),
                hmac_key = web2py_uuid()
                )

            self.user = user

            session.flash = self.messages.logged_in

        # how to continue
        if self.settings.login_form == self:
            if accepted_form:
                callback(onaccept,form)
                if isinstance(next, (list, tuple)):
                    # fix issue with 2.6
                    next = next[0]
                if next and not next[0] == '/' and next[:4] != 'http':
                    next = self.url(next.replace('[id]', str(form.vars.id)))
                redirect(next)
            table_user[username].requires = old_requires
            return form
        elif user:
            callback(onaccept,None)


        redirect(next)

    def logout(self, next=DEFAULT, onlogout=DEFAULT, log=DEFAULT):
        """
        logout and redirects to login

        .. method:: Auth.logout ([next=DEFAULT[, onlogout=DEFAULT[,
            log=DEFAULT]]])

        """

        if next == DEFAULT:
            next = self.settings.logout_next
        if onlogout == DEFAULT:
            onlogout = self.settings.logout_onlogout
        if onlogout:
            onlogout(self.user)
        if log == DEFAULT:
            log = self.messages.logout_log
        if log and self.user:
            self.log_event(log % self.user)

        if self.settings.login_form != self:
            cas = self.settings.login_form
            cas_user = cas.get_user()
            if cas_user:
                next = cas.logout_url(next)

        current.session.auth = None
        current.session.flash = self.messages.logged_out
        if next:
            redirect(next)

    def register(
        self,
        next=DEFAULT,
        onvalidation=DEFAULT,
        onaccept=DEFAULT,
        log=DEFAULT,







|
|











|
>

|


|

<





<
<
<











>






<
<
|
<
<





>
>



















|
|
<








<
|







1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702

1703
1704
1705
1706
1707



1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725


1726


1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754

1755
1756
1757
1758
1759
1760
1761
1762

1763
1764
1765
1766
1767
1768
1769
1770
                                                 request.vars[passfield]):
                                if not self in self.settings.login_methods:
                                    # do not store password in db
                                    form.vars[passfield] = None
                                user = self.get_or_create_user(form.vars)
                                break
                if not user:
                    self.log_event(self.settings.login_failed_log,
                                   request.post_vars)
                    # invalid login
                    session.flash = self.messages.invalid_login
                    redirect(self.url(args=request.args,vars=request.get_vars))

        else:
            # use a central authentication server
            cas = self.settings.login_form
            cas_user = cas.get_user()

            if cas_user:
                cas_user[passfield] = None
                user = self.get_or_create_user(
                    table_user._filter_fields(cas_user))
            elif hasattr(cas,'login_form'):
                return cas.login_form()            
            else:
                # we need to pass through login again before going on
                next = self.url('user',args='login')
                redirect(cas.login_url(next))


        # process authenticated users
        if user:
            user = Storage(table_user._filter_fields(user, id=True))




        # process authenticated users
            # user wants to be logged in for longer
            session.auth = Storage(
                user = user,
                last_visit = request.now,
                expiration = self.settings.long_expiration,
                remember = request.vars.has_key("remember"),
                hmac_key = web2py_uuid()
                )

            self.user = user
            self.log_event(log, user)
            session.flash = self.messages.logged_in

        # how to continue
        if self.settings.login_form == self:
            if accepted_form:
                callback(onaccept,form)


                next = replace_id(next, form)


                redirect(next)
            table_user[username].requires = old_requires
            return form
        elif user:
            callback(onaccept,None)
        if next == session._auth_next:
            del session._auth_next
        redirect(next)

    def logout(self, next=DEFAULT, onlogout=DEFAULT, log=DEFAULT):
        """
        logout and redirects to login

        .. method:: Auth.logout ([next=DEFAULT[, onlogout=DEFAULT[,
            log=DEFAULT]]])

        """

        if next == DEFAULT:
            next = self.settings.logout_next
        if onlogout == DEFAULT:
            onlogout = self.settings.logout_onlogout
        if onlogout:
            onlogout(self.user)
        if log == DEFAULT:
            log = self.messages.logout_log
        if self.user:
            self.log_event(log, self.user)

        if self.settings.login_form != self:
            cas = self.settings.login_form
            cas_user = cas.get_user()
            if cas_user:
                next = cas.logout_url(next)

        current.session.auth = None
        current.session.flash = self.messages.logged_out

        redirect(next)

    def register(
        self,
        next=DEFAULT,
        onvalidation=DEFAULT,
        onaccept=DEFAULT,
        log=DEFAULT,
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755

1756
1757
1758
1759
1760
1761

1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
        table_user = self.settings.table_user
        request = current.request
        response = current.response
        session = current.session
        if self.is_logged_in():
            redirect(self.settings.logged_url)
        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.register_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.register_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.register_onaccept
        if log == DEFAULT:
            log = self.messages.register_log

        passfield = self.settings.password_field
        formstyle = self.settings.formstyle
        form = SQLFORM(table_user,
                       fields = self.settings.register_fields,
                       hidden=dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.register_button,
                       delete_label=self.messages.delete_label,
                       formstyle=formstyle,
                       separator=self.settings.label_separator
                       )

        for i, row in enumerate(form[0].components):
            item = row.element('input',_name=passfield)
            if item:
                form.custom.widget.password_two = \
                    INPUT(_name="password_two",  _type="password",
                          requires=IS_EXPR('value==%s' % \

                          repr(request.vars.get(passfield, None)),
                          error_message=self.messages.mismatched_password))

                addrow(form, self.messages.verify_password + ':',
                       form.custom.widget.password_two,
                       self.messages.verify_password_comment,
                       formstyle,
                       '%s_%s__row' % (table_user, 'password_two'),
                       position=i+1)
                break
        captcha = self.settings.register_captcha or self.settings.captcha
        if captcha:
            addrow(form, captcha.label, captcha, captcha.comment,self.settings.formstyle, 'captcha__row')

        table_user.registration_key.default = key = web2py_uuid()
        if form.accepts(request, session, formname='register',
                        onvalidation=onvalidation,hideerror=self.settings.hideerror):







<
<
|







|
|


|






>
|
|
|
|
|
|
>
|
|

|
|
|
|
|
|
|







1780
1781
1782
1783
1784
1785
1786


1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
        table_user = self.settings.table_user
        request = current.request
        response = current.response
        session = current.session
        if self.is_logged_in():
            redirect(self.settings.logged_url)
        if next == DEFAULT:


            next = self.next or self.settings.register_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.register_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.register_onaccept
        if log == DEFAULT:
            log = self.messages.register_log

        passfield = self.settings.password_field        
        formstyle = self.settings.formstyle        
        form = SQLFORM(table_user,
                       fields = self.settings.register_fields,
                       hidden = dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.register_button,
                       delete_label=self.messages.delete_label,
                       formstyle=formstyle,
                       separator=self.settings.label_separator
                       )
        if self.settings.register_verify_password:
            for i, row in enumerate(form[0].components):
                item = row.element('input',_name=passfield)
                if item:
                    form.custom.widget.password_two = \
                        INPUT(_name="password_two",  _type="password",
                              requires=IS_EXPR(
                            'value==%s' % \
                                repr(request.vars.get(passfield, None)),
                            error_message=self.messages.mismatched_password))

                    addrow(form, self.messages.verify_password + ':',
                           form.custom.widget.password_two,
                           self.messages.verify_password_comment,
                           formstyle,
                           '%s_%s__row' % (table_user, 'password_two'),
                           position=i+1)
                    break
        captcha = self.settings.register_captcha or self.settings.captcha
        if captcha:
            addrow(form, captcha.label, captcha, captcha.comment,self.settings.formstyle, 'captcha__row')

        table_user.registration_key.default = key = web2py_uuid()
        if form.accepts(request, session, formname='register',
                        onvalidation=onvalidation,hideerror=self.settings.hideerror):
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796


1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
                        subject=self.messages.verify_email_subject,
                        message=self.messages.verify_email
                         % dict(key=key)):
                    self.db.rollback()
                    response.flash = self.messages.unable_send_email
                    return form
                session.flash = self.messages.email_sent
            elif self.settings.registration_requires_approval:
                table_user[form.vars.id] = dict(registration_key='pending')
                session.flash = self.messages.registration_pending
            else:


                table_user[form.vars.id] = dict(registration_key='')
                session.flash = self.messages.registration_successful
                table_user = self.settings.table_user
                if 'username' in table_user.fields:
                    username = 'username'
                else:
                    username = 'email'
                user = self.db(table_user[username] == form.vars[username]).select().first()
                user = Storage(table_user._filter_fields(user, id=True))
                session.auth = Storage(user=user, last_visit=request.now,
                                       expiration=self.settings.expiration,
                                       hmac_key = web2py_uuid())
                self.user = user
                session.flash = self.messages.logged_in
            if log:
                self.log_event(log % form.vars)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            elif isinstance(next, (list, tuple)): ### fix issue with 2.6
                next = next[0]
            elif next and not next[0] == '/' and next[:4] != 'http':
                next = self.url(next.replace('[id]', str(form.vars.id)))
            redirect(next)
        return form

    def is_logged_in(self):
        """
        checks if the user is logged in and returns True/False.
        if so user is in auth.user as well as in session.auth.user







|


|
>
>
|













<
|



|
|
<
<







1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864

1865
1866
1867
1868
1869
1870


1871
1872
1873
1874
1875
1876
1877
                        subject=self.messages.verify_email_subject,
                        message=self.messages.verify_email
                         % dict(key=key)):
                    self.db.rollback()
                    response.flash = self.messages.unable_send_email
                    return form
                session.flash = self.messages.email_sent
            if self.settings.registration_requires_approval:
                table_user[form.vars.id] = dict(registration_key='pending')
                session.flash = self.messages.registration_pending
            elif (not self.settings.registration_requires_verification or \
                      self.settings.login_after_registration):
                if not self.settings.registration_requires_verification:
                    table_user[form.vars.id] = dict(registration_key='')
                session.flash = self.messages.registration_successful
                table_user = self.settings.table_user
                if 'username' in table_user.fields:
                    username = 'username'
                else:
                    username = 'email'
                user = self.db(table_user[username] == form.vars[username]).select().first()
                user = Storage(table_user._filter_fields(user, id=True))
                session.auth = Storage(user=user, last_visit=request.now,
                                       expiration=self.settings.expiration,
                                       hmac_key = web2py_uuid())
                self.user = user
                session.flash = self.messages.logged_in

            self.log_event(log, form.vars)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            else:
                next = replace_id(next, form)


            redirect(next)
        return form

    def is_logged_in(self):
        """
        checks if the user is logged in and returns True/False.
        if so user is in auth.user as well as in session.auth.user
1851
1852
1853
1854
1855
1856
1857



1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
            redirect(self.settings.login_url)
        if self.settings.registration_requires_approval:
            user.update_record(registration_key = 'pending')
            current.session.flash = self.messages.registration_pending
        else:
            user.update_record(registration_key = '')
            current.session.flash = self.messages.email_verified



        if log == DEFAULT:
            log = self.messages.verify_email_log
        if next == DEFAULT:
            next = self.settings.verify_email_next
        if onaccept == DEFAULT:
            onaccept = self.settings.verify_email_onaccept
        if log:
            self.log_event(log % user)
        callback(onaccept,user)
        redirect(next)

    def retrieve_username(
        self,
        next=DEFAULT,
        onvalidation=DEFAULT,







>
>
>






<
|







1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917

1918
1919
1920
1921
1922
1923
1924
1925
            redirect(self.settings.login_url)
        if self.settings.registration_requires_approval:
            user.update_record(registration_key = 'pending')
            current.session.flash = self.messages.registration_pending
        else:
            user.update_record(registration_key = '')
            current.session.flash = self.messages.email_verified
        # make sure session has same user.registrato_key as db record
        if current.session.auth and current.session.auth.user:
            current.session.auth.user.registration_key = user.registration_key
        if log == DEFAULT:
            log = self.messages.verify_email_log
        if next == DEFAULT:
            next = self.settings.verify_email_next
        if onaccept == DEFAULT:
            onaccept = self.settings.verify_email_onaccept

        self.log_event(log, user)
        callback(onaccept,user)
        redirect(next)

    def retrieve_username(
        self,
        next=DEFAULT,
        onvalidation=DEFAULT,
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
        session = current.session
        captcha = self.settings.retrieve_username_captcha or \
                (self.settings.retrieve_username_captcha!=False and self.settings.captcha)
        if not self.settings.mailer:
            response.flash = self.messages.function_disabled
            return ''
        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.retrieve_username_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.retrieve_username_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.retrieve_username_onaccept
        if log == DEFAULT:
            log = self.messages.retrieve_username_log
        old_requires = table_user.email.requires
        table_user.email.requires = [IS_IN_DB(self.db, table_user.email,
            error_message=self.messages.invalid_email)]
        form = SQLFORM(table_user,
                       fields=['email'],
                       hidden=dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.submit_button,
                       delete_label=self.messages.delete_label,
                       formstyle=self.settings.formstyle,
                       separator=self.settings.label_separator
                       )
        if captcha:







<
<
|











|







1943
1944
1945
1946
1947
1948
1949


1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
        session = current.session
        captcha = self.settings.retrieve_username_captcha or \
                (self.settings.retrieve_username_captcha!=False and self.settings.captcha)
        if not self.settings.mailer:
            response.flash = self.messages.function_disabled
            return ''
        if next == DEFAULT:


            next = self.next or self.settings.retrieve_username_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.retrieve_username_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.retrieve_username_onaccept
        if log == DEFAULT:
            log = self.messages.retrieve_username_log
        old_requires = table_user.email.requires
        table_user.email.requires = [IS_IN_DB(self.db, table_user.email,
            error_message=self.messages.invalid_email)]
        form = SQLFORM(table_user,
                       fields=['email'],
                       hidden = dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.submit_button,
                       delete_label=self.messages.delete_label,
                       formstyle=self.settings.formstyle,
                       separator=self.settings.label_separator
                       )
        if captcha:
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
                redirect(self.url(args=request.args))
            username = user.username
            self.settings.mailer.send(to=form.vars.email,
                    subject=self.messages.retrieve_username_subject,
                    message=self.messages.retrieve_username
                     % dict(username=username))
            session.flash = self.messages.email_sent
            if log:
                self.log_event(log % user)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            elif isinstance(next, (list, tuple)): ### fix issue with 2.6
                next = next[0]
            elif next and not next[0] == '/' and next[:4] != 'http':
                next = self.url(next.replace('[id]', str(form.vars.id)))
            redirect(next)
        table_user.email.requires = old_requires
        return form

    def random_password(self):
        import string
        import random







<
|



|
|
<
<







1979
1980
1981
1982
1983
1984
1985

1986
1987
1988
1989
1990
1991


1992
1993
1994
1995
1996
1997
1998
                redirect(self.url(args=request.args))
            username = user.username
            self.settings.mailer.send(to=form.vars.email,
                    subject=self.messages.retrieve_username_subject,
                    message=self.messages.retrieve_username
                     % dict(username=username))
            session.flash = self.messages.email_sent

            self.log_event(log, user)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            else:
                next = replace_id(next, form)


            redirect(next)
        table_user.email.requires = old_requires
        return form

    def random_password(self):
        import string
        import random
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
        request = current.request
        response = current.response
        session = current.session
        if not self.settings.mailer:
            response.flash = self.messages.function_disabled
            return ''
        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.retrieve_password_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.retrieve_password_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.retrieve_password_onaccept
        if log == DEFAULT:
            log = self.messages.retrieve_password_log
        old_requires = table_user.email.requires
        table_user.email.requires = [IS_IN_DB(self.db, table_user.email,
            error_message=self.messages.invalid_email)]
        form = SQLFORM(table_user,
                       fields=['email'],
                       hidden=dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.submit_button,
                       delete_label=self.messages.delete_label,
                       formstyle=self.settings.formstyle,
                       separator=self.settings.label_separator
                       )
        if form.accepts(request, session,







<
<
|











|







2024
2025
2026
2027
2028
2029
2030


2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
        request = current.request
        response = current.response
        session = current.session
        if not self.settings.mailer:
            response.flash = self.messages.function_disabled
            return ''
        if next == DEFAULT:


            next = self.next or self.settings.retrieve_password_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.retrieve_password_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.retrieve_password_onaccept
        if log == DEFAULT:
            log = self.messages.retrieve_password_log
        old_requires = table_user.email.requires
        table_user.email.requires = [IS_IN_DB(self.db, table_user.email,
            error_message=self.messages.invalid_email)]
        form = SQLFORM(table_user,
                       fields=['email'],
                       hidden = dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.submit_button,
                       delete_label=self.messages.delete_label,
                       formstyle=self.settings.formstyle,
                       separator=self.settings.label_separator
                       )
        if form.accepts(request, session,
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
               self.settings.mailer.send(to=form.vars.email,
                        subject=self.messages.retrieve_password_subject,
                        message=self.messages.retrieve_password \
                        % dict(password=password)):
                session.flash = self.messages.email_sent
            else:
                session.flash = self.messages.unable_to_send_email
            if log:
                self.log_event(log % user)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            elif isinstance(next, (list, tuple)): ### fix issue with 2.6
                next = next[0]
            elif next and not next[0] == '/' and next[:4] != 'http':
                next = self.url(next.replace('[id]', str(form.vars.id)))
            redirect(next)
        table_user.email.requires = old_requires
        return form

    def reset_password(
        self,
        next=DEFAULT,







<
|



|
|
<
<







2068
2069
2070
2071
2072
2073
2074

2075
2076
2077
2078
2079
2080


2081
2082
2083
2084
2085
2086
2087
               self.settings.mailer.send(to=form.vars.email,
                        subject=self.messages.retrieve_password_subject,
                        message=self.messages.retrieve_password \
                        % dict(password=password)):
                session.flash = self.messages.email_sent
            else:
                session.flash = self.messages.unable_to_send_email

            self.log_event(log, user)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            else:
                next = replace_id(next, form)


            redirect(next)
        table_user.email.requires = old_requires
        return form

    def reset_password(
        self,
        next=DEFAULT,
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085

2086
2087
2088
2089
2090
2091
2092

        table_user = self.settings.table_user
        request = current.request
        # response = current.response
        session = current.session

        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.reset_password_next

        try:
            key = request.vars.key or request.args[-1]
            t0 = int(key.split('-')[0])
            if time.time()-t0 > 60*60*24: raise Exception
            user = self.db(table_user.reset_password_key == key).select().first()
            if not user: raise Exception
        except Exception:
            session.flash = self.messages.invalid_reset_password
            redirect(next)
        passfield = self.settings.password_field
        form = SQLFORM.factory(
            Field('new_password', 'password',
                  label=self.messages.new_password,
                  requires=self.settings.table_user[passfield].requires),
            Field('new_password2', 'password',
                  label=self.messages.verify_password,
                  requires=[IS_EXPR('value==%s' % repr(request.vars.new_password),
                                    self.messages.mismatched_password)]),
            submit_button=self.messages.password_reset_button,

            formstyle=self.settings.formstyle,
            separator=self.settings.label_separator
        )
        if form.accepts(request,session,hideerror=self.settings.hideerror):
            user.update_record(**{passfield:form.vars.new_password,
                                  'registration_key':'',
                                  'reset_password_key':''})







<
<
|
<



















>







2099
2100
2101
2102
2103
2104
2105


2106

2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133

        table_user = self.settings.table_user
        request = current.request
        # response = current.response
        session = current.session

        if next == DEFAULT:


            next = self.next or self.settings.reset_password_next

        try:
            key = request.vars.key or request.args[-1]
            t0 = int(key.split('-')[0])
            if time.time()-t0 > 60*60*24: raise Exception
            user = self.db(table_user.reset_password_key == key).select().first()
            if not user: raise Exception
        except Exception:
            session.flash = self.messages.invalid_reset_password
            redirect(next)
        passfield = self.settings.password_field
        form = SQLFORM.factory(
            Field('new_password', 'password',
                  label=self.messages.new_password,
                  requires=self.settings.table_user[passfield].requires),
            Field('new_password2', 'password',
                  label=self.messages.verify_password,
                  requires=[IS_EXPR('value==%s' % repr(request.vars.new_password),
                                    self.messages.mismatched_password)]),
            submit_button=self.messages.password_reset_button,
            hidden = dict(_next=next),
            formstyle=self.settings.formstyle,
            separator=self.settings.label_separator
        )
        if form.accepts(request,session,hideerror=self.settings.hideerror):
            user.update_record(**{passfield:form.vars.new_password,
                                  'registration_key':'',
                                  'reset_password_key':''})
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
        request = current.request
        response = current.response
        session = current.session
        captcha = self.settings.retrieve_password_captcha or \
                (self.settings.retrieve_password_captcha!=False and self.settings.captcha)

        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.request_reset_password_next

        if not self.settings.mailer:
            response.flash = self.messages.function_disabled
            return ''
        if onvalidation == DEFAULT:
            onvalidation = self.settings.reset_password_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.reset_password_onaccept
        if log == DEFAULT:
            log = self.messages.reset_password_log
        # old_requires = table_user.email.requires <<< perhaps should be restored
        table_user.email.requires = [
            IS_EMAIL(error_message=self.messages.invalid_email),
            IS_IN_DB(self.db, table_user.email,
                     error_message=self.messages.invalid_email)]
        form = SQLFORM(table_user,
                       fields=['email'],
                       hidden=dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.password_reset_button,
                       delete_label=self.messages.delete_label,
                       formstyle=self.settings.formstyle,
                       separator=self.settings.label_separator
                       )
        if captcha:







<
<
|
<









<






|







2154
2155
2156
2157
2158
2159
2160


2161

2162
2163
2164
2165
2166
2167
2168
2169
2170

2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
        request = current.request
        response = current.response
        session = current.session
        captcha = self.settings.retrieve_password_captcha or \
                (self.settings.retrieve_password_captcha!=False and self.settings.captcha)

        if next == DEFAULT:


            next = self.next or self.settings.request_reset_password_next

        if not self.settings.mailer:
            response.flash = self.messages.function_disabled
            return ''
        if onvalidation == DEFAULT:
            onvalidation = self.settings.reset_password_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.reset_password_onaccept
        if log == DEFAULT:
            log = self.messages.reset_password_log

        table_user.email.requires = [
            IS_EMAIL(error_message=self.messages.invalid_email),
            IS_IN_DB(self.db, table_user.email,
                     error_message=self.messages.invalid_email)]
        form = SQLFORM(table_user,
                       fields=['email'],
                       hidden = dict(_next=next),
                       showid=self.settings.showid,
                       submit_button=self.messages.password_reset_button,
                       delete_label=self.messages.delete_label,
                       formstyle=self.settings.formstyle,
                       separator=self.settings.label_separator
                       )
        if captcha:
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
                                         subject=self.messages.reset_password_subject,
                                         message=self.messages.reset_password % \
                                             dict(key=reset_password_key)):
                session.flash = self.messages.email_sent
                user.update_record(reset_password_key=reset_password_key)
            else:
                session.flash = self.messages.unable_to_send_email
            if log:
                self.log_event(log % user)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            elif isinstance(next, (list, tuple)): ### fix issue with 2.6
                next = next[0]
            elif next and not next[0] == '/' and next[:4] != 'http':
                next = self.url(next.replace('[id]', str(form.vars.id)))
            redirect(next)
        # old_requires = table_user.email.requires
        return form

    def retrieve_password(
        self,
        next=DEFAULT,







<
|



|
|
<
<







2200
2201
2202
2203
2204
2205
2206

2207
2208
2209
2210
2211
2212


2213
2214
2215
2216
2217
2218
2219
                                         subject=self.messages.reset_password_subject,
                                         message=self.messages.reset_password % \
                                             dict(key=reset_password_key)):
                session.flash = self.messages.email_sent
                user.update_record(reset_password_key=reset_password_key)
            else:
                session.flash = self.messages.unable_to_send_email

            self.log_event(log, user)
            callback(onaccept,form)
            if not next:
                next = self.url(args = request.args)
            else:
                next = replace_id(next, form)


            redirect(next)
        # old_requires = table_user.email.requires
        return form

    def retrieve_password(
        self,
        next=DEFAULT,
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
        table_user = self.settings.table_user
        usern = self.settings.table_user_name
        s = db(table_user.id == self.user.id)

        request = current.request
        session = current.session
        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.change_password_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.change_password_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.change_password_onaccept
        if log == DEFAULT:
            log = self.messages.change_password_log
        passfield = self.settings.password_field







<
<
|







2246
2247
2248
2249
2250
2251
2252


2253
2254
2255
2256
2257
2258
2259
2260
        table_user = self.settings.table_user
        usern = self.settings.table_user_name
        s = db(table_user.id == self.user.id)

        request = current.request
        session = current.session
        if next == DEFAULT:


            next = self.next or self.settings.change_password_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.change_password_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.change_password_onaccept
        if log == DEFAULT:
            log = self.messages.change_password_log
        passfield = self.settings.password_field
2237
2238
2239
2240
2241
2242
2243

2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
                label=self.messages.new_password,
                requires=table_user[passfield].requires),
            Field('new_password2', 'password',
                label=self.messages.verify_password,
                requires=[IS_EXPR('value==%s' % repr(request.vars.new_password),
                              self.messages.mismatched_password)]),
            submit_button=self.messages.password_change_button,

            formstyle = self.settings.formstyle,
            separator=self.settings.label_separator
        )
        if form.accepts(request, session,
                        formname='change_password',
                        onvalidation=onvalidation,
                        hideerror=self.settings.hideerror):
            d = {passfield: form.vars.new_password}
            s.update(**d)
            session.flash = self.messages.password_changed
            if log:
                self.log_event(log % self.user)
            callback(onaccept,form)
            if not next:
                next = self.url(args=request.args)
            elif isinstance(next, (list, tuple)): ### fix issue with 2.6
                next = next[0]
            elif next and not next[0] == '/' and next[:4] != 'http':
                next = self.url(next.replace('[id]', str(form.vars.id)))
            redirect(next)
        return form

    def profile(
        self,
        next=DEFAULT,
        onvalidation=DEFAULT,







>










<
|



|
|
<
<







2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286

2287
2288
2289
2290
2291
2292


2293
2294
2295
2296
2297
2298
2299
                label=self.messages.new_password,
                requires=table_user[passfield].requires),
            Field('new_password2', 'password',
                label=self.messages.verify_password,
                requires=[IS_EXPR('value==%s' % repr(request.vars.new_password),
                              self.messages.mismatched_password)]),
            submit_button=self.messages.password_change_button,
            hidden = dict(_next=next),
            formstyle = self.settings.formstyle,
            separator=self.settings.label_separator
        )
        if form.accepts(request, session,
                        formname='change_password',
                        onvalidation=onvalidation,
                        hideerror=self.settings.hideerror):
            d = {passfield: form.vars.new_password}
            s.update(**d)
            session.flash = self.messages.password_changed

            self.log_event(log, self.user)
            callback(onaccept,form)
            if not next:
                next = self.url(args=request.args)
            else:
                next = replace_id(next, form)


            redirect(next)
        return form

    def profile(
        self,
        next=DEFAULT,
        onvalidation=DEFAULT,
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
        if not self.is_logged_in():
            redirect(self.settings.login_url)
        passfield = self.settings.password_field
        self.settings.table_user[passfield].writable = False
        request = current.request
        session = current.session
        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.profile_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.profile_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.profile_onaccept
        if log == DEFAULT:
            log = self.messages.profile_log
        form = SQLFORM(
            table_user,
            self.user.id,
            fields = self.settings.profile_fields,
            hidden = dict(_next=next),
            showid = self.settings.showid,
            submit_button = self.messages.profile_save_button,
            delete_label = self.messages.delete_label,
            upload = self.settings.download_url,
            formstyle = self.settings.formstyle,
            separator=self.settings.label_separator
            )
        if form.accepts(request, session,
                        formname='profile',
                        onvalidation=onvalidation,hideerror=self.settings.hideerror):
            self.user.update(table_user._filter_fields(form.vars))
            session.flash = self.messages.profile_updated
            if log:
                self.log_event(log % self.user)
            callback(onaccept,form)
            if not next:
                next = self.url(args=request.args)
            elif isinstance(next, (list, tuple)): ### fix issue with 2.6
                next = next[0]
            elif next and not next[0] == '/' and next[:4] != 'http':
                next = self.url(next.replace('[id]', str(form.vars.id)))
            redirect(next)
        return form

    def is_impersonating(self):
        return current.session.auth.impersonator

    def impersonate(self, user_id=DEFAULT):







<
<
|




















|


<
|



|
|
<
<







2312
2313
2314
2315
2316
2317
2318


2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342

2343
2344
2345
2346
2347
2348


2349
2350
2351
2352
2353
2354
2355
        if not self.is_logged_in():
            redirect(self.settings.login_url)
        passfield = self.settings.password_field
        self.settings.table_user[passfield].writable = False
        request = current.request
        session = current.session
        if next == DEFAULT:


            next = self.next or self.settings.profile_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.profile_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.profile_onaccept
        if log == DEFAULT:
            log = self.messages.profile_log
        form = SQLFORM(
            table_user,
            self.user.id,
            fields = self.settings.profile_fields,
            hidden = dict(_next=next),
            showid = self.settings.showid,
            submit_button = self.messages.profile_save_button,
            delete_label = self.messages.delete_label,
            upload = self.settings.download_url,
            formstyle = self.settings.formstyle,
            separator=self.settings.label_separator
            )
        if form.accepts(request, session,
                        formname='profile',
                        onvalidation=onvalidation, hideerror=self.settings.hideerror):
            self.user.update(table_user._filter_fields(form.vars))
            session.flash = self.messages.profile_updated

            self.log_event(log,self.user)
            callback(onaccept,form)
            if not next:
                next = self.url(args=request.args)
            else:
                next = replace_id(next, form)


            redirect(next)
        return form

    def is_impersonating(self):
        return current.session.auth.impersonator

    def impersonate(self, user_id=DEFAULT):
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
            auth.user.update(
                self.settings.table_user._filter_fields(user, True))
            self.user = auth.user
            if self.settings.login_onaccept:
                form = Storage(dict(vars=self.user))
                self.settings.login_onaccept(form)
            log = self.messages.impersonate_log
            if log:
                self.log_event(log % dict(id=current_id,other_id=auth.user.id))
        elif user_id in (0, '0') and self.is_impersonating():
            session.clear()
            session.update(cPickle.loads(auth.impersonator))
            self.user = session.auth.user
        if requested_id == DEFAULT and not request.post_vars:
            return SQLFORM.factory(Field('user_id','integer'))
        return self.user

    def groups(self):
        """
        displays the groups and their roles for the logged in user
        """








<
|





|







2381
2382
2383
2384
2385
2386
2387

2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
            auth.user.update(
                self.settings.table_user._filter_fields(user, True))
            self.user = auth.user
            if self.settings.login_onaccept:
                form = Storage(dict(vars=self.user))
                self.settings.login_onaccept(form)
            log = self.messages.impersonate_log

            self.log_event(log,dict(id=current_id, other_id=auth.user.id))
        elif user_id in (0, '0') and self.is_impersonating():
            session.clear()
            session.update(cPickle.loads(auth.impersonator))
            self.user = session.auth.user
        if requested_id == DEFAULT and not request.post_vars:
            return SQLFORM.factory(Field('user_id', 'integer'))
        return self.user

    def groups(self):
        """
        displays the groups and their roles for the logged in user
        """

2391
2392
2393
2394
2395
2396
2397
2398

2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417

2418
2419
2420
2421
2422
2423
2424
2425
2426

2427
2428

2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
            return None
        return table

    def not_authorized(self):
        """
        you can change the view for this page to make it look as you like
        """


        return 'ACCESS DENIED'

    def requires(self, condition):
        """
        decorator that prevents access to action if not logged in
        """

        def decorator(action):

            def f(*a, **b):

                if self.settings.allow_basic_login_only and not self.basic():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    return call_or_redirect(self.settings.on_failed_authorization)

                if not condition:
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")

                    if not self.basic() and not self.is_logged_in():
                        request = current.request
                        next = URL(r=request,args=request.args,
                                   vars=request.get_vars)
                        current.session.flash = current.response.flash
                        return call_or_redirect(
                            self.settings.on_failed_authentication,
                            self.settings.login_url + '?_next='+urllib.quote(next))
                    else:

                        current.session.flash = self.messages.access_denied
                        return call_or_redirect(self.settings.on_failed_authorization)

                return action(*a, **b)
            f.__doc__ = action.__doc__
            f.__name__ = action.__name__
            f.__dict__.update(action.__dict__)
            return f

        return decorator

    def requires_login(self):
        """
        decorator that prevents access to action if not logged in
        """

        def decorator(action):

            def f(*a, **b):

                if self.settings.allow_basic_login_only and not self.basic():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    return call_or_redirect(self.settings.on_failed_authorization)

                if not self.basic() and not self.is_logged_in():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    request = current.request
                    next = URL(r=request,args=request.args,
                               vars=request.get_vars)
                    current.session.flash = current.response.flash
                    return call_or_redirect(
                        self.settings.on_failed_authentication,
                        self.settings.login_url + '?_next='+urllib.quote(next)
                        )
                return action(*a, **b)
            f.__doc__ = action.__doc__
            f.__name__ = action.__name__
            f.__dict__.update(action.__dict__)
            return f

        return decorator

    def requires_membership(self, role=None, group_id=None):
        """
        decorator that prevents access to action if not logged in or
        if user logged in is not a member of group_id.
        If role is provided instead of group_id then the
        group_id is calculated.
        """

        def decorator(action):
            def f(*a, **b):
                if self.settings.allow_basic_login_only and not self.basic():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    return call_or_redirect(self.settings.on_failed_authorization)

                if not self.basic() and not self.is_logged_in():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    request = current.request
                    next = URL(r=request,args=request.args,
                               vars=request.get_vars)
                    current.session.flash = current.response.flash
                    return call_or_redirect(
                        self.settings.on_failed_authentication,
                        self.settings.login_url + '?_next='+urllib.quote(next)
                        )
                if not self.has_membership(group_id=group_id, role=role):
                    current.session.flash = self.messages.access_denied
                    return call_or_redirect(self.settings.on_failed_authorization)
                return action(*a, **b)
            f.__doc__ = action.__doc__
            f.__name__ = action.__name__
            f.__dict__.update(action.__dict__)
            return f

        return decorator


    def requires_permission(
        self,
        name,
        table_name='',
        record_id=0,
        ):
        """
        decorator that prevents access to action if not logged in or
        if user logged in is not a member of any group (role) that
        has 'name' access to 'table_name', 'record_id'.
        """

        def decorator(action):

            def f(*a, **b):
                if self.settings.allow_basic_login_only and not self.basic():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    return call_or_redirect(self.settings.on_failed_authorization)

                if not self.basic() and not self.is_logged_in():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    request = current.request
                    next = URL(r=request,args=request.args,
                               vars=request.get_vars)
                    current.session.flash = current.response.flash
                    return call_or_redirect(
                        self.settings.on_failed_authentication,
                        self.settings.login_url + '?_next='+urllib.quote(next)
                        )
                if not self.has_permission(name, table_name, record_id):
                    current.session.flash = self.messages.access_denied
                    return call_or_redirect(self.settings.on_failed_authorization)
                return action(*a, **b)
            f.__doc__ = action.__doc__
            f.__name__ = action.__name__
            f.__dict__.update(action.__dict__)
            return f

        return decorator

    def requires_signature(self):
        """
        decorator that prevents access to action if not logged in or
        if user logged in is not a member of group_id.
        If role is provided instead of group_id then the
        group_id is calculated.
        """

        def decorator(action):
            def f(*a, **b):
                if self.settings.allow_basic_login_only and not self.basic():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    return call_or_redirect(self.settings.on_failed_authorization)

                if not self.basic() and not self.is_logged_in():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    request = current.request
                    next = URL(r=request,args=request.args,
                               vars=request.get_vars)
                    current.session.flash = current.response.flash
                    return call_or_redirect(
                        self.settings.on_failed_authentication,
                        self.settings.login_url + '?_next='+urllib.quote(next)
                        )
                if not URL.verify(current.request,user_signature=True):
                    current.session.flash = self.messages.access_denied
                    return call_or_redirect(self.settings.on_failed_authorization)
                return action(*a, **b)
            f.__doc__ = action.__doc__
            f.__name__ = action.__name__
            f.__dict__.update(action.__dict__)
            return f

        return decorator

    def add_group(self, role, description=''):
        """
        creates a group associated to a role
        """

        group_id = self.settings.table_group.insert(role=role,
                description=description)
        log = self.messages.add_group_log
        if log:
            self.log_event(log % dict(group_id=group_id, role=role))
        return group_id

    def del_group(self, group_id):
        """
        deletes a group
        """

        self.db(self.settings.table_group.id == group_id).delete()
        self.db(self.settings.table_membership.group_id
                 == group_id).delete()
        self.db(self.settings.table_permission.group_id
                 == group_id).delete()
        log = self.messages.del_group_log
        if log:
            self.log_event(log % dict(group_id=group_id))

    def id_group(self, role):
        """
        returns the group_id of the group specified by the role
        """
        rows = self.db(self.settings.table_group.role == role).select()
        if not rows:







|
>














|
|
|


>
|
|
|
<
|
|
|
|
|
>
|
|
>












<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|

<
<







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<

<
<
<
|
<
<
<
<
<





<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<






|
|
|
<
|








|
<
|
<
|
<
<







2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446

2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467

























2468
2469


2470
2471
2472
2473
2474
2475
2476



















2477







2478



2479





2480
2481
2482
2483
2484




















2485









2486
2487
2488
2489
2490
2491
2492
2493



















2494









2495
2496
2497
2498
2499
2500
2501
2502
2503

2504
2505
2506
2507
2508
2509
2510
2511
2512
2513

2514

2515


2516
2517
2518
2519
2520
2521
2522
            return None
        return table

    def not_authorized(self):
        """
        you can change the view for this page to make it look as you like
        """
        if current.request.ajax:
            raise HTTP(403,'ACCESS DENIED')
        return 'ACCESS DENIED'

    def requires(self, condition):
        """
        decorator that prevents access to action if not logged in
        """

        def decorator(action):

            def f(*a, **b):

                if self.settings.allow_basic_login_only and not self.basic():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    return call_or_redirect(
                        self.settings.on_failed_authorization)
                if not self.basic() and not self.is_logged_in():
                    if current.request.is_restful:
                        raise HTTP(403,"Not authorized")
                    elif current.request.ajax:
                        return A('login',_href=self.settings.login_url)
                    request = current.request
                    next = self.here()

                    current.session.flash = current.response.flash
                    return call_or_redirect(
                        self.settings.on_failed_authentication,
                        self.settings.login_url+\
                            '?_next='+urllib.quote(next))
                if not condition:
                    current.session.flash = self.messages.access_denied
                    return call_or_redirect(
                        self.settings.on_failed_authorization)
                return action(*a, **b)
            f.__doc__ = action.__doc__
            f.__name__ = action.__name__
            f.__dict__.update(action.__dict__)
            return f

        return decorator

    def requires_login(self):
        """
        decorator that prevents access to action if not logged in
        """

























        return self.requires(self.is_logged_in())



    def requires_membership(self, role=None, group_id=None):
        """
        decorator that prevents access to action if not logged in or
        if user logged in is not a member of group_id.
        If role is provided instead of group_id then the
        group_id is calculated.
        """



















        return self.requires(self.has_membership(group_id=group_id, role=role))











    def requires_permission(self, name, table_name='', record_id=0):





        """
        decorator that prevents access to action if not logged in or
        if user logged in is not a member of any group (role) that
        has 'name' access to 'table_name', 'record_id'.
        """




















        return self.requires(self.has_permission(name, table_name, record_id))










    def requires_signature(self):
        """
        decorator that prevents access to action if not logged in or
        if user logged in is not a member of group_id.
        If role is provided instead of group_id then the
        group_id is calculated.
        """



















        return self.requires(URL.verify(current.request,user_signature=True))










    def add_group(self, role, description=''):
        """
        creates a group associated to a role
        """

        group_id = self.settings.table_group.insert(
            role=role, description=description)
        self.log_event(self.messages.add_group_log,

                       dict(group_id=group_id, role=role))
        return group_id

    def del_group(self, group_id):
        """
        deletes a group
        """

        self.db(self.settings.table_group.id == group_id).delete()
        self.db(self.settings.table_membership.group_id == group_id).delete()

        self.db(self.settings.table_permission.group_id == group_id).delete()

        self.log_event(self.messages.del_group_log,dict(group_id=group_id))



    def id_group(self, role):
        """
        returns the group_id of the group specified by the role
        """
        rows = self.db(self.settings.table_group.role == role).select()
        if not rows:
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
            user_id = self.user.id
        membership = self.settings.table_membership
        if self.db((membership.user_id == user_id)
                    & (membership.group_id == group_id)).select():
            r = True
        else:
            r = False
        log = self.messages.has_membership_log
        if log:
            self.log_event(log % dict(user_id=user_id,
                                      group_id=group_id, check=r))
        return r

    def add_membership(self, group_id=None, user_id=None, role=None):
        """
        gives user_id membership of group_id or role
        if user_id==None than user_id is that of current logged in user
        """

        group_id = group_id or self.id_group(role)
        try:
            group_id = int(group_id)
        except:
            group_id = self.id_group(group_id) # interpret group_id as a role
        if not user_id and self.user:
            user_id = self.user.id
        membership = self.settings.table_membership
        record = membership(user_id = user_id,group_id = group_id)
        if record:
            return record.id
        else:
            id = membership.insert(group_id=group_id, user_id=user_id)
        log = self.messages.add_membership_log
        if log:
            self.log_event(log % dict(user_id=user_id,
                                      group_id=group_id))
        return id

    def del_membership(self, group_id, user_id=None, role=None):
        """
        revokes membership from group_id to user_id
        if user_id==None than user_id is that of current logged in user
        """

        group_id = group_id or self.id_group(role)
        if not user_id and self.user:
            user_id = self.user.id
        membership = self.settings.table_membership
        log = self.messages.del_membership_log
        if log:
            self.log_event(log % dict(user_id=user_id,
                                      group_id=group_id))
        return self.db(membership.user_id
                       == user_id)(membership.group_id
                                   == group_id).delete()

    def has_permission(
        self,
        name='any',







|
<
<
|





|















|
<
<
|





|






|
<
<
|







2547
2548
2549
2550
2551
2552
2553
2554


2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577


2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591


2592
2593
2594
2595
2596
2597
2598
2599
            user_id = self.user.id
        membership = self.settings.table_membership
        if self.db((membership.user_id == user_id)
                    & (membership.group_id == group_id)).select():
            r = True
        else:
            r = False
        self.log_event(self.messages.has_membership_log,


                       dict(user_id=user_id,group_id=group_id, check=r))
        return r

    def add_membership(self, group_id=None, user_id=None, role=None):
        """
        gives user_id membership of group_id or role
        if user is None than user_id is that of current logged in user
        """

        group_id = group_id or self.id_group(role)
        try:
            group_id = int(group_id)
        except:
            group_id = self.id_group(group_id) # interpret group_id as a role
        if not user_id and self.user:
            user_id = self.user.id
        membership = self.settings.table_membership
        record = membership(user_id = user_id,group_id = group_id)
        if record:
            return record.id
        else:
            id = membership.insert(group_id=group_id, user_id=user_id)
        self.log_event(self.messages.add_membership_log,


                       dict(user_id=user_id, group_id=group_id))
        return id

    def del_membership(self, group_id, user_id=None, role=None):
        """
        revokes membership from group_id to user_id
        if user_id is None than user_id is that of current logged in user
        """

        group_id = group_id or self.id_group(role)
        if not user_id and self.user:
            user_id = self.user.id
        membership = self.settings.table_membership
        self.log_event(self.messages.del_membership_log,


                       dict(user_id=user_id,group_id=group_id))
        return self.db(membership.user_id
                       == user_id)(membership.group_id
                                   == group_id).delete()

    def has_permission(
        self,
        name='any',
2733
2734
2735
2736
2737
2738
2739

2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814




2815































































2816
2817
2818
2819
2820
2821
2822


2823
2824
2825
2826
2827
2828
2829
2830
                     == 0).select(permission.group_id)
            groups_required = groups_required.union(set([row.group_id
                    for row in rows]))
        if groups.intersection(groups_required):
            r = True
        else:
            r = False

        log = self.messages.has_permission_log
        if log and user_id:
            self.log_event(log % dict(user_id=user_id, name=name,
                           table_name=table_name, record_id=record_id))
        return r

    def add_permission(
        self,
        group_id,
        name='any',
        table_name='',
        record_id=0,
        ):
        """
        gives group_id 'name' access to 'table_name' and 'record_id'
        """

        permission = self.settings.table_permission
        if group_id == 0:
            group_id = self.user_group()
        id = permission.insert(group_id=group_id, name=name,
                               table_name=str(table_name),
                               record_id=long(record_id))
        log = self.messages.add_permission_log
        if log:
            self.log_event(log % dict(permission_id=id, group_id=group_id,
                           name=name, table_name=table_name,
                           record_id=record_id))
        return id

    def del_permission(
        self,
        group_id,
        name='any',
        table_name='',
        record_id=0,
        ):
        """
        revokes group_id 'name' access to 'table_name' and 'record_id'
        """

        permission = self.settings.table_permission
        log = self.messages.del_permission_log
        if log:
            self.log_event(log % dict(group_id=group_id, name=name,
                           table_name=table_name, record_id=record_id))
        return self.db(permission.group_id == group_id)(permission.name
                 == name)(permission.table_name
                           == str(table_name))(permission.record_id
                 == long(record_id)).delete()

    def accessible_query(self, name, table, user_id=None):
        """
        returns a query with all accessible records for user_id or
        the current logged in user
        this method does not work on GAE because uses JOIN and IN

        example::

           db(auth.accessible_query('read', db.mytable)).select(db.mytable.ALL)

        """
        if not user_id:
            user_id = self.user.id
        if self.has_permission(name, table, 0, user_id):
            return table.id > 0
        db = self.db
        membership = self.settings.table_membership
        permission = self.settings.table_permission
        return table.id.belongs(db(membership.user_id == user_id)\
                           (membership.group_id == permission.group_id)\
                           (permission.name == name)\
                           (permission.table_name == table)\
                           ._select(permission.record_id))





































































class Crud(object):

    def url(self, f=None, args=[], vars={}):
        """
        this should point to the controller that exposes
        download and crud
        """


        return URL(c=self.settings.controller,f=f,args=args,vars=vars)

    def __init__(self, environment, db=None, controller='default'):
        self.db = db
        if not db and environment and isinstance(environment,DAL):
            self.db = environment
        elif not db:
            raise SyntaxError, "must pass db as first or second argument"







>
|
<
|
|



















|
<
|
|
|














|
<
|
|

















|











>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|




>
>
|







2631
2632
2633
2634
2635
2636
2637
2638
2639

2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661

2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679

2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
                     == 0).select(permission.group_id)
            groups_required = groups_required.union(set([row.group_id
                    for row in rows]))
        if groups.intersection(groups_required):
            r = True
        else:
            r = False
        if user_id:
            self.log_event(self.messages.has_permission_log,

                           dict(user_id=user_id, name=name,
                                table_name=table_name, record_id=record_id))
        return r

    def add_permission(
        self,
        group_id,
        name='any',
        table_name='',
        record_id=0,
        ):
        """
        gives group_id 'name' access to 'table_name' and 'record_id'
        """

        permission = self.settings.table_permission
        if group_id == 0:
            group_id = self.user_group()
        id = permission.insert(group_id=group_id, name=name,
                               table_name=str(table_name),
                               record_id=long(record_id))
        self.log_event(self.messages.add_permission_log,

                       dict(permission_id=id, group_id=group_id,
                            name=name, table_name=table_name,
                            record_id=record_id))
        return id

    def del_permission(
        self,
        group_id,
        name='any',
        table_name='',
        record_id=0,
        ):
        """
        revokes group_id 'name' access to 'table_name' and 'record_id'
        """

        permission = self.settings.table_permission
        self.log_event(self.messages.del_permission_log,

                       dict(group_id=group_id, name=name,
                            table_name=table_name, record_id=record_id))
        return self.db(permission.group_id == group_id)(permission.name
                 == name)(permission.table_name
                           == str(table_name))(permission.record_id
                 == long(record_id)).delete()

    def accessible_query(self, name, table, user_id=None):
        """
        returns a query with all accessible records for user_id or
        the current logged in user
        this method does not work on GAE because uses JOIN and IN

        example::

           db(auth.accessible_query('read', db.mytable)).select(db.mytable.ALL)

        """
        if not user_id:
            user_id = self.user_id
        if self.has_permission(name, table, 0, user_id):
            return table.id > 0
        db = self.db
        membership = self.settings.table_membership
        permission = self.settings.table_permission
        return table.id.belongs(db(membership.user_id == user_id)\
                           (membership.group_id == permission.group_id)\
                           (permission.name == name)\
                           (permission.table_name == table)\
                           ._select(permission.record_id))

    @staticmethod
    def archive(form,archive_table=None,current_record='current_record'):
        """
        If you have a table (db.mytable) that needs full revision history you can just do::

            form=crud.update(db.mytable,myrecord,onaccept=auth.archive)
            
        or

            form=SQLFORM(db.mytable,myrecord).process(onaccept=auth.archive)

        crud.archive will define a new table "mytable_archive" and store the
        previous record in the newly created table including a reference
        to the current record.

        If you want to access such table you need to define it yourself in a model::

            db.define_table('mytable_archive',
                Field('current_record',db.mytable),
                db.mytable)

        Notice such table includes all fields of db.mytable plus one: current_record.
        crud.archive does not timestamp the stored record unless your original table
        has a fields like::

            db.define_table(...,
                Field('saved_on','datetime',
                     default=request.now,update=request.now,writable=False),
                Field('saved_by',auth.user,
                     default=auth.user_id,update=auth.user_id,writable=False),

        there is nothing special about these fields since they are filled before
        the record is archived.

        If you want to change the archive table name and the name of the reference field
        you can do, for example::

            db.define_table('myhistory',
                Field('parent_record',db.mytable),
                db.mytable)

        and use it as::

            form=crud.update(db.mytable,myrecord,
                             onaccept=lambda form:crud.archive(form,
                             archive_table=db.myhistory,
                             current_record='parent_record'))

        """
        old_record = form.record
        if not old_record:
            return None
        table = form.table
        if not archive_table:
            archive_table_name = '%s_archive' % table
            if archive_table_name in table._db:
                archive_table = table._db[archive_table_name]
            else:
                archive_table = table._db.define_table(archive_table_name,
                                                       Field(current_record,table),
                                                       table)
        new_record = {current_record:old_record.id}
        for fieldname in archive_table.fields:
            if not fieldname in ['id',current_record] and fieldname in old_record:
                new_record[fieldname]=old_record[fieldname]
        id = archive_table.insert(**new_record)
        return id

class Crud(object):

    def url(self, f=None, args=None, vars=None):
        """
        this should point to the controller that exposes
        download and crud
        """
        if args is None: args=[]
        if vars is None: vars={}
        return URL(c=self.settings.controller, f=f, args=args, vars=vars)

    def __init__(self, environment, db=None, controller='default'):
        self.db = db
        if not db and environment and isinstance(environment,DAL):
            self.db = environment
        elif not db:
            raise SyntaxError, "must pass db as first or second argument"
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
        elif args[0] == 'update':
            return self.update(table, args(2))
        elif args[0] == 'delete':
            return self.delete(table, args(2))
        else:
            raise HTTP(404)

    def log_event(self, message):
        if self.settings.logger:
            self.settings.logger.log_event(message, 'crud')

    def has_permission(self, name, table, record=0):
        if not self.settings.auth:
            return True
        try:
            record_id = record.id
        except:
            record_id = record
        return self.settings.auth.has_permission(name, str(table), record_id)

    def tables(self):
        return TABLE(*[TR(A(name,
                            _href=self.url(args=('select',name)))) \
                           for name in self.db.tables])


    @staticmethod
    def archive(form,archive_table=None,current_record='current_record'):
        """
        If you have a table (db.mytable) that needs full revision history you can just do::

            form=crud.update(db.mytable,myrecord,onaccept=crud.archive)

        crud.archive will define a new table "mytable_archive" and store the
        previous record in the newly created table including a reference
        to the current record.

        If you want to access such table you need to define it yourself in a model::

            db.define_table('mytable_archive',
                Field('current_record',db.mytable),
                db.mytable)

        Notice such table includes all fields of db.mytable plus one: current_record.
        crud.archive does not timestamp the stored record unless your original table
        has a fields like::

            db.define_table(...,
                Field('saved_on','datetime',
                     default=request.now,update=request.now,writable=False),
                Field('saved_by',auth.user,
                     default=auth.user_id,update=auth.user_id,writable=False),

        there is nothing special about these fields since they are filled before
        the record is archived.

        If you want to change the archive table name and the name of the reference field
        you can do, for example::

            db.define_table('myhistory',
                Field('parent_record',db.mytable),
                db.mytable)

        and use it as::

            form=crud.update(db.mytable,myrecord,
                             onaccept=lambda form:crud.archive(form,
                             archive_table=db.myhistory,
                             current_record='parent_record'))

        """
        old_record = form.record
        if not old_record:
            return None
        table = form.table
        if not archive_table:
            archive_table_name = '%s_archive' % table
            if archive_table_name in table._db:
                archive_table = table._db[archive_table_name]
            else:
                archive_table = table._db.define_table(archive_table_name,
                                                       Field(current_record,table),
                                                       table)
        new_record = {current_record:old_record.id}
        for fieldname in archive_table.fields:
            if not fieldname in ['id',current_record] and fieldname in old_record:
                new_record[fieldname]=old_record[fieldname]
        id = archive_table.insert(**new_record)
        return id

    def update(
        self,
        table,
        record,
        next=DEFAULT,
        onvalidation=DEFAULT,







|

|















<


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882

2883
2884







































2885
2886




















2887
2888
2889
2890
2891
2892
2893
        elif args[0] == 'update':
            return self.update(table, args(2))
        elif args[0] == 'delete':
            return self.delete(table, args(2))
        else:
            raise HTTP(404)

    def log_event(self, message, vars):
        if self.settings.logger:
            self.settings.logger.log_event(message, vars, origin = 'crud')

    def has_permission(self, name, table, record=0):
        if not self.settings.auth:
            return True
        try:
            record_id = record.id
        except:
            record_id = record
        return self.settings.auth.has_permission(name, str(table), record_id)

    def tables(self):
        return TABLE(*[TR(A(name,
                            _href=self.url(args=('select',name)))) \
                           for name in self.db.tables])


    @staticmethod
    def archive(form,archive_table=None,current_record='current_record'):







































        return Auth.archive(form,archive_table=archive_table,
                            current_record=current_record)





















    def update(
        self,
        table,
        record,
        next=DEFAULT,
        onvalidation=DEFAULT,
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
            table = self.db[table]
        try:
            record_id = record.id
        except:
            record_id = record or 0
        if record_id and not self.has_permission('update', table, record_id):
            redirect(self.settings.auth.settings.on_failed_authorization)
        if not record_id \
                and not self.has_permission('create', table, record_id):
            redirect(self.settings.auth.settings.on_failed_authorization)

        request = current.request
        response = current.response
        session = current.session
        if request.extension == 'json' and request.vars.json:
            request.vars.update(simplejson.loads(request.vars.json))
        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.update_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.update_onvalidation
        if onaccept == DEFAULT:







<
|






|







2911
2912
2913
2914
2915
2916
2917

2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
            table = self.db[table]
        try:
            record_id = record.id
        except:
            record_id = record or 0
        if record_id and not self.has_permission('update', table, record_id):
            redirect(self.settings.auth.settings.on_failed_authorization)

        if not record_id and not self.has_permission('create', table, record_id):
            redirect(self.settings.auth.settings.on_failed_authorization)

        request = current.request
        response = current.response
        session = current.session
        if request.extension == 'json' and request.vars.json:
            request.vars.update(json_parser.loads(request.vars.json))
        if next == DEFAULT:
            next = request.get_vars._next \
                or request.post_vars._next \
                or self.settings.update_next
        if onvalidation == DEFAULT:
            onvalidation = self.settings.update_onvalidation
        if onaccept == DEFAULT:
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
            deletable=deletable,
            upload=self.settings.download_url,
            formstyle=self.settings.formstyle,
            separator=self.settings.label_separator
            )
        self.accepted = False
        self.deleted = False
        captcha = self.settings.update_captcha or \
                  self.settings.captcha
        if record and captcha:
            addrow(form, captcha.label, captcha, captcha.comment,
                         self.settings.formstyle,'captcha__row')
        captcha = self.settings.create_captcha or \
                  self.settings.captcha
        if not record and captcha:
            addrow(form, captcha.label, captcha, captcha.comment,
                         self.settings.formstyle,'captcha__row')
        if not request.extension in ('html','load'):
            (_session, _formname) = (None, None)
        else:
            (_session, _formname) = \
                (session, '%s/%s' % (table._tablename, form.record_id))
        if formname!=DEFAULT:
            _formname = formname
        keepvalues = self.settings.keepvalues
        if request.vars.delete_this_record:
            keepvalues = False
        if isinstance(onvalidation,StorageList):
            onvalidation=onvalidation.get(table._tablename, [])
        if form.accepts(request, _session, formname=_formname,
                        onvalidation=onvalidation, keepvalues=keepvalues,
                        hideerror=self.settings.hideerror,
                        detect_record_change = self.settings.detect_record_change):
            self.accepted = True
            response.flash = message
            if log:
                self.log_event(log % form.vars)
            if request.vars.delete_this_record:
                self.deleted = True
                message = self.messages.record_deleted
                callback(ondelete,form,table._tablename)
            response.flash = message
            callback(onaccept,form,table._tablename)
            if not request.extension in ('html','load'):
                raise HTTP(200, 'RECORD CREATED/UPDATED')
            if isinstance(next, (list, tuple)): ### fix issue with 2.6
               next = next[0]
            if next: # Only redirect when explicit
                if next[0] != '/' and next[:4] != 'http':
                    next = URL(r=request,
                               f=next.replace('[id]', str(form.vars.id)))
                session.flash = response.flash
                redirect(next)
        elif not request.extension in ('html','load'):
            raise HTTP(401)
        return form

    def create(







|
<



|
<






<
|














|











<
|
<







2949
2950
2951
2952
2953
2954
2955
2956

2957
2958
2959
2960

2961
2962
2963
2964
2965
2966

2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993

2994

2995
2996
2997
2998
2999
3000
3001
            deletable=deletable,
            upload=self.settings.download_url,
            formstyle=self.settings.formstyle,
            separator=self.settings.label_separator
            )
        self.accepted = False
        self.deleted = False
        captcha = self.settings.update_captcha or self.settings.captcha

        if record and captcha:
            addrow(form, captcha.label, captcha, captcha.comment,
                         self.settings.formstyle,'captcha__row')
        captcha = self.settings.create_captcha or self.settings.captcha

        if not record and captcha:
            addrow(form, captcha.label, captcha, captcha.comment,
                         self.settings.formstyle,'captcha__row')
        if not request.extension in ('html','load'):
            (_session, _formname) = (None, None)
        else:

            (_session, _formname) = (session, '%s/%s' % (table._tablename, form.record_id))
        if formname!=DEFAULT:
            _formname = formname
        keepvalues = self.settings.keepvalues
        if request.vars.delete_this_record:
            keepvalues = False
        if isinstance(onvalidation,StorageList):
            onvalidation=onvalidation.get(table._tablename, [])
        if form.accepts(request, _session, formname=_formname,
                        onvalidation=onvalidation, keepvalues=keepvalues,
                        hideerror=self.settings.hideerror,
                        detect_record_change = self.settings.detect_record_change):
            self.accepted = True
            response.flash = message
            if log:
                self.log_event(log, form.vars)
            if request.vars.delete_this_record:
                self.deleted = True
                message = self.messages.record_deleted
                callback(ondelete,form,table._tablename)
            response.flash = message
            callback(onaccept,form,table._tablename)
            if not request.extension in ('html','load'):
                raise HTTP(200, 'RECORD CREATED/UPDATED')
            if isinstance(next, (list, tuple)): ### fix issue with 2.6
               next = next[0]
            if next: # Only redirect when explicit

                next = replace_id(next, form)

                session.flash = response.flash
                redirect(next)
        elif not request.extension in ('html','load'):
            raise HTTP(401)
        return form

    def create(
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
            message = self.messages.record_deleted
        record = table[record_id]
        if record:
            callback(self.settings.delete_onvalidation,record)
            del table[record_id]
            callback(self.settings.delete_onaccept,record,table._tablename)
            session.flash = message
        if next: # Only redirect when explicit
            redirect(next)

    def rows(
        self,
        table,
        query=None,
        fields=None,
        orderby=None,
        limitby=None,
        ):
        request = current.request
        if not (isinstance(table, self.db.Table) or table in self.db.tables):
            raise HTTP(404)
        if not self.has_permission('select', table):
            redirect(self.settings.auth.settings.on_failed_authorization)
        #if record_id and not self.has_permission('select', table):
        #    redirect(self.settings.auth.settings.on_failed_authorization)
        if not isinstance(table, self.db.Table):







<
|









<







3085
3086
3087
3088
3089
3090
3091

3092
3093
3094
3095
3096
3097
3098
3099
3100
3101

3102
3103
3104
3105
3106
3107
3108
            message = self.messages.record_deleted
        record = table[record_id]
        if record:
            callback(self.settings.delete_onvalidation,record)
            del table[record_id]
            callback(self.settings.delete_onaccept,record,table._tablename)
            session.flash = message

        redirect(next)

    def rows(
        self,
        table,
        query=None,
        fields=None,
        orderby=None,
        limitby=None,
        ):

        if not (isinstance(table, self.db.Table) or table in self.db.tables):
            raise HTTP(404)
        if not self.has_permission('select', table):
            redirect(self.settings.auth.settings.on_failed_authorization)
        #if record_id and not self.has_permission('select', table):
        #    redirect(self.settings.auth.settings.on_failed_authorization)
        if not isinstance(table, self.db.Table):
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230

3231
3232
3233
3234
3235
3236
3237
    def select(
        self,
        table,
        query=None,
        fields=None,
        orderby=None,
        limitby=None,
        headers={},
        **attr
        ):

        rows = self.rows(table,query,fields,orderby,limitby)
        if not rows:
            return None # Nicer than an empty table.
        if not 'upload' in attr:
            attr['upload'] = self.url('download')
        if not current.request.extension in ('html','load'):
            return rows.as_list()







|


>







3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
    def select(
        self,
        table,
        query=None,
        fields=None,
        orderby=None,
        limitby=None,
        headers=None,
        **attr
        ):
        headers = headers or {}
        rows = self.rows(table,query,fields,orderby,limitby)
        if not rows:
            return None # Nicer than an empty table.
        if not 'upload' in attr:
            attr['upload'] = self.url('download')
        if not current.request.extension in ('html','load'):
            return rows.as_list()
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
                if not refsearch:
                    return field.like('%'+value+'%')
                else:
                    return lambda row: value in row[field.name][format]
        except:
            return None


    def search(self, *tables, **args):
        """
        Creates a search form and its results for a table
        Example usage:
        form, results = crud.search(db.test,
                               queries = ['equals', 'not equal', 'contains'],
                               query_labels={'equals':'Equals',







<







3183
3184
3185
3186
3187
3188
3189

3190
3191
3192
3193
3194
3195
3196
                if not refsearch:
                    return field.like('%'+value+'%')
                else:
                    return lambda row: value in row[field.name][format]
        except:
            return None


    def search(self, *tables, **args):
        """
        Creates a search form and its results for a table
        Example usage:
        form, results = crud.search(db.test,
                               queries = ['equals', 'not equal', 'contains'],
                               query_labels={'equals':'Equals',
3310
3311
3312
3313
3314
3315
3316







3317
3318
3319
3320
3321
3322
3323
        if not (isinstance(table, db.Table) or table in db.tables):
            raise HTTP(404)
        attributes = {}
        for key in ('orderby','groupby','left','distinct','limitby','cache'):
            if key in args: attributes[key]=args[key]
        tbl = TABLE()
        selected = []; refsearch = []; results = []







        ops = args.get('queries', [])
        zero = args.get('zero', '')
        if not ops:
            ops = ['equals', 'not equal', 'greater than',
                   'less than', 'starts with',
                   'ends with', 'contains']
        ops.insert(0,zero)







>
>
>
>
>
>
>







3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
        if not (isinstance(table, db.Table) or table in db.tables):
            raise HTTP(404)
        attributes = {}
        for key in ('orderby','groupby','left','distinct','limitby','cache'):
            if key in args: attributes[key]=args[key]
        tbl = TABLE()
        selected = []; refsearch = []; results = []
        showall = args.get('showall', False)
        if showall:
            selected = fields
        chkall = args.get('chkall', False)
        if chkall:
            for f in fields:
                request.vars['chk%s'%f] = 'on'
        ops = args.get('queries', [])
        zero = args.get('zero', '')
        if not ops:
            ops = ['equals', 'not equal', 'greater than',
                   'less than', 'starts with',
                   'ends with', 'contains']
        ops.insert(0,zero)
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374

3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
            except: # hmmm, we should do better here
                results = None
        return form, results


urllib2.install_opener(urllib2.build_opener(urllib2.HTTPCookieProcessor()))

def fetch(url, data=None, headers={},
          cookie=Cookie.SimpleCookie(),
          user_agent='Mozilla/5.0'):

    if data != None:
        data = urllib.urlencode(data)
    if user_agent: headers['User-agent'] = user_agent
    headers['Cookie'] = ' '.join(['%s=%s;'%(c.key,c.value) for c in cookie.values()])
    try:
        from google.appengine.api import urlfetch
    except ImportError:
        req = urllib2.Request(url, data, headers)
        html = urllib2.urlopen(req).read()
    else:
        method = ((data==None) and urlfetch.GET) or urlfetch.POST
        while url is not None:
            response = urlfetch.fetch(url=url, payload=data,
                                      method=method, headers=headers,
                                      allow_truncated=False,follow_redirects=False,
                                      deadline=10)
            # next request will be a get, so no need to send the data again
            data = None







|


>
|









|







3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
            except: # hmmm, we should do better here
                results = None
        return form, results


urllib2.install_opener(urllib2.build_opener(urllib2.HTTPCookieProcessor()))

def fetch(url, data=None, headers=None,
          cookie=Cookie.SimpleCookie(),
          user_agent='Mozilla/5.0'):
    headers = headers or {}
    if not data is None:
        data = urllib.urlencode(data)
    if user_agent: headers['User-agent'] = user_agent
    headers['Cookie'] = ' '.join(['%s=%s;'%(c.key,c.value) for c in cookie.values()])
    try:
        from google.appengine.api import urlfetch
    except ImportError:
        req = urllib2.Request(url, data, headers)
        html = urllib2.urlopen(req).read()
    else:
        method = ((data is None) and urlfetch.GET) or urlfetch.POST
        while url is not None:
            response = urlfetch.fetch(url=url, payload=data,
                                      method=method, headers=headers,
                                      allow_truncated=False,follow_redirects=False,
                                      deadline=10)
            # next request will be a get, so no need to send the data again
            data = None
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
        self.amfrpc3_procedures = {}
        self.soap_procedures = {}

    def run(self, f):
        """
        example::

            service = Service(globals())
            @service.run
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/run/myfunction?a=3&b=4

        """
        self.run_procedures[f.__name__] = f
        return f

    def csv(self, f):
        """
        example::

            service = Service(globals())
            @service.csv
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/csv/myfunction?a=3&b=4

        """
        self.run_procedures[f.__name__] = f
        return f

    def xml(self, f):
        """
        example::

            service = Service(globals())
            @service.xml
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/xml/myfunction?a=3&b=4

        """
        self.run_procedures[f.__name__] = f
        return f

    def rss(self, f):
        """
        example::

            service = Service(globals())
            @service.rss
            def myfunction():
                return dict(title=..., link=..., description=...,
                    created_on=..., entries=[dict(title=..., link=...,
                        description=..., created_on=...])
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/rss/myfunction

        """
        self.rss_procedures[f.__name__] = f
        return f

    def json(self, f):
        """
        example::

            service = Service(globals())
            @service.json
            def myfunction(a, b):
                return [{a: b}]
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/json/myfunction?a=hello&b=world

        """
        self.json_procedures[f.__name__] = f
        return f

    def jsonrpc(self, f):
        """
        example::

            service = Service(globals())
            @service.jsonrpc
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/jsonrpc/myfunction?a=hello&b=world

        """
        self.jsonrpc_procedures[f.__name__] = f
        return f

    def xmlrpc(self, f):
        """
        example::

            service = Service(globals())
            @service.xmlrpc
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::

            wget http://..../app/default/call/xmlrpc/myfunction?a=hello&b=world

        """
        self.xmlrpc_procedures[f.__name__] = f
        return f

    def amfrpc(self, f):
        """
        example::

            service = Service(globals())
            @service.amfrpc
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::

            wget http://..../app/default/call/amfrpc/myfunction?a=hello&b=world

        """
        self.amfrpc_procedures[f.__name__] = f
        return f

    def amfrpc3(self, domain='default'):
        """
        example::

            service = Service(globals())
            @service.amfrpc3('domain')
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::







|


















|


















|


















|




















|


















|


















|


















|


















|







3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
        self.amfrpc3_procedures = {}
        self.soap_procedures = {}

    def run(self, f):
        """
        example::

            service = Service()
            @service.run
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/run/myfunction?a=3&b=4

        """
        self.run_procedures[f.__name__] = f
        return f

    def csv(self, f):
        """
        example::

            service = Service()
            @service.csv
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/csv/myfunction?a=3&b=4

        """
        self.run_procedures[f.__name__] = f
        return f

    def xml(self, f):
        """
        example::

            service = Service()
            @service.xml
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/xml/myfunction?a=3&b=4

        """
        self.run_procedures[f.__name__] = f
        return f

    def rss(self, f):
        """
        example::

            service = Service()
            @service.rss
            def myfunction():
                return dict(title=..., link=..., description=...,
                    created_on=..., entries=[dict(title=..., link=...,
                        description=..., created_on=...])
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/rss/myfunction

        """
        self.rss_procedures[f.__name__] = f
        return f

    def json(self, f):
        """
        example::

            service = Service()
            @service.json
            def myfunction(a, b):
                return [{a: b}]
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/json/myfunction?a=hello&b=world

        """
        self.json_procedures[f.__name__] = f
        return f

    def jsonrpc(self, f):
        """
        example::

            service = Service()
            @service.jsonrpc
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        Then call it with::

            wget http://..../app/default/call/jsonrpc/myfunction?a=hello&b=world

        """
        self.jsonrpc_procedures[f.__name__] = f
        return f

    def xmlrpc(self, f):
        """
        example::

            service = Service()
            @service.xmlrpc
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::

            wget http://..../app/default/call/xmlrpc/myfunction?a=hello&b=world

        """
        self.xmlrpc_procedures[f.__name__] = f
        return f

    def amfrpc(self, f):
        """
        example::

            service = Service()
            @service.amfrpc
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::

            wget http://..../app/default/call/amfrpc/myfunction?a=hello&b=world

        """
        self.amfrpc_procedures[f.__name__] = f
        return f

    def amfrpc3(self, domain='default'):
        """
        example::

            service = Service()
            @service.amfrpc3('domain')
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
            return f
        return _amfrpc3

    def soap(self, name=None, returns=None, args=None,doc=None):
        """
        example::

            service = Service(globals())
            @service.soap('MyFunction',returns={'result':int},args={'a':int,'b':int,})
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::







|







3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
            return f
        return _amfrpc3

    def soap(self, name=None, returns=None, args=None,doc=None):
        """
        example::

            service = Service()
            @service.soap('MyFunction',returns={'result':int},args={'a':int,'b':int,})
            def myfunction(a, b):
                return a + b
            def call():
                return service()

        The call it with::
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
            args = request.args

        def none_exception(value):
            if isinstance(value, unicode):
                return value.encode('utf8')
            if hasattr(value, 'isoformat'):
                return value.isoformat()[:19].replace('T', ' ')
            if value == None:
                return '<NULL>'
            return value
        if args and args[0] in self.run_procedures:
            r = universal_caller(self.run_procedures[args[0]],
                                 *args[1:], **dict(request.vars))
            s = cStringIO.StringIO()
            if hasattr(r, 'export_to_csv_file'):







|







3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
            args = request.args

        def none_exception(value):
            if isinstance(value, unicode):
                return value.encode('utf8')
            if hasattr(value, 'isoformat'):
                return value.isoformat()[:19].replace('T', ' ')
            if value is None:
                return '<NULL>'
            return value
        if args and args[0] in self.run_procedures:
            r = universal_caller(self.run_procedures[args[0]],
                                 *args[1:], **dict(request.vars))
            s = cStringIO.StringIO()
            if hasattr(r, 'export_to_csv_file'):
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774


3775
3776
3777
3778
3779
3780
3781
3782
3783
            self.error()
        response.headers['Content-Type'] = 'application/rss+xml'
        return serializers.rss(feed)

    def serve_json(self, args=None):
        request = current.request
        response = current.response
        response.headers['Content-Type'] = 'text/x-json'
        if not args:
            args = request.args
        d = dict(request.vars)
        if args and args[0] in self.json_procedures:
            s = universal_caller(self.json_procedures[args[0]],*args[1:],**d)
            if hasattr(s, 'as_list'):
                s = s.as_list()
            return response.json(s)
        self.error()

    class JsonRpcException(Exception):
        def __init__(self,code,info):
            self.code,self.info = code,info

    def serve_jsonrpc(self):
        import contrib.simplejson as simplejson
        def return_response(id, result):
            return serializers.json({'version': '1.1',
                'id': id, 'result': result, 'error': None})

        def return_error(id, code, message):
            return serializers.json({'id': id,
                                     'version': '1.1',
                                     'error': {'name': 'JSONRPCError',
                                        'code': code, 'message': message}
                                     })

        request = current.request


        methods = self.jsonrpc_procedures
        data = simplejson.loads(request.body.read())
        id, method, params = data['id'], data['method'], data.get('params','')
        if not method in methods:
            return return_error(id, 100, 'method "%s" does not exist' % method)
        try:
            s = methods[method](*params)
            if hasattr(s, 'as_list'):
                s = s.as_list()







|















<



<








>
>

|







3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666

3667
3668
3669

3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
            self.error()
        response.headers['Content-Type'] = 'application/rss+xml'
        return serializers.rss(feed)

    def serve_json(self, args=None):
        request = current.request
        response = current.response
        response.headers['Content-Type'] = 'application/json; charset=utf-8'
        if not args:
            args = request.args
        d = dict(request.vars)
        if args and args[0] in self.json_procedures:
            s = universal_caller(self.json_procedures[args[0]],*args[1:],**d)
            if hasattr(s, 'as_list'):
                s = s.as_list()
            return response.json(s)
        self.error()

    class JsonRpcException(Exception):
        def __init__(self,code,info):
            self.code,self.info = code,info

    def serve_jsonrpc(self):

        def return_response(id, result):
            return serializers.json({'version': '1.1',
                'id': id, 'result': result, 'error': None})

        def return_error(id, code, message):
            return serializers.json({'id': id,
                                     'version': '1.1',
                                     'error': {'name': 'JSONRPCError',
                                        'code': code, 'message': message}
                                     })

        request = current.request
        response = current.response
        response.headers['Content-Type'] = 'application/json; charset=utf-8'
        methods = self.jsonrpc_procedures
        data = json_parser.loads(request.body.read())
        id, method, params = data['id'], data['method'], data.get('params','')
        if not method in methods:
            return return_error(id, 100, 'method "%s" does not exist' % method)
        try:
            s = methods[method](*params)
            if hasattr(s, 'as_list'):
                s = s.as_list()
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
                        for method, doc in dispatcher.list_methods()]),
                    ]
            return {'body': body}

    def __call__(self):
        """
        register services with:
        service = Service(globals())
        @service.run
        @service.rss
        @service.json
        @service.jsonrpc
        @service.xmlrpc
        @service.jsonrpc
        @service.amfrpc
        @service.amfrpc3('domain')
        @service.soap('Method', returns={'Result':int}, args={'a':int,'b':int,})

        expose services with

        def call(): return service()







|





<







3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806

3807
3808
3809
3810
3811
3812
3813
                        for method, doc in dispatcher.list_methods()]),
                    ]
            return {'body': body}

    def __call__(self):
        """
        register services with:
        service = Service()
        @service.run
        @service.rss
        @service.json
        @service.jsonrpc
        @service.xmlrpc

        @service.amfrpc
        @service.amfrpc3('domain')
        @service.soap('Method', returns={'Result':int}, args={'a':int,'b':int,})

        expose services with

        def call(): return service()
4095
4096
4097
4098
4099
4100
4101
4102

4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
        finally:
            lock.release()
    def __init__(self,plugin=None,**defaults):
        if not plugin:
            self.__dict__.clear()
        settings = self.__getattr__(plugin)
        settings.installed = True
        [settings.update({key:value}) for key,value in defaults.items() if not key in settings]

    def __getattr__(self, key):
        if not key in self.__dict__:
            self.__dict__[key] = Storage()
        return self.__dict__[key]
    def keys(self):
        return self.__dict__.keys()
    def __contains__(self,key):
        return key in self.__dict__

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








|
>












<
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019

        finally:
            lock.release()
    def __init__(self,plugin=None,**defaults):
        if not plugin:
            self.__dict__.clear()
        settings = self.__getattr__(plugin)
        settings.installed = True
        [settings.update({key:value}) for key,value in defaults.items() \
            if not key in settings]
    def __getattr__(self, key):
        if not key in self.__dict__:
            self.__dict__[key] = Storage()
        return self.__dict__[key]
    def keys(self):
        return self.__dict__.keys()
    def __contains__(self,key):
        return key in self.__dict__

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

Added gluon/tools.pyc version [3a8feefb6f].
Modified gluon/utils.py from [c924bf11cb] to [cd84275670].
120
121
122
123
124
125
126


127
        ubytes = [ord(c) for c in os.urandom(16)] # use /dev/urandom if possible
        bytes = [bytes[i] ^ ubytes[i] for i in range(16)]
    except NotImplementedError:
        pass
    ## xor bytes with constant ctokens
    bytes = ''.join(chr(c ^ ctokens[i]) for i,c in enumerate(bytes))
    return str(uuid.UUID(bytes=bytes, version=4))










>
>

120
121
122
123
124
125
126
127
128
129
        ubytes = [ord(c) for c in os.urandom(16)] # use /dev/urandom if possible
        bytes = [bytes[i] ^ ubytes[i] for i in range(16)]
    except NotImplementedError:
        pass
    ## xor bytes with constant ctokens
    bytes = ''.join(chr(c ^ ctokens[i]) for i,c in enumerate(bytes))
    return str(uuid.UUID(bytes=bytes, version=4))



Added gluon/utils.pyc version [59bcf5d046].
Modified gluon/validators.py from [0b976e1d6d] to [59f9c2fdd4].
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
import cgi
import urllib
import struct
import decimal
import unicodedata
from cStringIO import StringIO
from utils import simple_hash, hmac_hash

__all__ = [
    'CLEANUP',
    'CRYPT',
    'IS_ALPHANUMERIC',
    'IS_DATE_IN_RANGE',
    'IS_DATE',







|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
import cgi
import urllib
import struct
import decimal
import unicodedata
from cStringIO import StringIO
from utils import simple_hash, hmac_hash, web2py_uuid

__all__ = [
    'CLEANUP',
    'CRYPT',
    'IS_ALPHANUMERIC',
    'IS_DATE_IN_RANGE',
    'IS_DATE',
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

        INPUT(_type='text', _name='name', requires=IS_MATCH('.+'))

    the argument of IS_MATCH is a regular expression::

        >>> IS_MATCH('.+')('hello')
        ('hello', None)



















        >>> IS_MATCH('.+')('')
        ('', 'invalid expression')
    """

    def __init__(self, expression, error_message='invalid expression', strict=True):
        if strict:
            if not expression.endswith('$'):
                expression = '(%s)$' % expression



        self.regex = re.compile(expression)
        self.error_message = error_message

    def __call__(self, value):
        match = self.regex.match(value)
        if match:
            return (match.group(), None)
        return (value, translate(self.error_message))


class IS_EQUAL_TO(Validator):
    """







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|



>
>
>




|







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
162
163
164
165

        INPUT(_type='text', _name='name', requires=IS_MATCH('.+'))

    the argument of IS_MATCH is a regular expression::

        >>> IS_MATCH('.+')('hello')
        ('hello', None)

        >>> IS_MATCH('hell')('hello')
        ('hello', 'invalid expression')

        >>> IS_MATCH('hell.*', strict=False)('hello')
        ('hello', None)

        >>> IS_MATCH('hello')('shello')
        ('shello', 'invalid expression')

        >>> IS_MATCH('hello', search=True)('shello')
        ('hello', None)

        >>> IS_MATCH('hello', search=True, strict=False)('shellox')
        ('hello', None)

        >>> IS_MATCH('.*hello.*', search=True, strict=False)('shellox')
        ('shellox', None)

        >>> IS_MATCH('.+')('')
        ('', 'invalid expression')
    """

    def __init__(self, expression, error_message='invalid expression', strict=True, search=False):
        if strict:
            if not expression.endswith('$'):
                expression = '(%s)$' % expression
        if not search:
            if not expression.startswith('^'):
                expression = '^(%s)' % expression
        self.regex = re.compile(expression)
        self.error_message = error_message

    def __call__(self, value):
        match = self.regex.search(value)
        if match:
            return (match.group(), None)
        return (value, translate(self.error_message))


class IS_EQUAL_TO(Validator):
    """
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
    def options(self,zero=True):
        if not self.labels:
            items = [(k, k) for (i, k) in enumerate(self.theset)]
        else:
            items = [(k, self.labels[i]) for (i, k) in enumerate(self.theset)]
        if self.sort:
            items.sort(options_sorter)
        if zero and self.zero != None and not self.multiple:
            items.insert(0,('',self.zero))
        return items

    def __call__(self, value):
        if self.multiple:
            ### if below was values = re.compile("[\w\-:]+").findall(str(value))
            if isinstance(value, (str,unicode)):
                values = [value]
            elif isinstance(value, (tuple, list)):
                values = value
            elif not value:
                values = []
        else:
            values = [value]
        failures = [x for x in values if not x in self.theset]
        if failures and self.theset:
            if self.multiple and (value == None or value == ''):
                return ([], None)
            return (value, translate(self.error_message))
        if self.multiple:
            if isinstance(self.multiple,(tuple,list)) and \
                    not self.multiple[0]<=len(values)<self.multiple[1]:
                return (values, translate(self.error_message))
            return (values, None)







|
















|







335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
    def options(self,zero=True):
        if not self.labels:
            items = [(k, k) for (i, k) in enumerate(self.theset)]
        else:
            items = [(k, self.labels[i]) for (i, k) in enumerate(self.theset)]
        if self.sort:
            items.sort(options_sorter)
        if zero and not self.zero is None and not self.multiple:
            items.insert(0,('',self.zero))
        return items

    def __call__(self, value):
        if self.multiple:
            ### if below was values = re.compile("[\w\-:]+").findall(str(value))
            if isinstance(value, (str,unicode)):
                values = [value]
            elif isinstance(value, (tuple, list)):
                values = value
            elif not value:
                values = []
        else:
            values = [value]
        failures = [x for x in values if not x in self.theset]
        if failures and self.theset:
            if self.multiple and (value is None or value == ''):
                return ([], None)
            return (value, translate(self.error_message))
        if self.multiple:
            if isinstance(self.multiple,(tuple,list)) and \
                    not self.multiple[0]<=len(values)<self.multiple[1]:
                return (values, translate(self.error_message))
            return (values, None)
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
            self.labels = [self.label(r) for r in records]

    def options(self, zero=True):
        self.build_set()
        items = [(k, self.labels[i]) for (i, k) in enumerate(self.theset)]
        if self.sort:
            items.sort(options_sorter)
        if zero and self.zero != None and not self.multiple:
            items.insert(0,('',self.zero))
        return items

    def __call__(self, value):
        if self.multiple:
            if isinstance(value,list):
                values=value
            elif value:
                values = [value]
            else:
                values = []
            if isinstance(self.multiple,(tuple,list)) and \
                    not self.multiple[0]<=len(values)<self.multiple[1]:
                return (values, translate(self.error_message))
            if not [x for x in values if not x in self.theset]:
                return (values, None)
        elif self.theset:
            if value in self.theset:
                if self._and:
                    return self._and(value)
                else:
                    return (value, None)
        else:
            (ktable, kfield) = str(self.field).split('.')
            field = self.dbset.db[ktable][kfield]







|

















|







456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
            self.labels = [self.label(r) for r in records]

    def options(self, zero=True):
        self.build_set()
        items = [(k, self.labels[i]) for (i, k) in enumerate(self.theset)]
        if self.sort:
            items.sort(options_sorter)
        if zero and not self.zero is None and not self.multiple:
            items.insert(0,('',self.zero))
        return items

    def __call__(self, value):
        if self.multiple:
            if isinstance(value,list):
                values=value
            elif value:
                values = [value]
            else:
                values = []
            if isinstance(self.multiple,(tuple,list)) and \
                    not self.multiple[0]<=len(values)<self.multiple[1]:
                return (values, translate(self.error_message))
            if not [x for x in values if not x in self.theset]:
                return (values, None)
        elif self.theset:
            if str(value) in self.theset:
                if self._and:
                    return self._and(value)
                else:
                    return (value, None)
        else:
            (ktable, kfield) = str(self.field).split('.')
            field = self.dbset.db[ktable][kfield]
605
606
607
608
609
610
611





612
613
614
615
616
617
618
                    return (value, None)
            elif self.minimum <= value < self.maximum:
                    return (value, None)
        except ValueError:
            pass
        return (value, self.error_message)







class IS_FLOAT_IN_RANGE(Validator):
    """
    Determine that the argument is (or can be represented as) a float,
    and that it falls within the specified inclusive range.
    The comparison is made with native arithmetic.








>
>
>
>
>







626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
                    return (value, None)
            elif self.minimum <= value < self.maximum:
                    return (value, None)
        except ValueError:
            pass
        return (value, self.error_message)

def str2dec(number):
    s = str(number)
    if not '.' in s: s+='.00'
    else: s+='0'*(2-len(s.split('.')[1]))
    return s

class IS_FLOAT_IN_RANGE(Validator):
    """
    Determine that the argument is (or can be represented as) a float,
    and that it falls within the specified inclusive range.
    The comparison is made with native arithmetic.

693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
            elif self.minimum <= fvalue <= self.maximum:
                    return (fvalue, None)
        except (ValueError, TypeError):
            pass
        return (value, self.error_message)

    def formatter(self,value):
        if self.dot=='.':
            return str(value)
        else:
            return str(value).replace('.',self.dot)


class IS_DECIMAL_IN_RANGE(Validator):
    """
    Determine that the argument is (or can be represented as) a Python Decimal,
    and that it falls within the specified inclusive range.
    The comparison is made with Python Decimal arithmetic.







<
<
<
|







719
720
721
722
723
724
725



726
727
728
729
730
731
732
733
            elif self.minimum <= fvalue <= self.maximum:
                    return (fvalue, None)
        except (ValueError, TypeError):
            pass
        return (value, self.error_message)

    def formatter(self,value):



        return str2dec(value).replace('.',self.dot)


class IS_DECIMAL_IN_RANGE(Validator):
    """
    Determine that the argument is (or can be represented as) a Python Decimal,
    and that it falls within the specified inclusive range.
    The comparison is made with Python Decimal arithmetic.
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
            elif self.minimum <= v <= self.maximum:
                    return (v, None)
        except (ValueError, TypeError, decimal.InvalidOperation):
            pass
        return (value, self.error_message)

    def formatter(self, value):
        return str(value).replace('.',self.dot)

def is_empty(value, empty_regex=None):
    "test empty field"
    if isinstance(value, (str, unicode)):
        value = value.strip()
        if empty_regex is not None and empty_regex.match(value):
            value = ''
    if value == None or value == '' or value == []:
        return (value, True)
    return (value, False)

class IS_NOT_EMPTY(Validator):
    """
    example::








|







|







823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
            elif self.minimum <= v <= self.maximum:
                    return (v, None)
        except (ValueError, TypeError, decimal.InvalidOperation):
            pass
        return (value, self.error_message)

    def formatter(self, value):
        return str2dec(value).replace('.',self.dot)

def is_empty(value, empty_regex=None):
    "test empty field"
    if isinstance(value, (str, unicode)):
        value = value.strip()
        if empty_regex is not None and empty_regex.match(value):
            value = ''
    if value is None or value == '' or value == []:
        return (value, True)
    return (value, False)

class IS_NOT_EMPTY(Validator):
    """
    example::

1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
        :param allowed_schemes: a list containing strings or None. Each element
            is a scheme the inputed URL is allowed to use
        :param prepend_scheme: a string, this scheme is prepended if it's
            necessary to make the URL valid
        """

        self.error_message = error_message
        if allowed_schemes == None:
            self.allowed_schemes = all_url_schemes
        else:
            self.allowed_schemes = allowed_schemes
        self.prepend_scheme = prepend_scheme
        if self.prepend_scheme not in self.allowed_schemes:
            raise SyntaxError, \
                "prepend_scheme='%s' is not in allowed_schemes=%s" \







|







1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
        :param allowed_schemes: a list containing strings or None. Each element
            is a scheme the inputed URL is allowed to use
        :param prepend_scheme: a string, this scheme is prepended if it's
            necessary to make the URL valid
        """

        self.error_message = error_message
        if allowed_schemes is None:
            self.allowed_schemes = all_url_schemes
        else:
            self.allowed_schemes = allowed_schemes
        self.prepend_scheme = prepend_scheme
        if self.prepend_scheme not in self.allowed_schemes:
            raise SyntaxError, \
                "prepend_scheme='%s' is not in allowed_schemes=%s" \
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
                # if the URL is only composed of valid characters
                if re.compile(
                    r"[A-Za-z0-9;/?:@&=+$,\-_\.!~*'\(\)%#]+$").match(value):
                    # Then split up the URL into its components and check on
                    # the scheme
                    scheme = url_split_regex.match(value).group(2)
                    # Clean up the scheme before we check it
                    if scheme != None:
                        scheme = urllib.unquote(scheme).lower()
                    # If the scheme really exists
                    if scheme in self.allowed_schemes:
                        # Then the URL is valid
                        return (value, None)
                    else:
                        # else, for the possible case of abbreviated URLs with
                        # ports, check to see if adding a valid scheme fixes
                        # the problem (but only do this if it doesn't have
                        # one already!)
                        if not re.compile('://').search(value) and None\
                             in self.allowed_schemes:
                            schemeToUse = self.prepend_scheme or 'http'
                            prependTest = self.__call__(schemeToUse
                                     + '://' + value)
                            # if the prepend test succeeded
                            if prependTest[1] == None:
                                # if prepending in the output is enabled
                                if self.prepend_scheme:
                                    return prependTest
                                else:
                                    # else return the original,
                                    #  non-prepended value
                                    return (value, None)







|
















|







1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
                # if the URL is only composed of valid characters
                if re.compile(
                    r"[A-Za-z0-9;/?:@&=+$,\-_\.!~*'\(\)%#]+$").match(value):
                    # Then split up the URL into its components and check on
                    # the scheme
                    scheme = url_split_regex.match(value).group(2)
                    # Clean up the scheme before we check it
                    if not scheme is None:
                        scheme = urllib.unquote(scheme).lower()
                    # If the scheme really exists
                    if scheme in self.allowed_schemes:
                        # Then the URL is valid
                        return (value, None)
                    else:
                        # else, for the possible case of abbreviated URLs with
                        # ports, check to see if adding a valid scheme fixes
                        # the problem (but only do this if it doesn't have
                        # one already!)
                        if not re.compile('://').search(value) and None\
                             in self.allowed_schemes:
                            schemeToUse = self.prepend_scheme or 'http'
                            prependTest = self.__call__(schemeToUse
                                     + '://' + value)
                            # if the prepend test succeeded
                            if prependTest[1] is None:
                                # if prepending in the output is enabled
                                if self.prepend_scheme:
                                    return prependTest
                                else:
                                    # else return the original,
                                    #  non-prepended value
                                    return (value, None)
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
        :param allowed_schemes: a list containing strings or None. Each element
            is a scheme the inputed URL is allowed to use
        :param prepend_scheme: a string, this scheme is prepended if it's
            necessary to make the URL valid
        """

        self.error_message = error_message
        if allowed_schemes == None:
            self.allowed_schemes = http_schemes
        else:
            self.allowed_schemes = allowed_schemes
        self.prepend_scheme = prepend_scheme

        for i in self.allowed_schemes:
            if i not in http_schemes:







|







1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
        :param allowed_schemes: a list containing strings or None. Each element
            is a scheme the inputed URL is allowed to use
        :param prepend_scheme: a string, this scheme is prepended if it's
            necessary to make the URL valid
        """

        self.error_message = error_message
        if allowed_schemes is None:
            self.allowed_schemes = http_schemes
        else:
            self.allowed_schemes = allowed_schemes
        self.prepend_scheme = prepend_scheme

        for i in self.allowed_schemes:
            if i not in http_schemes:
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
        """

        try:
            # if the URL passes generic validation
            x = IS_GENERIC_URL(error_message=self.error_message,
                               allowed_schemes=self.allowed_schemes,
                               prepend_scheme=self.prepend_scheme)
            if x(value)[1] == None:
                componentsMatch = url_split_regex.match(value)
                authority = componentsMatch.group(4)
                # if there is an authority component
                if authority:
                    # if authority is a valid IP address
                    if re.compile(
                        "([\w.!~*'|;:&=+$,-]+@)?\d+\.\d+\.\d+\.\d+(:\d*)*$").match(authority):







|







1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
        """

        try:
            # if the URL passes generic validation
            x = IS_GENERIC_URL(error_message=self.error_message,
                               allowed_schemes=self.allowed_schemes,
                               prepend_scheme=self.prepend_scheme)
            if x(value)[1] is None:
                componentsMatch = url_split_regex.match(value)
                authority = componentsMatch.group(4)
                # if there is an authority component
                if authority:
                    # if authority is a valid IP address
                    if re.compile(
                        "([\w.!~*'|;:&=+$,-]+@)?\d+\.\d+\.\d+\.\d+(:\d*)*$").match(authority):
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
                        # abbreviated case: if we haven't already, prepend a
                        # scheme and see if it fixes the problem
                        if not re.compile('://').search(value):
                            schemeToUse = self.prepend_scheme or 'http'
                            prependTest = self.__call__(schemeToUse
                                     + '://' + value)
                            # if the prepend test succeeded
                            if prependTest[1] == None:
                                # if prepending in the output is enabled
                                if self.prepend_scheme:
                                    return prependTest
                                else:
                                    # else return the original, non-prepended
                                    # value
                                    return (value, None)







|







1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
                        # abbreviated case: if we haven't already, prepend a
                        # scheme and see if it fixes the problem
                        if not re.compile('://').search(value):
                            schemeToUse = self.prepend_scheme or 'http'
                            prependTest = self.__call__(schemeToUse
                                     + '://' + value)
                            # if the prepend test succeeded
                            if prependTest[1] is None:
                                # if prepending in the output is enabled
                                if self.prepend_scheme:
                                    return prependTest
                                else:
                                    # else return the original, non-prepended
                                    # value
                                    return (value, None)
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
            except Exception:
                #If we are not able to convert the unicode url into a
                # US-ASCII URL, then the URL is not valid
                return (value, translate(self.error_message))

            methodResult = subMethod(asciiValue)
            #if the validation of the US-ASCII version of the value failed
            if methodResult[1] != None:
                # then return the original input value, not the US-ASCII version
                return (value, methodResult[1])
            else:
                return methodResult


regex_time = re.compile(







|







2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
            except Exception:
                #If we are not able to convert the unicode url into a
                # US-ASCII URL, then the URL is not valid
                return (value, translate(self.error_message))

            methodResult = subMethod(asciiValue)
            #if the validation of the US-ASCII version of the value failed
            if not methodResult[1] is None:
                # then return the original input value, not the US-ASCII version
                return (value, methodResult[1])
            else:
                return methodResult


regex_time = re.compile(
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
        self.error_message = error_message

    def __call__(self, value):
        try:
            ivalue = value
            value = regex_time.match(value.lower())
            (h, m, s) = (int(value.group('h')), 0, 0)
            if value.group('m') != None:
                m = int(value.group('m'))
            if value.group('s') != None:
                s = int(value.group('s'))
            if value.group('d') == 'pm' and 0 < h < 12:
                h = h + 12
            if not (h in range(24) and m in range(60) and s
                     in range(60)):
                raise ValueError\
                    ('Hours or minutes or seconds are outside of allowed range')







|

|







2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
        self.error_message = error_message

    def __call__(self, value):
        try:
            ivalue = value
            value = regex_time.match(value.lower())
            (h, m, s) = (int(value.group('h')), 0, 0)
            if not value.group('m') is None:
                m = int(value.group('m'))
            if not value.group('s') is None:
                s = int(value.group('s'))
            if value.group('d') == 'pm' and 0 < h < 12:
                h = h + 12
            if not (h in range(24) and m in range(60) and s
                     in range(60)):
                raise ValueError\
                    ('Hours or minutes or seconds are outside of allowed range')
2476
2477
2478
2479
2480
2481
2482






2483
2484
2485
2486
2487


2488
2489




2490
2491
2492
2493
2494
2495
2496
    encodes the value on validation with a digest.

    If no arguments are provided CRYPT uses the MD5 algorithm.
    If the key argument is provided the HMAC+MD5 algorithm is used.
    If the digest_alg is specified this is used to replace the
    MD5 with, for example, SHA512. The digest_alg can be
    the name of a hashlib algorithm as a string or the algorithm itself.






    """

    def __init__(self, key=None, digest_alg='md5'):
        self.key = key
        self.digest_alg = digest_alg



    def __call__(self, value):




        if self.key:
            return (hmac_hash(value, self.key, self.digest_alg), None)
        else:
            return (simple_hash(value, self.digest_alg), None)


class IS_STRONG(object):







>
>
>
>
>
>


|


>
>


>
>
>
>







2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
    encodes the value on validation with a digest.

    If no arguments are provided CRYPT uses the MD5 algorithm.
    If the key argument is provided the HMAC+MD5 algorithm is used.
    If the digest_alg is specified this is used to replace the
    MD5 with, for example, SHA512. The digest_alg can be
    the name of a hashlib algorithm as a string or the algorithm itself.
    
    min_length is the minimal password length (default 4) - IS_STRONG for serious security
    error_message is the message if password is too short
    
    Notice that an empty password is accepted but invalid. It will not allow login back.
    Stores junk as hashed password.
    """

    def __init__(self, key=None, digest_alg='md5', min_length=0, error_message='too short'):
        self.key = key
        self.digest_alg = digest_alg
        self.min_length = min_length
        self.error_message = error_message

    def __call__(self, value):
        if not value and self.min_length>0:
            value = web2py_uuid()
        elif len(value)<self.min_length:
            return ('',translate(self.error_message))
        if self.key:
            return (hmac_hash(value, self.key, self.digest_alg), None)
        else:
            return (simple_hash(value, self.digest_alg), None)


class IS_STRONG(object):
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934


            number = 0
            for i, j in zip(self.numbers, value.split('.')):
                number += i * int(j)
            ok = False
            for bottom, top in zip(self.minip, self.maxip):
                if self.invert != (bottom <= number <= top):
                    ok = True
            if not (self.is_localhost == None or self.is_localhost == \
                (number == self.localhost)):
                    ok = False
            if not (self.is_private == None or self.is_private == \
                (sum([number[0] <= number <= number[1] for number in self.private]) > 0)):
                    ok = False
            if not (self.is_automatic == None or self.is_automatic == \
                (self.automatic[0] <= number <= self.automatic[1])):
                    ok = False
            if ok:
                return (value, None)
        return (value, translate(self.error_message))

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










|


|


|










>
>
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
            number = 0
            for i, j in zip(self.numbers, value.split('.')):
                number += i * int(j)
            ok = False
            for bottom, top in zip(self.minip, self.maxip):
                if self.invert != (bottom <= number <= top):
                    ok = True
            if not (self.is_localhost is None or self.is_localhost == \
                (number == self.localhost)):
                    ok = False
            if not (self.is_private is None or self.is_private == \
                (sum([number[0] <= number <= number[1] for number in self.private]) > 0)):
                    ok = False
            if not (self.is_automatic is None or self.is_automatic == \
                (self.automatic[0] <= number <= self.automatic[1])):
                    ok = False
            if ok:
                return (value, None)
        return (value, translate(self.error_message))

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



Added gluon/validators.pyc version [4ee16a78b6].
Modified gluon/widget.py from [1adeccc7f3] to [6fe94e9bd5].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

The widget is called from web2py.
"""

import sys
import cStringIO
import time
import thread
import re
import os
import socket
import signal
import math
import logging

import newcron
import main

from fileutils import w2p_pack, read_file, write_file
from shell import run, test
from settings import global_settings

|




















<







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
#!/-usr/bin/env python
# -*- coding: utf-8 -*-

"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

The widget is called from web2py.
"""

import sys
import cStringIO
import time
import thread
import re
import os
import socket
import signal
import math
import logging

import newcron
import main

from fileutils import w2p_pack, read_file, write_file
from shell import run, test
from settings import global_settings

108
109
110
111
112
113
114


115
116
117
118
119
120
121
122
123
124
125
126
    canvas = Tkinter.Canvas(dialog,
                            background='white',
                            width=500,
                            height=300)
    canvas.pack()
    root.update()



    img = Tkinter.PhotoImage(file='splashlogo.gif')
    pnl = Tkinter.Label(canvas, image=img, background='white', bd=0)
    pnl.pack(side='top', fill='both', expand='yes')
    # Prevent garbage collection of img
    pnl.image=img

    def add_label(text='Change Me', font_size=12, foreground='#195866', height=1):
        return Tkinter.Label(
            master=canvas,
            width=250,
            height=height,
            text=text,







>
>
|
|
|
|
|







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    canvas = Tkinter.Canvas(dialog,
                            background='white',
                            width=500,
                            height=300)
    canvas.pack()
    root.update()

    logo = 'splashlogo.gif'
    if os.path.exists(logo):
        img = Tkinter.PhotoImage(file=logo)
        pnl = Tkinter.Label(canvas, image=img, background='white', bd=0)
        pnl.pack(side='top', fill='both', expand='yes')
        # Prevent garbage collection of img
        pnl.image=img

    def add_label(text='Change Me', font_size=12, foreground='#195866', height=1):
        return Tkinter.Label(
            master=canvas,
            width=250,
            height=height,
            text=text,
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
                      text='Choose Password:',
                      justify=Tkinter.LEFT).grid(row=2,
                                                 column=0,
                                                 sticky=sticky)

        self.password = Tkinter.Entry(self.root, show='*')
        self.password.bind('<Return>', lambda e: self.start())
        self.password.focus_force()
        self.password.grid(row=2, column=1, sticky=sticky)

        # Prepare the canvas
        self.canvas = Tkinter.Canvas(self.root,
                                     width=300,
                                     height=100,
                                     bg='black')







|







218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
                      text='Choose Password:',
                      justify=Tkinter.LEFT).grid(row=2,
                                                 column=0,
                                                 sticky=sticky)

        self.password = Tkinter.Entry(self.root, show='*')
        self.password.bind('<Return>', lambda e: self.start())
        self.password.focus_force() 
        self.password.grid(row=2, column=1, sticky=sticky)

        # Prepare the canvas
        self.canvas = Tkinter.Canvas(self.root,
                                     width=300,
                                     height=100,
                                     bg='black')
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

            try:
                self.tb.Destroy()
            except:
                pass

            self.root.destroy()
            sys.exit()

    def error(self, message):
        """ Show error message """

        tkMessageBox.showerror('web2py start server', message)

    def start(self):







|







318
319
320
321
322
323
324
325
326
327
328
329
330
331
332

            try:
                self.tb.Destroy()
            except:
                pass

            self.root.destroy()
            sys.exit(0)

    def error(self, message):
        """ Show error message """

        tkMessageBox.showerror('web2py start server', message)

    def start(self):
484
485
486
487
488
489
490






491
492
493
494
495
496
497

    parser.add_option('-k',
                      '--ssl_private_key',
                      default='',
                      dest='ssl_private_key',
                      help='file that contains ssl private key')







    parser.add_option('-d',
                      '--pid_filename',
                      default='httpserver.pid',
                      dest='pid_filename',
                      help='file to store the pid of the server')

    parser.add_option('-l',







>
>
>
>
>
>







485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504

    parser.add_option('-k',
                      '--ssl_private_key',
                      default='',
                      dest='ssl_private_key',
                      help='file that contains ssl private key')

    parser.add_option('--ca-cert',
                      action='store',
                      dest='ssl_ca_certificate',
                      default=None,
                      help='Use this file containing the CA certificate to validate X509 certificates from clients')

    parser.add_option('-d',
                      '--pid_filename',
                      default='httpserver.pid',
                      dest='pid_filename',
                      help='file to store the pid of the server')

    parser.add_option('-l',
615
616
617
618
619
620
621









622
623
624
625
626
627
628
    msg += ' should be used with --shell option'
    parser.add_option('-R',
                      '--run',
                      dest='run',
                      metavar='PYTHON_FILE',
                      default='',
                      help=msg)










    msg = 'run doctests in web2py environment; ' +\
        'TEST_PATH like a/c/f (c,f optional)'
    parser.add_option('-T',
                      '--test',
                      dest='test',
                      metavar='TEST_PATH',







>
>
>
>
>
>
>
>
>







622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
    msg += ' should be used with --shell option'
    parser.add_option('-R',
                      '--run',
                      dest='run',
                      metavar='PYTHON_FILE',
                      default='',
                      help=msg)

    msg = 'run scheduled tasks for the specified apps'
    msg += '-K app1,app2,app3'
    msg += 'requires a scheduler defined in the models'
    parser.add_option('-K',
                      '--scheduler',
                      dest='scheduler',
                      default=None,
                      help=msg)

    msg = 'run doctests in web2py environment; ' +\
        'TEST_PATH like a/c/f (c,f optional)'
    parser.add_option('-T',
                      '--test',
                      dest='test',
                      metavar='TEST_PATH',
699
700
701
702
703
704
705

706
707
708
709
710
711
712
713

    parser.add_option('--no-banner',
                      action='store_true',
                      default=False,
                      dest='nobanner',
                      help='Do not print header banner')


    msg = 'listen on multiple addresses: "ip:port:cert:key;ip2:port2:cert2:key2;..." (:cert:key optional; no spaces)'
    parser.add_option('--interfaces',
                      action='store',
                      dest='interfaces',
                      default=None,
                      help=msg)

    if '-A' in sys.argv: k = sys.argv.index('-A')







>
|







715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730

    parser.add_option('--no-banner',
                      action='store_true',
                      default=False,
                      dest='nobanner',
                      help='Do not print header banner')


    msg = 'listen on multiple addresses: "ip:port:cert:key:ca_cert;ip2:port2:cert2:key2:ca_cert2;..." (:cert:key optional; no spaces)'
    parser.add_option('--interfaces',
                      action='store',
                      dest='interfaces',
                      default=None,
                      help=msg)

    if '-A' in sys.argv: k = sys.argv.index('-A')
732
733
734
735
736
737
738
739

740
741
742

743
744
745

746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
























766

767
768
769
770
771
772
773
    if options.cronjob:
        global_settings.cronjob = True  # tell the world
        options.nocron = True   # don't start cron jobs
        options.plain = True    # cronjobs use a plain shell

    options.folder = os.path.abspath(options.folder)

    #  accept --interfaces in the form "ip:port:cert:key;ip2:port2;ip3:port3:cert3:key3"

    #  (no spaces; optional cert:key indicate SSL)
    #
    if isinstance(options.interfaces, str):

        options.interfaces = [interface.split(':') for interface in options.interfaces.split(';')]
        for interface in options.interfaces:
            interface[1] = int(interface[1])    # numeric port

        options.interfaces = [tuple(interface) for interface in options.interfaces]

    if options.numthreads is not None and options.minthreads is None:
        options.minthreads = options.numthreads  # legacy

    if not options.cronjob:
        # If we have the applications package or if we should upgrade
        if not os.path.exists('applications/__init__.py'):
            write_file('applications/__init__.py', '')

        if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'):
            try:
                w2p_pack('welcome.w2p','applications/welcome')
                os.unlink('NEWINSTALL')
            except:
                msg = "New installation: unable to create welcome.w2p file"
                sys.stderr.write(msg)

    return (options, args)



























def start(cron=True):
    """ Start server  """

    # ## get command line arguments

    (options, args) = console()








|
>

<

>
|


>
|



















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>







749
750
751
752
753
754
755
756
757
758

759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
    if options.cronjob:
        global_settings.cronjob = True  # tell the world
        options.nocron = True   # don't start cron jobs
        options.plain = True    # cronjobs use a plain shell

    options.folder = os.path.abspath(options.folder)

    #  accept --interfaces in the form 
    #  "ip:port:cert:key;ip2:port2;ip3:port3:cert3:key3"
    #  (no spaces; optional cert:key indicate SSL)

    if isinstance(options.interfaces, str):
        options.interfaces = [
            interface.split(':') for interface in options.interfaces.split(';')]
        for interface in options.interfaces:
            interface[1] = int(interface[1])    # numeric port
        options.interfaces = [
            tuple(interface) for interface in options.interfaces]

    if options.numthreads is not None and options.minthreads is None:
        options.minthreads = options.numthreads  # legacy

    if not options.cronjob:
        # If we have the applications package or if we should upgrade
        if not os.path.exists('applications/__init__.py'):
            write_file('applications/__init__.py', '')

        if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'):
            try:
                w2p_pack('welcome.w2p','applications/welcome')
                os.unlink('NEWINSTALL')
            except:
                msg = "New installation: unable to create welcome.w2p file"
                sys.stderr.write(msg)

    return (options, args)

def start_schedulers(options):
    apps = [app.strip() for app in options.scheduler.split(',')]
    try:
        from multiprocessing import Process
    except:
        sys.stderr.write('Sorry, -K only supported for python 2.6-2.7\n')
        return
    processes = []
    code = "from gluon import current; current._scheduler.loop()"
    for app in apps:
        print 'starting scheduler for "%s"...' % app
        args = (app,True,True,None,False,code)
        logging.getLogger().setLevel(logging.DEBUG)        
        p = Process(target=run, args=args)
        processes.append(p)
        print "Currently running %s scheduler processes" % (len(processes))
        p.start()
        print "Processes started"
    for p in processes:
        try:
            p.join()
        except KeyboardInterrupt:
            p.terminate()
            p.join()

            
def start(cron=True):
    """ Start server  """

    # ## get command line arguments

    (options, args) = console()

796
797
798
799
800
801
802








803
804
805
806
807
808
809
810
811
812
813
            if hasattr(options,key):
                setattr(options,key,getattr(options2,key))

    # ## if -T run doctests (no cron)
    if hasattr(options,'test') and options.test:
        test(options.test, verbose=options.verbose)
        return









    # ## if -S start interactive shell (also no cron)
    if options.shell:
        if options.args!=None:
            sys.argv[:] = options.args
        run(options.shell, plain=options.plain, bpython=options.bpython,
            import_models=options.import_models, startfile=options.run)
        return

    # ## if -C start cron run (extcron) and exit
    # ## if -N or not cron disable cron in this *process*







>
>
>
>
>
>
>
>



|







840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
            if hasattr(options,key):
                setattr(options,key,getattr(options2,key))

    # ## if -T run doctests (no cron)
    if hasattr(options,'test') and options.test:
        test(options.test, verbose=options.verbose)
        return

    # ## if -K
    if options.scheduler:
        try:
            start_schedulers(options)
        except KeyboardInterrupt:
            pass
        return

    # ## if -S start interactive shell (also no cron)
    if options.shell:
        if not options.args is None:
            sys.argv[:] = options.args
        run(options.shell, plain=options.plain, bpython=options.bpython,
            import_models=options.import_models, startfile=options.run)
        return

    # ## if -C start cron run (extcron) and exit
    # ## if -N or not cron disable cron in this *process*
901
902
903
904
905
906
907

908
909
910
911
912
913
914
915
916
917
918
919
920
921
922


                             port=port,
                             password=options.password,
                             pid_filename=options.pid_filename,
                             log_filename=options.log_filename,
                             profiler_filename=options.profiler_filename,
                             ssl_certificate=options.ssl_certificate,
                             ssl_private_key=options.ssl_private_key,

                             min_threads=options.minthreads,
                             max_threads=options.maxthreads,
                             server_name=options.server_name,
                             request_queue_size=options.request_queue_size,
                             timeout=options.timeout,
                             shutdown_timeout=options.shutdown_timeout,
                             path=options.folder,
                             interfaces=options.interfaces)

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
    logging.shutdown()










>















>
>
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
                             port=port,
                             password=options.password,
                             pid_filename=options.pid_filename,
                             log_filename=options.log_filename,
                             profiler_filename=options.profiler_filename,
                             ssl_certificate=options.ssl_certificate,
                             ssl_private_key=options.ssl_private_key,
                             ssl_ca_certificate=options.ssl_ca_certificate,
                             min_threads=options.minthreads,
                             max_threads=options.maxthreads,
                             server_name=options.server_name,
                             request_queue_size=options.request_queue_size,
                             timeout=options.timeout,
                             shutdown_timeout=options.shutdown_timeout,
                             path=options.folder,
                             interfaces=options.interfaces)

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
    logging.shutdown()



Added gluon/widget.pyc version [5fe6811bf3].
Modified gluon/winservice.py from [e1ec3d2e01] to [c975849a71].
157
158
159
160
161
162
163


164
                serviceClassString=classstring, argv=['', 'install'])
    win32serviceutil.HandleCommandLine(Web2pyService,
            serviceClassString=classstring, argv=argv)


if __name__ == '__main__':
    web2py_windows_service_handler()










>
>

157
158
159
160
161
162
163
164
165
166
                serviceClassString=classstring, argv=['', 'install'])
    win32serviceutil.HandleCommandLine(Web2pyService,
            serviceClassString=classstring, argv=argv)


if __name__ == '__main__':
    web2py_windows_service_handler()



Modified gluon/xmlrpc.py from [ae09470e68] to [1514bfb6b9].
15
16
17
18
19
20
21


22
    dispatcher = SimpleXMLRPCDispatcher(allow_none=True, encoding=None)
    for method in methods:
        dispatcher.register_function(method)
    dispatcher.register_introspection_functions()
    response.headers['Content-Type'] = 'text/xml'
    dispatch = getattr(dispatcher, '_dispatch', None)
    return dispatcher._marshaled_dispatch(request.body.read(), dispatch)










>
>

15
16
17
18
19
20
21
22
23
24
    dispatcher = SimpleXMLRPCDispatcher(allow_none=True, encoding=None)
    for method in methods:
        dispatcher.register_function(method)
    dispatcher.register_introspection_functions()
    response.headers['Content-Type'] = 'text/xml'
    dispatch = getattr(dispatcher, '_dispatch', None)
    return dispatcher._marshaled_dispatch(request.body.read(), dispatch)



Added gluon/xmlrpc.pyc version [6e66be7d0b].
Added isapiwsgihandler.py version [bfc5478b76].
Modified modpythonhandler.py from [72691ad73a] to [416a807373].
218
219
220
221
222
223
224



def handler(req):
    """ Execute the gluon app  """

    Handler(req).run(gluon.main.wsgibase)
    return apache.OK








>
218
219
220
221
222
223
224
225


def handler(req):
    """ Execute the gluon app  """

    Handler(req).run(gluon.main.wsgibase)
    return apache.OK

Modified options_std.py from [2c6b93cdaf] to [52a1ee322a].
27
28
29
30
31
32
33

server_name = socket.gethostname()
request_queue_size = 5
timeout = 30
shutdown_timeout = 5
folder = os.getcwd()
extcron = None
nocron = None








>
27
28
29
30
31
32
33
34
server_name = socket.gethostname()
request_queue_size = 5
timeout = 30
shutdown_timeout = 5
folder = os.getcwd()
extcron = None
nocron = None

Modified router.example.py from [c5219c298b] to [3c04e682e7].
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#    updated by the app-specific router from applications/app/routes.py routers (if any)
#
#
#  Router members:
#
#  default_application: default application name
#  applications: list of all recognized applications, or 'ALL' to use all currently installed applications
#      Names in applications are always treated as an application names when they appear first in an incoming URL.
#      Set applications=None to disable the removal of application names from outgoing URLs.
#  domains: optional dict mapping domain names to application names
#      The domain name can include a port number: domain.com:8080
#      The application name can include a controller:  appx/ctlrx

#      Example:
#      domains = {   "domain.com" : "app",
#                  "x.domain.com" : "appx",
#                },
#  path_prefix: a path fragment that is prefixed to all outgoing URLs and stripped from all incoming URLs
#
#  Note: default_application, applications, domains & path_prefix are permitted only in the BASE router,
#        and domain makes sense only in an application-specific router.
#        The remaining members can appear in the BASE router (as defaults for all applications)
#        or in application-specific routers.
#
#  default_controller: name of default controller
#  default_function: name of default function (in all controllers)

#  controllers: list of valid controllers in selected app
#       or "DEFAULT" to use all controllers in the selected app plus 'static'
#       or None to disable controller-name removal.
#      Names in controllers are always treated as controller names when they appear in an incoming URL after
#      the (optional) application and language names. 
#  functions: list of valid functions in the default controller (default None)

#      If present, the default function name will be omitted when the controller is the default controller
#      and the first arg does not create an ambiguity.
#  languages: list of all supported languages
#      Names in languages are always treated as language names when they appear in an incoming URL after
#      the (optional) application name. 
#  default_language
#       The language code (for example: en, it-it) optionally appears in the URL following
#       the application (which may be omitted). For incoming URLs, the code is copied to
#       request.language; for outgoing URLs it is taken from request.language.
#       If languages=None, language support is disabled.
#       The default_language, if any, is omitted from the URL.
#  root_static: list of static files accessed from root (by default, favicon.ico & robots.txt)
#       (mapped to the default application's static/ directory)
#       Each default (including domain-mapped) application has its own root-static files.
#  domain: the domain that maps to this application (alternative to using domains in the BASE router)
#  exclusive_domain: If True (default is False), an exception is raised if an attempt is made to generate
#                    an outgoing URL with a different application without providing an explicit host.
#  map_hyphen: If True (default is False), hyphens in incoming /a/c/f fields are converted 
#              to underscores, and back to hyphens in outgoing URLs.
#              Language, args and the query string are not affected.
#  map_static: By default, the default application is not stripped from static URLs. 
#       Set map_static=True to override this policy.
#  acfe_match: regex for valid application, controller, function, extension /a/c/f.e
#  file_match: regex for valid file (used for static file names)
#  args_match: regex for valid args
#       This validation provides a measure of security. 
#       If it is changed, the application perform its own validation.
#
#
#  The built-in default router supplies default values (undefined members are None):
#
#     default_router = dict(
#         default_application = 'init',







|
|

|
|
>
|
|

|








|
>




|
|
>
|
|

|
|











|
|
|
|
|




|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#    updated by the app-specific router from applications/app/routes.py routers (if any)
#
#
#  Router members:
#
#  default_application: default application name
#  applications: list of all recognized applications, or 'ALL' to use all currently installed applications
#       Names in applications are always treated as an application names when they appear first in an incoming URL.
#       Set applications=None to disable the removal of application names from outgoing URLs.
#  domains: optional dict mapping domain names to application names
#       The domain name can include a port number: domain.com:8080
#       The application name can include a controller:  appx/ctlrx
#           or a controller and a function: appx/ctlrx/fcnx
#       Example:
#       domains = {   "domain.com" : "app",
#                  "x.domain.com" : "appx",
#                 },
#  path_prefix: a path fragment that is prefixed to all outgoing URLs and stripped from all incoming URLs
#
#  Note: default_application, applications, domains & path_prefix are permitted only in the BASE router,
#        and domain makes sense only in an application-specific router.
#        The remaining members can appear in the BASE router (as defaults for all applications)
#        or in application-specific routers.
#
#  default_controller: name of default controller
#  default_function: name of default function (in all controllers) or dictionary of default functions
#       by controller
#  controllers: list of valid controllers in selected app
#       or "DEFAULT" to use all controllers in the selected app plus 'static'
#       or None to disable controller-name removal.
#      Names in controllers are always treated as controller names when they appear in an incoming URL after
#      the (optional) application and language names.
#  functions: list of valid functions in the default controller (default None) or dictionary of valid
#       functions by controller.
#       If present, the default function name will be omitted when the controller is the default controller
#       and the first arg does not create an ambiguity.
#  languages: list of all supported languages
#       Names in languages are always treated as language names when they appear in an incoming URL after
#       the (optional) application name.
#  default_language
#       The language code (for example: en, it-it) optionally appears in the URL following
#       the application (which may be omitted). For incoming URLs, the code is copied to
#       request.language; for outgoing URLs it is taken from request.language.
#       If languages=None, language support is disabled.
#       The default_language, if any, is omitted from the URL.
#  root_static: list of static files accessed from root (by default, favicon.ico & robots.txt)
#       (mapped to the default application's static/ directory)
#       Each default (including domain-mapped) application has its own root-static files.
#  domain: the domain that maps to this application (alternative to using domains in the BASE router)
#  exclusive_domain: If True (default is False), an exception is raised if an attempt is made to generate
#       an outgoing URL with a different application without providing an explicit host.
#  map_hyphen: If True (default is False), hyphens in incoming /a/c/f fields are converted
#       to underscores, and back to hyphens in outgoing URLs.
#       Language, args and the query string are not affected.
#  map_static: By default, the default application is not stripped from static URLs.
#       Set map_static=True to override this policy.
#  acfe_match: regex for valid application, controller, function, extension /a/c/f.e
#  file_match: regex for valid file (used for static file names)
#  args_match: regex for valid args
#       This validation provides a measure of security.
#       If it is changed, the application perform its own validation.
#
#
#  The built-in default router supplies default values (undefined members are None):
#
#     default_router = dict(
#         default_application = 'init',
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

    '/appadmin'
    >>> filter_url('http://domain.com/welcome/default/fcn?query', out=True)
    '/fcn?query'
    >>> filter_url('http://domain.com/welcome/default/fcn#anchor', out=True)
    '/fcn#anchor'
    >>> filter_url('http://domain.com/welcome/default/fcn?query#anchor', out=True)
    '/fcn?query#anchor'
    
    >>> filter_err(200)
    200
    >>> filter_err(399)
    399
    >>> filter_err(400)
    400
    '''
    pass

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








|












>
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
    '/appadmin'
    >>> filter_url('http://domain.com/welcome/default/fcn?query', out=True)
    '/fcn?query'
    >>> filter_url('http://domain.com/welcome/default/fcn#anchor', out=True)
    '/fcn#anchor'
    >>> filter_url('http://domain.com/welcome/default/fcn?query#anchor', out=True)
    '/fcn?query#anchor'

    >>> filter_err(200)
    200
    >>> filter_err(399)
    399
    >>> filter_err(400)
    400
    '''
    pass

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

Modified routes.example.py from [1f6aac3108] to [65d7dd7768].
159
160
161
162
163
164
165

    '/init/\\\\g<c>/\\\\g<f>'
    '''
    pass

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








>
159
160
161
162
163
164
165
166
    '/init/\\\\g<c>/\\\\g<f>'
    '''
    pass

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

Modified scgihandler.py from [4e7a23db5a] to [dbbd6de105].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
scgihandler.py - handler for SCGI protocol

Modified by Michele Comitini <michele.comitini@glisco.it>
from fcgihandler.py to support SCGI

fcgihandler has the following copyright:
" This file is part of the web2py Web Framework
  Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
  License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) 
"
                                                                            
This is a handler for lighttpd+scgi
This file has to be in the PYTHONPATH
Put something like this in the lighttpd.conf file:

server.document-root="/var/www/web2py/"
# for >= linux-2.6
server.event-handler = "linux-sysepoll"












|

|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
scgihandler.py - handler for SCGI protocol

Modified by Michele Comitini <michele.comitini@glisco.it>
from fcgihandler.py to support SCGI

fcgihandler has the following copyright:
" This file is part of the web2py Web Framework
  Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
  License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
"

This is a handler for lighttpd+scgi
This file has to be in the PYTHONPATH
Put something like this in the lighttpd.conf file:

server.document-root="/var/www/web2py/"
# for >= linux-2.6
server.event-handler = "linux-sysepoll"
65
66
67
68
69
70
71

if SOFTCRON:
    from gluon.settings import global_settings
    global_settings.web2py_crontype = 'soft'

# uncomment one of the two rows below depending on the SCGIWSGI server installed
#scgi.serve_application(application, '', 4000).run()
SCGIServer(application, port=4000).run()








>
65
66
67
68
69
70
71
72
if SOFTCRON:
    from gluon.settings import global_settings
    global_settings.web2py_crontype = 'soft'

# uncomment one of the two rows below depending on the SCGIWSGI server installed
#scgi.serve_application(application, '', 4000).run()
SCGIServer(application, port=4000).run()

Added scripts/cleanjs.py version [39f912b954].
Added scripts/dbsessions2trash.py version [2744c716b7].
Added scripts/make_min_web2py.py version [985a57dae4].
Added scripts/sessions2trash.py version [7405bf23ba].
Added scripts/standalone_exe_cxfreeze.py version [b8ce9fd231].
Added scripts/update_web2py.py version [15d639cdcd].
Modified scripts/web2py.fedora.sh from [f5d343a911] to [1f7bae23e0].
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
	fi
	echo
	return $RETVAL
}

stop() {
	echo -n $"Shutting down $DESC ($NAME): "
	if [ -r "$PIDFILE" ]; then
		pid=`cat $PIDFILE`
		kill -TERM $pid
		RETVAL=$?
	else
		RETVAL=1
	fi
	[ $RETVAL -eq 0 ] && success || failure
	echo
	if [ $RETVAL -eq 0 ]; then
		rm -f /var/lock/subsys/$NAME
		rm -f $PIDFILE
	fi
	return $RETVAL
}







|
<
<
<
<
<
<
<







36
37
38
39
40
41
42
43







44
45
46
47
48
49
50
	fi
	echo
	return $RETVAL
}

stop() {
	echo -n $"Shutting down $DESC ($NAME): "
	killproc -p "$PIDFILE" -d 3 "$NAME"







	echo
	if [ $RETVAL -eq 0 ]; then
		rm -f /var/lock/subsys/$NAME
		rm -f $PIDFILE
	fi
	return $RETVAL
}
Modified setup.py from [e143c2d3be] to [7163108957].
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
                    'gluon/contrib/pymysql',
                    'gluon/contrib/pyrtf',
                    'gluon/contrib/pysimplesoap',
                    'gluon/contrib/simplejson',
                    'gluon/tests',
                    ],
          package_data = {'gluon':['env.tar']},
          scripts = ['mkweb2pyenv','runweb2py'],
          )
    
if __name__ == '__main__':
    print "web2py does not require installation and"
    print "you should just start it with:"
    print 
    print "$ python web2py.py"
    print 
    print "are you sure you want to install it anyway (y/n)?"
    s = raw_input('>')
    if s.lower()[:1]=='y':
        start()
        







|



|
|
|
|
|
|
|
|
|

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
                    'gluon/contrib/pymysql',
                    'gluon/contrib/pyrtf',
                    'gluon/contrib/pysimplesoap',
                    'gluon/contrib/simplejson',
                    'gluon/tests',
                    ],
          package_data = {'gluon':['env.tar']},
          scripts = ['w2p_apps','w2p_run','w2p_clone'],
          )
    
if __name__ == '__main__':
    #print "web2py does not require installation and"
    #print "you should just start it with:"
    #print 
    #print "$ python web2py.py"
    #print 
    #print "are you sure you want to install it anyway (y/n)?"
    #s = raw_input('>')
    #if s.lower()[:1]=='y':
    start()
        
Modified setup_app.py from [f5b77e5447] to [b03e3576c0].
48
49
50
51
52
53
54

          [x for x in reglob('applications/admin')],
      options={'py2app': {
            'argv_emulation': True,
            'includes': base_modules,
            'packages': contributed_modules,
            }},
      setup_requires=['py2app'])








>
48
49
50
51
52
53
54
55
          [x for x in reglob('applications/admin')],
      options={'py2app': {
            'argv_emulation': True,
            'includes': base_modules,
            'packages': contributed_modules,
            }},
      setup_requires=['py2app'])

Modified setup_exe.py from [cc0ba04b6a] to [8533c30924].
178
179
180
181
182
183
184


#final info
if not make_zip and not remove_build_files:
    print "Your Windows binary & associated files can also be found in /dist"

print "Finished!"
print "Enjoy web2py " +web2py_version_line








>
178
179
180
181
182
183
184
185

#final info
if not make_zip and not remove_build_files:
    print "Your Windows binary & associated files can also be found in /dist"

print "Finished!"
print "Enjoy web2py " +web2py_version_line

Modified setup_exe_2.6.py from [8ed272e097] to [5c9c529861].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Usage:
    Install py2exe: http://sourceforge.net/projects/py2exe/files/
    Copy script to the web2py directory
    c:\bin\python26\python build_windows_exe.py py2exe
    
Adapted from http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/view/head:/static/scripts/tools/standalone_exe.py
"""

from distutils.core import setup
import py2exe
from gluon.import_all import base_modules, contributed_modules
from glob import glob








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Usage:
    Install py2exe: http://sourceforge.net/projects/py2exe/files/
    Copy script to the web2py directory
    c:\bin\python26\python build_windows_exe.py py2exe

Adapted from http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/view/head:/static/scripts/tools/standalone_exe.py
"""

from distutils.core import setup
import py2exe
from gluon.import_all import base_modules, contributed_modules
from glob import glob
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#I don't know if this is even necessary
if python_version == '2.6':
    # Python26 compatibility: http://www.py2exe.org/index.cgi/Tutorial#Step52
    try:
        shutil.copytree('C:\Bin\Microsoft.VC90.CRT', 'dist/')
    except:
        print "You MUST copy Microsoft.VC90.CRT folder into the dist directory"
        
#read web2py version from VERSION file
web2py_version_line = readlines_file('VERSION')[0]
#use regular expression to get just the version number
v_re = re.compile('[0-9]+\.[0-9]+\.[0-9]+')
web2py_version = v_re.search(web2py_version_line).group(0)

setup(







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#I don't know if this is even necessary
if python_version == '2.6':
    # Python26 compatibility: http://www.py2exe.org/index.cgi/Tutorial#Step52
    try:
        shutil.copytree('C:\Bin\Microsoft.VC90.CRT', 'dist/')
    except:
        print "You MUST copy Microsoft.VC90.CRT folder into the dist directory"

#read web2py version from VERSION file
web2py_version_line = readlines_file('VERSION')[0]
#use regular expression to get just the version number
v_re = re.compile('[0-9]+\.[0-9]+\.[0-9]+')
web2py_version = v_re.search(web2py_version_line).group(0)

setup(
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
delete_ms_files = raw_input("Delete API-MS-Win-* files that are probably unsafe for distribution? (Y/n) ")
if delete_ms_files.lower().startswith("y"):
    print "Deleted Microsoft files not licensed for open source distribution"
    print "You are still responsible for making sure you have the rights to distribute any other included files!"
    #delete the API-MS-Win-Core DLLs
    for f in glob ('dist/API-MS-Win-*.dll'):
        os.unlink (f)
    #then delete some other files belonging to Microsoft    
    other_ms_files = ['KERNELBASE.dll', 'MPR.dll', 'MSWSOCK.dll', 'POWRPROF.dll']
    for f in other_ms_files:
        try:
            os.unlink(os.path.join('dist',f))
        except:
            print "unable to delete dist/"+f
            sys.exit(1)







|







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
delete_ms_files = raw_input("Delete API-MS-Win-* files that are probably unsafe for distribution? (Y/n) ")
if delete_ms_files.lower().startswith("y"):
    print "Deleted Microsoft files not licensed for open source distribution"
    print "You are still responsible for making sure you have the rights to distribute any other included files!"
    #delete the API-MS-Win-Core DLLs
    for f in glob ('dist/API-MS-Win-*.dll'):
        os.unlink (f)
    #then delete some other files belonging to Microsoft
    other_ms_files = ['KERNELBASE.dll', 'MPR.dll', 'MSWSOCK.dll', 'POWRPROF.dll']
    for f in other_ms_files:
        try:
            os.unlink(os.path.join('dist',f))
        except:
            print "unable to delete dist/"+f
            sys.exit(1)
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#Offer to copy project's site-packages into dist/site-packages
copy_apps = raw_input("Include your web2py site-packages & scripts folders? (Y/n) ")
if copy_apps.lower().startswith("y"):
    #copy site-packages
    if os.path.exists('dist/site-packages')
        shutil.rmtree('dist/site-packages')
    shutil.copytree('site-packages', 'dist/site-packages')
    #copy scripts 
    if os.path.exists('dist/scripts'):
        shutil.rmtree('dist/scripts')
    shutil.copytree('scripts', 'dist/scripts')
else:
    #no worries, web2py will create the (empty) folder first run
    print "Skipping site-packages & scripts"
    pass
    

print ""

#borrowed from http://bytes.com/topic/python/answers/851018-how-zip-directory-python-using-zipfile
def recursive_zip(zipf, directory, folder = ""):
   for item in os.listdir(directory):
      if os.path.isfile(os.path.join(directory, item)):







|







|







109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#Offer to copy project's site-packages into dist/site-packages
copy_apps = raw_input("Include your web2py site-packages & scripts folders? (Y/n) ")
if copy_apps.lower().startswith("y"):
    #copy site-packages
    if os.path.exists('dist/site-packages')
        shutil.rmtree('dist/site-packages')
    shutil.copytree('site-packages', 'dist/site-packages')
    #copy scripts
    if os.path.exists('dist/scripts'):
        shutil.rmtree('dist/scripts')
    shutil.copytree('scripts', 'dist/scripts')
else:
    #no worries, web2py will create the (empty) folder first run
    print "Skipping site-packages & scripts"
    pass


print ""

#borrowed from http://bytes.com/topic/python/answers/851018-how-zip-directory-python-using-zipfile
def recursive_zip(zipf, directory, folder = ""):
   for item in os.listdir(directory):
      if os.path.isfile(os.path.join(directory, item)):
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

    zipf = zipfile.ZipFile("web2py_win.zip", "w", compression=zipfile.ZIP_DEFLATED )
    path = 'zip_temp' #just temp so the web2py directory is included in our zip file
    recursive_zip(zipf, path) #leave the first folder as None, as path is root.
    zipf.close()
    shutil.rmtree('zip_temp')
    print "Your Windows binary version of web2py can be found in web2py_win.zip"
    print "You may extract the archive anywhere and then run web2py/web2py.exe"
    
    # offer to clear up
    print "Since you created a zip file you likely do not need the build, deposit and dist folders used while building binary."
    clean_up_files = raw_input("Delete these un-necessary folders/files? (Y/n) ")
    if clean_up_files.lower().startswith("y"):
        shutil.rmtree('build')
        shutil.rmtree('deposit')
        shutil.rmtree('dist')
    else:
        print "Your Windows binary & associated files can also be found in /dist"
else:
    #Didn't want zip file created
    print ""
    print "Creation of web2py Windows binary completed."
    print "You should copy the /dist directory and its contents." 
    print "To run use web2py.exe"
print "Finished!"
print "Enjoy web2py " +web2py_version_line








|













|



>
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    zipf = zipfile.ZipFile("web2py_win.zip", "w", compression=zipfile.ZIP_DEFLATED )
    path = 'zip_temp' #just temp so the web2py directory is included in our zip file
    recursive_zip(zipf, path) #leave the first folder as None, as path is root.
    zipf.close()
    shutil.rmtree('zip_temp')
    print "Your Windows binary version of web2py can be found in web2py_win.zip"
    print "You may extract the archive anywhere and then run web2py/web2py.exe"

    # offer to clear up
    print "Since you created a zip file you likely do not need the build, deposit and dist folders used while building binary."
    clean_up_files = raw_input("Delete these un-necessary folders/files? (Y/n) ")
    if clean_up_files.lower().startswith("y"):
        shutil.rmtree('build')
        shutil.rmtree('deposit')
        shutil.rmtree('dist')
    else:
        print "Your Windows binary & associated files can also be found in /dist"
else:
    #Didn't want zip file created
    print ""
    print "Creation of web2py Windows binary completed."
    print "You should copy the /dist directory and its contents."
    print "To run use web2py.exe"
print "Finished!"
print "Enjoy web2py " +web2py_version_line

Modified web2py.py from [a779743757] to [e074945d06].
12
13
14
15
16
17
18

19


sys.path = [path]+[p for p in sys.path if not p==path]

# import gluon.import_all ##### This should be uncommented for py2exe.py
import gluon.widget

# Start Web2py and Web2py cron service!

gluon.widget.start(cron=True)








>
|
>
12
13
14
15
16
17
18
19
20
21

sys.path = [path]+[p for p in sys.path if not p==path]

# import gluon.import_all ##### This should be uncommented for py2exe.py
import gluon.widget

# Start Web2py and Web2py cron service!
if __name__ == '__main__':
    gluon.widget.start(cron=True)

Deleted web2py_src.zip version [b21e798e47].
Modified wsgihandler.py from [7a279d863a] to [a67672ef28].
38
39
40
41
42
43
44

                                        profilerfilename=None)
else:
    application = gluon.main.wsgibase

if SOFTCRON:
    from gluon.settings import global_settings
    global_settings.web2py_crontype = 'soft'








>
38
39
40
41
42
43
44
45
                                        profilerfilename=None)
else:
    application = gluon.main.wsgibase

if SOFTCRON:
    from gluon.settings import global_settings
    global_settings.web2py_crontype = 'soft'