R
RDJ
http://spazioinwind.libero.it/rdjhome/BrowAppSys-0.0.1.zip
=== This is a AoooAoooA project (^_^) ===
BrowAppSys (BAS): Browser Applications System V.0.0.1 (2004 Oct 16)
Copyright (C) 2004 RDJ
This program is free software; you can redistribute it and/or
modify
it under the terms of the GNU General Public License as published
by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
TABLE OF CONTENTS
*****************
_REFERENCES
_FILES
_RUN_BAS
_REFERENCES
************
Redirect: AoooAoooA.too.it
WebSpace: spazioinwind.libero.it/rdjhome/AoooAoooA.html
___Email: (e-mail address removed) (OBJECT: [AoooAoooA] your object)
_FILES
******
BrowAppSys/BAS.py...........main program
BrowAppSys/BAS_index.py.....default application
BrowAppSys/BAS_static.py....files loader application
BrowAppSys/BAS_utility.py...utility for applications
BrowAppSys/GNU_GPL.txt......GNU GENERAL PUBLIC LICENSE
BrowAppSys/GNU_LGPL.txt.....GNU LIBRARY GENERAL PUBLIC LICENSE
BrowAppSys/README.txt.......this file
_RUN_BAS
********
BAS.py starts a server to http://localhost/
---------------------------------- code
#
# Main
#
if __name__ == '__main__':
BAS(80)
---------------------------------- code
You can change BAS(80) in another port, for example BAS(8080).
Now you can run the program:
python BAS.py
then open http://localhost/ or http://localhost:8080 or other,
with your browser. Appear:
AoooAoooA image
[________] [________] [get method]
[________] [________] [post method]
Error
Reload
Exit
It is OK! Now view the source code...
#
# Import
#
import BAS_utility, re, socket, urllib
#
# Class
#
class BAS:
def __init__(self,port):
self.apps = {}
self.loop = True
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('',port))
s.listen(1)
while self.loop:
conn, addr = s.accept()
method = []
headers = {}
data = ''
sendstr = ''
while 1:
data += conn.recv(1024)
end = data.find('\r\n\r\n')
if end != -1:
datal = data[:end].split('\r\n')
method = datal[0].split(' ')
method[1] = urllib.unquote(method[1])
for r in datal[1:]:
rr = r.split(': ')
headers[rr[0]] = rr[1]
if method[0] == 'GET':
sendstr = self.getResp(method,self.getModule(method[1]),self.getParams(method[1]),headers)
elif method[0] == 'POST':
cnt_len = int(headers['Content-Length'])
dataCnt = data[end+4:]
while len(dataCnt) < cnt_len:
dataCnt += conn.recv(1024)
dataCnt = dataCnt[0:cnt_len]
dataCnt = urllib.unquote(dataCnt)
sendstr = self.getResp(method,self.getModule(method[1]),self.getParams(dataCnt),headers)
break
conn.send(sendstr)
conn.close()
def getResp(self,method,module,params,headers):
print method
try:
if module == 'BAS_exit':
self.loop = False
return BAS_utility.makeResp('text/html','Exit')
elif module == 'BAS_reload' and self.apps.has_key(params['mod']):
exec 'import '+params['mod']
exec 'reload('+params['mod']+')'
exec 'self.apps["'+params['mod']+'"] =
'+params['mod']+'.BAS_main()'
return self.apps[params['mod']].getResp(method,params,headers)
elif self.apps.has_key(module) == False:
exec 'import '+module
exec 'self.apps["'+module+'"] = '+module+'.BAS_main()'
return self.apps[module].getResp(method,params,headers)
except Exception, e:
return BAS_utility.makeResp('text/html',str(e))
def getModule(self,url):
res = re.search('/([-_\.\w]+)',url)
if res == None:
return 'BAS_index'
else:
return res.group(1)
def getParams(self,url):
res = re.search('\?(.*)',url)
if res != None:
url = res.group(1)
params = {}
for r in url.split('&'):
rs = r.split('=')
if len(rs) == 2:
params[rs[0]] = rs[1]
return params
#
# Main
#
if __name__ == '__main__':
BAS(80)
=== This is a AoooAoooA project (^_^) ===
BrowAppSys (BAS): Browser Applications System V.0.0.1 (2004 Oct 16)
Copyright (C) 2004 RDJ
This program is free software; you can redistribute it and/or
modify
it under the terms of the GNU General Public License as published
by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
TABLE OF CONTENTS
*****************
_REFERENCES
_FILES
_RUN_BAS
_REFERENCES
************
Redirect: AoooAoooA.too.it
WebSpace: spazioinwind.libero.it/rdjhome/AoooAoooA.html
___Email: (e-mail address removed) (OBJECT: [AoooAoooA] your object)
_FILES
******
BrowAppSys/BAS.py...........main program
BrowAppSys/BAS_index.py.....default application
BrowAppSys/BAS_static.py....files loader application
BrowAppSys/BAS_utility.py...utility for applications
BrowAppSys/GNU_GPL.txt......GNU GENERAL PUBLIC LICENSE
BrowAppSys/GNU_LGPL.txt.....GNU LIBRARY GENERAL PUBLIC LICENSE
BrowAppSys/README.txt.......this file
_RUN_BAS
********
BAS.py starts a server to http://localhost/
---------------------------------- code
#
# Main
#
if __name__ == '__main__':
BAS(80)
---------------------------------- code
You can change BAS(80) in another port, for example BAS(8080).
Now you can run the program:
python BAS.py
then open http://localhost/ or http://localhost:8080 or other,
with your browser. Appear:
AoooAoooA image
[________] [________] [get method]
[________] [________] [post method]
Error
Reload
Exit
It is OK! Now view the source code...
#
# Import
#
import BAS_utility, re, socket, urllib
#
# Class
#
class BAS:
def __init__(self,port):
self.apps = {}
self.loop = True
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('',port))
s.listen(1)
while self.loop:
conn, addr = s.accept()
method = []
headers = {}
data = ''
sendstr = ''
while 1:
data += conn.recv(1024)
end = data.find('\r\n\r\n')
if end != -1:
datal = data[:end].split('\r\n')
method = datal[0].split(' ')
method[1] = urllib.unquote(method[1])
for r in datal[1:]:
rr = r.split(': ')
headers[rr[0]] = rr[1]
if method[0] == 'GET':
sendstr = self.getResp(method,self.getModule(method[1]),self.getParams(method[1]),headers)
elif method[0] == 'POST':
cnt_len = int(headers['Content-Length'])
dataCnt = data[end+4:]
while len(dataCnt) < cnt_len:
dataCnt += conn.recv(1024)
dataCnt = dataCnt[0:cnt_len]
dataCnt = urllib.unquote(dataCnt)
sendstr = self.getResp(method,self.getModule(method[1]),self.getParams(dataCnt),headers)
break
conn.send(sendstr)
conn.close()
def getResp(self,method,module,params,headers):
print method
try:
if module == 'BAS_exit':
self.loop = False
return BAS_utility.makeResp('text/html','Exit')
elif module == 'BAS_reload' and self.apps.has_key(params['mod']):
exec 'import '+params['mod']
exec 'reload('+params['mod']+')'
exec 'self.apps["'+params['mod']+'"] =
'+params['mod']+'.BAS_main()'
return self.apps[params['mod']].getResp(method,params,headers)
elif self.apps.has_key(module) == False:
exec 'import '+module
exec 'self.apps["'+module+'"] = '+module+'.BAS_main()'
return self.apps[module].getResp(method,params,headers)
except Exception, e:
return BAS_utility.makeResp('text/html',str(e))
def getModule(self,url):
res = re.search('/([-_\.\w]+)',url)
if res == None:
return 'BAS_index'
else:
return res.group(1)
def getParams(self,url):
res = re.search('\?(.*)',url)
if res != None:
url = res.group(1)
params = {}
for r in url.split('&'):
rs = r.split('=')
if len(rs) == 2:
params[rs[0]] = rs[1]
return params
#
# Main
#
if __name__ == '__main__':
BAS(80)