473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

locawapp-001.zip

LocaWapp: localhost web applications V.0.0.1 (2005 Dec 10)

Copyright (C) 2005 RDJ
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.

http://LocaWapp.blogspot.com
----------------------------
- Run with:

python run.py

- or:

python run.py 8081

- and browse with:

http://localhost:8080/locawapp/main.py

- or:

http://localhost:8081/locawapp/main.py

- If this is good for you, then you can help me developing with:

HTML + CSS + JS + PYTHON = LocaWapp
-----------------------------------
- Put your application in root:

[your_application]
[locawapp]
.....__init__.py
.....common.py
.....main.py
.....[static]
.........logo.gif
.........main.css
.........main.js
README.TXT
run.py

- Your application must to have "init" and "main" (for convention):

[your_application]
.....__init__.py
.....main.py

- main.py is a web application, then it has "locawapp_main" function:

def locawapp_main(request):
[...]
return [string]

- See locawapp.main.py and locawapp.common.py

- Send me your comment, thanks :-)
- Bye

http://LocaWapp.blogspot.com
----------------------------
class Server:
def __init__(self,port):
self.resp = None
self.session = {'_stopServer':False}

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('127.0.0.1',port))
s.listen(5)
while 1:
self.resp = ''
conn,addr = s.accept()
data = ''
while 1:
tmp = conn.recv(BUFFER)
if tmp == '':
break
data += tmp
end = data.find('\r\n\r\n')
if end != -1:
data2 =
data[:end].split('\r\n')
method = data2[0].split(' ')
method[1] =
urllib.unquote(method[1])
header = {}
for r in data2[1:]:
rr = r.split(': ')
header[rr[0]] = rr[1]
if method[0] == 'GET':

self.getResp(method,header,None)
elif method[0] == 'POST':
cnt_len =
int(header['Content-Length'])
content = data[end+4:]
while len(content) <
cnt_len:
tmp =
conn.recv(BUFFER)
if tmp == '':
break
content += tmp
content =
content[:cnt_len] # for MSIE 5.5 that append \r\n
content =
urllib.unquote(content)

self.getResp(method,header,content)
break
conn.send(self.resp)
conn.close()
if self.session['_stopServer']:
break
s.close()

def getResp(self,method,header,content):
url = method[1].split('?')
path = url[0][1:]
ext = os.path.splitext(path)
try:
if ext[1] == '.py':
get = {}
if len(url) == 2:
get = self.getParams(url[1])
post = {}
if content != None:
post = self.getParams(content)
request = {
'header':header,
'get':get,
'post':post,
'session':self.session
}
exec 'import ' +
ext[0].replace('/','.') + ' as app'
response = app.locawapp_main(request)
self.resp =
self.makeResp(200,'text/html',response['content'])
else:
try:
f = open(path,'rb')
fs = f.read()
f.close()
self.resp =
self.makeResp(200,self.getCntType(ext[1]),fs)
except IOError:
self.resp =
self.makeResp(404,'text/html','404 Not Found')
except Exception, e:
trace =
traceback.format_exception(sys.exc_type,sys.exc_va lue,sys.exc_traceback)
self.resp =
self.makeResp(200,'text/html',self.getError(trace))

Dec 10 '05 #1
1 1074
"class Server" has a big error: what is?

Dec 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: LocaWapp | last post by:
"class Server" has a big error: what is? http://groups.google.it/group/comp.lang.python/browse_thread/thread/de458cb7675ff4b6/f333453b0dc1aab6?q=locawapp&rnum=1#f333453b0dc1aab6
0
by: LocaWapp | last post by:
Hi Hamish Sanderson. I am seeing your project "HTMLTemplate". I like it. You see my project: LocaWapp: localhost web applications V.0.0.2 (2005 Dec 20) http://LocaWapp.blogspot.com...
0
by: LocaWapp | last post by:
http://cheeseshop.python.org/packages/source/L/LocaWapp/locawapp-03.tar.gz LocaWapp: localhost web applications (v.03 - 2005 Dec 31) Copyright (c) 2005 RDJ This code is distributed for your...
0
by: . | last post by:
http://daviderognoni.blogspot.com?locawapp - MAIN NEWS =========== * add thread * add "Request" object * new "locawapp_main" function * fixed files.py
0
by: . | last post by:
http://daviderognoni.blogspot.com?locawapp - MAIN NEWS =========== * add thread * add "Request" object * new "locawapp_main" function * fixed files.py
9
by: Jacky | last post by:
Hi all, I just started learning Python and would like to starting writing some web-based applications with Python. I did have pretty much experience with doing so with PHP and Java, but...
0
by: . | last post by:
http://daviderognoni.blogspot.com?locawapp - MAIN NEWS =========== * add ajax * new "Request" methods * fixed editor.py * fixed files.py
3
by: . | last post by:
Hi, now you can use my free web application, LocaWapp, to making Ajax sites: http://daviderognoni.blogspot.com?locawapp (9 KB) Request Python or lwaPython:...
10
by: . | last post by:
Yes, now you can with LocaWapp (and async Ajax): http://daviderognoni.blogspot.com/?locawapp jsFileWrite("testJsFile.txt","This is a test."); alert(jsFileRead("testJsFile.txt"));
3
by: laredotornado | last post by:
Hi, I have two <SELECT> elements on my page. I want to use the first to populate the second. That is, upon selecting an option from the first, I want the second to populate with items. ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.