[Pkg-mozext-commits] [adblock-plus] 258/464: Locale processing: Added parsing of comments

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit 8408001373c679e11a18fb5bb562d620fe17b2a1
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Wed Jul 4 15:03:04 2012 +0200

    Locale processing: Added parsing of comments
---
 localeTools.py | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/localeTools.py b/localeTools.py
index 289a031..8e08246 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -10,7 +10,9 @@ from ConfigParser import SafeConfigParser
 from xml.parsers.expat import ParserCreate, XML_PARAM_ENTITY_PARSING_ALWAYS
 
 def parseDTDString(data, path):
-  result = {}
+  result = []
+  currentComment = [None]
+
   parser = ParserCreate()
   parser.UseForeignDTD(True)
   parser.SetParamEntityParsing(XML_PARAM_ENTITY_PARSING_ALWAYS)
@@ -20,36 +22,47 @@ def parseDTDString(data, path):
     subparser.Parse(data.encode('utf-8'), True)
     return 1
 
+  def CommentHandler(data):
+    currentComment[0] = data
+
   def EntityDeclHandler(entityName, is_parameter_entity, value, base, systemId, publicId, notationName):
-    result[entityName] = value
+    result.append((entityName, currentComment[0], value))
+    currentComment[0] = None
 
   parser.ExternalEntityRefHandler = ExternalEntityRefHandler
+  parser.CommentHandler = CommentHandler
   parser.EntityDeclHandler = EntityDeclHandler
   parser.Parse('<!DOCTYPE root SYSTEM "foo"><root/>', True)
-  result['_origData'] = data
-  return result
+
+  for entry in result:
+    yield entry
 
 def parsePropertiesString(data, path):
-  result = {}
+  currentComment = None
   for line in data.splitlines():
-    if re.search(r'^\s*[#!]', line):
-      continue
+    match = re.search(r'^\s*[#!]\s*(.*)', line)
+    if match:
+      currentComment = match.group(1)
     elif '=' in line:
       key, value = line.split('=', 1)
-      result[key] = value
+      yield (key, currentComment, value)
+      currentComment = None
     elif re.search(r'\S', line):
       print >>sys.stderr, 'Unrecognized data in file %s: %s' % (path, line)
-  result['_origData'] = data
-  return result
 
 def parseString(data, path):
+  result = {'_origData': data}
   if path.endswith('.dtd'):
-    return parseDTDString(data, path)
+    it = parseDTDString(data, path)
   elif path.endswith('.properties'):
-    return parsePropertiesString(data, path)
+    it = parsePropertiesString(data, path)
   else:
     return None
 
+  for name, comment, value in it:
+    result[name] = value
+  return result
+
 def readFile(path):
   fileHandle = codecs.open(path, 'rb', encoding='utf-8')
   data = fileHandle.read()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list