473,396 Members | 2,070 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,396 software developers and data experts.

[AoooAoooA] BrowAppSys (BAS): Browser Applications System V.0.0.1

RDJ
http://spazioinwind.libero.it/rdjhom...pSys-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: rd****@inwind.it (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)
Jul 18 '05 #1
0 1015

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

Similar topics

22
by: Theo | last post by:
Question for the group The authentication system for the site Im working on seems to function properly and all is good. A session keeps track of everything and a cookie is used to accept or deny...
52
by: Harlan Messinger | last post by:
Can you help me figure out what to do about popups? Sometimes we develop web applications where popups make very good sense for precisely the same reasons they make sense in traditional...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
54
by: Matt | last post by:
How do we define systems programs? when we say systems programming, does it necessary mean that the programs we write need to interact with hardware directly? For example, OS, compiler, kernel,...
0
by: Horia Tudosie | last post by:
Using Visual Studio 2003 This is to report a series of bugs regarding the FlagsAttribute and (independently) the usage of interfaces in Web applications. Let’s declare xColors type like: ...
5
by: Shacker | last post by:
Hi, A collegue of mine and I have a matter that needs to be settled... We have old VB6 code that uses a common SQL connection module and it's used widely in all of our VB6 code. We're now...
2
by: Jeff | last post by:
Please note this is NOT a rant or complaint! And yes, I'm over-simplifying, but intentionally. Here goes... With ASP.NET Web applications I like that I can access data from anywhere without...
3
by: plangla | last post by:
I am trying to start the default e-mail browser automatically from a menu item click. The code works for the web browser but not for e-mail. This is the sample for web browser that works ...
20
by: Nates | last post by:
I have a .bas file saved locally that I load into my Acces project to run a particular sub. I use the following code to load the module (which works fine): I use the following loop to remove...
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
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.