[lxml-dev] [objectify] __MATCH_PATH_SEGMENT regexmodificationsuggestion

Stefan Behnel stefan_ml at behnel.de
Wed Feb 21 16:01:40 CET 2007


Hi Holger,

Holger Joukl wrote:
> just noticed this has probably gone down and wanted to bring it up
> once more:

Good idea. :)


> I suggest to loosen the __MATCH_PATH_SEGMENT regex a little
> to care for more possible element names, which are sometimes
> outside of my control.
> Currently ObjectPath chokes on paths like 'root.a-x.a-y'.
> While such names are often inconvenient at best I found that
> python itself is quite non-restrictive wrt attibute names:

> >>> setattr(Foo, 'a-b', "hmm")

>>
>> __MATCH_PATH_SEGMENT = re.compile(
>>
> r"(\.?)\s*(?:\{([^}]*)\})?\s*([^.{}\[\]]+)\s*(?:\[\s*([-0-9]+)\s*\])?",
>>     re.U).match
>>
>> (Changed: (([^.{}\[\]]+) replaces (\w+))

That's ok with me. I applied the following patch to the trunk. Note the "\s"
bit, which excludes white space from the character set.

Stefan

Index: src/lxml/objectify.pyx
===================================================================
--- src/lxml/objectify.pyx      (Revision 39233)
+++ src/lxml/objectify.pyx      (Arbeitskopie)
@@ -1130,7 +1130,7 @@

 cdef object __MATCH_PATH_SEGMENT
 __MATCH_PATH_SEGMENT = re.compile(
-    r"(\.?)\s*(?:\{([^}]*)\})?\s*(\w+)\s*(?:\[\s*([-0-9]+)\s*\])?",
+    r"(\.?)\s*(?:\{([^}]*)\})?\s*([^.{}\[\]\s]+)\s*(?:\[\s*([-0-9]+)\s*\])?",
     re.U).match

 cdef _parseObjectPathString(path):



More information about the lxml-dev mailing list