[pypy-svn] r79020 - pypy/branch/fast-forward/pypy/module/pyexpat

afa at codespeak.net afa at codespeak.net
Fri Nov 12 00:15:20 CET 2010


Author: afa
Date: Fri Nov 12 00:15:18 2010
New Revision: 79020

Modified:
   pypy/branch/fast-forward/pypy/module/pyexpat/interp_pyexpat.py
Log:
Refactor a bit, reduce stored attributes


Modified: pypy/branch/fast-forward/pypy/module/pyexpat/interp_pyexpat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/pyexpat/interp_pyexpat.py	(original)
+++ pypy/branch/fast-forward/pypy/module/pyexpat/interp_pyexpat.py	Fri Nov 12 00:15:18 2010
@@ -276,10 +276,8 @@
 
 class W_XMLParserType(Wrappable):
 
-    def __init__(self, encoding, namespace_separator, w_intern,
-                 _from_external_entity=False):
-        self.encoding = encoding
-        self.namespace_separator = namespace_separator
+    def __init__(self, space, parser, w_intern):
+        self.itself = parser
 
         self.w_intern = w_intern
 
@@ -287,14 +285,6 @@
         self.ordered_attributes = False
         self.specified_attributes = False
 
-        if not _from_external_entity:
-            if namespace_separator:
-                self.itself = XML_ParserCreateNS(
-                    self.encoding,
-                    rffi.cast(rffi.CHAR, namespace_separator))
-            else:
-                self.itself = XML_ParserCreate(self.encoding)
-
         self.handlers = [None] * NB_HANDLERS
 
         self.buffer_w = None
@@ -304,6 +294,12 @@
 
         self._exc_info = None
 
+        # Set user data for callback function
+        global_storage.get_nonmoving_id(
+            CallbackData(space, self),
+            id=rffi.cast(lltype.Signed, self.itself))
+        XML_SetUserData(self.itself, rffi.cast(rffi.VOIDP, self.itself))
+
     def __del__(self):
         if XML_ParserFree: # careful with CPython interpreter shutdown
             XML_ParserFree(self.itself)
@@ -494,14 +490,9 @@
         else:
             encoding = space.str_w(w_encoding)
 
-        parser = W_XMLParserType(encoding, 0, self.w_intern,
-                                 _from_external_entity=True)
-        parser.itself = XML_ExternalEntityParserCreate(self.itself,
-                                                       context, encoding)
-        global_storage.get_nonmoving_id(
-            CallbackData(space, parser),
-            id=rffi.cast(lltype.Signed, parser.itself))
-        XML_SetUserData(parser.itself, rffi.cast(rffi.VOIDP, parser.itself))
+        xmlparser = XML_ExternalEntityParserCreate(
+            self.itself, context, encoding)
+        parser = W_XMLParserType(space, xmlparser, self.w_intern)
 
         # copy handlers from self
         for i in range(NB_HANDLERS):
@@ -659,16 +650,18 @@
     elif space.is_w(w_intern, space.w_None):
         w_intern = None
 
-    parser = W_XMLParserType(encoding, namespace_separator, w_intern)
+    if namespace_separator:
+        xmlparser = XML_ParserCreateNS(
+            encoding,
+            rffi.cast(rffi.CHAR, namespace_separator))
+    else:
+        xmlparser = XML_ParserCreate(encoding)
+
+    parser = W_XMLParserType(space, xmlparser, w_intern)
     if not parser.itself:
         raise OperationError(space.w_RuntimeError,
                              space.wrap('XML_ParserCreate failed'))
 
-    global_storage.get_nonmoving_id(
-        CallbackData(space, parser),
-        id=rffi.cast(lltype.Signed, parser.itself))
-    XML_SetUserData(parser.itself, rffi.cast(rffi.VOIDP, parser.itself))
-
     return space.wrap(parser)
 ParserCreate.unwrap_spec = [ObjSpace, W_Root, W_Root, W_Root]
 



More information about the Pypy-commit mailing list