Exemple #1
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])
Exemple #2
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)
 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)
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)
Exemple #7
0
 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)
Exemple #8
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)
Exemple #9
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)
 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)
Exemple #11
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])
Exemple #12
0
def Application(name, uid=None, gid=None):
    """Return a compound class.

    Return an object supporting the C{IService}, C{IServiceCollection},
    C{IProcess} and C{sob.IPersistable} interfaces, with the given
    parameters. Always access the return value by explicit casting to
    one of the interfaces.
    """
    ret = components.Componentized()
    for comp in (Bots(), sob.Persistent(ret, name), service.Process(uid, gid)):
        ret.addComponent(comp, ignoreClass=1)
    service.IService(ret).setName(name)
    return ret
Exemple #13
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)
Exemple #14
0
def Application(name, uid=None, gid=None):
    """
    Return a compound class.
    Return an object supporting the L{IService}, L{IPausable}, L{IReloadable}, L{IServiceCollection},
    L{IProcess} and L{sob.IPersistable} interfaces, with the given
    parameters. Always access the return value by explicit casting to
    one of the interfaces.
    """
    ret = components.Componentized()
    availableComponents = [TopLevelService(), Process(uid, gid),
                           sob.Persistent(ret, name)]

    for comp in availableComponents:
        ret.addComponent(comp, ignoreClass=1)
    IService(ret).setName(name)
    return ret  
Exemple #15
0
def Application(name, uid=None, gid=None):
    """
    Return a compound class.

    Return an object supporting the L{IService}, L{IServiceCollection},
    L{IProcess} and L{sob.IPersistable} interfaces, with the given
    parameters. Always access the return value by explicit casting to
    one of the interfaces.
    """
    ret = components.Componentized()
    availableComponents = [MultiService(), Process(uid, gid)]

    if not _PY3:
        # 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
        availableComponents.append(sob.Persistent(ret, name))

    for comp in availableComponents:
        ret.addComponent(comp, ignoreClass=1)
    IService(ret).setName(name)
    return ret
Exemple #16
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'])