how to save python interpreter's command history
this has been a problem for me for some time. I want to save the interpretters command history to a file, there is a history file in my user directory .pyhistory but it saves only like 500 or so how can I make it save all the commands and not delete it, any other suggestions that people use is welcome thanks -- http://mail.python.org/mailman/listinfo/python-list
catching doctype using xml.sax -- please
Hi I would really appreciate if soemone can point me to the direction. how can I use xml.sax to catch doctype entities. there is a xml.sax.DTDHandler , but how should i use it? thanks -- http://mail.python.org/mailman/listinfo/python-list
converting xmllib to xml.sax
Hi I am trying to convert an override of xmllib.XMLparser , in the handle_doctype method we are catching the entities using load_dtd(sysid).gen_ents how can I do the same with xml.sax, does xml.sax has anything to catch the entties thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: socket connetion to url with port 80
thanks for the help I got the response using s.send("GET / HTTP/1.0\r\n\r\n"), but this socket is being blocked by squid server that we have installed in our socket. do you know how can i configure the squid to stop blocking the socket thanks -- http://mail.python.org/mailman/listinfo/python-list
socket connetion to url with port 80
Hi this is really a stupid question, how can i get page rsponse from a site e.g. google.com port 80 form socket, can i do something import socket s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) s.connect( ( "www.google.com", 80 ) ) s.send( "Hello" ) # GET?? response = s.recv(8048) print response can i do soemthign like that , can i send somehting to google and get webpage in return, I know that I can use urllib or httplib etc, but can i do at socket level? thanks -- http://mail.python.org/mailman/listinfo/python-list
Credit card API Sol with python interface
Hi does anybody know of any credit card merchant slution with python API. we used to use cybercash long time ago, but are willing to switch to something good and not pricy. we want to accept credit cards and process them. something with python wrapper will be great , as I would not have to build urllib wrappers around its functions. thanks -- http://mail.python.org/mailman/listinfo/python-list
dynamic construction of variables / function names
python provides a great way of dynamically creating fuctions calls and class names from string a function/class name can be stored as string and called/initilzed e.g def foo(a,b): return a+b def blah(c,d): return c*d list = ["foo", "blah"] for func in list: print func(2,4) or similar items what is the way if the names of functions are some modification e.g def Newfoo(a,b): return a+b def Newblah(c,d): return c*d list = ["foo", "blah"] for func in list: print "New"+func(2,4) or define a variable "New"+list[0] = "First Funciton" I think , print "New"+func(2,4) and "New"+list[0] = "First Funciton" will not work, either eval or exec should be used is it correct way, is there a simple way, is this techniqe has a name? thanks -- http://mail.python.org/mailman/listinfo/python-list
global namescape of multilevel hierarchy
Hi I have a script e.g. import package.module ID = "55" package.module.checkID() now in package.module.checkID function, i wnat to know what is the ID defiend in the calling scriipt if I dot globals(), it returns only items in module. is there a way to get the script level namesapce thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: html parser , unexpected '<' char in declaration
thanks for the suggestions, this is not happening frequently, actually this is the first time I have seen this exception in the system, which means that some spam message was generated with ill-formated html. i guess the best way would be to check using regular expression and delete the unclosed tags. -- http://mail.python.org/mailman/listinfo/python-list
Re: html parser , unexpected '<' char in declaration
thanks for the reply well probabbly I should explain more. this is part of an email . after the mta delivers the email, it is stored in a local dir. After that the email is being parsed by the parser inside an web based imap client at display time. I dont think I have the choice of rewriting the message!? and I dont want to reject the message alltogether. I can either 1-fix the incoming html by tidying it up or 2- strip only plain text out and dispaly that you have spam, 3 - or ignore that mal-formatted tag and display the rest -- http://mail.python.org/mailman/listinfo/python-list
html parser , unexpected '<' char in declaration
html = ' \r\n Foo foo , blah blah ' >>> import htmllib >>> import formatter >>> parser=htmllib.HTMLParser(formatter.NullFormatter()) >>> parser.feed(html) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/sgmllib.py", line 95, in feed self.goahead(0) File "/usr/lib/python2.4/sgmllib.py", line 165, in goahead k = self.parse_declaration(i) File "/usr/lib/python2.4/markupbase.py", line 132, in parse_declaration self.error( File "/usr/lib/python2.4/htmllib.py", line 40, in error raise HTMLParseError(message) htmllib.HTMLParseError: unexpected '<' char in declaration the error is generated by unclosed DOCTYPE declaration what is the best way to handle this kind of document. should I use regex to check and strip, or does HTMLParser offers something? , can i override default sgmllib behaviour I have to work with this htmllib because of existing modules . thanks -- http://mail.python.org/mailman/listinfo/python-list
.py vs .pyc
Hi all is execution of pyc files faster than py files? since both files are interpreted by python , is there any speedup in using one or other? what is difference if i type from cmd line, python test.py vs. python test.pyc thanks -- http://mail.python.org/mailman/listinfo/python-list
py vs pyc
Hi I want to know that is .pyc files execute faster than .py files,? since both are interpreted by python , is there any speedup in using one or other.? e.g. what is the difference between runing from cmd "python test.py" and "python test.pyc" thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: xsl and unicode surrogate characters
thanks very much for the info, it really helped we are using the text from file to display on webpage and we have a method for conversion the parsed data to utf-8 and then displaying, all the data looks fine after parsing except the surrogate pair, since i can not guess what it was supposed to be , is it ok to strip it using regex re.complie(' [\xed|\xa0] ')? Martin v. Löwis wrote: > Sakcee wrote: > > Hi > > > > In one of the data files that I have , I am seeing these characters > > \xed\xa0\xa0 . They seem to break the xsl. > [...] > > is this a unicode utf-16 surrogate pair ? > > Yes and no. This is the UTF-8 encoding of U+D820, which is a high > surrogate code point. So yes. It's not yet a pair; there would have to > be a second such code point. So no. > > Furthermore, in UTF-8, you should never ever have encoded surrogate > codes; instead, whoever generated the UTF-8 should have combined the > two surrogate code point into a single coded character, and should > have encoded *that* character. So no - this byte sequence isn't > even valid UTF-8. > > > for displaying it on xml/xsl, should I extract only \xa0? > > You should tell your parser to reject the file as ill-formed. > > > since this is hingher than 00-7f range can i just strip it? > > Depending an what you want to achieve: sure! It will modify > the meaning of the bytes, of course. > > > under what condition the encoding software put this string in? > > If it has a bug. > > Regards, > Martin -- http://mail.python.org/mailman/listinfo/python-list
xsl and unicode surrogate characters
Hi In one of the data files that I have , I am seeing these characters \xed\xa0\xa0 . They seem to break the xsl. --- Extra content at the end of the document XML/XSL Error:
rss parsing: sax or dom
hi I am trying to parse rss2 feeds in python, should I use sax and define handler and then functions for each tag or should I go for dom approach. thanks for any comments -- http://mail.python.org/mailman/listinfo/python-list
Rss/xml namespaces sgmllib, sax, minidom
I want to build a simple validator for rss2 feeds, that checks basic structure and reports channels , items , and their attributes etc. I have been reading Mark Pilgrims articles on xml.com, diveintopython and someother stuff on sgmllib, sax.handlers and content handlers, xml.dom.minidom why is all of this necessary, what is the difference between all these libraries, it seems to me that I can parse the rss2 feed with any of these libraries.!! ? what is the difference between namespaces and non-namspaces functions in sax.handlers.contenthandler , is the namespace defined like domain names on some website? thanks for any comments -- http://mail.python.org/mailman/listinfo/python-list
Re: pyUnit and dynamic test functions
Excellent , your example is elegant and runs beautifully so the idea is to create a testcase which runs a general function "testRun" (which calls the function defined in file )and loads data based on type , add this testcase to suite and run suite. thanks , this is exactly what I was looking for. Fabrizio Milo wrote: > > thanks for any input or any alternate approach to it > > I think that your approach is not fair. > > You should create a TestCase for each of your data input, add it to a > TestSuite > and run the test suite. > > Here is a stub for loading just a 'dict' type, hoping it is helpful > > > import unittest > import glob > from string import split,strip > > def getUSStates(*args): >#Fake >return {'AK:': 'Alaska', 'CA:': 'California', 'AR:': 'Arkansas', > 'CO:': 'Colorado', 'WY:': 'Wyoming', 'AZ:': 'Arizona', 'AL:': > 'Alabama'} > > class TestStubException( Exception ): >''' >Test case creation failed. >''' > > class TestStub( unittest.TestCase ): > >def __init__( self, fname, farg, t_out, out ): >unittest.TestCase.__init__(self,'testRun') >self.fname = eval(fname,globals()) >self.input = farg >self.fparse = getattr(self,'load_%s' % t_out) >self.output = self.fparse( out ) > >def load_dict(self,data): >assert data[0] is '{', 'Wrong dict format %s' % data >assert data[-1] is '}', 'Wrong dict format %s' % data >items = data[1:-1].split(',') >return dict( map( split, map( strip, items ) ) ) > >def testRun(self): >self.assertEquals( self.fname(self.input), self.output ) > > > def build_tests( filename ): >try: >fd = open( filename, 'r') >tc = TestStub( *fd.read().split("~") ) >del fd >return tc >except: >import traceback; traceback.print_exc() >raise TestStubException( 'Failed creating test case from file > : %s'%filename ) > > if __name__== '__main__': > >tc_data = glob.glob('*.txt') # all text files with data > >ts = unittest.TestSuite() > >for tc_file in tc_data: >ts.addTest( build_tests( tc_file ) ) > >unittest.TextTestRunner().run(ts) > > > Fabrizio Milo aka Misto -- http://mail.python.org/mailman/listinfo/python-list
Re: pyUnit and dynamic test functions
Thanks for reply, here is the script with trucated datafile The data file is following , --- data file getUSStates~~dict~ {AK: Alaska, AL: Alabama, AR: Arkansas, AZ: Arizona, CA: California, CO: Colorado, WY: Wyoming } data file I want to test function:getUSStates that takes input none and outputs a dict of us states.the first line shows function name~input~output_format~expected_output Now I have following class and loadTestInfoFromFile function for loading the values for file and assinging the data to self.outputOfFunc etc class getUsStates( unittest.TestCase ): func_name = None inputToFunc = None outputOfFunc = None outputType = None setup = None testUsStates = None testLength = None def loadTestInfoFromFile(self): """ read function name, input to function, output format and output from file""" rest = file('data.txt').read() self.func_name , self.inputToFunc, self.outputType,outputOfFuncRaw = rest.split("~") if self.outputType == 'dict': outputOfFuncRaw = outputOfFuncRaw.split(",") self.outputOfFunc = {} for i in range(0,len(outputOfFuncRaw)): li= ( (outputOfFuncRaw[i].strip()).replace('}','') ).split(':') self.outputOfFunc[li[0]]=li[1] def buildTestFunctions( self, returnedVals, func_name, inp ): self.testReturnVal = lambda : self.assertEqual( inp, returnedVals ) self.testLength= lambda : self.assertEqual( len(returnedVals) , len(inp) ) def runFunction(): g = getUsStatesTest() g.loadTestInfoFromFile() g.buildFunctions(g.returnedVals,g.func_name,g.outputOfFunc) if __name__ == "__main__": unittest.main(defaultTest="runFunction") Now in the buildTestFunctions() I want to setup 2 unittest test function that do assertEqual so that I have 2 functions which are dynamically created from file , now I want to associate these function with unittest and run them. the above runs correctly reads the data and make 2 funcitons testReturnVal and testLength but then I want to associate those funcitons to unittest. and run unit test but that part i dont know how to do. in this way I can define 100 functions with inputs and expected outputs in a data file and this type of script will generate similar assert functions for all of them on fly and run them thanks for any input or any alternate approach to it Kent Johnson wrote: > Sakcee wrote: > > Hi > > > > I am trying to use pyUnit to create a framework for testing functions > > > > I am reading function name, expected output, from a text file. > > Can you show a sample of what the text file might look like, and what tests > you want to > generate from it? > > > and in python generating dynamic test functions > > something like this > > > > > > class getUsStatesTest( unittest.TestCase ): > > > > self.setUp = lambda : function_call > > self.testReturnVal = lambda : self.assertEqual( fileInput, > > function_returnedVals ) > > self.testLength= lambda : self.assertEqual( len(returnedVals) > > , len(inp) ) > > I don't understand the above at all. What do function_call, > function_returnedVals, > returnedVals and inp refer to? What is the point of the lambdas and the > assignment to > attributes of (undefined) self? > > Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: pyUnit and dynamic test functions
Please anyone help, is this kind of dynamin thing possible? any suggestion for creating frameworks for automated testing , all comments appreciated thanks Sakcee wrote: > Hi > > I am trying to use pyUnit to create a framework for testing functions > > I am reading function name, expected output, from a text file. > and in python generating dynamic test functions > something like this > > > class getUsStatesTest( unittest.TestCase ): > > self.setUp = lambda : function_call > self.testReturnVal = lambda : self.assertEqual( fileInput, > function_returnedVals ) > self.testLength= lambda : self.assertEqual( len(returnedVals) > , len(inp) ) > > > > is it possible to load these dynamic functions via pyUnit, instead of > defining in text form , > can i use loadfromname etc to load these dynamic test functions. > > something like this > > unittest.TestSuite(unittest.defaultTestLoader.loadTestsFromName( > getUsStatesTest() )) > > in this way I can completely automate every function that returns some > output by dynamically generating its > test functions > > thanks -- http://mail.python.org/mailman/listinfo/python-list
pyUnit and dynamic test functions
Hi I am trying to use pyUnit to create a framework for testing functions I am reading function name, expected output, from a text file. and in python generating dynamic test functions something like this class getUsStatesTest( unittest.TestCase ): self.setUp = lambda : function_call self.testReturnVal = lambda : self.assertEqual( fileInput, function_returnedVals ) self.testLength= lambda : self.assertEqual( len(returnedVals) , len(inp) ) is it possible to load these dynamic functions via pyUnit, instead of defining in text form , can i use loadfromname etc to load these dynamic test functions. something like this unittest.TestSuite(unittest.defaultTestLoader.loadTestsFromName( getUsStatesTest() )) in this way I can completely automate every function that returns some output by dynamically generating its test functions thanks -- http://mail.python.org/mailman/listinfo/python-list
ddd or eclipse with mod_python
Hi I am using mod_python for web development, I am in need of some ide , can i use ddd or eclipse with pydev with mod_python. can these ide's handle requests from mod_python and run server side scripts any help or pointers are greatly appreciated thanks clive -- http://mail.python.org/mailman/listinfo/python-list
pydoc search in browser
Hi I am a newbie to pydoc and I need some help. I would really appreciate if some one can tell me how to add search box in a page generated by pydoc, e.g. I want to add serch like the one in pydoc.org thanks sakcee -- http://mail.python.org/mailman/listinfo/python-list