Пример #1
0
def fast_encode():
    # Only use in cases where you *know* the data contains only basic
    # Python objects
    pickler = Pickler(1)
    pickler.fast = 1
    dump = pickler.dump

    def fast_encode(*args):
        return dump(args, 1)

    return fast_encode
Пример #2
0
def encode(*args):  # args: (msgid, flags, name, args)
    # (We used to have a global pickler, but that's not thread-safe. :-( )

    # It's not thread safe if, in the couse of pickling, we call the
    # Python interpeter, which releases the GIL.

    # Note that args may contain very large binary pickles already; for
    # this reason, it's important to use proto 1 (or higher) pickles here
    # too.  For a long time, this used proto 0 pickles, and that can
    # bloat our pickle to 4x the size (due to high-bit and control bytes
    # being represented by \xij escapes in proto 0).
    # Undocumented:  cPickle.Pickler accepts a lone protocol argument;
    # pickle.py does not.
    pickler = Pickler(1)
    pickler.fast = 1
    return pickler.dump(args, 1)