def testEncryptedPython(self): phrase = 'once I was the king of spain' f = open("epersisttest.python", 'w') f.write(sob._encrypt(phrase, 'foo=[1,2,3]')) f.close() o = sob.loadValueFromFile('epersisttest.python', 'foo', phrase) self.assertEqual(o, [1, 2, 3])
def testEncryptedPython(self): phrase='once I was the king of spain' f = open("epersisttest.python", 'w') f.write( sob._encrypt(phrase, 'foo=[1,2,3]')) f.close() o = sob.loadValueFromFile('epersisttest.python', 'foo', phrase) self.failUnlessEqual(o, [1,2,3])
def testEncryptedPython(self): try: import Crypto except ImportError: raise unittest.SkipTest() phrase='once I was the king of spain' open("epersisttest.python", 'w').write( sob._encrypt(phrase, 'foo=[1,2,3]')) o = sob.loadValueFromFile('epersisttest.python', 'foo', phrase) self.failUnlessEqual(o, [1,2,3])
def test_loadValueFromFileEncryptedPython(self): """ Encrypted Python data can be loaded from a file. """ phrase = b'once I was the king of spain' with open("epersisttest.python", 'wb') as f: f.write(sob._encrypt(phrase, b'foo=[1,2,3]')) o = sob.loadValueFromFile('epersisttest.python', 'foo', phrase) self.assertEqual(o, [1,2,3]) self.flushWarnings([ sob.loadValueFromFile, self.test_loadValueFromFileEncryptedPython])
def test_loadValueFromFileEncryptedPython(self): """ Encrypted Python data can be loaded from a file. """ phrase = b'once I was the king of spain' with open("epersisttest.python", 'wb') as f: f.write(sob._encrypt(phrase, b'outputFile=[1,2,3]')) o = sob.loadValueFromFile('epersisttest.python', 'outputFile', phrase) self.assertEqual(o, [1, 2, 3]) self.flushWarnings([ sob.loadValueFromFile, self.test_loadValueFromFileEncryptedPython ])
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
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
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
def test_loadValueFromFileEncryptedDeprecation(self): """ Loading encrypted persisted data is deprecated. """ tempDir = FilePath(self.mktemp()) tempDir.makedirs() persistedPath = tempDir.child('epersisttest.python') persistedPath.setContent(sob._encrypt(b'some-pass', b'foo=[1,2,3]')) # Clean all previous warnings as _encpryt will also raise a warning. self.flushWarnings([self.test_loadValueFromFileEncryptedDeprecation]) loadedData = sob.loadValueFromFile(persistedPath.path, 'foo', b'some-pass') self.assertEqual([1, 2, 3], loadedData) warnings = self.flushWarnings([sob.loadValueFromFile]) 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'])
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
def test_loadValueFromFileEncryptedDeprecation(self): """ Loading encrypted persisted data is deprecated. """ tempDir = FilePath(self.mktemp()) tempDir.makedirs() persistedPath = tempDir.child('epersisttest.python') persistedPath.setContent(sob._encrypt(b'some-pass', b'foo=[1,2,3]')) # Clean all previous warnings as _encpryt will also raise a warning. self.flushWarnings([ self.test_loadValueFromFileEncryptedDeprecation]) loadedData = sob.loadValueFromFile( persistedPath.path, 'foo', b'some-pass') self.assertEqual([1, 2, 3], loadedData) warnings = self.flushWarnings([sob.loadValueFromFile]) 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'])
def testPython(self): open("persisttest.python", 'w').write('foo=[1,2,3] ') o = sob.loadValueFromFile('persisttest.python', 'foo') self.failUnlessEqual(o, [1,2,3])
def testEncryptedPython(self): phrase = b'once I was the king of spain' with open("epersisttest.python", 'wb') as f: f.write(sob._encrypt(phrase, b'foo=[1,2,3]')) o = sob.loadValueFromFile('epersisttest.python', 'foo', phrase) self.assertEqual(o, [1, 2, 3])
def testPython(self): with open("persisttest.python", "w") as f: f.write("foo=[1,2,3] ") o = sob.loadValueFromFile("persisttest.python", "foo") self.assertEqual(o, [1, 2, 3])
def testPython(self): f = open("persisttest.python", 'w') f.write('foo=[1,2,3] ') f.close() o = sob.loadValueFromFile('persisttest.python', 'foo') self.assertEqual(o, [1, 2, 3])
def testEncryptedPython(self): phrase = b"once I was the king of spain" with open("epersisttest.python", "wb") as f: f.write(sob._encrypt(phrase, b"foo=[1,2,3]")) o = sob.loadValueFromFile("epersisttest.python", "foo", phrase) self.assertEqual(o, [1, 2, 3])
def testPython(self): with open("persisttest.python", 'w') as f: f.write('outputFile=[1,2,3] ') o = sob.loadValueFromFile('persisttest.python', 'outputFile') self.assertEqual(o, [1, 2, 3])
def testPython(self): with open("persisttest.python", 'w') as f: f.write('foo=[1,2,3] ') o = sob.loadValueFromFile('persisttest.python', 'foo') self.assertEqual(o, [1,2,3])