Re: [Tutor] distutils problem
On Sat, Apr 16, 2005 at 12:58:33PM -0400, Paul Tremblay wrote: > I have written a script that is available at: > > https://sourceforge.net/projects/rtf2xml/ > > This script has gotten about 1600 downloads and I have not got many > bug complaints. However, recently I got the bug complaint listed > below. > > This bug--if it is one--seems to be related to the person't version > and setup of python rather than my script. Can anyone make sense of > it? > > Thanks > > Paul > > forwarded message > = > > I tried to set this up according to the documentation at > > http://rtf2xml.sourceforge.net/docs/installation.html#install-rtf2xml-module > > But when I try to run > >python setup.py install > > (both as user and as root) > > I get > > xps8250:/home/chuck/rtf2xml-1.0a# python setup.py install > > running install > > error: invalid Python installation: unable to open > /usr/lib/python2.3/config/Makefile (No such file or directory) > > According to apt-get, I do have Python correctly installed. I also did > this: > > xps8250:/home/chuck/rtf2xml-1.0a# python > > Python 2.3.5 (#2, Mar 26 2005, 17:32:32) > > [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2 > > However, in /usr/lib/python2.3/ there is no subdirectory for > /config/Makefile, nor any Makefile in any python subtree. I've looked > around the Python online documentation, but haven't found any > clues. Any suggestions? > > Okay, I just did a web search (which I should have done before I posted this!) and discovered that the problem is probably due to the user not having the development package of python installed as well. I posted him and will wait to hear from him. Paul -- *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] distutils problem
I have written a script that is available at: https://sourceforge.net/projects/rtf2xml/ This script has gotten about 1600 downloads and I have not got many bug complaints. However, recently I got the bug complaint listed below. This bug--if it is one--seems to be related to the person't version and setup of python rather than my script. Can anyone make sense of it? Thanks Paul forwarded message = I tried to set this up according to the documentation at http://rtf2xml.sourceforge.net/docs/installation.html#install-rtf2xml-module But when I try to run python setup.py install (both as user and as root) I get xps8250:/home/chuck/rtf2xml-1.0a# python setup.py install running install error: invalid Python installation: unable to open /usr/lib/python2.3/config/Makefile (No such file or directory) According to apt-get, I do have Python correctly installed. I also did this: xps8250:/home/chuck/rtf2xml-1.0a# python Python 2.3.5 (#2, Mar 26 2005, 17:32:32) [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2 However, in /usr/lib/python2.3/ there is no subdirectory for /config/Makefile, nor any Makefile in any python subtree. I've looked around the Python online documentation, but haven't found any clues. Any suggestions? -- **** *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CGI authentication
On Mon, Mar 14, 2005 at 08:04:10AM -0500, Kent Johnson wrote: > Date: Mon, 14 Mar 2005 08:04:10 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) > To: Python Tutor > Subject: [Tutor] CGI authentication > > There was a question on this list recently about how to authenticate users > of a web server from a simple CGI script. I just came across a module that > might help: > http://www.voidspace.org.uk/python/logintools.html > > Kent > That would be for me! This looks pretty nice. On problem I have with the python url2lib is the dfficulty of determining the realm. For example, bot lynx and curl (command line url tools) don't need a realm to work. This seems to mean that lynx and curl provide more flexibility. Paul -- *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] and once i have learned how to program ?
On Fri, Mar 11, 2005 at 02:26:48PM -0500, [EMAIL PROTECTED] wrote: > From: [EMAIL PROTECTED] > Date: Fri, 11 Mar 2005 14:26:48 EST > To: tutor@python.org > Subject: [Tutor] and once i have learned how to program ? > > Once i have learned how to program what can i do with the programs can they > run out side of the python shell like on My OS or a game? My OS is window XP > home Yes, python will act like any other program, such as C++. If you want to use python to run a gui (graphical user interface), then you would use Tinker. Just to give you an idea, I just downloaded a program called skencil. I get in the shell and type "skencil". I then get a window for to draw in. I take my mouse and make lines and drawings. I point my mouse to the file window and pull down the menu for save to save my document. So the application works exactly like, say, Adobe Draw, with small difference that I had to start it form my shell. I'm pretty sure there are ways to start applications without a shell. That isn't too hard. The hard part is writing a program with a graphical interface. This is always hard, in any languge. Paul -- *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting a webpage via python
On Wed, Mar 09, 2005 at 08:29:46AM -0500, Kent Johnson wrote: > > Kent Johnson wrote: > >Paul Tremblay wrote: > > > >>So I just make a file called /etc/router_passwords and include > >>something like > >>WRT54G username password > >> > >>Then parse the file, and supply the info to the password handler? This > >>is easy to do, and I guess it is secure. > > The book "Foundations of Python Network Programming" has a sample program > that uses a custom urllib2.HTTPPasswordMgr to ask the user for the username > and password, maybe you would like to use that? > > The examples can be downloaded from the book Web site at > http://www.apress.com/book/bookDisplay.html?bID=363 > > Look for the one called dump_info_auth.py > Thanks. There are lots of good examples in the free download examples. Paul -- *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting a webpage via python
On Tue, Mar 08, 2005 at 01:42:40PM -0500, Kent Johnson wrote: > Date: Tue, 08 Mar 2005 13:42:40 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) > Cc: python tutor > Subject: Re: [Tutor] getting a webpage via python > > Paul Tremblay wrote: > >This is giving me 401 error, authorization required. Here's what I have: > > > > > >auth_handler = urllib2.HTTPBasicAuthHandler() > >auth_handler.add_password('realm', '127.0.0.1', 'myname', 'password') > >opener = urllib2.build_opener(auth_handler) > ># ...and install it globally so it can be used with urlopen. > >urllib2.install_opener(opener) > >print urllib2.urlopen('http://nnn.nnn.n.n').read() > > > >This is almost the literal code, except I changed my log in name and > >passowrd. > > > >What am I supposed to put for realm? I checked the docs on line, and it > >doens't mention what realm is. > > The realm name is part of the web server authentication configuration. If > you browse to the web page in your browser it will show the realm in the > auth dialog. For example my browser (Firefox) shows > > Enter user name and password for "Curriculum Builder" at http://localhost > > The realm name is "Curriculum Builder" Thanks. I got it to work. I tired to open the page in Koqueror web browser and got this message: Authorization Dialog You need to supply a username and password to access this site. Site: WRT54G at nnn.nnn.n.n I tried useing "Authorizaiton Dialog" with no success. So I tried opening the same page with lynx with the trace option on. I found that lynx used WRT54G as the realm, so I tried it and it worked. > > >Also, I assume I am supposed to use the loopback address when I set up > >the handler? > > No, use your server name, in your example nnn.nn.n.n > > >Also, I know I am going to have another question once I solve this one, > >and since it is directly related, I'll ask it now. How can I use a > >password system that is not hardcoded in my text? Should I just setup a > >password file? > > Yes, something like that. You will have to store the password in plaintext > (or a reversible cipher) since that is what HTTPBasicAuthHandler needs. > So I just make a file called /etc/router_passwords and include something like WRT54G username password Then parse the file, and supply the info to the password handler? This is easy to do, and I guess it is secure. I am networking on a home system, so security is not so big a concern. However, I have seen a lot of people struggle with getting router addresses from the WRT54G,so I thought I might offer my script, and I wanted to do things a secure, normal way. Thanks Paul -- *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting a webpage via python
On Tue, Mar 08, 2005 at 11:50:12AM -0500, Kent Johnson wrote: > > Paul Tremblay wrote: > > You can use urllib2 to do this. It is a little work to set it up to use > Basic authentication. Here is an example (slightly modified from the > urllib2 example page): > > import urllib2 > > # Create an OpenerDirector with support for Basic HTTP Authentication... > auth_handler = urllib2.HTTPBasicAuthHandler() > auth_handler.add_password('realm', '127.0.0.1', 'username', 'password') > opener = urllib2.build_opener(auth_handler) > # ...and install it globally so it can be used with urlopen. > urllib2.install_opener(opener) > print urllib2.urlopen('http://127.0.0.1/my/protected/page.html').read() > > Kent > This is giving me 401 error, authorization required. Here's what I have: auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password('realm', '127.0.0.1', 'myname', 'password') opener = urllib2.build_opener(auth_handler) # ...and install it globally so it can be used with urlopen. urllib2.install_opener(opener) print urllib2.urlopen('http://nnn.nnn.n.n').read() This is almost the literal code, except I changed my log in name and passowrd. What am I supposed to put for realm? I checked the docs on line, and it doens't mention what realm is. Also, I assume I am supposed to use the loopback address when I set up the handler? Also, I know I am going to have another question once I solve this one, and since it is directly related, I'll ask it now. How can I use a password system that is not hardcoded in my text? Should I just setup a password file? Thanks Paul -- *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] getting a webpage via python
Is there a simple way to get a web page with python? I have done no network programming with python before. My router (a Linksys 54G model) stores the IP/MAC addresss in a web page. There is no way for me to access them except through the web. Righ now, I am using this code: command = 'lynx -reload -auth %s:%s -source http://%s/DHCPTable.asp > %s' % ( self.__log_name, self.__log_password, self.__router_address, temp_out1) (exit_status, out_text) = commands.getstatusoutput(command) The lynx terminal browser dumps the raw HTML page to the out_text, and I can then parse it. I would like to make the code independent of lynx, if possible. Thanks Paul -- **** *Paul Tremblay * [EMAIL PROTECTED]* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] style question: when to "hide" variable, modules
Thanks for your input (and others, too!). On Fri, Jan 14, 2005 at 08:11:32PM -0500, Kent Johnson wrote: > Date: Fri, 14 Jan 2005 20:11:32 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) > Cc: tutor@python.org > Subject: Re: [Tutor] style question: when to "hide" variable, modules > > A few thoughts: > - you might want to make a configuration object that you can pass around, > this is probably better than passing around an instance of the main Burn > class. I actually pass around many instances. Maybe this is bad programming, but I can't think of a better way to share attributes across modules. For example, one class splits lists. I want both my message class and my burn class to have access to the current state of the split list. > - typical Python style is *not* to define setter and getter functions. If > you need to mediate attribute access you can do it later using properties. I treid to figure out how this works with no luck. It seems that when you use property, you don't necessarily update the attribute. It seems I want the setattr() and getattr() functions? I always thought it was bad programming to alter an attribute directly in OO programming, but it seems I am mistaken? class Backup: __init__(self): self.some_var = 5 burn_obj = Burn(self) class Burn: __init__(self, main): setattr(main, 'some_var', 6) ??? > - you might want to consolidate your classes into a small number of > modules. This is the style of much of the Python standard library. Look at > optparse.py for an example (picked more-or-less at random). I couldn't find the optparse.py module. But looking at other packages and modules, it seems that the one module shouldn't run more than 500 lines. I * could* consolidate many of my classes in one file, but that would make very long files. Thanks Paul > - if one class has a helper class or function that isn't used anywhere > else, put the helper into the same module as the client and name the helper > starting with _. > - I tend to worry more about naming with _ in a module that is likely to be > reused. For a module that will probably be only be used once, I don't use _ > at all. In a module that has a public API I try to use _ to distinguish the > implementation details from the public stuff. > > HTH > Kent > > Paul Tremblay wrote: > >During the recent discussion on jython, a poster > >brought up the good point that one should hide > >variables and modules to indicate that they are > >not for public use: > > > >self.__for_internal_purposes = 5 > > > >__internal_stuff.py > >""" > >This module only makes sense for use with > >the parent module. > >""" > > > >So one could write several modules using these > >guidelines. One could then issue the command > >from a shell pydoc internal_stuff, and sure enough, > >one gets a nice listing of all the methods with the > >__methods listed first, signalling to someone who > >hasn't written the program (or to the author who > >returns to it a few years later), that one shouldn't > >look at these methods when looking what is useful > >from the script. > > > >My question is, how far should one take these guidlines? > > > >I am working on an OO script with several modules that > >backs up a hardrive. There will be about 10 modules, but > >really only *one* of them, called backup, would be used > >as a pubilc interface. Should I name the rest of them things > >like __handle_archive.py, __file_system.py, and so on? That > >seems odd, since I have never seen this done before. However, > >it does have an elegance of clearly telling someone how to > >hook into the modules. > > > >Also, maybe more importantly, I want to know how to handle > >attributes that need to be shared. Imagine that there are around > >20 attributes, such as the level the program runs at, and the number > >of the disk being copied that need to be shared with different > >modules. Right now, my setup looks like this: > > > ># this module is called backup.py > > > >class Backup: > > > > __init__(self, verbose, level ): > > self.__make_objects() > > self.verbose = verbose > > self.level = level > > > > > > def __make_objects(self): > >self.burn_obj = paxbac.burn.Burn(self) > >self.archive_obj = paxbac.archive.Archive(self) > > > > def get_disk(self): > >return self.__disk > > > > def set_disk(self, the_num): > > self.__disk = the_
[Tutor] style question: when to "hide" variable, modules
During the recent discussion on jython, a poster brought up the good point that one should hide variables and modules to indicate that they are not for public use: self.__for_internal_purposes = 5 __internal_stuff.py """ This module only makes sense for use with the parent module. """ So one could write several modules using these guidelines. One could then issue the command from a shell pydoc internal_stuff, and sure enough, one gets a nice listing of all the methods with the __methods listed first, signalling to someone who hasn't written the program (or to the author who returns to it a few years later), that one shouldn't look at these methods when looking what is useful from the script. My question is, how far should one take these guidlines? I am working on an OO script with several modules that backs up a hardrive. There will be about 10 modules, but really only *one* of them, called backup, would be used as a pubilc interface. Should I name the rest of them things like __handle_archive.py, __file_system.py, and so on? That seems odd, since I have never seen this done before. However, it does have an elegance of clearly telling someone how to hook into the modules. Also, maybe more importantly, I want to know how to handle attributes that need to be shared. Imagine that there are around 20 attributes, such as the level the program runs at, and the number of the disk being copied that need to be shared with different modules. Right now, my setup looks like this: # this module is called backup.py class Backup: __init__(self, verbose, level ): self.__make_objects() self.verbose = verbose self.level = level def __make_objects(self): self.burn_obj = paxbac.burn.Burn(self) self.archive_obj = paxbac.archive.Archive(self) def get_disk(self): return self.__disk def set_disk(self, the_num): self.__disk = the_num def backup(self): archive_obj.archive() burn_obj.burn() * #this is aother module called burn.py class Burn: def __init__(self, main): self.__main = main def burn(self): cd_num = self.main.get_disk() if self__main.level > 3: sys.stdout.write('Burning disk %s\n' %cd_num) The main module backukp provides a number of public methods that are really not public. For examle, no one is going to want to use this module to find out what disk the method is on. If I wanted to be very strict with public and private variables and methods, I would have to: 1. change burn.py to __burn.py 2. create a module called __attributes.py, create an object in burn.py called self.__attributes_obj, and pass this object to each method. These two steps seem to take things a bit far. On the other hand, one could look at the set of modules and immediately know how to use them. Thanks Paul ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Time script help sought!
Hi Kevin Is all your data in one big text file? Or do you have to type it in by hand and want some type of script to do the calcluations? I have to run right now. I'll be back in a few hours and can give you some more help then, if no one else has offered. Paul On Tue, Jan 11, 2005 at 12:18:15PM -0500, kevin parks wrote: > From: kevin parks <[EMAIL PROTECTED]> > Date: Tue, 11 Jan 2005 12:18:15 -0500 > To: tutor@python.org > Cc: Kevin Parks <[EMAIL PROTECTED]> > Subject: [Tutor] Time script help sought! > > I am kind of in a bit of a jam (okay a big jam) and i was hoping that > someone here could give me a quick hand. I had a few pages of time > calculations to do. So, i just started in on them typing them in my > time calculator and writing them in by hand. Now i realize, that i > really need a script to do this because: > > 1. It turns out there are hundreds of pages of this stuff. > 2. I have to do something similar in again soon. > 3. By doing it by hand i am introducing wonderful new errors! > 4. It all has to be typed up anyway (which means weeks of work and even > more typos!) > > The input would like so: > > Item_1TAPE_1100:238:23 > > Item_2TAPE_128:239:41 > > Item_3TAPE_139:4110:41 > Item_3TAPE_1410:4711:19 > Item_3TAPE_1511:2111:55 > Item_3TAPE_1611:5812:10 > Item_3TAPE_1712:1512:45Defect in analog tape sound. > Item_3TAPE_1812:5824:20Defect in analog tape sound. > > Item_4TAPE_1924:33 > Item_4TAPE_11025:48 > Item_4TAPE_11129:48 > Item_4TAPE_11231:46 > Item_4TAPE_11334:17Electronic sounds. > Item_4TAPE_11435:21 > Item_4TAPE_11536:06 > Item_4TAPE_11637:0137:38 > > These are analog tapes that were digitized (on to CD or a digital tape) > that have now been exported as individual files that are meant to be > part of an on-line audio archive. The timings refer to the time display > on the CD or digital tape. The now all have to adjusted so that each > item starts at 0.00 since they have all been edited out of their > context and are now all individual items that start at 00:00. So Item_1 > which was started at 00:23 on the tape and ended at 8:23 needs to have > 23 seconds subtracted to it so that it says: > > Item_1TAPE_1100:0008:00 > > Item_2TAPE_1208:2309:41 > > would change to: > > Item_2TAPE_1200:0001:18 > > etc. > > but as always you may notice a wrinkle some items have many times > (here 6) indicated: > > Item_3TAPE_139:4110:41 > Item_3TAPE_1410:4711:19 > Item_3TAPE_1511:2111:55 > Item_3TAPE_1611:5812:10 > Item_3TAPE_1712:1512:45Defect in analog tape sound. > Item_3TAPE_1812:5824:20Defect in analog tape sound. > > This is all a single sound file and these separate times mark where > there was a break, defect, or edit in the individual item. These have > to be adjusted as well to show where these events would appear in the > new sound file which now starts at 00:00. > > Item_3TAPE_1300:0001:00 > Item_3TAPE_1401:0001:38 > Item_3TAPE_1501:3802:14 > Item_3TAPE_1602:1402:29 > Item_3TAPE_1702:2903:04Defect in analog tape sound. > Item_3TAPE_1803:0414:39Defect in analog tape sound. > > Further wrinkles: Some have start and end times indicated, some only > start times. I suppose that the output would ideally have both some > have comments and others don't ... and I need these comments echo-ed or > since i probably need to make a database or table eventually non > comments just have some place holder. > > I'd have a lot of similar type calculations to do... I was hoping and > praying that some one here was feeling generous and show me the way and > then, of course i could modify that to do other tasks... Usually i am > happy to take the long road and all but i'll be honest, i am in a big > jam here and this huge task was just dumped on me. I am frankly a > little desperate for help on this and hoping someone is feeling up to > spoon feeding me a clear modifiable example that works. Sorry. > > cheers, > > kevin > k p 8 'at ' m a c 'dot' c o m > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- *Paul Tremblay * [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] need to hide process
I am trying to hide a process from a python script and don't know if I can do so. The process is a pax command, and my unsucesful code is below. I am trying to read from a pax archive (similar to a tar archive) to get a list of files. As long as the pax archive is valid, the code below works fine. The problem arises when the pax archive is not valid. In this case, the pax commnad gives this message: ATTENTION! pax archive volume change required. Ready for archive volume: 1 Input archive name or "." to quit pax. Archive name > pax then waits for the user to type in a command. I would like to supress both the message and the need for user input, because whenever this message appears, it always means the pax archive is corrupt. So ther is no need to see this confusing and misleading message. However, no matter what I have tried, I can't get away from pax both displaying the message and demanding the user type in a command. Do I need to fork a process? I have never done this, and the documentation is confusing to me. Thanks Paul def make_verify_list(self, archive, write_obj): if self.__main.verbose: sys.stdout.write('Making file from archive...\n') if self.__main.platform == 'darwin': command = 'hfspax -f %s ' % archive elif self.__main.platform == 'linux': command = 'pax -f %s' % archive junk_obj, read_obj, error_obj = os.popen3(command ) errors = [] line = 1 while 1: line = read_obj.readline() if line: # add a leading /, which was stripped away line = '/%s' % line line = line.replace('//', '/') index = line.find('\/..namedfork\/rsrc$') if index > -1: continue index = line.find('\/..namedfork\/finf$') if index > -1: continue write_obj.write(line) else: break # test for errors error_result = error_obj.readlines() read_obj.close() junk_obj.close() error_obj.close() if error_result: return 1 -- *Paul Tremblay * [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor