Help with regular expression patterns
Hi: i'm so newbie in python that i don't get the right idea about regular expressions. This is what i want to do: Extract using python some information and them replace this expresion for others, i use as a base the wikitext and this is what i do: paragraphs = """ = Test '''wikitest'''= [[Image:image_link.jpg|rigth|thumbnail|200px|"PREMIER"]] [http://www.google.com.cu] ::''Note: This is just an example to test some regular expressions stuffs.'' The ''wikitext'' is a text format that helps a lot. In concept is a simple [[markup]] [[programming_language|language]]. That helps to make simple create documentations texts. ==Wikitext== Created by Warn as a ... [ this is a normal sign] """.split('\n\n') import re wikipatterns = { 'a_nowiki' : re.compile(r"(.\S+)"), # nowiki 'section' : re.compile(r"\=(.*)\="),# section one tags 'sectiontwo' : re.compile(r"\=\=(.*?)\=\="),# section two tags 'wikilink': re.compile(r"\[\[(.*?)\]\]"), # links tags 'link': re.compile(r"\[(.*?)\]"), # external links tags 'italic': re.compile(r"\'\'(.*?)\'\'"), # italic text tags 'bold' : re.compile(r"\'\'\'(.*?)\'\'\'"), # bold text tags } for pattern in wikipatterns: print "===> processing pattern :", pattern, "<==" for paragraph in paragraphs: print wikipatterns[pattern].findall(paragraph) But When i run it the result is not what i want, it's something like: [EMAIL PROTECTED]:/local/python$python parser.py ===> processing pattern : bold <== ['braille'] [] [] [] [] [] ===> processing pattern : section <== [" Test '''wikitest'''"] [] [] ['=Wikitext='] [] [] ===> processing pattern : sectiontwo <== [] [] [] ['Wikitext'] [] [] ===> processing pattern : link <== ['[Image:image_link.jpg|rigth|thumbnail|200px|"PREMIER"'] ['http://www.google.com.cu'] ['[markup', '[programming_language|language'] [] [] [' this is a normal sign'] ===> processing pattern : italic <== ["'wikitest"] ['Note: This is just an example to test some regular expressions stuffs.'] ['wikitext'] [] [] [] ===> processing pattern : wikilink <== ['Image:image_link.jpg|rigth|thumbnail|200px|"PREMIER"'] [] ['markup', 'programming_language|language'] [] [] [] ===> processing pattern : a_nowiki <== [] [] [] [] [] ['sign]'] In the first case the result it's Ok In the second the first it's Ok, but the second it's not because second result it's a level two section not a level one. In the third result things are Ok The fourth, the first and thrid result are wrong beacuse they are level two links, but the second it's Ok. The fifth it Ok The sixth shows only one result and it should show two. Please help. PS: am really sorry about my technical English. -- Michel Perez )\._.,--,'``. Ulrico Software Group/, _.. \ _\ ;`._ ,. Nihil est tam arduo et difficile human `._.-(,_..'--(,_..'`-.;.' mens vincat. Séneca. = --- Red Telematica de Salud - Cuba CNICM - Infomed -- http://mail.python.org/mailman/listinfo/python-list
about recursive load
Hi, am very newbie in Python, but as part of a project i need to load configuration -a settings.py file in the package dir- of my apps recursively, something like this: settings.load_config("project.test.app") settings.load_config("project.test.*") settings.load_config("project.test") settings.load_config("*") this allows me to load them as: settings.project.CONFIG_PARAMETER_1 # project configuration settings.project.test.CONFIG_PARAMETER_1 # sub project and so on. This it's what i've done, class Settings: def __getattr__( self, attr): return self.__dict__['flags'][attr] def __setattr__(self, attr, value): self.__dict__['flags'][attr]=value def __init__(self, package = None, parent = None): self.__package = package self.__parent = None self.__dict__['flags']={} def get_parent ( self): return self.__parent def create_config_structure( self, pkg, parent = None ): # ... assuming no error and all that if pkg.count(".") > 0: if parent is None: if not self.__dict__['flags'].has_key(pkg[:pkg.find(".")]): father=self.__dict__['flags'][pkg]=Settings( \ pkg[:pkg.find(".")],self) else: father = parent else: if not parent.__dict__['flags'].has_key(pkg[:pkg.find(".")]): father=parent.__dict__['flags'][pkg[:pkg.find(".")]]= \ Settings(pkg[:pkg.find(".")], parent) else: father = parent self.create_config_structure( pkg [pkg.find(".")+1:],father) else: if not parent.__dict__['flags'].has_key: parent.__dict__['flags'][pkg]=Settings(pkg,parent) return parent.__dict__['flags'][pkg] def load_config ( self, pkg= None ): config_module_object = self.create_config_structure( pkg ) # the loading configuration part try: if pkg is not None: mod = __import__( pkg + ".settings", {},{},['']) else: mod = __import__( "settings", {},{},['']) except: raise ImportError("Settings not found") data={} for setting in dir(mod): if setting == setting.upper(): data[setting]=getattr(mod, setting) for key in data: if pkg is not None: setattr( config_module_object.__dict__['flags'], key, data[key]) else: setattr(self.__dict__['flags'], key, data[key]) Any idea it's welcome --- Red Telematica de Salud - Cuba CNICM - Infomed -- http://mail.python.org/mailman/listinfo/python-list
find an object ancestor
HI all: imagine something like this: class father: pass class son( father ): pass I need to know the son ancestor class how can i know this. Thanks --- Red Telematica de Salud - Cuba CNICM - Infomed -- http://mail.python.org/mailman/listinfo/python-list
Re: find an object ancestor
Thanks it works OK On Thu, 2008-11-06 at 13:14 +1000, James Mills wrote: > On Mon, Nov 3, 2008 at 7:16 AM, Michel Perez <[EMAIL PROTECTED]> > wrote: > > HI all: > > > > imagine something like this: > > > > class father: > >pass > > class son( father ): > >pass > > > > I need to know the son ancestor class how can i know this. > > >>> class Father(object): pass > ... > >>> class Son(Father): pass > ... > >>> son = Son() > >>> isinstance(son, Father) > True > >>> isinstance(son, Son) > True > >>> son.__class__.__bases__ > (,) > >>> > > --JamesMills > --- Red Telematica de Salud - Cuba CNICM - Infomed -- http://mail.python.org/mailman/listinfo/python-list
convert to XMLRPC
Que vola a todos: I have an object abstraction layer that allows me to comunicate and interact with my DB server without much problems -am thinking in possibles contributors. In the stdlib xmlrpclib handles this in a common way, but i use a customized GatewayHandler that give me the posibility to serialize my objects and send them to my clients but my real need is to convert this object to XML -or something like it- to send it in a way i can use them in every presentation a suggest like GUI, WEB or anything i like. There's any thing i can do to convert them. Don't worry about the way i handle the result i only need to convert them to XML or else. -- Michel Perez )\._.,--,'``. Ulrico Software Group/, _.. \ _\ ;`._ ,. Nihil est tam arduo et difficile human `._.-(,_..'--(,_..'`-.;.' mens vincat.Séneca. = --- Red Telematica de Salud - Cuba CNICM - Infomed -- http://mail.python.org/mailman/listinfo/python-list
problem with JSON-RPC
Hi everybody: I'm trying to use JSON-RPC to provide my services but produce this exception: Traceback (most recent call last): File "", line 1, in File "jsonrpc/proxy.py", line 43, in __call__ resp = loads(respdata) File "jsonrpc/json.py", line 211, in loads raise JSONDecodeException('Expected []{}," or Number, Null, False or True') jsonrpc.json.JSONDecodeException: Expected []{}," or Number, Null, False or True This is what am doing configuration file for apache Alias /services/ //home/mperez/Desktop/test_jsonrpc/ Options Indexes MultiViews FollowSymLinks Order deny,allow Allow from All AddHandler mod_python .py PythonHandler jsonrpc service for jsonrpc test.py from jsonrpc import ServiceMethod class MyService(object): @ServiceMethod def echo(self, msg): return msg service = MyService() service client #!/usr/bin/env python from jsonrpc import ServiceProxy s = ServiceProxy("http://localhost/services/test.py";) print s.echo("foobar") Regards -- Michel Perez )\._.,--,'``. Ulrico Software Group/, _.. \ _\ ;`._ ,. Nihil est tam arduo et difficile human `._.-(,_..'--(,_..'`-.;.' mens vincat.Séneca. = --- Red Telematica de Salud - Cuba CNICM - Infomed -- http://mail.python.org/mailman/listinfo/python-list