Re: [PATCH] Fixed parsing of strings with multiple values in pyudev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Hans,

the problem with this is, that we get some lvm properties, which look like this:

{ 'LVM_SOMETHING' : 'abc LVM_SOMETHING=def LVM_SOMETHING=xyz' }

With regular split(), I would have to go over the list, and remove the LVM_SOMETHING= parts from [1:] items,
re.split() does this for me.

But you're right about the re special chars in name, that would break everything.
I don't know if there are some special chars allowed in the udev properties keys, are they?

If yes, I can do it with, .find(), .split(), .replace(), do you think it will be a better solution?



--

  Martin Gracik

----- "Hans de Goede" <hdegoede@xxxxxxxxxx> wrote:

> Hi,
> 
> Why are you using a re.split and not just a regular split,
> also what happens if name has any re special chars in it,
> is there a re escape function you can use?
> 
> Regards,
> 
> Hans
> 
> 
> On 02/02/2010 07:48 PM, Martin Gracik wrote:
> > Some of the values which are returned by udev are strings,
> > which contain more values for the same key.
> > The string format is "val1 key=val2 key=val3 ...".
> > This fix makes sure we split this string into a list of values.
> > ---
> >   pyudev.py |    6 ++++++
> >   1 files changed, 6 insertions(+), 0 deletions(-)
> >
> > diff --git a/pyudev.py b/pyudev.py
> > index 6ab5d30..a16f9c3 100644
> > --- a/pyudev.py
> > +++ b/pyudev.py
> > @@ -3,6 +3,7 @@ from __future__ import print_function
> >   import sys
> >   import os
> >   import fnmatch
> > +import re
> >   from ctypes import *
> >
> >
> > @@ -145,6 +146,11 @@ class UdevDevice(dict):
> >               name =
> libudev_udev_list_entry_get_name(property_entry)
> >               value =
> libudev_udev_list_entry_get_value(property_entry)
> >
> > +            # XXX some of the strings contain a list of values in
> them,
> > +            # we want to split them and make a list
> > +            if re.match(".* %s=.*" % name, value):
> > +                value = re.split(" %s=" % name, value)
> > +
> >               self[name] = value
> >
> >               # get next property entry
> 
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux