From Gideon.STREET at ergon.com.au Wed Mar 1 00:47:54 2006 From: Gideon.STREET at ergon.com.au (STREET Gideon (SPARQ)) Date: Wed, 1 Mar 2006 09:47:54 +1000 Subject: [Tutor] Telnet to cisco device Message-ID: <5A504BF2C0C9F5438ACBF61D35D49FFC06E35B@ebnewem01.ergon> Thanks all for the replies. I got tcpwatch up and running and where the program was hanging is actually a page prompt, so now I just need to get the script to pass a space whenever that prompt comes up.... I'm surprised it worked and got to that point (that's a testament to the online tutorials). Fun and games :) -----Original Message----- From: Python [mailto:python at venix.com] Sent: Tuesday, 28 February 2006 11:05 PM To: STREET Gideon (SPARQ) Cc: Tutor Python Subject: Re: [Tutor] Telnet to cisco device On Tue, 2006-02-28 at 16:36 +1000, STREET Gideon (SPARQ) wrote: > tn.read_until('Username: ') #expected prompt after telnetting to the > router tn.write(user + '\r\n') #hopefully write username and pass > character return > Sending both \r and \n may be confusing things. I'd recommend using tcpwatch.py http://hathawaymix.org/Software/TCPWatch to monitor a telnet session that works. That way you will have a collection of exact prompts available to build your script. -- Lloyd Kvam Venix Corp This e-mail (including any attachments) may contain confidential or privileged information and is intended for the sole use of the person(s) to whom it is addressed. If you are not the intended recipient, or the person responsible for delivering this message to the intended recipient, please notify the sender of the message or send an e-mail to mailto:help.desk at ergon.com.au immediately, and delete all copies. Any unauthorised review, use, alteration, disclosure or distribution of this e-mail by an unintended recipient is prohibited. Ergon Energy accepts no responsibility for the content of any e-mail sent by an employee which is of a personal nature. Ergon Energy Corporation Limited ABN 50 087 646 062 Ergon Energy Pty Ltd ABN 66 078 875 902 From prabhu.chinnee at gmail.com Wed Mar 1 08:05:08 2006 From: prabhu.chinnee at gmail.com (Prabhakar K) Date: Wed, 1 Mar 2006 12:35:08 +0530 Subject: [Tutor] Fwd: Problem wxPython In-Reply-To: <7528bcdd0602170522i395a391dp8af5e56305e409cb@mail.gmail.com> References: <3ae549770602170513o1c4a51e2x67fc09024df1f40@mail.gmail.com> <7528bcdd0602170522i395a391dp8af5e56305e409cb@mail.gmail.com> Message-ID: <3ae549770602282305o533ba085o4eaf9ecc9e590d1f@mail.gmail.com> Hai to all, I installed ActivePython-2.4.1-247-win32-ix86 and wxPython2.6-win32-ansi-2.6.2.1-py2 in my system. When i Run a wxPython example.. geeting an Errors Traceback (most recent call last): File "E:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "F:\python\wx.py", line 1, in ? from wxPython.wx import * File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\__init__.py", line 10, in ? import _wx File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\_wx.py ", line 3, in ? from _core import * File "E:\Python24\lib\site-packages\wx-2.6-msw-ansi\wxPython\_core.py", line 15, in ? import wx._core File "F:\python\wx.py", line 1, in ? from wxPython.wx import * ImportError: No module named wx Program Code: from wxPython.wx import * class MyApp(wxApp): def OnInit(self): frame = wxFrame(NULL, -1, "Hello from wxPython") frame.Show(true) self.SetTopWindow(frame) return true app = MyApp(0) app.MainLoop() -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20060301/251fc8c3/attachment.html From andreengels at gmail.com Wed Mar 1 11:58:19 2006 From: andreengels at gmail.com (Andre Engels) Date: Wed, 1 Mar 2006 11:58:19 +0100 Subject: [Tutor] password protection in httplib Message-ID: <6faf39c90603010258w53737201n@mail.gmail.com> I am active in pywikipediabot, which is programmed in Python and is used to edit wikis (based on MediaWiki, such as Wikpedia). It uses httplib to connect to the site and get the HTML data. I now want to use it on another site, but this site is password protected (we want to first improve it before releasing it to the public). Is it possible with httplib to connect to password protected sites (given that I know the login and password of course), and if so, how is this done? If not, is there an alternative? -- Andre Engels, andreengels at gmail.com ICQ: 6260644 -- Skype: a_engels From kent37 at tds.net Wed Mar 1 13:05:08 2006 From: kent37 at tds.net (Kent Johnson) Date: Wed, 01 Mar 2006 07:05:08 -0500 Subject: [Tutor] password protection in httplib In-Reply-To: <6faf39c90603010258w53737201n@mail.gmail.com> References: <6faf39c90603010258w53737201n@mail.gmail.com> Message-ID: <44058DF4.10402@tds.net> Andre Engels wrote: > I am active in pywikipediabot, which is programmed in Python and is > used to edit wikis (based on MediaWiki, such as Wikpedia). It uses > httplib to connect to the site and get the HTML data. > > I now want to use it on another site, but this site is password > protected (we want to first improve it before releasing it to the > public). Is it possible with httplib to connect to password protected > sites (given that I know the login and password of course), and if so, > how is this done? If not, is there an alternative? What kind of authentication is used? Basic and digest authentication will pop up a dialog in the browser asking for your credentials. The browser then remembers the credentials and includes them in subsequent requests. With form-based authentication, a page displays in the browser with a login form; the web site authenticates and usually sends a cookie to the browser which must be included in subsequent requests. urllib2 has good built-in support for basic and digest authentication of web sites. For form-based authentication you have to do a bit more work - install a cookie manager and post to the form yourself. See http://www.voidspace.org.uk/python/articles/authentication.shtml for examples of basic auth. Digest auth works pretty much the same way. Make sure you read to the section "Doing It Properly" - the author likes to show you the hard way first. The article http://www.voidspace.org.uk/python/articles/cookielib.shtml shows how to use cookies, though again the presentation makes it look harder than it really is, at least in Python 2.4 that has CookieLib built in. You have to post to the login form yourself, but that is just another urllib2 request. Kent From joaquin_barcelo_12 at yahoo.es Wed Mar 1 17:13:54 2006 From: joaquin_barcelo_12 at yahoo.es (Joaquin Sanchez Sanchez) Date: Wed, 1 Mar 2006 17:13:54 +0100 (CET) Subject: [Tutor] URGENT doubt!!!! Message-ID: <20060301161354.69849.qmail@web26910.mail.ukl.yahoo.com> I have a doubt I have some modules in python, and in one of them, i have to dictionarys. In them, i have some vars yhat I want to save before clossing my session, ande then, in a new session, i want to load them. I have heard about "pickle" How does it work?I dont understand the help page example How have I to used it? Another suggestion? THANKS A LOT --------------------------------- LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y m?viles desde 1 c?ntimo por minuto. http://es.voice.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20060301/a1ddcbfc/attachment.htm From python at venix.com Wed Mar 1 17:29:48 2006 From: python at venix.com (Python) Date: Wed, 01 Mar 2006 11:29:48 -0500 Subject: [Tutor] URGENT doubt!!!! In-Reply-To: <20060301161354.69849.qmail@web26910.mail.ukl.yahoo.com> References: <20060301161354.69849.qmail@web26910.mail.ukl.yahoo.com> Message-ID: <1141230588.15743.500.camel@www.venix.com> On Wed, 2006-03-01 at 17:13 +0100, Joaquin Sanchez Sanchez wrote: > I have a doubt > > I have some modules in python, and in one of them, i have to > dictionarys. In them, i have some vars yhat I want to save before > clossing my session, ande then, in a new session, i want to load them. > > I have heard about "pickle" > How does it work?I dont understand the help page example > How have I to used it? > Another suggestion? I think the shelve module better fits what you are trying to do. It will store the pickle into a file for later retrieval and possible modification. http://docs.python.org/lib/module-shelve.html Note that you should be using strings for the shelve keys. > > THANKS A LOT > > > ______________________________________________________________________ > > LLama Gratis a cualquier PC del Mundo. > Llamadas a fijos y m?viles desde 1 c?ntimo por minuto. > http://es.voice.yahoo.com > _______________________________________________ > Tutor maillist - Tutor at python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp From kent37 at tds.net Wed Mar 1 17:37:51 2006 From: kent37 at tds.net (Kent Johnson) Date: Wed, 01 Mar 2006 11:37:51 -0500 Subject: [Tutor] URGENT doubt!!!! In-Reply-To: <20060301161354.69849.qmail@web26910.mail.ukl.yahoo.com> References: <20060301161354.69849.qmail@web26910.mail.ukl.yahoo.com> Message-ID: <4405CDDF.7090808@tds.net> Joaquin Sanchez Sanchez wrote: > I have a doubt > > I have some modules in python, and in one of them, i have to > dictionarys. In them, i have some vars yhat I want to save before > clossing my session, ande then, in a new session, i want to load them. > > I have heard about "pickle" > How does it work?I dont understand the help page example Yeah, that is an advanced example, for a simple example look at example 2 on this page: http://www-128.ibm.com/developerworks/library/l-pypers.html Kent From hugonz-lists at h-lab.net Wed Mar 1 18:08:10 2006 From: hugonz-lists at h-lab.net (=?ISO-8859-1?Q?Hugo_Gonz=E1lez_Monteverde?=) Date: Wed, 01 Mar 2006 11:08:10 -0600 Subject: [Tutor] URGENT doubt!!!! In-Reply-To: <20060301161354.69849.qmail@web26910.mail.ukl.yahoo.com> References: <20060301161354.69849.qmail@web26910.mail.ukl.yahoo.com> Message-ID: <4405D4FA.6020309@h-lab.net> Ok, if it's so urgent. import cPickle mydict = {1:"one", 2:"two"} #Saving fileo = open("mysavedfile", "w") cPickle.dump(mydict, fileo) fileo.close() fileo2 = open("mysavedfile", "r") saved_dict = cPickle.load(fileo2) print saved_dict Hope this one is simple enough Hugo From max.mail.lists at googlemail.com Wed Mar 1 12:32:42 2006 From: max.mail.lists at googlemail.com (Max Russell) Date: Wed, 1 Mar 2006 11:32:42 +0000 Subject: [Tutor] Non type object? Message-ID: <101a41db0603010332h3bb1dab7x26ceaa4a36cef983@mail.gmail.com> I'm trying to debug a script that takes a load of Python files and checks them against original text files- it's for checking headers: #script to verify content of a header is what is should be. import difflib, os, re, sys class HeaderChecker(object): def __init__(self, directoryPy, directoryTxt, outputFilePath=None): """script that reverts the headers from a set of Python files and checks them against the original text from a test""" self._directoryToCheck = directoryPy self._directoryForCompare =directoryTxt self._outputFileName = outputFilePath # open file to create/clear it if self._outputFileName != None: outputFile = open(self._outputFileName, "w") outputFile.write("Log file for verifying headers") outputFile.close() # get the contents of the Python directory if not os.path.exists(self._directoryToCheck): raise ScriptException("Directory %s does not exist"%self._directoryToCheck) fileList = os.listdir(self._directoryToCheck) # just look at the python files (make entries with an absolute file path) self._pythonFileList = [] for file in fileList: if file.endswith(".py"): self._pythonFileList.append(self._directoryToCheck + "\\" + file) print self._pythonFileList if len(self._pythonFileList) == 0: raise ScriptException("Directory %s does not contain any python files "%directoryPy) #get the contents of the original text directory for comparison if not os.path.exists(self._directoryForCompare): raise ScriptException("Directory %s does not exist"%self._directoryForCompare) txtList = os.listdir(self._directoryForCompare) self._txtFileList = [] for item in txtList: if item.endswith(".txt"): self._txtFileList.append(self._directoryForCompare + "\\" + item) print self._txtFileList if len(self._txtFileList)==0: raise ScriptException("Directory %s does not contain any python files "%directoryTxt) def getValidPythonFiles(self): """ get valid python files """ self.log(["found %d python files in %s"%(len(self._pythonFileList), self._directoryToCheck)]) return self._pythonFileList def getTextFiles(self): """ get method for list of text files """ self.log(["found %d text files in %s"%(len(self._txtFileList), self._directoryForCompare)]) return self._txtFileList def getFileNameFromPath(self, filePath): """ Extract the file name from the file path @param filePath File path for the python file. @return File name """ path, file = os.path.split(filePath) return file def stripFile(self, filetostrip): """ Strips Python files of "#> " commenting and removes the code, writes out to a stripped file """ print "\n" + "stripFile is executed" + "\n" print ("\n" + filetostrip) fh = open(filetostrip, "r") filelines = fh.readlines() filetostrip = filetostrip.rstrip("py") filetostrip = (filetostrip + "strp") strippedfile = open(filetostrip, "w") for thisline in filelines: if thisline.startswith ("#> "): thisline.lstrip("#> ") strippedfile.write(thisline + "\n") strippedfile.close() fh.close() def compStripToTxt(self, origfile, strippedfile): """ Compares the stripped Python header file to the original text of a test """ print "compStripToTxt is executed" orig = open(origfile, "r") stripped = open(strippedfile, "r") origentry = orig.readlines() strippedentry = stripped.readlines() orig.close() stripped.close() if origentry != strippedentry: d = difflib.Differ() variance = list(d.compare(origentry, strippedentry)) print variance return variance else: return None def log(self, linesToLog): """ Log the script output to a file - echo to the console. @param linesToLog List of strings to write out """ # if we have a output file write to it if self._outputFileName != None: outputFile = open(self._outputFileName, "a") if len(linesToLog) == 0: outputFile.write("\n") for line in linesToLog: outputFile.write(line + "\n") outputFile.close() # output to shell if len(linesToLog) == 0: print for line in linesToLog: print line ###################################### #MAIN SECTION ###################################### if __name__ == "__main__": checker = HeaderChecker(sys.argv[1], sys.argv[2], sys.argv[3]) pythonFileList = checker.getValidPythonFiles() checker.log([]) checker.log(pythonFileList) #For all files in the list of Python files, strip the files of the header #comments markings changes = [] for text in checker._txtFileList: file1 = checker.getFileNameFromPath(text) for pyfile in pythonFileList: file2 = checker.getFileNameFromPath(pyfile) print "comparing %s to %s"%(file1[:-4], file2[:-3]) if file1[:-4] == file2[:-3]: print "matched %s to %s"%(file1[:-4], file2[:-3]) pytostrip = checker._directoryToCheck + "\\" + file2 print pytostrip stripped = checker.stripFile(pytostrip) print stripped #print "\n" + stripped + "\n" diff =checker.compStripToTxt(text, stripped) print diff if diff: # changes.append(diff) print changes break Now, I have a lot of print statements in there for debugging purposes, but I don't understand why when I run it, and it parses through my input directory and comparison directory it returns this None compStripToTxt is executed Traceback (most recent call last): File "HeaderChecker.py", line 182, in ? diff =checker.compStripToTxt(text, stripped) File "HeaderChecker.py", line 114, in compStripToTxt stripped = open(strippedfile, "r") TypeError: coercing to Unicode: need string or buffer, NoneType found Why is it returning the None type? How can I fix this? thanks Max -- Max Russell Senior Test Engineer Barco Bonnington Bond, 2 Anderson Place, Edinburgh EH6 5NP, UK Tel + 44 (0) 131 472 5731 Fax + 44 (0) 131 472 4799 www.barco.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20060301/db734e02/attachment.htm From kent37 at tds.net Wed Mar 1 19:25:11 2006 From: kent37 at tds.net (Kent Johnson) Date: Wed, 01 Mar 2006 13:25:11 -0500 Subject: [Tutor] Non type object? In-Reply-To: <101a41db0603010332h3bb1dab7x26ceaa4a36cef983@mail.gmail.com> References: <101a41db0603010332h3bb1dab7x26ceaa4a36cef983@mail.gmail.com> Message-ID: <4405E707.10105@tds.net> Max Russell wrote: > None > compStripToTxt is executed > Traceback (most recent call last): > File "HeaderChecker.py", line 182, in ? > diff =checker.compStripToTxt(text, stripped) > File "HeaderChecker.py", line 114, in compStripToTxt > stripped = open(strippedfile, "r") > TypeError: coercing to Unicode: need string or buffer, NoneType found > > > > Why is it returning the None type? > > How can I fix this? It's because stripped is None in your main program, as the print statement shows. stripped is the value returned from stripFile(). Since stripFile() doesn't explicitly return anything, its return value is None. I think you want stripFile() to return the name of the stripped file, which is filetostrip. Kent From Barry.Carroll at psc.com Wed Mar 1 21:13:30 2006 From: Barry.Carroll at psc.com (Carroll, Barry) Date: Wed, 1 Mar 2006 12:13:30 -0800 Subject: [Tutor] Unexpected Behavior in unittest Message-ID: <2BBAEE949D384D40A2B851287ADB6A432C3607@eugsrv400.psc.pscnet.com> Danny: I went back and double checked all of my test files, and you were right I was actually running an older version of test3.py. In that, the assignment to the character separator was wrong: lg.sc = 2.5 Having forgotten that Python allows dynamic creation of object attributes at run time, I assumed (incorrectly) that the interpreter would catch a misspelled attribute name. lg.sc was being assigned just fine, leaving lg.cs blissfully unchanged. The test case caught the error as it should, leaving me scratching my head and bothering you. A case of C++ memory intruding into Python space. Thank you for pointing out the real problem. Regards, Barry barry.carroll at psc.com 541-302-1107 ________________________ We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed > -----Original Message----- > From: Danny Yoo [mailto:dyoo at hkn.eecs.berkeley.edu] > Sent: Tuesday, February 28, 2006 2:57 PM > To: Carroll, Barry > Cc: tutor at python.org > Subject: RE: [Tutor] Unexpected Behavior in unittest > > > > > I wish it were that simple. 'test3.py' is the name of the file > > containing the test case class. I left the invocation out of my output > > excerpt. It should look like this: > > Hi Barry, > > > Ok. > > But still go back and make sure you're running the right file. <> > Python isn't magical, so I have to assume that some program, > different than the one you've shown us, is being executed. > > > Does this make sense? > From Simo10 at mchsi.com Thu Mar 2 01:36:26 2006 From: Simo10 at mchsi.com (Jacob Simonovich) Date: Wed, 1 Mar 2006 18:36:26 -0600 Subject: [Tutor] (no subject) Message-ID: <000601c63d91$579ac1b0$6600a8c0@LivingRoom> I want to learn how to hack but don't know where to start. I have been searching all over the internet to try to find things out but none of the websites have helped me. I would like to know the tools needed and just a step by step process on how to do it using widows xp home edition. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20060301/680c01c3/attachment.html From benvinger at googlemail.com Thu Mar 2 11:25:19 2006 From: benvinger at googlemail.com (Ben Vinger) Date: Thu, 2 Mar 2006 10:25:19 +0000 Subject: [Tutor] How can a function know where it was called from Message-ID: Hello I want myfunction in the pseudocode below return something different if it was called from indexfunction. def indexfunction(): blah def myfunction(): x = 'whatever' if : return x else: return
+ x +