Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare stable #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 104 additions & 76 deletions addon/globalPlugins/readFeeds/__init__.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,3 @@


__all__ = ["dom", "parsers", "sax", "etree"]

_MINIMUM_XMLPLUS_VERSION = (0, 8, 4)


try:
import _xmlplus
except ImportError:
pass
else:
try:
v = _xmlplus.version_info
except AttributeError:
# _xmlplus is too old; ignore it
pass
else:
if v >= _MINIMUM_XMLPLUS_VERSION:
import sys
_xmlplus.__path__.extend(__path__)
sys.modules[__name__] = _xmlplus
else:
del v

import globalPluginHandler

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class NodeFilter:
FILTER_REJECT = 2
FILTER_SKIP = 3

SHOW_ALL = 0xFFFFFFFFL
SHOW_ALL = 0xFFFFFFFF
SHOW_ELEMENT = 0x00000001
SHOW_ATTRIBUTE = 0x00000002
SHOW_TEXT = 0x00000004
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class Node:
"""Class giving the NodeType constants."""
__slots__ = ()

# DOM implementations may use this as a base class for their own
# Node implementations. If they don't, the constants defined here
Expand Down Expand Up @@ -136,4 +137,4 @@ class UserDataHandler:
EMPTY_NAMESPACE = None
EMPTY_PREFIX = None

from domreg import getDOMImplementation,registerDOMImplementation
from .domreg import getDOMImplementation, registerDOMImplementation
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
directly. Instead, the functions getDOMImplementation and
registerDOMImplementation should be imported from xml.dom."""

from xml2.dom.minicompat import * # isinstance, StringTypes

# This is a list of well-known implementations. Well-known names
# should be published by posting to xml-sig@python.org, and are
# subsequently recorded in this file.

import sys

well_known_implementations = {
'minidom':'xml.dom.minidom',
'4DOM': 'xml.dom.DOMImplementation',
Expand Down Expand Up @@ -36,7 +36,7 @@ def _good_enough(dom, features):
return 0
return 1

def getDOMImplementation(name = None, features = ()):
def getDOMImplementation(name=None, features=()):
"""getDOMImplementation(name = None, features = ()) -> DOM implementation.

Return a suitable DOM implementation. The name is either
Expand All @@ -57,12 +57,12 @@ def getDOMImplementation(name = None, features = ()):
return mod.getDOMImplementation()
elif name:
return registered[name]()
elif "PYTHON_DOM" in os.environ:
elif not sys.flags.ignore_environment and "PYTHON_DOM" in os.environ:
return getDOMImplementation(name = os.environ["PYTHON_DOM"])

# User did not specify a name, try implementations in arbitrary
# order, returning the one that has the required features
if isinstance(features, StringTypes):
if isinstance(features, str):
features = _parse_feature_string(features)
for creator in registered.values():
dom = creator()
Expand All @@ -72,12 +72,12 @@ def getDOMImplementation(name = None, features = ()):
for creator in well_known_implementations.keys():
try:
dom = getDOMImplementation(name = creator)
except StandardError: # typically ImportError, or AttributeError
except Exception: # typically ImportError, or AttributeError
continue
if _good_enough(dom, features):
return dom

raise ImportError,"no suitable DOM implementation found"
raise ImportError("no suitable DOM implementation found")

def _parse_feature_string(s):
features = []
Expand All @@ -87,7 +87,7 @@ def _parse_feature_string(s):
while i < length:
feature = parts[i]
if feature[0] in "0123456789":
raise ValueError, "bad feature name: %r" % (feature,)
raise ValueError("bad feature name: %r" % (feature,))
i = i + 1
version = None
if i < length:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# minidom DOM and can't be used with other DOM implementations. This
# is due, in part, to a lack of appropriate methods in the DOM (there is
# no way to create Entity and Notation nodes via the DOM Level 2
# interface), and for performance. The later is the cause of some fairly
# interface), and for performance. The latter is the cause of some fairly
# cryptic code.
#
# Performance hacks:
Expand All @@ -27,13 +27,11 @@
# calling any methods on the node object if it exists. (A rather
# nice speedup is achieved this way as well!)

from xml2.dom import xmlbuilder, minidom, Node
from xml2.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE
from xml2.parsers import expat
from xml2.dom.minidom import _append_child, _set_attribute_node
from xml2.dom.NodeFilter import NodeFilter

from xml2.dom.minicompat import *
from xml.dom import xmlbuilder, minidom, Node
from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE
from xml.parsers import expat
from xml.dom.minidom import _append_child, _set_attribute_node
from xml.dom.NodeFilter import NodeFilter

TEXT_NODE = Node.TEXT_NODE
CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE
Expand Down Expand Up @@ -123,10 +121,12 @@ def _parse_ns_name(builder, name):
qname = "%s:%s" % (prefix, localname)
qname = intern(qname, qname)
localname = intern(localname, localname)
else:
elif len(parts) == 2:
uri, localname = parts
prefix = EMPTY_PREFIX
qname = localname = intern(localname, localname)
else:
raise ValueError("Unsupported syntax: spaces in URIs not supported: %r" % name)
return intern(uri, uri), localname, prefix, qname


Expand Down Expand Up @@ -283,27 +283,23 @@ def character_data_handler_cdata(self, data):
elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
node = childNodes[-1]
value = node.data + data
d = node.__dict__
d['data'] = d['nodeValue'] = value
node.data = value
return
else:
node = minidom.Text()
d = node.__dict__
d['data'] = d['nodeValue'] = data
d['ownerDocument'] = self.document
node.data = data
node.ownerDocument = self.document
_append_child(self.curNode, node)

def character_data_handler(self, data):
childNodes = self.curNode.childNodes
if childNodes and childNodes[-1].nodeType == TEXT_NODE:
node = childNodes[-1]
d = node.__dict__
d['data'] = d['nodeValue'] = node.data + data
node.data = node.data + data
return
node = minidom.Text()
d = node.__dict__
d['data'] = d['nodeValue'] = node.data + data
d['ownerDocument'] = self.document
node.data = node.data + data
node.ownerDocument = self.document
_append_child(self.curNode, node)

def entity_decl_handler(self, entityName, is_parameter_entity, value,
Expand Down Expand Up @@ -363,11 +359,8 @@ def start_element_handler(self, name, attributes):
a = minidom.Attr(attributes[i], EMPTY_NAMESPACE,
None, EMPTY_PREFIX)
value = attributes[i+1]
d = a.childNodes[0].__dict__
d['data'] = d['nodeValue'] = value
d = a.__dict__
d['value'] = d['nodeValue'] = value
d['ownerDocument'] = self.document
a.value = value
a.ownerDocument = self.document
_set_attribute_node(node, a)

if node is not self.document.documentElement:
Expand Down Expand Up @@ -476,8 +469,8 @@ def startContainer(self, node):
if val == FILTER_INTERRUPT:
raise ParseEscape
if val not in _ALLOWED_FILTER_RETURNS:
raise ValueError, \
"startContainer() returned illegal value: " + repr(val)
raise ValueError(
"startContainer() returned illegal value: " + repr(val))
return val
else:
return FILTER_ACCEPT
Expand All @@ -496,8 +489,8 @@ def acceptNode(self, node):
# node is handled by the caller
return FILTER_REJECT
if val not in _ALLOWED_FILTER_RETURNS:
raise ValueError, \
"acceptNode() returned illegal value: " + repr(val)
raise ValueError(
"acceptNode() returned illegal value: " + repr(val))
return val
else:
return FILTER_ACCEPT
Expand Down Expand Up @@ -761,15 +754,13 @@ def start_element_handler(self, name, attributes):
else:
a = minidom.Attr("xmlns", XMLNS_NAMESPACE,
"xmlns", EMPTY_PREFIX)
d = a.childNodes[0].__dict__
d['data'] = d['nodeValue'] = uri
d = a.__dict__
d['value'] = d['nodeValue'] = uri
d['ownerDocument'] = self.document
a.value = uri
a.ownerDocument = self.document
_set_attribute_node(node, a)
del self._ns_ordered_prefixes[:]

if attributes:
node._ensure_attributes()
_attrs = node._attrs
_attrsNS = node._attrsNS
for i in range(0, len(attributes), 2):
Expand All @@ -785,12 +776,9 @@ def start_element_handler(self, name, attributes):
aname, EMPTY_PREFIX)
_attrs[aname] = a
_attrsNS[(EMPTY_NAMESPACE, aname)] = a
d = a.childNodes[0].__dict__
d['data'] = d['nodeValue'] = value
d = a.__dict__
d['ownerDocument'] = self.document
d['value'] = d['nodeValue'] = value
d['ownerElement'] = node
a.ownerDocument = self.document
a.value = value
a.ownerElement = node

if __debug__:
# This only adds some asserts to the original
Expand Down Expand Up @@ -918,12 +906,9 @@ def parse(file, namespaces=True):
else:
builder = ExpatBuilder()

if isinstance(file, StringTypes):
fp = open(file, 'rb')
try:
if isinstance(file, str):
with open(file, 'rb') as fp:
result = builder.parseFile(fp)
finally:
fp.close()
else:
result = builder.parseFile(file)
return result
Expand Down Expand Up @@ -952,12 +937,9 @@ def parseFragment(file, context, namespaces=True):
else:
builder = FragmentBuilder(context)

if isinstance(file, StringTypes):
fp = open(file, 'rb')
try:
if isinstance(file, str):
with open(file, 'rb') as fp:
result = builder.parseFile(fp)
finally:
fp.close()
else:
result = builder.parseFile(file)
return result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Python version compatibility support for minidom."""
"""Python version compatibility support for minidom.

This module contains internal implementation details and
should not be imported; use xml.dom.minidom instead.
"""

# This module should only be imported using "import *".
#
Expand Down Expand Up @@ -38,14 +42,9 @@

__all__ = ["NodeList", "EmptyNodeList", "StringTypes", "defproperty"]

import xml2.dom
import xml.dom

try:
unicode
except NameError:
StringTypes = type(''),
else:
StringTypes = type(''), type(unicode(''))
StringTypes = (str,)


class NodeList(list):
Expand All @@ -65,10 +64,10 @@ def _set_length(self, value):
length = property(_get_length, _set_length,
doc="The number of nodes in the NodeList.")

def __getstate__(self):
return list(self)

# For backward compatibility
def __setstate__(self, state):
if state is None:
state = []
self[:] = state


Expand Down Expand Up @@ -100,7 +99,7 @@ def _set_length(self, value):


def defproperty(klass, name, doc):
get = getattr(klass, ("_get_" + name)).im_func
get = getattr(klass, ("_get_" + name))
def set(self, value, name=name):
raise xml.dom.NoModificationAllowedErr(
"attempt to modify read-only attribute " + repr(name))
Expand Down
Loading