eval(WsgiApplication)

G

gert

I would like to read the following from a text file

from json import loads
from gert.db import Db
def application(environ, response):
v = loads(environ['wsgi.input'].read(int(environ
['CONTENT_LENGTH'])).decode('utf-8'))
db = Db()
db.execute('UPDATE votes SET count=count+1 WHERE vid=?',(v
['vid'],))
db.execute('SELECT * FROM votes')
j = '{"rec":'+db.json()+',\n'
j+= ' "des":'+db.jdes()+'}'
j = j.encode('utf-8')
response('200 OK', [('Content-type', 'text/
javascript;charset=utf-8'), ('Content-Length', str(len(j)))])
return [j]

execute it, and wrap a new function name around it for example

def wrapper(environ, response):
exec(file)
return application(environ, response)

How do I do this in python3?
 
A

Arnaud Delobelle

gert said:
I would like to read the following from a text file

from json import loads
from gert.db import Db
def application(environ, response):
v = loads(environ['wsgi.input'].read(int(environ
['CONTENT_LENGTH'])).decode('utf-8'))
db = Db()
db.execute('UPDATE votes SET count=count+1 WHERE vid=?',(v
['vid'],))
db.execute('SELECT * FROM votes')
j = '{"rec":'+db.json()+',\n'
j+= ' "des":'+db.jdes()+'}'
j = j.encode('utf-8')
response('200 OK', [('Content-type', 'text/
javascript;charset=utf-8'), ('Content-Length', str(len(j)))])
return [j]

execute it, and wrap a new function name around it for example

def wrapper(environ, response):
exec(file)
return application(environ, response)

How do I do this in python3?

What's wrong with importing it?
 
P

paul

gert said:
I would like to read the following from a text file
Hi gert,

I'm puzzled, what is wrong with using wsgi as advertised? Just import
your code and insert it in the wsgi chain no?

cheers
Paul
from json import loads
from gert.db import Db
def application(environ, response):
v = loads(environ['wsgi.input'].read(int(environ
['CONTENT_LENGTH'])).decode('utf-8'))
db = Db()
db.execute('UPDATE votes SET count=count+1 WHERE vid=?',(v
['vid'],))
db.execute('SELECT * FROM votes')
j = '{"rec":'+db.json()+',\n'
j+= ' "des":'+db.jdes()+'}'
j = j.encode('utf-8')
response('200 OK', [('Content-type', 'text/
javascript;charset=utf-8'), ('Content-Length', str(len(j)))])
return [j]

execute it, and wrap a new function name around it for example

def wrapper(environ, response):
exec(file)
return application(environ, response)

How do I do this in python3?
 
G

gert

gert said:
I would like to read the following from a text file
from json import loads
from gert.db import Db
def application(environ, response):
    v = loads(environ['wsgi.input'].read(int(environ
['CONTENT_LENGTH'])).decode('utf-8'))
    db = Db()
    db.execute('UPDATE votes SET count=count+1 WHERE vid=?',(v
['vid'],))
    db.execute('SELECT * FROM votes')
    j = '{"rec":'+db.json()+',\n'
    j+= ' "des":'+db.jdes()+'}'
    j = j.encode('utf-8')
    response('200 OK', [('Content-type', 'text/
javascript;charset=utf-8'), ('Content-Length', str(len(j)))])
    return [j]
execute it, and wrap a new function name around it for example
def wrapper(environ, response):
     exec(file)
     return application(environ, response)
How do I do this in python3?

What's wrong with importing it?

The problem is that my wsgi files have a wsgi extention for mod_wsgi
use

package
- __init__.py
- session.py
- db.py
- sqlite
- - sql.db
- www
- - test.htm
- - test.css
- - test.js
- - test.wsgi

i would like to make this package work both in mod_wsgi and cherrypy
server
mod_wsgi has a .wsgi handler because it is recommended to rename the
wsgi file with wsgi extensions to avoid double imports
cherrypy server has a dispatcher class
 
Ð

Дамјан ГеоргиевÑки

How do I do this in python3?
The problem is that my wsgi files have a wsgi extention for mod_wsgi
use ...
mod_wsgi has a .wsgi handler because it is recommended to rename the
wsgi file with wsgi extensions to avoid double imports
cherrypy server has a dispatcher class


You can either use .py extension for the wsgi files OR use a custom
importer that can import your .wsgi files
http://docs.python.org/library/modules.html
 
G

gert

You can either use .py extension for the wsgi files OR use a custom
importer that can import your .wsgi fileshttp://docs.python.org/library/modules.html

--
дамјан (http://softver.org.mk/damjan/)

Scarlett Johansson: You always see the glass half-empty.
Woody Allen: No. I see the glass half-full, but of poison.

I stick with the .py files thank you :)
 
G

Graham Dumpleton

You can either use .py extension for the wsgi files OR use a custom
importer that can import your .wsgi fileshttp://docs.python.org/library/modules.html

You don't have to go to such an extreme if it is only for one file to
be used as root WSGI application. Can use something like:

def load_script(filename, label='__wsgi__'):
module = imp.new_module(label)
module.__file__ = filename
execfile(filename, module.__dict__)
return module

module = load_script('/some/path/file.wsgi')

application = module.application

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,160
Latest member
KieranKisc

Latest Threads

Top