[Baypiggies] Discussion for newbies/beginner night talks
Keith Dart
keith at dartworks.biz
Wed Feb 28 04:32:47 CET 2007
On Tue, 13 Feb 2007 15:33:53 -0800
"Shannon -jj Behrens" <jjinux at gmail.com> wrote:
> #) Monkey patching!
>
> At runtime, anything is hackable. Sometimes you have to rely on a
> third party library that does the wrong thing. Now, you should start
How's this for "monkey patching":
import new
parser = xml.sax.sax2exts.XMLParserFactory.make_parser()
...
# since the xml API provides some generic parser I can't just
# subclass I have to "patch" the object in-place with this trick.
# This is to a) make the API compatible with the HTMLParser, and b)
# allow specifing the encoding in the request.
parser.parse_orig = parser.parse
def parse(self, url, data=None, encoding=POM.DEFAULT_ENCODING):
import WWW.urllibplus
fo = WWW.urllibplus.urlopen(url, data, encoding)
return self.parse_orig(fo)
parser.parse = new.instancemethod(parse, parser, parser.__class__)
return parser
(sorry about the late reply)
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Dart <keith at dartworks.biz>
public key: ID: 19017044
<http://www.dartworks.biz/>
=====================================================================
More information about the Baypiggies
mailing list