[gentoo-commits] proj/javatoolkit:master commit in: src/py/javatoolkit/xml/, src/py/

2020-11-05 Thread Patrice Clement
commit: 5480034ddf29a050671aa22effdd1cefb1a97f55
Author: Arfrever Frehtes Taifersar Arahesis  Apache  Org>
AuthorDate: Mon Oct 19 16:00:00 2020 +
Commit: Patrice Clement  gentoo  org>
CommitDate: Thu Nov  5 21:05:44 2020 +
URL:https://gitweb.gentoo.org/proj/javatoolkit.git/commit/?id=5480034d

allow expanding external entities through SAX parser.

Python xml.sax module by default does not expand external entities since
Python 3.6.7, 3.7.1 and 3.8.0:
https://bugs.python.org/issue17239
3.6: 
https://github.com/python/cpython/commit/582d188e6e3487180891f1fc457a80dec8be26a8
3.7: 
https://github.com/python/cpython/commit/394e55a9279d17240ef6fe85d3b4ea3fe7b6dff5
3.8: 
https://github.com/python/cpython/commit/17b1d5d4e36aa57a9b25a0e694affbd1ee637e45

build.xml files may contain external entities resolving to other .xml files
in given package.

Closes: https://bugs.gentoo.org/698954
Signed-off-by: Arfrever Frehtes Taifersar Arahesis  Apache.Org>
Signed-off-by: Patrice Clement  gentoo.org>

 src/py/javatoolkit/xml/SaxRewriter.py | 10 
 src/py/javatoolkit/xml/sax.py | 44 +++
 src/py/xml-rewrite-2.py   | 17 --
 3 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/src/py/javatoolkit/xml/SaxRewriter.py 
b/src/py/javatoolkit/xml/SaxRewriter.py
index f9e224a..8d76de2 100644
--- a/src/py/javatoolkit/xml/SaxRewriter.py
+++ b/src/py/javatoolkit/xml/SaxRewriter.py
@@ -1,14 +1,17 @@
 # -*- coding: UTF-8 -*-
-# Copyright 2004-2005 Gentoo Foundation
+# Copyright 2004-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import io
 import os
 import sys
-import io
 
+import xml.sax.handler
 from xml.sax.saxutils import XMLGenerator
 from xml.sax.saxutils import quoteattr
 
+import javatoolkit.xml.sax
+
 class SaxRewriter(XMLGenerator):
 """
 Using Sax gives us the support for writing back doctypes and all easily
@@ -124,8 +127,7 @@ class SaxRewriter(XMLGenerator):
 
 def process(self, in_stream, callback):
 self.startElement = callback
-from xml.sax import parseString
-parseString(in_stream.encode('UTF8'), self)
+javatoolkit.xml.sax.parse_string(in_stream.encode('UTF8'), 
content_handler=self, features={xml.sax.handler.feature_external_ges: 1})
 self.p('\n')
 
 # vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:

diff --git a/src/py/javatoolkit/xml/sax.py b/src/py/javatoolkit/xml/sax.py
new file mode 100644
index 000..d3d2a4c
--- /dev/null
+++ b/src/py/javatoolkit/xml/sax.py
@@ -0,0 +1,44 @@
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import io
+import xml.sax
+import xml.sax.xmlreader
+
+def _make_parser(*, content_handler=None, dtd_handler=None, 
entity_resolver=None, error_handler=None, locale=None, features=None, 
properties=None):
+parser = xml.sax.make_parser()
+
+if content_handler is not None:
+parser.setContentHandler(content_handler)
+if dtd_handler is not None:
+parser.setDTDHandler(dtd_handler)
+if entity_resolver is not None:
+parser.setEntityResolver(entity_resolver)
+if error_handler is not None:
+parser.setErrorHandler(error_handler)
+if locale is not None:
+parser.setLocale(locale)
+if features is not None:
+for feature, value in features.items():
+parser.setFeature(feature, value)
+if properties is not None:
+for property, value in properties.items():
+parser.setProperty(property, value)
+
+return parser
+
+def parse(source, *, content_handler=None, dtd_handler=None, 
entity_resolver=None, error_handler=None, locale=None, features=None, 
properties=None):
+parser = _make_parser(content_handler=content_handler, 
dtd_handler=dtd_handler, entity_resolver=entity_resolver, 
error_handler=error_handler, locale=locale, features=features, 
properties=properties)
+
+parser.parse(source)
+
+def parse_string(string, *, content_handler=None, dtd_handler=None, 
entity_resolver=None, error_handler=None, locale=None, features=None, 
properties=None):
+parser = _make_parser(content_handler=content_handler, 
dtd_handler=dtd_handler, entity_resolver=entity_resolver, 
error_handler=error_handler, locale=locale, features=features, 
properties=properties)
+
+inputsource = xml.sax.xmlreader.InputSource()
+if isinstance(string, str):
+inputsource.setCharacterStream(io.StringIO(string))
+else:
+inputsource.setByteStream(io.BytesIO(string))
+
+parser.parse(inputsource)

diff --git a/src/py/xml-rewrite-2.py b/src/py/xml-rewrite-2.py
index 4035119..ad0f12e 100755
--- a/src/py/xml-rewrite-2.py
+++ b/src/py/xml-rewrite-2.py
@@ -1,13 +1,17 @@
 #!/usr/bin/env python3
-# Copyright 2004-2006 Gentoo Foundation
-# Distributed under the terms of the GNU General Public Licence v2
+# Copyright 2004-2020 Gentoo Authors

[gentoo-commits] proj/javatoolkit:master commit in: src/py/javatoolkit/xml/, src/py/javatoolkit/java/, src/py/javatoolkit/parser/, ...

2017-08-07 Thread Patrice Clement
commit: 1a722e7e516d75885022ff8c14e668d1c8d73d56
Author: Patrice Clement  gentoo  org>
AuthorDate: Mon Aug  7 19:13:38 2017 +
Commit: Patrice Clement  gentoo  org>
CommitDate: Mon Aug  7 19:13:38 2017 +
URL:https://gitweb.gentoo.org/proj/javatoolkit.git/commit/?id=1a722e7e

remove a few more headers and add braces around two print functions

 src/py/buildparser   | 2 --
 src/py/javatoolkit/__init__.py   | 4 +---
 src/py/javatoolkit/java/__init__.py  | 4 +---
 src/py/javatoolkit/parser/buildproperties.py | 2 --
 src/py/javatoolkit/parser/helpers.py | 2 --
 src/py/javatoolkit/parser/manifest.py| 3 ---
 src/py/javatoolkit/xml/SaxRewriter.py| 2 --
 7 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/src/py/buildparser b/src/py/buildparser
index a7e656d..7af980d 100755
--- a/src/py/buildparser
+++ b/src/py/buildparser
@@ -5,8 +5,6 @@
 #
 # Licensed under the GNU General Public License, v2
 #
-# $Header:$
-
 import os
 import sys
 from optparse import OptionParser

diff --git a/src/py/javatoolkit/__init__.py b/src/py/javatoolkit/__init__.py
index 5d9dcee..77b273b 100644
--- a/src/py/javatoolkit/__init__.py
+++ b/src/py/javatoolkit/__init__.py
@@ -4,11 +4,9 @@
 # Copyright(c) 2004, Gentoo Foundation
 #
 # Licensed under the GNU General Public License, v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/javatoolkit/__init__.py,v 
1.2 2004/11/08 19:21:52 karltk Exp $
 
 from classpath import *
 from output import *
 
 if __name__ == "__main__":
-   print "This is not an executable module"
+print("This is not an executable module")

diff --git a/src/py/javatoolkit/java/__init__.py 
b/src/py/javatoolkit/java/__init__.py
index 20432bd..0e3a32d 100644
--- a/src/py/javatoolkit/java/__init__.py
+++ b/src/py/javatoolkit/java/__init__.py
@@ -3,8 +3,6 @@
 # Copyright(c) 2008, Gentoo Foundation
 #
 # Licensed under the GNU General Public License, v2
-#
-# $Header: $
 
 if __name__ == "__main__":
-   print "This is not an executable module"
+print("This is not an executable module")

diff --git a/src/py/javatoolkit/parser/buildproperties.py 
b/src/py/javatoolkit/parser/buildproperties.py
index a09614d..9a73f78 100644
--- a/src/py/javatoolkit/parser/buildproperties.py
+++ b/src/py/javatoolkit/parser/buildproperties.py
@@ -3,8 +3,6 @@
 # Copyright(c) 2004, Gentoo Foundation
 #
 # Licensed under the GNU General Public License, v2
-#
-# $Header: $
 
 from .tree import *
 from . import parser

diff --git a/src/py/javatoolkit/parser/helpers.py 
b/src/py/javatoolkit/parser/helpers.py
index b11b08b..c0e1bb3 100644
--- a/src/py/javatoolkit/parser/helpers.py
+++ b/src/py/javatoolkit/parser/helpers.py
@@ -3,8 +3,6 @@
 # Copyright(c) 2004, Gentoo Foundation
 #
 # Licensed under the GNU General Public License, v2
-#
-# $Header: $
 
 def expand(root, expr, realroot = None):
 """Evaluates a path expression on a given tree.

diff --git a/src/py/javatoolkit/parser/manifest.py 
b/src/py/javatoolkit/parser/manifest.py
index b5a1701..b55a28a 100644
--- a/src/py/javatoolkit/parser/manifest.py
+++ b/src/py/javatoolkit/parser/manifest.py
@@ -1,8 +1,5 @@
 # Copyright(c) 2006, 2008, James Le Cuirot 
-#
 # Licensed under the GNU General Public License, v2
-#
-# $Header: $
 
 from .tree import *
 from . import parser

diff --git a/src/py/javatoolkit/xml/SaxRewriter.py 
b/src/py/javatoolkit/xml/SaxRewriter.py
index 07528c9..bd6e8de 100644
--- a/src/py/javatoolkit/xml/SaxRewriter.py
+++ b/src/py/javatoolkit/xml/SaxRewriter.py
@@ -1,8 +1,6 @@
 # -*- coding: UTF-8 -*-
-
 # Copyright 2004-2005 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: $
 
 import os
 import sys