• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sob.load函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.persisted.sob.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了load函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testNames

 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)
开发者ID:ssilverek,项目名称:kodb,代码行数:12,代码来源:test_sob.py


示例2: testNames

 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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:12,代码来源:test_sob.py


示例3: test_saveEncryptedDeprecation

    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])
开发者ID:Architektor,项目名称:PySnip,代码行数:26,代码来源:test_sob.py


示例4: testStyles

 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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:8,代码来源:test_sob.py


示例5: restore

 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)
开发者ID:Darkpaw95,项目名称:pymon,代码行数:8,代码来源:application.py


示例6: testStyles

 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)
开发者ID:ssilverek,项目名称:kodb,代码行数:8,代码来源:test_sob.py


示例7: testEverythingEphemeralGetattr

    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')
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:18,代码来源:test_sob.py


示例8: testEncryptedStyles

 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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:9,代码来源:test_sob.py


示例9: testEncryptedStyles

 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)
开发者ID:ssilverek,项目名称:kodb,代码行数:9,代码来源:test_sob.py


示例10: testEverythingEphemeralSetattr

    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)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:18,代码来源:test_sob.py


示例11: testStylesBeingSet

 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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:10,代码来源:test_sob.py


示例12: testStyles

 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)
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:10,代码来源:test_sob.py


示例13: testStylesBeingSet

 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)
开发者ID:ssilverek,项目名称:kodb,代码行数:10,代码来源:test_sob.py


示例14: test_encryptedStyles

 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])
开发者ID:Architektor,项目名称:PySnip,代码行数:13,代码来源:test_sob.py


示例15: testEncryptedStyles

 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)
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:15,代码来源:test_sob.py


示例16: loadApplication

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
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:17,代码来源:service.py


示例17: testEverythingEphemeralGetattr

    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
开发者ID:ssilverek,项目名称:kodb,代码行数:41,代码来源:test_sob.py


示例18: loadApplication

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
开发者ID:vmarkovtsev,项目名称:twisted,代码行数:23,代码来源:service.py


示例19: test_loadEncryptedDeprecation

    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'])
开发者ID:Architektor,项目名称:PySnip,代码行数:24,代码来源:test_sob.py



注:本文中的twisted.persisted.sob.load函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python styles.doUpgrade函数代码示例发布时间:2022-05-27
下一篇:
Python aot.jellyToSource函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap