python类Unpickler()的实例源码

cache.py 文件源码 项目:isar 作者: ilbers 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def save_merge(self):
        if not self.cachefile:
            return

        glf = bb.utils.lockfile(self.cachefile + ".lock")

        data = self.cachedata

        for f in [y for y in os.listdir(os.path.dirname(self.cachefile)) if y.startswith(os.path.basename(self.cachefile) + '-')]:
            f = os.path.join(os.path.dirname(self.cachefile), f)
            try:
                with open(f, "rb") as fd:
                    p = pickle.Unpickler(fd)
                    extradata, version = p.load()
            except (IOError, EOFError):
                os.unlink(f)
                continue

            if version != self.__class__.CACHE_VERSION:
                os.unlink(f)
                continue

            self.merge_data(extradata, data)
            os.unlink(f)

        with open(self.cachefile, "wb") as f:
            p = pickle.Pickler(f, -1)
            p.dump([data, self.__class__.CACHE_VERSION])

        bb.utils.unlockfile(glf)
loading.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, f, objmap, shortcuts=None):
        pickle.Unpickler.__init__(self, f)

        if shortcuts:
            objmap = dict((k % shortcuts, v % shortcuts)
                          for k, v in objmap.items())
        self._objmap = objmap
pickletester.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_bad_init(self):
        # Test issue3664 (pickle can segfault from a badly initialized Pickler).
        # Override initialization without calling __init__() of the superclass.
        class BadPickler(pickle.Pickler):
            def __init__(self): pass

        class BadUnpickler(pickle.Unpickler):
            def __init__(self): pass

        self.assertRaises(pickle.PicklingError, BadPickler().dump, 0)
        self.assertRaises(pickle.UnpicklingError, BadUnpickler().load)
pickletester.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_priming_unpickler_memo(self):
        # Verify that we can set the Unpickler's memo attribute.
        data = ["abcdefg", "abcdefg", 44]
        f = io.BytesIO()
        pickler = self.pickler_class(f)

        pickler.dump(data)
        first_pickled = f.getvalue()

        f = io.BytesIO()
        primed = self.pickler_class(f)
        primed.memo = pickler.memo

        primed.dump(data)
        primed_pickled = f.getvalue()

        unpickler = self.unpickler_class(io.BytesIO(first_pickled))
        unpickled_data1 = unpickler.load()

        self.assertEqual(unpickled_data1, data)

        primed = self.unpickler_class(io.BytesIO(primed_pickled))
        primed.memo = unpickler.memo
        unpickled_data2 = primed.load()

        primed.memo.clear()

        self.assertEqual(unpickled_data2, data)
        self.assertTrue(unpickled_data2 is unpickled_data1)
shelve.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = BytesIO(self.dict[key.encode(self.keyencoding)])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value
shelve.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load())
shelve.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def previous(self):
        (key, value) = self.dict.previous()
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load())
shelve.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def first(self):
        (key, value) = self.dict.first()
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load())
shelve.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def last(self):
        (key, value) = self.dict.last()
        f = BytesIO(value)
        return (key.decode(self.keyencoding), Unpickler(f).load())
run_job.py 文件源码 项目:py-cloud-compute-cannon 作者: Autodesk 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def find_class(self, module, name):
        """ This override is here to help pickle find the modules that classes are defined in.

        It does three things:
         1) remaps the "PackagedFunction" class from pyccc to the `source.py` module.
         2) Remaps any classes created in the client's '__main__' to the `source.py` module
         3) Creates on-the-fly modules to store any other classes present in source.py

        References:
                This is a modified version of the 2-only recipe from
                https://wiki.python.org/moin/UsingPickle/RenamingModules.
                It's been modified for 2/3 cross-compatibility    """
        import pickle

        modname = self.RENAMETABLE.get(module, module)

        try:
            # can't use ``super`` here (not 2/3 compatible)
            klass = pickle.Unpickler.find_class(self, modname, name)

        except (ImportError, RuntimeError):
            definition = getattr(source, name)
            newmod = _makemod(modname)
            sys.modules[modname] = newmod
            setattr(newmod, name, definition)
            klass = pickle.Unpickler.find_class(self, newmod.__name__, name)
            klass.__module__ = module
        return klass
pickle.py 文件源码 项目:serialize 作者: hgrecco 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def load(fp):
    return pickle.Unpickler(fp).load()
moderation.py 文件源码 项目:FalltoSkyBot 作者: Sakiut 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def start():
    if os.path.exists(fileName):
        f = open(fileName, "rb")
        d = pickle.Unpickler(f)
        data = d.load()
        f.close()
    else:
        data = {}

    return data

#####################################################################################################################################################
casino.py 文件源码 项目:FalltoSkyBot 作者: Sakiut 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def start():
    if os.path.exists(fileName):
        f = open(fileName, "rb")
        d = pickle.Unpickler(f)
        data = d.load()
        f.close()
    else:
        data = {}

    return data

########################################################################################################################
rs_utils.py 文件源码 项目:Red_Star 作者: medeor413 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, filename, flag='c', protocol=None, keyencoding='utf-8'):
        self.db = filename
        self.flag = flag
        self.dict = {}
        with dbm.open(self.db, self.flag) as db:
            for k in db.keys():
                v = BytesIO(db[k])
                self.dict[k] = Unpickler(v).load()
        shelve.Shelf.__init__(self, self.dict, protocol, False, keyencoding)
filterservice.py 文件源码 项目:asbhp 作者: arbuz-team 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self):

        # ustawienia przegl?darki
        binary = FirefoxBinary('/home/endo93/Firefox 46.0/firefox')
        self.firefox = webdriver.Firefox(firefox_binary=binary)
        os.system('rm sql/filterservice.log')

        self.Wczytaj_Adresy_URL()
        self.Zapisz_Adresy_URL()

        # pickler - zapis/odczyt produktów z pliku
        pickler = None
        plik = None

        if os.path.exists('sql/filterservice.prod'):
            Kierownik.odczyt_produktow = True
            plik = open('sql/filterservice.prod', 'rb')
            pickler = pickle.Unpickler(plik)

        else: # do zapisywania
            plik = open('sql/filterservice.prod', 'wb')
            pickler = pickle.Pickler(plik, pickle.HIGHEST_PROTOCOL)

            # dla ka?dego adresu url
        for url in self.adresy_url:
            self.Dodaj_Produkt_Do_Bazy_Danych(url, 'Inne', 'Inne',
                                              'Inne', pickler)

        plik.close()
        self.firefox.close()
adler.py 文件源码 项目:asbhp 作者: arbuz-team 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self):

        # ustawienia przegl?darki
        binary = FirefoxBinary('/home/endo93/Firefox 46.0/firefox')
        self.firefox = webdriver.Firefox(firefox_binary=binary)
        os.system('rm sql/adler.log')

        self.Wczytaj_Adresy_URL()
        self.Zapisz_Adresy_URL()

        # pickler - zapis/odczyt produktów z pliku
        pickler = None
        plik = None

        if os.path.exists('sql/adler.prod'):
            Kierownik.odczyt_produktow = True
            plik = open('sql/adler.prod', 'rb')
            pickler = pickle.Unpickler(plik)

        else: # do zapisywania
            plik = open('sql/adler.prod', 'wb')
            pickler = pickle.Pickler(plik, pickle.HIGHEST_PROTOCOL)

            # dla ka?dego adresu url
        for typ in self.adresy_url:
            for dziedzina in self.adresy_url[typ]:
                for rodzaj in self.adresy_url[typ][dziedzina]:
                    for url in self.adresy_url[typ][dziedzina][rodzaj]:
                        self.Dodaj_Produkt_Do_Bazy_Danych(url, typ, dziedzina,
                                                          rodzaj, pickler)

        plik.close()
        self.firefox.close()
polstar.py 文件源码 项目:asbhp 作者: arbuz-team 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self):

            # ustawienia przegl?darki
        binary = FirefoxBinary('/home/endo93/Firefox 46.0/firefox')
        self.firefox = webdriver.Firefox(firefox_binary=binary)
        os.system('rm sql/polstar.log')

        self.Wczytaj_Adresy_URL()
        self.Zapisz_Adresy_URL()

            # pickler - zapis/odczyt produktów z pliku
        pickler = None
        plik = None

        if os.path.exists('sql/polstar.prod'):
            Kierownik.odczyt_produktow = True
            plik = open('sql/polstar.prod', 'rb')
            pickler = pickle.Unpickler(plik)

        else: # do zapisywania
            plik = open('sql/polstar.prod', 'wb')
            pickler = pickle.Pickler(plik, pickle.HIGHEST_PROTOCOL)

            # dla ka?dego adresu url
        for typ in self.adresy_url:
            for dziedzina in self.adresy_url[typ]:
                for url in self.adresy_url[typ][dziedzina]:
                    self.Dodaj_Produkt_Do_Bazy_Danych(url, typ, dziedzina,
                                                      'Inne', pickler)

        plik.close()
        self.firefox.close()
loading.py 文件源码 项目:WhooshSearch 作者: rokartnaz 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, f, objmap, shortcuts=None):
        pickle.Unpickler.__init__(self, f)

        if shortcuts:
            objmap = dict((k % shortcuts, v % shortcuts)
                          for k, v in objmap.items())
        self._objmap = objmap
test_pickle.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def loads(self, buf):
        f = StringIO(buf)
        u = pickle.Unpickler(f)
        return u.load()
test_pickle.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def loads(self, buf):
        f = StringIO(buf)
        u = pickle.Unpickler(f)
        return u.load()


问题


面经


文章

微信
公众号

扫码关注公众号