Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: third_party/logilab/logilab/common/xmlutils.py

Issue 1920403002: [content/test/gpu] Run pylint check of gpu tests in unittest instead of PRESUBMIT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update path to LICENSE.txt of logilab/README.chromium Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/logilab/logilab/common/xmlrpcutils.py ('k') | third_party/pylint/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # -*- coding: utf-8 -*-
2 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
4 #
5 # This file is part of logilab-common.
6 #
7 # logilab-common is free software: you can redistribute it and/or modify it unde r
8 # the terms of the GNU Lesser General Public License as published by the Free
9 # Software Foundation, either version 2.1 of the License, or (at your option) an y
10 # later version.
11 #
12 # logilab-common is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License along
18 # with logilab-common. If not, see <http://www.gnu.org/licenses/>.
19 """XML utilities.
20
21 This module contains useful functions for parsing and using XML data. For the
22 moment, there is only one function that can parse the data inside a processing
23 instruction and return a Python dictionary.
24
25
26
27
28 """
29 __docformat__ = "restructuredtext en"
30
31 import re
32
33 RE_DOUBLE_QUOTE = re.compile('([\w\-\.]+)="([^"]+)"')
34 RE_SIMPLE_QUOTE = re.compile("([\w\-\.]+)='([^']+)'")
35
36 def parse_pi_data(pi_data):
37 """
38 Utility function that parses the data contained in an XML
39 processing instruction and returns a dictionary of keywords and their
40 associated values (most of the time, the processing instructions contain
41 data like ``keyword="value"``, if a keyword is not associated to a value,
42 for example ``keyword``, it will be associated to ``None``).
43
44 :param pi_data: data contained in an XML processing instruction.
45 :type pi_data: unicode
46
47 :returns: Dictionary of the keywords (Unicode strings) associated to
48 their values (Unicode strings) as they were defined in the
49 data.
50 :rtype: dict
51 """
52 results = {}
53 for elt in pi_data.split():
54 if RE_DOUBLE_QUOTE.match(elt):
55 kwd, val = RE_DOUBLE_QUOTE.match(elt).groups()
56 elif RE_SIMPLE_QUOTE.match(elt):
57 kwd, val = RE_SIMPLE_QUOTE.match(elt).groups()
58 else:
59 kwd, val = elt, None
60 results[kwd] = val
61 return results
OLDNEW
« no previous file with comments | « third_party/logilab/logilab/common/xmlrpcutils.py ('k') | third_party/pylint/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698