예제 #1
0
 def testNames(self):
     o = [1, 2, 3]
     p = sob.Persistent(o, "object")
     for style in "source pickle".split():
         p.setStyle(style)
         p.save()
         o1 = sob.load("object.ta" + style[0], style)
         self.assertEqual(o, o1)
         for tag in "lala lolo".split():
             p.save(tag)
             o1 = sob.load("object-" + tag + ".ta" + style[0], style)
             self.assertEqual(o, o1)
예제 #2
0
파일: test_sob.py 프로젝트: ssilverek/kodb
 def testNames(self):
     o = [1, 2, 3]
     p = sob.Persistent(o, "object")
     for style in "source pickle".split():
         p.setStyle(style)
         p.save()
         o1 = sob.load("object.ta" + style[0], style)
         self.assertEqual(o, o1)
         for tag in "lala lolo".split():
             p.save(tag)
             o1 = sob.load("object-" + tag + ".ta" + style[0], style)
             self.assertEqual(o, o1)
예제 #3
0
 def testNames(self):
     o = [1,2,3]
     p = sob.Persistent(o, 'object')
     for style in 'source pickle'.split():
         p.setStyle(style)
         p.save()
         o1 = sob.load('object.ta'+style[0], style)
         self.failUnlessEqual(o, o1)
         for tag in 'lala lolo'.split():
             p.save(tag)
             o1 = sob.load('object-'+tag+'.ta'+style[0], style)
             self.failUnlessEqual(o, o1)
예제 #4
0
 def testNames(self):
     o = [1, 2, 3]
     p = sob.Persistent(o, 'object')
     for style in 'source pickle'.split():
         p.setStyle(style)
         p.save()
         o1 = sob.load('object.ta' + style[0], style)
         self.assertEqual(o, o1)
         for tag in 'lala lolo'.split():
             p.save(tag)
             o1 = sob.load('object-' + tag + '.ta' + style[0], style)
             self.assertEqual(o, o1)
예제 #5
0
 def testNames(self):
     o = [1,2,3]
     p = sob.Persistent(o, 'object')
     for style in 'xml source pickle'.split():
         if style == 'xml' and not gotMicrodom:
             continue
         p.setStyle(style)
         p.save()
         o1 = sob.load('object.ta'+style[0], style)
         self.failUnlessEqual(o, o1)
         for tag in 'lala lolo'.split():
             p.save(tag)
             o1 = sob.load('object-'+tag+'.ta'+style[0], style)
             self.failUnlessEqual(o, o1)
예제 #6
0
    def test_saveEncryptedDeprecation(self):
        """
        Persisting data with encryption is deprecated.
        """
        tempDir = FilePath(self.mktemp())
        tempDir.makedirs()
        persistedPath = tempDir.child('epersisttest.python')
        data = b'once I was the king of spain'
        persistance = sob.Persistent(data, 'test-data')

        persistance.save(filename=persistedPath.path, passphrase=b'some-pass')

        # Check deprecation message.
        warnings = self.flushWarnings([persistance._saveTemp])
        self.assertEqual(1, len(warnings))
        self.assertIs(DeprecationWarning, warnings[0]['category'])
        self.assertEqual(
            'Saving encrypted persisted data is deprecated since '
            'Twisted 15.5.0',
            warnings[0]['message'])
        # Check that data is still valid, even if we are deprecating this
        # functionality.
        loadedData = sob.load(
            persistedPath.path, persistance.style, b'some-pass')
        self.assertEqual(data, loadedData)
        self.flushWarnings([sob.load])
예제 #7
0
    def test_saveEncryptedDeprecation(self):
        """
        Persisting data with encryption is deprecated.
        """
        tempDir = FilePath(self.mktemp())
        tempDir.makedirs()
        persistedPath = tempDir.child('epersisttest.python')
        data = b'once I was the king of spain'
        persistance = sob.Persistent(data, 'test-data')

        persistance.save(filename=persistedPath.path, passphrase=b'some-pass')

        # Check deprecation message.
        warnings = self.flushWarnings([persistance._saveTemp])
        self.assertEqual(1, len(warnings))
        self.assertIs(DeprecationWarning, warnings[0]['category'])
        self.assertEqual(
            'Saving encrypted persisted data is deprecated since '
            'Twisted 15.5.0', warnings[0]['message'])
        # Check that data is still valid, even if we are deprecating this
        # functionality.
        loadedData = sob.load(persistedPath.path, persistance.style,
                              b'some-pass')
        self.assertEqual(data, loadedData)
        self.flushWarnings([sob.load])
예제 #8
0
파일: test_sob.py 프로젝트: ssilverek/kodb
 def testStyles(self):
     for o in objects:
         p = sob.Persistent(o, "")
         for style in "source pickle".split():
             p.setStyle(style)
             p.save(filename="persisttest." + style)
             o1 = sob.load("persisttest." + style, style)
             self.assertEqual(o, o1)
예제 #9
0
 def testStyles(self):
     for o in objects:
         p = sob.Persistent(o, '')
         for style in 'source pickle'.split():
             p.setStyle(style)
             p.save(filename='persisttest.' + style)
             o1 = sob.load('persisttest.' + style, style)
             self.assertEqual(o, o1)
예제 #10
0
 def testStyles(self):
     for o in objects:
         p = sob.Persistent(o, "")
         for style in "source pickle".split():
             p.setStyle(style)
             p.save(filename="persisttest." + style)
             o1 = sob.load("persisttest." + style, style)
             self.assertEqual(o, o1)
예제 #11
0
 def testStyles(self):
     for o in objects:
         p = sob.Persistent(o, '')
         for style in 'source pickle'.split():
             p.setStyle(style)
             p.save(filename='persisttest.'+style)
             o1 = sob.load('persisttest.'+style, style)
             self.failUnlessEqual(o, o1)
예제 #12
0
 def restore(self):
     if not self.filename:
         raise exceptions.StateRestoreError, \
             "It appears that state was never saved; cannot restore"
     if os.path.exists(self.filename):
         s = sob.load(self.filename, 'pickle')
         for key, val in s.__dict__.items():
             setattr(self, key, val)
예제 #13
0
 def restore(self):
     if not self.filename:
         raise exceptions.StateRestoreError, \
             "It appears that state was never saved; cannot restore"
     if os.path.exists(self.filename):
         s = sob.load(self.filename, 'pickle')
         for key, val in s.__dict__.items():
             setattr(self, key, val)
예제 #14
0
 def testEncryptedStyles(self):
     for o in objects:
         phrase='once I was the king of spain'
         p = sob.Persistent(o, '')
         for style in 'source pickle'.split():
             p.setStyle(style)
             p.save(filename='epersisttest.'+style, passphrase=phrase)
             o1 = sob.load('epersisttest.'+style, style, phrase)
             self.failUnlessEqual(o, o1)
예제 #15
0
    def testEverythingEphemeralGetattr(self):
        """
        Verify that _EverythingEphermal.__getattr__ works.
        """
        self.fakeMain.testMainModGetattr = 1

        dirname = self.mktemp()
        os.mkdir(dirname)

        filename = os.path.join(dirname, 'persisttest.ee_getattr')

        f = file(filename, 'w')
        f.write('import __main__\n')
        f.write('if __main__.testMainModGetattr != 1: raise AssertionError\n')
        f.write('app = None\n')
        f.close()

        sob.load(filename, 'source')
예제 #16
0
    def testEverythingEphemeralSetattr(self):
        """
        Verify that _EverythingEphemeral.__setattr__ won't affect __main__.
        """
        self.fakeMain.testMainModSetattr = 1

        dirname = self.mktemp()
        os.mkdir(dirname)

        filename = os.path.join(dirname, 'persisttest.ee_setattr')
        with open(filename, 'w') as f:
            f.write('import __main__\n')
            f.write('__main__.testMainModSetattr = 2\n')
            f.write('app = None\n')

        sob.load(filename, 'source')

        self.assertEqual(self.fakeMain.testMainModSetattr, 1)
예제 #17
0
    def testEverythingEphemeralGetattr(self):
        """
        Verify that _EverythingEphermal.__getattr__ works.
        """
        self.fakeMain.testMainModGetattr = 1

        dirname = self.mktemp()
        os.mkdir(dirname)

        filename = os.path.join(dirname, 'persisttest.ee_getattr')

        f = file(filename, 'w')
        f.write('import __main__\n')
        f.write('if __main__.testMainModGetattr != 1: raise AssertionError\n')
        f.write('app = None\n')
        f.close()

        sob.load(filename, 'source')
예제 #18
0
 def testEncryptedStyles(self):
     for o in objects:
         phrase = b'once I was the king of spain'
         p = sob.Persistent(o, '')
         for style in 'source pickle'.split():
             p.setStyle(style)
             p.save(filename='epersisttest.' + style, passphrase=phrase)
             o1 = sob.load('epersisttest.' + style, style, phrase)
             self.assertEqual(o, o1)
예제 #19
0
    def testEverythingEphemeralSetattr(self):
        """
        Verify that _EverythingEphemeral.__setattr__ won't affect __main__.
        """
        self.fakeMain.testMainModSetattr = 1

        dirname = self.mktemp()
        os.mkdir(dirname)

        filename = os.path.join(dirname, 'persisttest.ee_setattr')
        with open(filename, 'w') as f:
            f.write('import __main__\n')
            f.write('__main__.testMainModSetattr = 2\n')
            f.write('app = None\n')

        sob.load(filename, 'source')

        self.assertEqual(self.fakeMain.testMainModSetattr, 1)
예제 #20
0
파일: test_sob.py 프로젝트: ssilverek/kodb
 def testEncryptedStyles(self):
     for o in objects:
         phrase = b"once I was the king of spain"
         p = sob.Persistent(o, "")
         for style in "source pickle".split():
             p.setStyle(style)
             p.save(filename="epersisttest." + style, passphrase=phrase)
             o1 = sob.load("epersisttest." + style, style, phrase)
             self.assertEqual(o, o1)
예제 #21
0
파일: test_sob.py 프로젝트: ssilverek/kodb
 def testStylesBeingSet(self):
     o = Dummy()
     o.foo = 5
     o.setComponent(sob.IPersistable, sob.Persistent(o, "lala"))
     for style in "source pickle".split():
         sob.IPersistable(o).setStyle(style)
         sob.IPersistable(o).save(filename="lala." + style)
         o1 = sob.load("lala." + style, style)
         self.assertEqual(o.foo, o1.foo)
         self.assertEqual(sob.IPersistable(o1).style, style)
예제 #22
0
 def testStylesBeingSet(self):
     o = Dummy()
     o.foo = 5
     o.setComponent(sob.IPersistable, sob.Persistent(o, 'lala'))
     for style in 'source pickle'.split():
         sob.IPersistable(o).setStyle(style)
         sob.IPersistable(o).save(filename='lala.'+style)
         o1 = sob.load('lala.'+style, style)
         self.failUnlessEqual(o.foo, o1.foo)
         self.failUnlessEqual(sob.IPersistable(o1).style, style)
예제 #23
0
 def testStyles(self):
     for o in objects:
         p = sob.Persistent(o, '')
         for style in 'xml source pickle'.split():
             if style == 'xml' and not gotMicrodom:
                 continue
             p.setStyle(style)
             p.save(filename='persisttest.'+style)
             o1 = sob.load('persisttest.'+style, style)
             self.failUnlessEqual(o, o1)
예제 #24
0
 def testStylesBeingSet(self):
     o = Dummy()
     o.foo = 5
     o.setComponent(sob.IPersistable, sob.Persistent(o, 'lala'))
     for style in 'source pickle'.split():
         sob.IPersistable(o).setStyle(style)
         sob.IPersistable(o).save(filename='lala.' + style)
         o1 = sob.load('lala.' + style, style)
         self.assertEqual(o.foo, o1.foo)
         self.assertEqual(sob.IPersistable(o1).style, style)
예제 #25
0
파일: test_sob.py 프로젝트: emragins/tribal
 def testEncryptedStyles(self):
     for o in objects:
         phrase = 'once I was the king of spain'
         p = sob.Persistent(o, '')
         for style in 'xml source pickle'.split():
             if style == 'xml' and not gotMicrodom:
                 continue
             p.setStyle(style)
             p.save(filename='epersisttest.' + style, passphrase=phrase)
             o1 = sob.load('epersisttest.' + style, style, phrase)
             self.failUnlessEqual(o, o1)
예제 #26
0
 def testStylesBeingSet(self):
     o = Dummy()
     o.foo = 5
     o.setComponent(sob.IPersistable, sob.Persistent(o, 'lala'))
     for style in 'xml source pickle'.split():
         if style == 'xml' and not gotMicrodom:
             continue
         sob.IPersistable(o).setStyle(style)
         sob.IPersistable(o).save(filename='lala.'+style)
         o1 = sob.load('lala.'+style, style)
         self.failUnlessEqual(o.foo, o1.foo)
         self.failUnlessEqual(sob.IPersistable(o1).style, style)
예제 #27
0
 def test_encryptedStyles(self):
     """
     Data can be persisted with encryption for all the supported styles.
     """
     for o in objects:
         phrase = b'once I was the king of spain'
         p = sob.Persistent(o, '')
         for style in 'source pickle'.split():
             p.setStyle(style)
             p.save(filename='epersisttest.' + style, passphrase=phrase)
             o1 = sob.load('epersisttest.' + style, style, phrase)
             self.assertEqual(o, o1)
             self.flushWarnings([p._saveTemp, sob.load])
예제 #28
0
 def test_encryptedStyles(self):
     """
     Data can be persisted with encryption for all the supported styles.
     """
     for o in objects:
         phrase = b'once I was the king of spain'
         p = sob.Persistent(o, '')
         for style in 'source pickle'.split():
             p.setStyle(style)
             p.save(filename='epersisttest.'+style, passphrase=phrase)
             o1 = sob.load('epersisttest.'+style, style, phrase)
             self.assertEqual(o, o1)
             self.flushWarnings([p._saveTemp, sob.load])
예제 #29
0
 def testEncryptedStyles(self):
     try:
         import Crypto
     except ImportError:
         raise unittest.SkipTest()
     for o in objects:
         phrase='once I was the king of spain'
         p = sob.Persistent(o, '')
         for style in 'xml source pickle'.split():
             if style == 'xml' and not gotMicrodom:
                 continue
             p.setStyle(style)
             p.save(filename='epersisttest.'+style, passphrase=phrase)
             o1 = sob.load('epersisttest.'+style, style, phrase)
             self.failUnlessEqual(o, o1)
예제 #30
0
def loadApplication(filename, kind, passphrase=None):
    """Load Application from a given file.

    The serialization format it was saved in should be given as
    C{kind}, and is one of 'pickle', 'source', 'xml' or 'python'. If
    C{passphrase} is given, the application was encrypted with the
    given passphrase.

    @type filename: C{str}
    @type kind: C{str}
    @type passphrase: C{str}
    """
    if kind == 'python':
        application = sob.loadValueFromFile(filename, 'application', passphrase)
    else:
        application = sob.load(filename, kind, passphrase)
    return application
예제 #31
0
파일: service.py 프로젝트: kusoof/wprof
def loadApplication(filename, kind, passphrase=None):
    """Load Application from a given file.

    The serialization format it was saved in should be given as
    C{kind}, and is one of 'pickle', 'source', 'xml' or 'python'. If
    C{passphrase} is given, the application was encrypted with the
    given passphrase.

    @type filename: C{str}
    @type kind: C{str}
    @type passphrase: C{str}
    """
    if kind == 'python':
        application = sob.loadValueFromFile(filename, 'application', passphrase)
    else:
        application = sob.load(filename, kind, passphrase)
    return application
예제 #32
0
def loadApplication(filename, kind, passphrase=None):
    """
    Load Application from a given file.

    The serialization format it was saved in should be given as
    C{kind}, and is one of C{pickle}, C{source}, C{xml} or C{python}. If
    C{passphrase} is given, the application was encrypted with the
    given passphrase.

    @type filename: C{str}
    @type kind: C{str}
    @type passphrase: C{str}
    """
    if kind == "python":
        application = sob.loadValueFromFile(filename, "application")
    else:
        application = sob.load(filename, kind)
    return application
예제 #33
0
def loadApplication(filename, kind, passphrase=None):
    """Load Application from file
    @type filename: C{str}
    @type kind: C{str}
    @type passphrase: C{str}
    Load application from a given file. The serialization format it
    was saved in should be given as C{kind}, and is one of 'pickle', 'source',
    'xml' or 'python'. If C{passphrase} is given, the application was encrypted
    with the given passphrase.
    """
    if kind == 'python':
        application = sob.loadValueFromFile(filename, 'application', passphrase)
    else:
        application = sob.load(filename, kind, passphrase)
    if IService(application, None) is None:
        from twisted.application import compat
        application = compat.convert(application)
    return application
예제 #34
0
def loadApplication(filename, kind, passphrase=None):
    """Load Application from file

    @type filename: C{str}
    @type kind: C{str}
    @type passphrase: C{str}

    Load application from a given file. The serialization format it
    was saved in should be given as C{kind}, and is one of 'pickle', 'source',
    'xml' or 'python'. If C{passphrase} is given, the application was encrypted
    with the given passphrase.
    """
    if kind == 'python':
        application = sob.loadValueFromFile(filename, 'application', passphrase)
    else:
        application = sob.load(filename, kind, passphrase)
    if IService(application, None) is None:
        from twisted.application import compat
        application = compat.convert(application)
    return application
예제 #35
0
    def testEverythingEphemeralGetattr(self):
        """
        L{_EverythingEphermal.__getattr__} will proxy the __main__ module as an
        L{Ephemeral} object, and during load will be transparent, but after
        load will return L{Ephemeral} objects from any accessed attributes.
        """
        self.fakeMain.testMainModGetattr = 1

        dirname = self.mktemp()
        os.mkdir(dirname)

        filename = os.path.join(dirname, "persisttest.ee_getattr")

        global mainWhileLoading
        mainWhileLoading = None
        with open(filename, "w") as f:
            f.write(
                dedent(
                    """
            app = []
            import __main__
            app.append(__main__.testMainModGetattr == 1)
            try:
                __main__.somethingElse
            except AttributeError:
                app.append(True)
            else:
                app.append(False)
            from twisted.test import test_sob
            test_sob.mainWhileLoading = __main__
            """
                )
            )

        loaded = sob.load(filename, "source")
        self.assertIsInstance(loaded, list)
        self.assertTrue(loaded[0], "Expected attribute not set.")
        self.assertTrue(loaded[1], "Unexpected attribute set.")
        self.assertIsInstance(mainWhileLoading, Ephemeral)
        self.assertIsInstance(mainWhileLoading.somethingElse, Ephemeral)
        del mainWhileLoading
예제 #36
0
파일: test_sob.py 프로젝트: ssilverek/kodb
    def testEverythingEphemeralGetattr(self):
        """
        L{_EverythingEphermal.__getattr__} will proxy the __main__ module as an
        L{Ephemeral} object, and during load will be transparent, but after
        load will return L{Ephemeral} objects from any accessed attributes.
        """
        self.fakeMain.testMainModGetattr = 1

        dirname = self.mktemp()
        os.mkdir(dirname)

        filename = os.path.join(dirname, "persisttest.ee_getattr")

        global mainWhileLoading
        mainWhileLoading = None
        with open(filename, "w") as f:
            f.write(
                dedent(
                    """
            app = []
            import __main__
            app.append(__main__.testMainModGetattr == 1)
            try:
                __main__.somethingElse
            except AttributeError:
                app.append(True)
            else:
                app.append(False)
            from twisted.test import test_sob
            test_sob.mainWhileLoading = __main__
            """
                )
            )

        loaded = sob.load(filename, "source")
        self.assertIsInstance(loaded, list)
        self.assertTrue(loaded[0], "Expected attribute not set.")
        self.assertTrue(loaded[1], "Unexpected attribute set.")
        self.assertIsInstance(mainWhileLoading, Ephemeral)
        self.assertIsInstance(mainWhileLoading.somethingElse, Ephemeral)
        del mainWhileLoading
예제 #37
0
    def test_loadEncryptedDeprecation(self):
        """
        Loading encrypted persisted data is deprecated.
        """
        tempDir = FilePath(self.mktemp())
        tempDir.makedirs()
        persistedPath = tempDir.child('epersisttest.python')
        data = b'once I was the king of spain'
        persistance = sob.Persistent(data, 'test-data')
        persistance.save(filename=persistedPath.path, passphrase=b'some-pass')
        # Clean all previous warnings as save will also raise a warning.
        self.flushWarnings([persistance._saveTemp])

        loadedData = sob.load(persistedPath.path, persistance.style,
                              b'some-pass')

        self.assertEqual(data, loadedData)
        warnings = self.flushWarnings([sob.load])
        self.assertEqual(1, len(warnings))
        self.assertIs(DeprecationWarning, warnings[0]['category'])
        self.assertEqual(
            'Loading encrypted persisted data is deprecated since '
            'Twisted 15.5.0', warnings[0]['message'])
예제 #38
0
def loadApplication(filename, kind, passphrase=None):
    """
    Load Application from a given file.

    The serialization format it was saved in should be given as
    C{kind}, and is one of C{pickle}, C{source}, C{xml} or C{python}. If
    C{passphrase} is given, the application was encrypted with the
    given passphrase.

    @type filename: C{str}
    @type kind: C{str}
    @type passphrase: C{str}
    """
    # FIXME: https://twistedmatrix.com/trac/ticket/7827
    # twisted.persisted is not yet ported to Python 3, so import it here.
    from twisted.persisted import sob

    if kind == 'python':
        application = sob.loadValueFromFile(filename, 'application',
                                            passphrase)
    else:
        application = sob.load(filename, kind, passphrase)
    return application
예제 #39
0
def loadApplication(filename, kind, passphrase=None):
    """
    Load Application from a given file.

    The serialization format it was saved in should be given as
    C{kind}, and is one of C{pickle}, C{source}, C{xml} or C{python}. If
    C{passphrase} is given, the application was encrypted with the
    given passphrase.

    @type filename: C{str}
    @type kind: C{str}
    @type passphrase: C{str}
    """
    # FIXME: https://twistedmatrix.com/trac/ticket/7827
    # twisted.persisted is not yet ported to Python 3, so import it here.
    from twisted.persisted import sob

    if kind == 'python':
        application = sob.loadValueFromFile(filename, 'application',
                                            passphrase)
    else:
        application = sob.load(filename, kind, passphrase)
    return application
예제 #40
0
    def test_loadEncryptedDeprecation(self):
        """
        Loading encrypted persisted data is deprecated.
        """
        tempDir = FilePath(self.mktemp())
        tempDir.makedirs()
        persistedPath = tempDir.child('epersisttest.python')
        data = b'once I was the king of spain'
        persistance = sob.Persistent(data, 'test-data')
        persistance.save(filename=persistedPath.path, passphrase=b'some-pass')
        # Clean all previous warnings as save will also raise a warning.
        self.flushWarnings([persistance._saveTemp])

        loadedData = sob.load(
            persistedPath.path, persistance.style, b'some-pass')

        self.assertEqual(data, loadedData)
        warnings = self.flushWarnings([sob.load])
        self.assertEqual(1, len(warnings))
        self.assertIs(DeprecationWarning, warnings[0]['category'])
        self.assertEqual(
            'Loading encrypted persisted data is deprecated since '
            'Twisted 15.5.0',
            warnings[0]['message'])