[pypy-svn] r40045 - in pypy/branch/rope-branch2/pypy: config module/marshal/test objspace/std objspace/std/test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Mar 7 20:53:52 CET 2007


Author: cfbolz
Date: Wed Mar  7 20:53:51 2007
New Revision: 40045

Added:
   pypy/branch/rope-branch2/pypy/objspace/std/rope.py
      - copied unchanged from r40043, pypy/branch/rope-branch/pypy/objspace/std/rope.py
   pypy/branch/rope-branch2/pypy/objspace/std/ropeobject.py
      - copied unchanged from r40043, pypy/branch/rope-branch/pypy/objspace/std/ropeobject.py
   pypy/branch/rope-branch2/pypy/objspace/std/test/test_rope.py
      - copied unchanged from r40043, pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py
   pypy/branch/rope-branch2/pypy/objspace/std/test/test_ropeobject.py
      - copied unchanged from r40043, pypy/branch/rope-branch/pypy/objspace/std/test/test_ropeobject.py
Modified:
   pypy/branch/rope-branch2/pypy/config/pypyoption.py
   pypy/branch/rope-branch2/pypy/module/marshal/test/test_marshal.py
   pypy/branch/rope-branch2/pypy/objspace/std/marshal_impl.py
   pypy/branch/rope-branch2/pypy/objspace/std/model.py
   pypy/branch/rope-branch2/pypy/objspace/std/objspace.py
   pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py
   pypy/branch/rope-branch2/pypy/objspace/std/unicodeobject.py
Log:
svn merge -r 39693:HEAD svn+ssh://codespeak.net/svn/pypy/branch/rope-branch


Modified: pypy/branch/rope-branch2/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/config/pypyoption.py	(original)
+++ pypy/branch/rope-branch2/pypy/config/pypyoption.py	Wed Mar  7 20:53:51 2007
@@ -129,6 +129,8 @@
 
         BoolOption("withprebuiltchar",
                    "use prebuilt single-character string objects",
+
+        BoolOption("withrope", "use ropes as the string implementation",
                    default=False),
 
         BoolOption("sharesmallstr",

Modified: pypy/branch/rope-branch2/pypy/module/marshal/test/test_marshal.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/module/marshal/test/test_marshal.py	(original)
+++ pypy/branch/rope-branch2/pypy/module/marshal/test/test_marshal.py	Wed Mar  7 20:53:51 2007
@@ -12,12 +12,12 @@
         print "case: %-30s   func=None" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_False(self):
         import sys
@@ -31,12 +31,12 @@
         print "case: %-30s   func=False" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_True(self):
         import sys
@@ -50,12 +50,12 @@
         print "case: %-30s   func=True" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_StopIteration(self):
         import sys
@@ -69,12 +69,12 @@
         print "case: %-30s   func=StopIteration" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_Ellipsis(self):
         import sys
@@ -88,12 +88,12 @@
         print "case: %-30s   func=Ellipsis" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_42(self):
         import sys
@@ -107,12 +107,12 @@
         print "case: %-30s   func=42" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__minus_17(self):
         import sys
@@ -126,12 +126,12 @@
         print "case: %-30s   func=_minus_17" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_sys_dot_maxint(self):
         import sys
@@ -145,12 +145,12 @@
         print "case: %-30s   func=sys_dot_maxint" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__minus_1_dot_25(self):
         import sys
@@ -164,12 +164,12 @@
         print "case: %-30s   func=_minus_1_dot_25" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__minus_1_dot_25__2(self):
         import sys
@@ -183,12 +183,12 @@
         print "case: %-30s   func=_minus_1_dot_25__2" % (case, )
         s = marshal.dumps(case, 2); assert len(s) in (9, 17)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_2_plus_5j(self):
         import sys
@@ -202,12 +202,12 @@
         print "case: %-30s   func=2_plus_5j" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_2_plus_5j__2(self):
         import sys
@@ -221,12 +221,12 @@
         print "case: %-30s   func=2_plus_5j__2" % (case, )
         s = marshal.dumps(case, 2); assert len(s) in (9, 17)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_42L(self):
         import sys
@@ -240,12 +240,12 @@
         print "case: %-30s   func=42L" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__minus_1234567890123456789012345678901234567890L(self):
         import sys
@@ -259,12 +259,12 @@
         print "case: %-30s   func=_minus_1234567890123456789012345678901234567890L" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_hello_____not_interned(self):
         import sys
@@ -278,12 +278,12 @@
         print "case: %-30s   func=hello_____not_interned" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__Quote_hello_Quote_(self):
         import sys
@@ -297,12 +297,12 @@
         print "case: %-30s   func=_Quote_hello_Quote_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__brace__ecarb_(self):
         import sys
@@ -316,12 +316,12 @@
         print "case: %-30s   func=_brace__ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__brace_1_comma__2_ecarb_(self):
         import sys
@@ -335,12 +335,12 @@
         print "case: %-30s   func=_brace_1_comma__2_ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__list__tsil_(self):
         import sys
@@ -354,12 +354,12 @@
         print "case: %-30s   func=_list__tsil_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__list_3_comma__4_tsil_(self):
         import sys
@@ -373,12 +373,12 @@
         print "case: %-30s   func=_list_3_comma__4_tsil_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__dict__tcid_(self):
         import sys
@@ -392,12 +392,12 @@
         print "case: %-30s   func=_dict__tcid_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test__dict_5_colon__6_comma__7_colon__8_tcid_(self):
         import sys
@@ -411,12 +411,12 @@
         print "case: %-30s   func=_dict_5_colon__6_comma__7_colon__8_tcid_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_func_dot_func_code(self):
         import sys
@@ -430,12 +430,12 @@
         print "case: %-30s   func=func_dot_func_code" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_scopefunc_dot_func_code(self):
         import sys
@@ -449,12 +449,12 @@
         print "case: %-30s   func=scopefunc_dot_func_code" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_u_quote_hello_quote_(self):
         import sys
@@ -468,12 +468,12 @@
         print "case: %-30s   func=u_quote_hello_quote_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_buffer_brace_hello_ecarb_(self):
         import sys
@@ -487,12 +487,12 @@
         print "case: %-30s   func=buffer_brace_hello_ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_buffer_brace_u_quote_unicode_comma__too_quote__ecarb_(self):
         import sys
@@ -506,12 +506,12 @@
         print "case: %-30s   func=buffer_brace_u_quote_unicode_comma__too_quote__ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_set_brace__ecarb_(self):
         import sys
@@ -525,12 +525,12 @@
         print "case: %-30s   func=set_brace__ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_set_brace__list_1_comma__2_tsil__ecarb_(self):
         import sys
@@ -544,12 +544,12 @@
         print "case: %-30s   func=set_brace__list_1_comma__2_tsil__ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_frozenset_brace__ecarb_(self):
         import sys
@@ -563,12 +563,12 @@
         print "case: %-30s   func=frozenset_brace__ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
     def test_frozenset_brace__list_3_comma__4_tsil__ecarb_(self):
         import sys
@@ -582,12 +582,12 @@
         print "case: %-30s   func=frozenset_brace__list_3_comma__4_tsil__ecarb_" % (case, )
         s = marshal.dumps(case)
         x = marshal.loads(s)
-        assert x == case
+        assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)
         x = marshal.load(f)
-        assert x == case
+        assert x == case and type(x) is type(case)
 
 
 class AppTestMultiDict(object):
@@ -597,3 +597,8 @@
 
     test__dict__tcid_ = AppTestMarshal.test__dict__tcid_.im_func
     test__dict_5_colon__6_comma__7_colon__8_tcid_ = AppTestMarshal.test__dict_5_colon__6_comma__7_colon__8_tcid_.im_func
+
+class AppTestRope(AppTestMarshal):
+    def setup_class(cls):
+        from pypy.conftest import gettestobjspace
+        cls.space = gettestobjspace(**{"objspace.std.withrope": True})

Modified: pypy/branch/rope-branch2/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/marshal_impl.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/marshal_impl.py	Wed Mar  7 20:53:51 2007
@@ -27,6 +27,7 @@
 from pypy.objspace.std.dictobject    import W_DictObject
 from pypy.objspace.std.dictmultiobject    import W_DictMultiObject
 from pypy.objspace.std.stringobject  import W_StringObject
+from pypy.objspace.std.ropeobject    import W_RopeObject
 from pypy.objspace.std.typeobject    import W_TypeObject
 from pypy.objspace.std.longobject    import W_LongObject
 from pypy.objspace.std.noneobject    import W_NoneObject
@@ -301,6 +302,8 @@
     else:
         m.atom_str(TYPE_STRING, s)
 
+marshal_w__Rope = marshal_w__String
+
 def unmarshal_String(space, u, tc):
     return space.wrap(u.get_str())
 register(TYPE_STRING, unmarshal_String)

Modified: pypy/branch/rope-branch2/pypy/objspace/std/model.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/model.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/model.py	Wed Mar  7 20:53:51 2007
@@ -15,6 +15,8 @@
     "withmultidict"  : ["dictmultiobject.W_DictMultiObject",
                         "dictmultiobject.W_DictMultiIterObject"],
     "withmultilist"  : ["listmultiobject.W_ListMultiObject"],
+    "withrope"       : ["ropeobject.W_RopeObject",
+                        "ropeobject.W_RopeIterObject"],
     "withrangelist"  : ["rangeobject.W_RangeListObject",
                         "rangeobject.W_RangeIterObject"],
     "withtproxy" : ["proxyobject.W_TransparentList",
@@ -65,6 +67,7 @@
         from pypy.objspace.std import dictmultiobject
         from pypy.objspace.std import listmultiobject
         from pypy.objspace.std import stringobject
+        from pypy.objspace.std import ropeobject
         from pypy.objspace.std import strsliceobject
         from pypy.objspace.std import strjoinobject
         from pypy.objspace.std import typeobject
@@ -108,10 +111,11 @@
         self.typeorder[setobject.W_FrozensetObject] = []
         self.typeorder[setobject.W_SetIterObject] = []
 
-        imported_but_not_registered = {
+        self.imported_but_not_registered = {
             dictobject.W_DictObject: True,
             dictobject.W_DictIterObject: True,
             listobject.W_ListObject: True,
+            stringobject.W_StringObject: True,
         }
         for option, value in config.objspace.std:
             if option.startswith("with") and option in option_to_typename:
@@ -120,7 +124,7 @@
                     if value:
                         self.typeorder[implcls] = []
                     else:
-                        imported_but_not_registered[implcls] = True
+                        self.imported_but_not_registered[implcls] = True
 
         if config.objspace.std.withmultidict:
             del self.typeorder[dictobject.W_DictObject]
@@ -128,12 +132,14 @@
 
         if config.objspace.std.withmultilist:
             del self.typeorder[listobject.W_ListObject]
+        if config.objspace.std.withrope:
+            del self.typeorder[stringobject.W_StringObject]
 
         #check if we missed implementations
         from pypy.objspace.std.objspace import _registered_implementations
         for implcls in _registered_implementations:
             assert (implcls in self.typeorder or
-                    implcls in imported_but_not_registered), (
+                    implcls in self.imported_but_not_registered), (
                 "please add %r in StdTypeModel.typeorder" % (implcls,))
 
 
@@ -175,9 +181,14 @@
             (complexobject.W_ComplexObject, 
                     complexobject.delegate_Float2Complex),
             ]
-        self.typeorder[stringobject.W_StringObject] += [
-         (unicodeobject.W_UnicodeObject, unicodeobject.delegate_String2Unicode),
-            ]
+        if not config.objspace.std.withrope:
+            self.typeorder[stringobject.W_StringObject] += [
+             (unicodeobject.W_UnicodeObject, unicodeobject.delegate_String2Unicode),
+                ]
+        else:
+            self.typeorder[ropeobject.W_RopeObject] += [
+             (unicodeobject.W_UnicodeObject, unicodeobject.delegate_String2Unicode),
+                ]
 
         if config.objspace.std.withstrslice:
             self.typeorder[strsliceobject.W_StringSliceObject] += [

Modified: pypy/branch/rope-branch2/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/objspace.py	Wed Mar  7 20:53:51 2007
@@ -157,6 +157,8 @@
         # hack to avoid imports in the time-critical functions below
         for cls in self.model.typeorder:
             globals()[cls.__name__] = cls
+        for cls in self.model.imported_but_not_registered:
+            globals()[cls.__name__] = cls
 
         # singletons
         self.w_None  = W_NoneObject()

Modified: pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py	Wed Mar  7 20:53:51 2007
@@ -18,6 +18,9 @@
             # only share the empty string
             if len(s) == 0:
                 return W_StringObject.EMPTY
+    if self.config.objspace.std.withrope:
+        from pypy.objspace.std.ropeobject import rope, W_RopeObject
+        return W_RopeObject(rope.LiteralStringNode(s))
     return W_StringObject(s)
 
 def wrapchar(space, c):
@@ -30,6 +33,7 @@
 def sliced(space, s, start, stop):
     assert start >= 0
     assert stop >= 0 
+    assert not space.config.objspace.std.withrope
     if space.config.objspace.std.withstrslice:
         from pypy.objspace.std.strsliceobject import W_StringSliceObject
         # XXX heuristic, should be improved!
@@ -38,6 +42,7 @@
     return wrapstr(space, s[start:stop])
 
 def joined(space, strlist):
+    assert not space.config.objspace.std.withrope
     if space.config.objspace.std.withstrjoin:
         from pypy.objspace.std.strjoinobject import W_StringJoinObject
         return W_StringJoinObject(strlist)
@@ -254,9 +259,15 @@
     if space.is_w(w_stringtype, space.w_str):
         return w_obj  # XXX might be reworked when space.str() typechecks
     value = space.str_w(w_obj)
-    w_obj = space.allocate_instance(W_StringObject, w_stringtype)
-    W_StringObject.__init__(w_obj, value)
-    return w_obj
+    if space.config.objspace.std.withrope:
+        from pypy.objspace.std.ropeobject import rope, W_RopeObject
+        w_obj = space.allocate_instance(W_RopeObject, w_stringtype)
+        W_RopeObject.__init__(w_obj, rope.LiteralStringNode(value))
+        return w_obj
+    else:
+        w_obj = space.allocate_instance(W_StringObject, w_stringtype)
+        W_StringObject.__init__(w_obj, value)
+        return w_obj
 
 # ____________________________________________________________
 

Modified: pypy/branch/rope-branch2/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/unicodeobject.py	Wed Mar  7 20:53:51 2007
@@ -1,6 +1,7 @@
 from pypy.objspace.std.objspace import *
 from pypy.interpreter import gateway
 from pypy.objspace.std.stringobject import W_StringObject
+from pypy.objspace.std.ropeobject import W_RopeObject
 from pypy.objspace.std.noneobject import W_NoneObject
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.objspace.std.tupleobject import W_TupleObject
@@ -101,11 +102,17 @@
 def add__String_Unicode(space, w_left, w_right):
     return space.add(space.call_function(space.w_unicode, w_left) , w_right)
 
+add__Rope_Unicode = add__String_Unicode
+
 def add__Unicode_String(space, w_left, w_right):
     return space.add(w_left, space.call_function(space.w_unicode, w_right))
 
+add__Unicode_Rope = add__Unicode_String
+
 def contains__String_Unicode(space, w_container, w_item):
     return space.contains(space.call_function(space.w_unicode, w_container), w_item )
+contains__Rope_Unicode = contains__String_Unicode
+
 
 def _find(self, sub, start, end):
     if len(sub) == 0:
@@ -188,15 +195,25 @@
 
 def hash__Unicode(space, w_uni):
     if w_uni.w_hash is None:
+        # hrmpf
         chars = w_uni._value
         if len(chars) == 0:
             return space.wrap(0)
-        x = ord(chars[0]) << 7
-        for c in chars:
-            x = intmask((1000003 * x) ^ ord(c))
-        h = intmask(x ^ len(chars))
-        if h == -1:
-            h = -2
+        if space.config.objspace.std.withrope:
+            x = 0
+            for c in chars:
+                x = intmask((1000003 * x) + ord(c))
+            x <<= 1
+            x ^= len(chars)
+            x ^= ord(chars[0])
+            h = intmask(x)
+        else:
+            x = ord(chars[0]) << 7
+            for c in chars:
+                x = intmask((1000003 * x) ^ ord(c))
+            h = intmask(x ^ len(chars))
+            if h == -1:
+                h = -2
         w_uni.w_hash = space.wrap(h)
     return w_uni.w_hash
 
@@ -394,6 +411,7 @@
 def unicode_strip__Unicode_String(space, w_self, w_chars):
     return space.call_method(w_self, 'strip',
                              space.call_function(space.w_unicode, w_chars))
+unicode_strip__Unicode_Rope = unicode_strip__Unicode_String
 
 def unicode_lstrip__Unicode_None(space, w_self, w_chars):
     return _strip_none(space, w_self, 1, 0)
@@ -403,6 +421,8 @@
     return space.call_method(w_self, 'lstrip',
                              space.call_function(space.w_unicode, w_chars))
 
+unicode_lstrip__Unicode_Rope = unicode_lstrip__Unicode_String
+
 def unicode_rstrip__Unicode_None(space, w_self, w_chars):
     return _strip_none(space, w_self, 0, 1)
 def unicode_rstrip__Unicode_Unicode(space, w_self, w_chars):
@@ -411,6 +431,8 @@
     return space.call_method(w_self, 'rstrip',
                              space.call_function(space.w_unicode, w_chars))
 
+unicode_rstrip__Unicode_Rope = unicode_rstrip__Unicode_String
+
 def unicode_capitalize__Unicode(space, w_self):
     input = w_self._value
     if len(input) == 0:
@@ -1034,41 +1056,49 @@
     import stringtype
     W_UnicodeObject = W_UnicodeObject
     from pypy.objspace.std.stringobject import W_StringObject
+    from pypy.objspace.std.ropeobject import W_RopeObject
     def str_strip__String_Unicode(space, w_self, w_chars):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'strip', w_chars)
+    str_strip__Rope_Unicode = str_strip__String_Unicode
     def str_lstrip__String_Unicode(space, w_self, w_chars):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'lstrip', w_chars)
+    str_lstrip__Rope_Unicode = str_lstrip__String_Unicode
     def str_rstrip__String_Unicode(space, w_self, w_chars):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'rstrip', w_chars)
+    str_rstrip__Rope_Unicode = str_rstrip__String_Unicode
     def str_count__String_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'count', w_substr, w_start, w_end)
+    str_count__Rope_Unicode_ANY_ANY = str_count__String_Unicode_ANY_ANY
     def str_find__String_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'find', w_substr, w_start, w_end)
+    str_find__Rope_Unicode_ANY_ANY = str_find__String_Unicode_ANY_ANY
     def str_rfind__String_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'rfind', w_substr, w_start, w_end)
+    str_rfind__Rope_Unicode_ANY_ANY = str_rfind__String_Unicode_ANY_ANY
     def str_index__String_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'index', w_substr, w_start, w_end)
+    str_index__Rope_Unicode_ANY_ANY = str_index__String_Unicode_ANY_ANY
     def str_rindex__String_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'rindex', w_substr, w_start, w_end)
-
+    str_rindex__Rope_Unicode_ANY_ANY = str_rindex__String_Unicode_ANY_ANY
     def str_replace__String_Unicode_Unicode_ANY(space, w_self, w_old, w_new, w_maxsplit):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'replace', w_old, w_new, w_maxsplit)
-
+    str_replace__Rope_Unicode_Unicode_ANY = str_replace__String_Unicode_Unicode_ANY
     def str_split__String_Unicode_ANY(space, w_self, w_delim, w_maxsplit):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'split', w_delim, w_maxsplit)
-
+    str_split__Rope_Unicode_ANY = str_split__String_Unicode_ANY
     def str_rsplit__String_Unicode_ANY(space, w_self, w_delim, w_maxsplit):
         return space.call_method(space.call_function(space.w_unicode, w_self),
                                  'rsplit', w_delim, w_maxsplit)
-
+    str_rsplit__Rope_Unicode_ANY = str_rsplit__String_Unicode_ANY
     register_all(vars(), stringtype)



More information about the Pypy-commit mailing list