Skip to content

Commit

Permalink
fixws and 'new' button in grid query
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Dec 5, 2011
1 parent 01f6f82 commit d281acb
Show file tree
Hide file tree
Showing 305 changed files with 8,352 additions and 8,032 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Version 1.99.3 (2011-12-05 11:26:15) dev
Version 1.99.3 (2011-12-05 11:39:10) dev
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@




55 changes: 28 additions & 27 deletions anyserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,17 @@ def gnuicorn(app,address, **options):
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()),
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:
Expand All @@ -161,37 +161,37 @@ 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.
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

# 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

# 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
Expand All @@ -211,44 +211,44 @@ def mongrel2_handler(application,conn,debug=False):
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 responses
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 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)
data = "%s\r\n\r\n%s" % (data, errors)
conn.reply_http(req, data, code = code, status = status, headers = headers)

def main():
Expand Down Expand Up @@ -298,3 +298,4 @@ def main():
if __name__=='__main__':
main()


1 change: 1 addition & 0 deletions appengine_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ def webapp_add_wsgi_middleware(app):
app = recording.appstats_wsgi_middleware(app)
return app


12 changes: 7 additions & 5 deletions applications/admin/controllers/appadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def GetInHMS(seconds):
seconds = math.floor(seconds)

return (hours, minutes, seconds)

for key, value in cache.ram.storage.items():
if isinstance(value, dict):
ram['hits'] = value['hit_total'] - value['misses']
Expand Down Expand Up @@ -388,7 +388,7 @@ def GetInHMS(seconds):
if value[0] < disk['oldest']:
disk['oldest'] = value[0]
disk['keys'].append((key, GetInHMS(time.time() - value[0])))

finally:
portalocker.unlock(locker)
locker.close()
Expand Down Expand Up @@ -417,14 +417,16 @@ def GetInHMS(seconds):
def key_table(keys):
return TABLE(
TR(TD(B('Key')), TD(B('Time in Cache (h:m:s)'))),
*[TR(TD(k[0]), TD('%02d:%02d:%02d' % k[1])) for k in keys],
*[TR(TD(k[0]), TD('%02d:%02d:%02d' % k[1])) for k in keys],
**dict(_class='cache-keys',
_style="border-collapse: separate; border-spacing: .5em;"))

ram['keys'] = key_table(ram['keys'])
disk['keys'] = key_table(disk['keys'])
total['keys'] = key_table(total['keys'])

return dict(form=form, total=total,
ram=ram, disk=disk, object_stats=hp != False)



2 changes: 2 additions & 0 deletions applications/admin/controllers/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ def reset():
session['debug_commands:'+app] = []
return 'done'



26 changes: 14 additions & 12 deletions applications/admin/controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def uninstall():
else:
session.flash = T('no permission to uninstall "%s"', app)
redirect(URL('site'))
if app_uninstall(app, request):
if app_uninstall(app, request):
session.flash = T('application "%s" uninstalled', app)
else:
session.flash = T('unable to uninstall "%s"', app)
Expand Down Expand Up @@ -946,7 +946,7 @@ def create_file():
raise SyntaxError

msg = T('This is the %(filename)s template',
dict(filename=filename))
dict(filename=filename))
if extension == 'html':
text = dedent("""
{{extend 'layout.html'}}
Expand All @@ -958,7 +958,7 @@ def create_file():
text = read_file(generic)
else:
text = ''

elif path[-9:] == '/modules/':
if request.vars.plugin and not filename.startswith('plugin_%s/' % request.vars.plugin):
filename = 'plugin_%s/%s' % (request.vars.plugin, filename)
Expand Down Expand Up @@ -1103,27 +1103,27 @@ def errors():
decorated.sort(key=operator.itemgetter(0), reverse=True)

return dict(errors = [x[1] for x in decorated], app=app, method=method)

elif method == 'dbnew':
errors_path = apath('%s/errors' % app, r=request)
tk_db, tk_table = get_ticket_storage(app)

delete_hashes = []
for item in request.vars:
if item[:7] == 'delete_':
delete_hashes.append(item[7:])

hash2error = dict()

for fn in tk_db(tk_table.id>0).select():
try:
error = pickle.loads(fn.ticket_data)
except AttributeError:
tk_db(tk_table.id == fn.id).delete()
tk_db.commit()

hash = hashlib.md5(error['traceback']).hexdigest()

if hash in delete_hashes:
tk_db(tk_table.id == fn.id).delete()
tk_db.commit()
Expand All @@ -1140,9 +1140,9 @@ def errors():
hash=hash,ticket=fn.ticket_id)

decorated = [(x['count'], x) for x in hash2error.values()]

decorated.sort(key=operator.itemgetter(0), reverse=True)

return dict(errors = [x[1] for x in decorated], app=app, method=method)

elif method == 'dbold':
Expand All @@ -1153,7 +1153,7 @@ def errors():
tk_db.commit()
tickets_ = tk_db(tk_table.id>0).select(tk_table.ticket_id, tk_table.created_datetime, orderby=~tk_table.created_datetime)
tickets = [row.ticket_id for row in tickets_]
times = dict([(row.ticket_id, row.created_datetime) for row in tickets_])
times = dict([(row.ticket_id, row.created_datetime) for row in tickets_])

return dict(app=app, tickets=tickets, method=method, times=times)

Expand Down Expand Up @@ -1323,7 +1323,7 @@ def twitter():
def user():
if MULTI_USER_MODE:
if not db(db.auth_user).count():
auth.settings.registration_requires_approval = False
auth.settings.registration_requires_approval = False
return dict(form=auth())
else:
return dict(form=T("Disabled"))
Expand All @@ -1333,3 +1333,5 @@ def reload_routes():
import gluon.rewrite
gluon.rewrite.load()
redirect(URL('site'))


6 changes: 4 additions & 2 deletions applications/admin/controllers/gae.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import signal
import os
import shutil
from gluon.fileutils import read_file, write_file
from gluon.fileutils import read_file, write_file
except:
session.flash='sorry, only on Unix systems'
redirect(URL(request.application,'default','site'))
Expand Down Expand Up @@ -53,7 +53,7 @@ def deploy():
yaml = apath('../app.yaml', r=request)
if not os.path.exists(yaml):
example = apath('../app.example.yaml', r=request)
shutil.copyfile(example,yaml)
shutil.copyfile(example,yaml)
data = read_file(yaml)
data = re.sub('application:.*','application: %s' % form.vars.google_application_id,data)
data = regex.sub('(applications/(%s)/.*)|' % '|'.join(ignore_apps),data)
Expand Down Expand Up @@ -85,3 +85,5 @@ def callback():
except:
errors=''
return (output+errors).replace('\n','<br/>')


2 changes: 2 additions & 0 deletions applications/admin/controllers/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ def revision():
desc=ctx.description(),
form=form
)


2 changes: 2 additions & 0 deletions applications/admin/controllers/plugin_jqmobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ def index():

def about():
return locals()


2 changes: 2 additions & 0 deletions applications/admin/controllers/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ def reset():
session['commands:'+app] = []
session['history:'+app] = gluon.contrib.shell.History()
return 'done'


6 changes: 4 additions & 2 deletions applications/admin/controllers/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def profiler():
size = 0
if os.path.exists(filename):
data = read_file('profiler.log','rb')
if size<len(data):
if size<len(data):
data = data[size:]
else:
else:
size=0
size += len(data)
response.cookies[KEY] = size
return data


12 changes: 7 additions & 5 deletions applications/admin/controllers/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def make_table(table,fields):
'text':'text','file':'upload','image':'upload',
'upload':'upload','wiki':'text', 'html':'text'}
for key,t in deftypes.items():
if key in has:
if key in has:
ftype = t
if refs:
key = refs[0]
Expand Down Expand Up @@ -458,7 +458,7 @@ def create(options):
fn = 'web2py.plugin.layout_%s.w2p' % params['layout_theme']
theme = urllib.urlopen(LAYOUTS_APP+'/static/plugin_layouts/plugins/'+fn)
plugin_install(app, theme, request, fn)
except:
except:
session.flash = T("unable to download layout")

### apply plugins
Expand All @@ -467,9 +467,9 @@ def create(options):
plugin_name = 'web2py.plugin.'+plugin+'.w2p'
stream = urllib.urlopen(PLUGINS_APP+'/static/'+plugin_name)
plugin_install(app, stream, request, plugin_name)
except Exception, e:
except Exception, e:
session.flash = T("unable to download plugin: %s" % plugin)

### write configuration file into newapp/models/0.py
model = os.path.join(request.folder,'..',app,'models','0.py')
file = open(model, 'wb')
Expand Down Expand Up @@ -547,5 +547,7 @@ def call(): return service()

if options.erase_database:
path = os.path.join(request.folder,'..',app,'databases','*')
for file in glob.glob(path):
for file in glob.glob(path):
os.unlink(file)


1 change: 1 addition & 0 deletions applications/admin/cron/crontab
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
10 * * * * root **applications/admin/cron/expire_sessions.py

2 changes: 2 additions & 0 deletions applications/admin/cron/expire_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
os.unlink(fullpath)
except:
logging.exception('failure to check %s'%fullpath)


2 changes: 2 additions & 0 deletions applications/admin/languages/af.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@
'views': 'views',
'web2py Recent Tweets': 'web2py Onlangse Tweets',
}


Loading

0 comments on commit d281acb

Please sign in to comment.