Re: [Tutor] Tutorial for creating web server
Rakesh Mishra wrote: > hi > > i wanted to create my own web server, can any body suggest any tutorial, > by the way i have gone through book Core Python Programing, in this book > one example is given but it is to abstract, that i am unable to understand . Can you be more specific? Creating a web server in Python can be done in one line: python -c "import CGIHTTPServer; CGIHTTPServer.test()" will start a web server that serves static files and cgi's. There are *many* options for creating a full web application in Python (too many options, some say). Two currently popular choices are Django and TurboGears but they may be overkill for what you need. Anyway we really need more details of what you want to do and why to be able to help you. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] windows help system
>> You can do this by setting an environment variable named PYTHONSTARTUP to >> name of a file containing your start-up commands > > How do I set environmental variables in Windows? If it's Windows 9x/Me use AUTOEXEC.BAT. SET PTYTHONSTARTUP C:\mypath\myfile.py If its Windows NT/2000/XP right click My Computer, select Properties, select Advanced tab click Environment Variables. click New Hopefully self explanatory after that. In either environment searching for envoironment variable in the windows help system gives the answer... The Windows help files are a greatly under used feature of the OS...IMHO Alan G. Hello Alan! Thanks. I found the windows help and support center. It's not obvious how to use it. Could not find an index search box. I finally did find the windows web newsgroup, and found where someone posted a question about environmental variables, in which he just happened to list the same information you did about environment variable. Environmental variable is not in the windows help glossary. Before today I did not know that a windows help existed. Kermit [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] odbchelper
When I tried to run a program show at the beginning of "Dive into Python", I got. Traceback (most recent call last): File "", line 1, in -toplevel- import odbchelper ImportError: No module named odbchelper >>> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] password protection in httplib
2006/3/2, Kent Johnson <[EMAIL PROTECTED]>: > Andre Engels wrote: > > Thanks for your help; it brought me quite a bit farther, but not as > > far as I wanted to come. The authentication is basic authentication, > > and I have been able to adapt the programs so that I now get my pages > > correctly. > > > > However, the program uses not only 'GET' operations, but also 'PUT' > > operations. These are done using httplib rather than urllib, and I > > cannot see at this point how I can mimick those using urllib2. > > The docs don't spell it out, but if you pass the 'data' parameter to > urllib2.urlopen(), it will make a POST request instead of a GET. The > data has to be formatted as application/x-www-form-urlencoded; > urllib.urlencode() will do this for you. > > So for example: > > import urllib, urllib2 > data = dict(param1='foo', param2='bar') > data = urllib.urlencode(data) > > # set up your basic auth as before > result = urllib2.urlopen('http://some.server.com', data).read() Thanks, I've gotten some further again, but the following problem is that I am using this connection to get some cookies, which are read from the page headers. As far as I can see, urllib2 puts the page headers into a dictionary, which is not what I need, because there are 4 different set-cookie headers sent out by the site, and I get only one "set-cookie" value. Am I right in this, and is there a way around it? -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] odbchelper
Hi! How have you started the script? As far as I could see, in the Chapter 1 of "Dive into Python", the odbchelper.py is just a script-File and not a module to be imported, therefore the Exception with the "ImportError". I do not have a Windows box here to check if the problem is with the PythonIDE. Testing with idle ( the python ide ) under solaris and putting the source-Code from Chapter 1 into the buffer, saving it and just starting with "F5" = "Run Module" just gives the string. Otherwise under unix just start "python odbchelper.py" on the commandline. HTH Ewald Kermit Rose wrote: > When I tried to run a program show at the beginning of "Dive into Python", > > I got. > > > Traceback (most recent call last): > File "", line 1, in -toplevel- > import odbchelper > ImportError: No module named odbchelper > > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] odbchelper
Kermit Rose wrote: > When I tried to run a program show at the beginning of "Dive into Python", > > I got. > > > Traceback (most recent call last): > File "", line 1, in -toplevel- > import odbchelper > ImportError: No module named odbchelper odbchelper is the module defined in Example 2.1. You need this file stored somewhere on the python search path; the current working directory is probably a good choice. In the future if you could give a pointer to the program you are trying to run that would be helpful. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] password protection in httplib
Andre Engels wrote: > 2006/3/2, Kent Johnson <[EMAIL PROTECTED]>: > >>Andre Engels wrote: >> >>>Thanks for your help; it brought me quite a bit farther, but not as >>>far as I wanted to come. The authentication is basic authentication, >>>and I have been able to adapt the programs so that I now get my pages >>>correctly. >>> >>>However, the program uses not only 'GET' operations, but also 'PUT' >>>operations. These are done using httplib rather than urllib, and I >>>cannot see at this point how I can mimick those using urllib2. >> >>The docs don't spell it out, but if you pass the 'data' parameter to >>urllib2.urlopen(), it will make a POST request instead of a GET. The >>data has to be formatted as application/x-www-form-urlencoded; >>urllib.urlencode() will do this for you. >> >>So for example: >> >>import urllib, urllib2 >>data = dict(param1='foo', param2='bar') >>data = urllib.urlencode(data) >> >># set up your basic auth as before >>result = urllib2.urlopen('http://some.server.com', data).read() > > > Thanks, I've gotten some further again, but the following problem is > that I am using this connection to get some cookies, which are read > from the page headers. As far as I can see, urllib2 puts the page > headers into a dictionary, which is not what I need, because there are > 4 different set-cookie headers sent out by the site, and I get only > one "set-cookie" value. Am I right in this, and is there a way around > it? Have you tried using a CookieManager as shown in the first example here: http://docs.python.org/lib/cookielib-examples.html Once you set up your opener with a CookieJar the cookies should be handled automatically - if a server sets a cookie it will be remembered and returned back to the server on subsequent requests. This page has more examples though again IMO they are overly complex: http://www.voidspace.org.uk/python/articles/cookielib.shtml Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] odbchelper
Ewald Ertl wrote: > Hi! > > How have you started the script? As far as I could see, in the Chapter 1 of > "Dive into Python", the odbchelper.py is just a script-File and not a module > to be imported, therefore the Exception with the "ImportError". It is both, if by "just a script-File" you mean a top-level program intended to be run from the command line. If you import odbchelper it will give you access to the buildConnectionString() function. If you run it from the command line, it will also run the code after if __name__ == "__main__": This is pretty common - to write a module so it can be imported or used as a main program. The parts you want to run only from the command line are set off by this conditional. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] password protection in httplib
2006/3/3, Kent Johnson <[EMAIL PROTECTED]>: > Have you tried using a CookieManager as shown in the first example here: > http://docs.python.org/lib/cookielib-examples.html > > Once you set up your opener with a CookieJar the cookies should be > handled automatically - if a server sets a cookie it will be remembered > and returned back to the server on subsequent requests. > > This page has more examples though again IMO they are overly complex: > http://www.voidspace.org.uk/python/articles/cookielib.shtml I had looked at it yes, but I don't know how to combine the two handlers (the one for authentication and the one for cookies). Apart from that I hoped that because the program already has cookie handling programmed in, reusing that code might be less trouble than splitting the authenticated and the non-authenticated case everywhere. -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] password protection in httplib
Andre Engels wrote: > 2006/3/3, Kent Johnson <[EMAIL PROTECTED]>: > > >>Have you tried using a CookieManager as shown in the first example here: >>http://docs.python.org/lib/cookielib-examples.html >> >>Once you set up your opener with a CookieJar the cookies should be >>handled automatically - if a server sets a cookie it will be remembered >>and returned back to the server on subsequent requests. >> >>This page has more examples though again IMO they are overly complex: >>http://www.voidspace.org.uk/python/articles/cookielib.shtml > > > I had looked at it yes, but I don't know how to combine the two > handlers (the one for authentication and the one for cookies). Apart > from that I hoped that because the program already has cookie handling > programmed in, reusing that code might be less trouble than splitting > the authenticated and the non-authenticated case everywhere. The call to urllib2.build_opener() accepts multiple arguments, just list both handlers. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutorial for creating web server
Hi Johnson I wanted to create web server some think like similar to ZServer of zope. I wanted to use it for publishing my home page (it is in php), or any web application. I am confused with arch. , bye rakeshOn 3/3/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Rakesh Mishra wrote:> hi>> i wanted to create my own web server, can any body suggest any tutorial,> by the way i have gone through book Core Python Programing, in this book> one example is given but it is to abstract, that i am unable to understand . Can you be more specific? Creating a web server in Python can be done inone line:python -c "import CGIHTTPServer; CGIHTTPServer.test()"will start a web server that serves static files and cgi's. There are *many* options for creating a full web application in Python(too many options, some say). Two currently popular choices are Djangoand TurboGears but they may be overkill for what you need. Anyway we really need more details of what you want to do and why to beable to help you.Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutorial for creating web server
Rakesh Mishra wrote: > Hi Johnson > I wanted to create web server some think like similar to ZServer of zope. > I wanted to use it for publishing my home page (it is in php), or any > web application. > I am confused with arch. I still am not sure what you are asking for. Do you want to create something like Zope? Or do you want to use Zope to create your home page? If you want to learn Zope you should go to the Zope web site. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] odbchelper
Hi Kent! You are absolutely right. Sorry for my bad description. Kent Johnson wrote: > Ewald Ertl wrote: >> Hi! >> >> How have you started the script? As far as I could see, in the Chapter 1 of >> "Dive into Python", the odbchelper.py is just a script-File and not a module >> to be imported, therefore the Exception with the "ImportError". > > It is both, if by "just a script-File" you mean a top-level program > intended to be run from the command line. > Yes I meant a top-level-program. > If you import odbchelper it will give you access to the > buildConnectionString() function. If you run it from the command line, > it will also run the code after > if __name__ == "__main__": > > This is pretty common - to write a module so it can be imported or used > as a main program. The parts you want to run only from the command line > are set off by this conditional. > I looked at the code of odbchelper.py in Example 2.1 in my printed Version of "Dive into Python" and there was no "import", so I assumed some problem with the IDE. But the Traceback came from Example 2.5 in my version. Thanks for your response on my attempt to help Ewald ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] windows help system
> Environmental variable is not in the windows help glossary. Strange, in both Windows 2000 and XP I type 'environment variable' into the search box and the list of topics returned includes "Setting environment variables" I'm sure Win98 does too because I've used it in the past. > Before today I did not know that a windows help existed. You are not alone, for some reason people never seem to notice it despite it being a standard menu feature. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] windows help system
From: Alan Gauld Date: 03/03/06 11:41:05 To: Kermit Rose; tutor@python.org Subject: Re: [Tutor] windows help system > Environmental variable is not in the windows help glossary. Strange, in both Windows 2000 and XP I type 'environment variable' into the search box and the list of topics returned includes "Setting environment variables" I'm sure Win98 does too because I've used it in the past. I found the windows help glossary, but did not find a search box. How would I find the search box in Microsoft Windows XP Home Edition ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] password protection in httplib
Thanks for your answers! It is working now! 2006/3/3, Kent Johnson <[EMAIL PROTECTED]>: > Andre Engels wrote: > > 2006/3/3, Kent Johnson <[EMAIL PROTECTED]>: > > > > > >>Have you tried using a CookieManager as shown in the first example here: > >>http://docs.python.org/lib/cookielib-examples.html > >> > >>Once you set up your opener with a CookieJar the cookies should be > >>handled automatically - if a server sets a cookie it will be remembered > >>and returned back to the server on subsequent requests. > >> > >>This page has more examples though again IMO they are overly complex: > >>http://www.voidspace.org.uk/python/articles/cookielib.shtml > > > > > > I had looked at it yes, but I don't know how to combine the two > > handlers (the one for authentication and the one for cookies). Apart > > from that I hoped that because the program already has cookie handling > > programmed in, reusing that code might be less trouble than splitting > > the authenticated and the non-authenticated case everywhere. > > The call to urllib2.build_opener() accepts multiple arguments, just list > both handlers. > > Kent > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] windows help system
> I found the windows help glossary, but did not find a search box. > > How would I find the search box in > Microsoft Windows XP Home Edition When you open Help and Support, just above where it says "Pick a Help Topic" there is a text entry box labelled Search and a green arrow. At least there is on mine! Actually I don't see a Glossary link anywhere! Or do you mean the Index? But if so it does include "environment variables"... Strange! I wobnder? Are you using the Classic Windows interface rather than the XP one? It might be different. PS This is getting well off-topic for Python so any further emails should probably be offlist. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print list vs telnetlib.telnet.write differences
On Fri, 2006-03-03 at 15:41 +1000, STREET Gideon (SPARQ) wrote: > The problem I'm stumbling over is that when I print x, the output is > what I want. If I delete the print x and #, leaving only tn.write(x) > on > the last line everything looks good except it writes the 1st item in > "lines" (the banner exec command) twice, once at the beginning where > it's supposed to, but then once again at the end. See except below for > example. > > Anyone able to explain why that is happening or is it me just not > understanding what I'm doing? Hope my explanation is clear I'm still > unfamiliar with the exact phrasology. > Could that be your data being echoed back to you? Is the router configured correctly after the script runs? I normally feed commands to Cisco devices using tftp. It is relatively easy to edit a file to get the commands correct. Then you could limit your "conversational script" to logging in and running tftp to transfer the command file. It looks like you are pretty close to having this working. -- Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358 voice: 603-653-8139 fax:320-210-3409 -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] usernames and uid in linux
On Fri, Mar 03, 2006, Pat Martin wrote: > > Hello all, > I seem to be having a problem finding the right tool in python. Given > a username I want to find the uid for it. I can do the reverse very > easily with: > pwd.getpwuid(2012) > This returns a tuple of data from the passwd file. But I want to do > something like: > command(username) > And get something that returns the uid (the number). You're close: import pwd pw = pwd.getpwnam('username') Bill -- INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Systems, Inc. URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 There is no distinctly native American criminal class save Congress -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] usernames and uid in linux
Hello all,I seem to be having a problem finding the right tool in python. Given a username I want to find the uid for it. I can do the reverse very easily with:pwd.getpwuid(2012)This returns a tuple of data from the passwd file. But I want to do something like: command(username) And get something that returns the uid (the number).Thanks-- Pat Martin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] usernames and uid in linux
You're close:import pwdpw = pwd.getpwnam('username') Bill--INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Systems, Inc.URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676There is no distinctly native American criminal class save Congress-- Mark Twain___ Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutorI completely missed that. Thank you so much. -- Pat Martin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] One shared object. class attribute or global variable?
I've got a module that needs to share a pack of cards pack = ["14s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s", "12s", "13s", "14d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "10d", "11d", "12d", "13d", "14c", "2c", "3c", "4c", "5c", "6c", "7c", "8c", "9c", "10c", "11c", "12c", "13c", "14h", "2h", "3h", "4h", "5h", "6h", "7h", "8h", "9h", "10h", "11h", "12h", "13h"] random.shuffle(pack) do you think it is worth making a class with just this attribute or would this be a good place to use a global variable? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] One shared object. class attribute or global variable?
On 04/03/06, Adam <[EMAIL PROTECTED]> wrote: > I've got a module that needs to share a pack of cards > > pack = ["14s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s", > "12s", "13s", "14d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", > "10d", > "11d", "12d", "13d", "14c", "2c", "3c", "4c", "5c", "6c", "7c", "8c", > "9c", > "10c", "11c", "12c", "13c", "14h", "2h", "3h", "4h", "5h", "6h", "7h", > "8h", > "9h", "10h", "11h", "12h", "13h"] > random.shuffle(pack) > > do you think it is worth making a class with just this attribute or > would this be a good place to use a global variable? > I just realised this probably isn't as clear as it should be, sorry it's late. It needs to share the variable with the functions (or methods) in the module not with anything outside of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] One shared object. class attribute or global variable?
Adam wrote: > I've got a module that needs to share a pack of cards > > pack = ["14s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s", > "12s", "13s", "14d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", > "10d", > "11d", "12d", "13d", "14c", "2c", "3c", "4c", "5c", "6c", "7c", "8c", > "9c", > "10c", "11c", "12c", "13c", "14h", "2h", "3h", "4h", "5h", "6h", "7h", > "8h", > "9h", "10h", "11h", "12h", "13h"] > random.shuffle(pack) > > do you think it is worth making a class with just this attribute or > would this be a good place to use a global variable? Some choices: 1. Pass the pack as a parameter to the functions that need to use it. 2. Make the pack a class attribute, maybe you can have a Game class. The functions that need it are good candidates for class methods. 3. Make pack a global variable I would start with 1. If you have to pass it to a lot of functions, and the functions seem to cohere into a class, then maybe pick 2. The tipping point between 1 and 2 is a judgement call. I almost never use global variables except for constants and in short throwaway scripts. By the way you may find that a Pack class makes sense, too, with methods like shuffle(), deal(howMany), isEmpty(). Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] One shared object. class attribute or global variable?
On Sat, 2006-03-04 at 00:42 +, Adam wrote: > On 04/03/06, Adam <[EMAIL PROTECTED]> wrote: > > I've got a module that needs to share a pack of cards > > > > pack = ["14s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s", > > "12s", "13s", "14d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", > > "10d", > > "11d", "12d", "13d", "14c", "2c", "3c", "4c", "5c", "6c", "7c", "8c", > > "9c", > > "10c", "11c", "12c", "13c", "14h", "2h", "3h", "4h", "5h", "6h", "7h", > > "8h", > > "9h", "10h", "11h", "12h", "13h"] > > random.shuffle(pack) > > > > do you think it is worth making a class with just this attribute or > > would this be a good place to use a global variable? > > > > I just realised this probably isn't as clear as it should be, sorry > it's late. It needs to share the variable with the functions (or > methods) in the module not with anything outside of it. It looks like this will be shared and modified. In general, I think read-only variables (initialized at start-up when not constants) can work OK as globals. A container that will be changed and shared should almost certainly go in a class. > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Urgent - Using Threads for processing each single Packet ?
Hi All, Currently i am planning for writing a tool which gets a webpage and fills the appropriate fields and posts the page back to the server. The problem is that i am using SCAPY for doing http as i need VLAN TAG to be supported to get the HTTP Page. So before starting this i had couple of questions. 1. As we need to establish a TCP session for http to work , do we need to process each packet as a seperate thread ? I am not sure how the system would respond if we have to get 500 webpages - in the sense the total number of tcp connection is around 500 . Could any body tell me what would be best design ? Using each thread for single packet processing is it worth ? 2. Is there any specific tool or any built in APIs which can parse Http part of the packet ? Please help me . Thanks in advance, Sudarshana K S ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutorial for creating web server
hi Johnson late me try to explain what I wants... I am not interested in tool which is used to creating the web pages. but I am interested in tool which is used for webcasting the web pages. in contax of Zope... Apart from creating web pages it has its own web server called as ZServer. which is used by zope internally to web cast the pages. Even you not clear than simply in one word I wanted to built Apache web server in python. I think now you will understand what I want. please help me out . rakesh On 3/3/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Rakesh Mishra wrote:> Hi Johnson> I wanted to create web server some think like similar to ZServer of zope.> I wanted to use it for publishing my home page (it is in php), or any> web application. > I am confused with arch.I still am not sure what you are asking for. Do you want to createsomething like Zope? Or do you want to use Zope to create your homepage? If you want to learn Zope you should go to the Zope web site. Kent___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor