From b9b00757728bdbbcfcf1b26ebb7dc974d5db3b1d 2013-02-05 14:59:19
From: Thomas Kluyver <takowl@gmail.com>
Date: 2013-02-05 14:59:19
Subject: [PATCH] Remove unused utils.newserialized

---

diff --git a/IPython/parallel/tests/test_newserialized.py b/IPython/parallel/tests/test_newserialized.py
deleted file mode 100644
index c7a6180..0000000
--- a/IPython/parallel/tests/test_newserialized.py
+++ /dev/null
@@ -1,117 +0,0 @@
-"""test serialization with newserialized
-
-Authors:
-
-* Min RK
-"""
-
-#-------------------------------------------------------------------------------
-#  Copyright (C) 2011  The IPython Development Team
-#
-#  Distributed under the terms of the BSD License.  The full license is in
-#  the file COPYING, distributed as part of this software.
-#-------------------------------------------------------------------------------
-
-#-------------------------------------------------------------------------------
-# Imports
-#-------------------------------------------------------------------------------
-
-import sys
-
-from unittest import TestCase
-
-from IPython.testing.decorators import parametric
-from IPython.utils import newserialized as ns
-from IPython.utils.pickleutil import can, uncan, CannedObject, CannedFunction
-from IPython.parallel.tests.clienttest import skip_without
-
-if sys.version_info[0] >= 3:
-    buffer = memoryview
-
-class CanningTestCase(TestCase):
-    def test_canning(self):
-        d = dict(a=5,b=6)
-        cd = can(d)
-        self.assertTrue(isinstance(cd, dict))
-
-    def test_canned_function(self):
-        f = lambda : 7
-        cf = can(f)
-        self.assertTrue(isinstance(cf, CannedFunction))
-    
-    @parametric
-    def test_can_roundtrip(cls):
-        objs = [
-            dict(),
-            set(),
-            list(),
-            ['a',1,['a',1],u'e'],
-        ]
-        return map(cls.run_roundtrip, objs)
-    
-    @classmethod
-    def run_roundtrip(self, obj):
-        o = uncan(can(obj))
-        assert o == obj, "failed assertion: %r == %r"%(o,obj)
-    
-    def test_serialized_interfaces(self):
-
-        us = {'a':10, 'b':range(10)}
-        s = ns.serialize(us)
-        uus = ns.unserialize(s)
-        self.assertTrue(isinstance(s, ns.SerializeIt))
-        self.assertEqual(uus, us)
-
-    def test_pickle_serialized(self):
-        obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
-        original = ns.UnSerialized(obj)
-        originalSer = ns.SerializeIt(original)
-        firstData = originalSer.getData()
-        firstTD = originalSer.getTypeDescriptor()
-        firstMD = originalSer.getMetadata()
-        self.assertEqual(firstTD, 'pickle')
-        self.assertEqual(firstMD, {})
-        unSerialized = ns.UnSerializeIt(originalSer)
-        secondObj = unSerialized.getObject()
-        for k, v in secondObj.iteritems():
-            self.assertEqual(obj[k], v)
-        secondSer = ns.SerializeIt(ns.UnSerialized(secondObj))
-        self.assertEqual(firstData, secondSer.getData())
-        self.assertEqual(firstTD, secondSer.getTypeDescriptor() )
-        self.assertEqual(firstMD, secondSer.getMetadata())
-    
-    @skip_without('numpy')
-    def test_ndarray_serialized(self):
-        import numpy
-        a = numpy.linspace(0.0, 1.0, 1000)
-        unSer1 = ns.UnSerialized(a)
-        ser1 = ns.SerializeIt(unSer1)
-        td = ser1.getTypeDescriptor()
-        self.assertEqual(td, 'ndarray')
-        md = ser1.getMetadata()
-        self.assertEqual(md['shape'], a.shape)
-        self.assertEqual(md['dtype'], a.dtype)
-        buff = ser1.getData()
-        self.assertEqual(buff, buffer(a))
-        s = ns.Serialized(buff, td, md)
-        final = ns.unserialize(s)
-        self.assertEqual(buffer(a), buffer(final))
-        self.assertTrue((a==final).all())
-        self.assertEqual(a.dtype, final.dtype)
-        self.assertEqual(a.shape, final.shape)
-        # test non-copying:
-        a[2] = 1e9
-        self.assertTrue((a==final).all())
-    
-    def test_uncan_function_globals(self):
-        """test that uncanning a module function restores it into its module"""
-        from re import search
-        cf = can(search)
-        csearch = uncan(cf)
-        self.assertEqual(csearch.__module__, search.__module__)
-        self.assertNotEqual(csearch('asd', 'asdf'), None)
-        csearch = uncan(cf, dict(a=5))
-        self.assertEqual(csearch.__module__, search.__module__)
-        self.assertNotEqual(csearch('asd', 'asdf'), None)
-        
-        
\ No newline at end of file
diff --git a/IPython/utils/newserialized.py b/IPython/utils/newserialized.py
deleted file mode 100644
index c3336c7..0000000
--- a/IPython/utils/newserialized.py
+++ /dev/null
@@ -1,177 +0,0 @@
-# encoding: utf-8
-# -*- test-case-name: IPython.kernel.test.test_newserialized -*-
-
-"""Refactored serialization classes and interfaces."""
-
-__docformat__ = "restructuredtext en"
-
-# Tell nose to skip this module
-__test__ = {}
-
-#-------------------------------------------------------------------------------
-#  Copyright (C) 2008-2011  The IPython Development Team
-#
-#  Distributed under the terms of the BSD License.  The full license is in
-#  the file COPYING, distributed as part of this software.
-#-------------------------------------------------------------------------------
-
-#-------------------------------------------------------------------------------
-# Imports
-#-------------------------------------------------------------------------------
-
-import sys
-import cPickle as pickle
-
-try:
-    import numpy
-except ImportError:
-    numpy = None
-
-class SerializationError(Exception):
-    pass
-
-if sys.version_info[0] >= 3:
-    buffer = memoryview
-    py3k = True
-else:
-    py3k = False
-    if sys.version_info[:2] <= (2,6):
-        memoryview = buffer
-
-#-----------------------------------------------------------------------------
-# Classes and functions
-#-----------------------------------------------------------------------------
-
-class ISerialized:
-    
-    def getData():
-        """"""
-
-    def getDataSize(units=10.0**6):
-        """"""
-
-    def getTypeDescriptor():
-        """"""
-
-    def getMetadata():
-        """"""
-        
-        
-class IUnSerialized:
-    
-    def getObject():
-        """"""
-        
-class Serialized(object):
-    
-    # implements(ISerialized)
-    
-    def __init__(self, data, typeDescriptor, metadata={}):
-        self.data = data
-        self.typeDescriptor = typeDescriptor
-        self.metadata = metadata
-        
-    def getData(self):
-        return self.data
-        
-    def getDataSize(self, units=10.0**6):
-        return len(self.data)/units
-        
-    def getTypeDescriptor(self):
-        return self.typeDescriptor
-        
-    def getMetadata(self):
-        return self.metadata
-
-        
-class UnSerialized(object):
-    
-    # implements(IUnSerialized)
-        
-    def __init__(self, obj):
-        self.obj = obj
-        
-    def getObject(self):
-        return self.obj
-
-        
-class SerializeIt(object):
-    
-    # implements(ISerialized)
-    
-    def __init__(self, unSerialized):
-        self.data = None
-        self.obj = unSerialized.getObject()
-        if numpy is not None and isinstance(self.obj, numpy.ndarray):
-            if len(self.obj.shape) == 0: # length 0 arrays are just pickled
-                self.typeDescriptor = 'pickle'
-                self.metadata = {}
-            else:
-                self.obj = numpy.ascontiguousarray(self.obj, dtype=None)
-                self.typeDescriptor = 'ndarray'
-                self.metadata = {'shape':self.obj.shape,
-                                 'dtype':self.obj.dtype}
-        elif isinstance(self.obj, bytes):
-            self.typeDescriptor = 'bytes'
-            self.metadata = {}
-        elif isinstance(self.obj, buffer):
-            self.typeDescriptor = 'buffer'
-            self.metadata = {}
-        else:
-            self.typeDescriptor = 'pickle'
-            self.metadata = {}
-        self._generateData()
-    
-    def _generateData(self):
-        if self.typeDescriptor == 'ndarray':
-            self.data = buffer(self.obj)
-        elif self.typeDescriptor in ('bytes', 'buffer'):
-            self.data = self.obj
-        elif self.typeDescriptor == 'pickle':
-            self.data = pickle.dumps(self.obj, -1)
-        else:
-            raise SerializationError("Really wierd serialization error.")
-        del self.obj
-        
-    def getData(self):
-        return self.data
-        
-    def getDataSize(self, units=10.0**6):
-        return 1.0*len(self.data)/units
-        
-    def getTypeDescriptor(self):
-        return self.typeDescriptor
-        
-    def getMetadata(self):
-        return self.metadata
-
-
-class UnSerializeIt(UnSerialized):
-    
-    # implements(IUnSerialized)
-    
-    def __init__(self, serialized):
-        self.serialized = serialized
-        
-    def getObject(self):
-        typeDescriptor = self.serialized.getTypeDescriptor()
-        if numpy is not None and typeDescriptor == 'ndarray':
-                buf = self.serialized.getData()
-                if isinstance(buf, (bytes, buffer, memoryview)):
-                    result = numpy.frombuffer(buf, dtype = self.serialized.metadata['dtype'])
-                else:
-                    raise TypeError("Expected bytes or buffer/memoryview, but got %r"%type(buf))
-                result.shape = self.serialized.metadata['shape']
-        elif typeDescriptor == 'pickle':
-            result = pickle.loads(self.serialized.getData())
-        elif typeDescriptor in ('bytes', 'buffer'):
-            result = self.serialized.getData()
-        else:
-            raise SerializationError("Really wierd serialization error.")
-        return result
-
-def serialize(obj):
-    return SerializeIt(UnSerialized(obj))
-    
-def unserialize(serialized):
-    return UnSerializeIt(serialized).getObject()