You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2015/06/22 14:57:07 UTC

[04/34] qpid-proton git commit: PROTON-490: port mllib document parser to Python 3

PROTON-490: port mllib document parser to Python 3

Ported from the original patch supplied by Mickael Maison.  Uses the
six compatibility library.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5d7a4586
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5d7a4586
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5d7a4586

Branch: refs/heads/master
Commit: 5d7a458635eb55167e33875e040b8147230c4c1b
Parents: 979471f
Author: Ken Giusti <kg...@apache.org>
Authored: Mon Apr 20 11:55:27 2015 -0400
Committer: Ken Giusti <kg...@apache.org>
Committed: Mon Apr 20 13:04:56 2015 -0400

----------------------------------------------------------------------
 proton-c/mllib/__init__.py   | 23 ++++-------------------
 proton-c/mllib/dom.py        |  7 ++++---
 proton-c/mllib/parsers.py    | 37 ++-----------------------------------
 proton-c/mllib/transforms.py |  2 +-
 4 files changed, 11 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5d7a4586/proton-c/mllib/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/__init__.py b/proton-c/mllib/__init__.py
index c6fccf1..9e78a87 100644
--- a/proton-c/mllib/__init__.py
+++ b/proton-c/mllib/__init__.py
@@ -18,8 +18,7 @@
 #
 
 """
-This module provides document parsing and transformation utilities for
-both SGML and XML.
+This module provides document parsing and transformation utilities for XML.
 """
 
 from __future__ import absolute_import
@@ -28,7 +27,8 @@ import os, sys
 import xml.sax, types
 from xml.sax.handler import ErrorHandler
 from xml.sax.xmlreader import InputSource
-from cStringIO import StringIO
+import six
+from six.moves import cStringIO as StringIO
 
 from . import dom
 from . import transforms
@@ -37,26 +37,11 @@ from . import parsers
 def transform(node, *args):
   result = node
   for t in args:
-    if isinstance(t, type):
+    if isinstance(t, six.class_types):
       t = t()
     result = result.dispatch(t)
   return result
 
-def sgml_parse(source):
-  if isinstance(source, basestring):
-    source = StringIO(source)
-    fname = "<string>"
-  elif hasattr(source, "name"):
-    fname = source.name
-  p = parsers.SGMLParser()
-  num = 1
-  for line in source:
-    p.feed(line)
-    p.parser.line(fname, num, None)
-    num += 1
-  p.close()
-  return p.parser.tree
-
 class Resolver:
 
   def __init__(self, path):

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5d7a4586/proton-c/mllib/dom.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/dom.py b/proton-c/mllib/dom.py
index 4cbac26..b6ca27d 100644
--- a/proton-c/mllib/dom.py
+++ b/proton-c/mllib/dom.py
@@ -26,6 +26,7 @@ from __future__ import generators
 from __future__ import nested_scopes
 from __future__ import absolute_import
 
+import six
 
 class Container:
 
@@ -178,7 +179,7 @@ class Leaf(Component, Dispatcher):
   base = None
 
   def __init__(self, data):
-    assert isinstance(data, basestring)
+    assert isinstance(data, six.string_types)
     self.data = data
 
 class Data(Leaf):
@@ -268,7 +269,7 @@ class Values(View):
       yield value
 
 def flatten_path(path):
-  if isinstance(path, basestring):
+  if isinstance(path, six.string_types):
     for part in path.split("/"):
       yield part
   elif callable(path):
@@ -291,7 +292,7 @@ class Query(View):
         select = Query
         pred = p
         source = query
-      elif isinstance(p, basestring):
+      elif isinstance(p, six.string_types):
         if p[0] == "@":
           select = Values
           pred = lambda x, n=p[1:]: x[0] == n

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5d7a4586/proton-c/mllib/parsers.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/parsers.py b/proton-c/mllib/parsers.py
index e71018d..72d44ab 100644
--- a/proton-c/mllib/parsers.py
+++ b/proton-c/mllib/parsers.py
@@ -18,11 +18,11 @@
 #
 
 """
-Parsers for SGML and XML to dom.
+Parsers for XML to dom.
 """
 from __future__ import absolute_import
 
-import sgmllib, xml.sax.handler
+import xml.sax.handler
 from .dom import *
 
 class Parser:
@@ -74,39 +74,6 @@ class Parser:
       self.node = self.node.parent
 
 
-class SGMLParser(sgmllib.SGMLParser):
-
-  def __init__(self, entitydefs = None):
-    sgmllib.SGMLParser.__init__(self)
-    if entitydefs == None:
-      self.entitydefs = {}
-    else:
-      self.entitydefs = entitydefs
-    self.parser = Parser()
-
-  def unknown_starttag(self, name, attrs):
-    self.parser.start(name, attrs)
-
-  def handle_data(self, data):
-    self.parser.data(data)
-
-  def handle_comment(self, comment):
-    self.parser.comment(comment)
-
-  def unknown_entityref(self, ref):
-    self.parser.entity(ref)
-
-  def unknown_charref(self, ref):
-    self.parser.character(ref)
-
-  def unknown_endtag(self, name):
-    self.parser.end(name)
-
-  def close(self):
-    sgmllib.SGMLParser.close(self)
-    self.parser.balance()
-    assert self.parser.node == self.parser.tree
-
 class XMLParser(xml.sax.handler.ContentHandler):
 
   def __init__(self):

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5d7a4586/proton-c/mllib/transforms.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/transforms.py b/proton-c/mllib/transforms.py
index 383add3..43e9ef2 100644
--- a/proton-c/mllib/transforms.py
+++ b/proton-c/mllib/transforms.py
@@ -23,7 +23,7 @@ Useful transforms for dom objects.
 from __future__ import absolute_import
 
 from . import dom
-from cStringIO import StringIO
+from six.moves import cStringIO as StringIO
 
 class Visitor:
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org