本文整理汇总了Python中utils.to_bytes函数的典型用法代码示例。如果您正苦于以下问题:Python to_bytes函数的具体用法?Python to_bytes怎么用?Python to_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_as
def run_as(lockfile, group, user):
"""
Drop the process ID into the lockfile, with exclusive lock, and switch
the process to the specified group and/or user. Any of the arguments
may be null, indicating a no-op. Returns 0 on success, -1 on failure.
Note if you combine this with zsys_daemonize, run after, not before
that method, or the lockfile will hold the wrong process ID.
"""
return utils.lib.zsys_run_as(utils.to_bytes(lockfile), utils.to_bytes(group), utils.to_bytes(user))
示例2: __init__
def __init__(self, path, file, op, alias):
"""
Create new patch
"""
p = utils.lib.zdir_patch_new(utils.to_bytes(path), file._p, op, utils.to_bytes(alias))
if p == utils.ffi.NULL:
raise MemoryError("Could not allocate person")
# ffi.gc returns a copy of the cdata object which will have the
# destructor called when the Python object is GC'd:
# https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
self._p = utils.ffi.gc(p, libczmq_destructors.zdir_patch_destroy_py)
示例3: __init__
def __init__(self, path, parent):
"""
Create a new directory item that loads in the full tree of the specified
path, optionally located under some parent path. If parent is "-", then
loads only the top-level directory, and does not use parent as a path.
"""
p = utils.lib.zdir_new(utils.to_bytes(path), utils.to_bytes(parent))
if p == utils.ffi.NULL:
raise MemoryError("Could not allocate person")
# ffi.gc returns a copy of the cdata object which will have the
# destructor called when the Python object is GC'd:
# https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
self._p = utils.ffi.gc(p, libczmq_destructors.zdir_destroy_py)
示例4: __init__
def __init__(self, servers, username=None, password=None, binary=False,
key_prefix='', cache_seconds=DEFAULT_CACHE_SECONDS):
self.cache = pylibmc.Client(servers=servers, binary=binary,
username=username, password=password)
self.key_prefix = to_bytes(key_prefix) # key must be bytes
self.cache_seconds = cache_seconds
示例5: insert_route
def insert_route(self, path, data, destroy_data_fn):
"""
Inserts a new route into the tree and attaches the data. Returns -1
if the route already exists, otherwise 0. This method takes ownership of
the provided data if a destroy_data_fn is provided.
"""
return utils.lib.ztrie_insert_route(self._p, utils.to_bytes(path), data._p, destroy_data_fn)
示例6: remove_route
def remove_route(self, path):
"""
Removes a route from the trie and destroys its data. Returns -1 if the
route does not exists, otherwise 0.
the start of the list call zlist_first (). Advances the cursor.
"""
return utils.lib.ztrie_remove_route(self._p, utils.to_bytes(path))
示例7: meta
def meta(self, property):
"""
Return meta data property for frame
The caller shall not modify or free the returned value, which shall be
owned by the message.
"""
return utils.lib.zframe_meta(self._p, utils.to_bytes(property))
示例8: __init__
def __init__(self, path, name):
"""
If file exists, populates properties. CZMQ supports portable symbolic
links, which are files with the extension ".ln". A symbolic link is a
text file containing one line, the filename of a target file. Reading
data from the symbolic link actually reads from the target file. Path
may be NULL, in which case it is not used.
"""
p = utils.lib.zfile_new(utils.to_bytes(path), utils.to_bytes(name))
if p == utils.ffi.NULL:
raise MemoryError("Could not allocate person")
# ffi.gc returns a copy of the cdata object which will have the
# destructor called when the Python object is GC'd:
# https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
self._p = utils.ffi.gc(p, libczmq_destructors.zfile_destroy_py)
示例9: sprintf
def sprintf(format, ):
"""
Format a string using printf formatting, returning a freshly allocated
buffer. If there was insufficient memory, returns NULL. Free the returned
string using zstr_free().
"""
return utils.lib.zsys_sprintf(utils.to_bytes(format), )
示例10: socket_error
def socket_error(reason):
"""
Handle an I/O error on some socket operation; will report and die on
fatal errors, and continue silently on "try again" errors.
*** This is for CZMQ internal use only and may change arbitrarily ***
"""
utils.lib.zsys_socket_error(utils.to_bytes(reason))
示例11: vsend
def vsend(self, picture, argptr):
"""
Send a 'picture' message to the socket (or actor). This is a va_list
version of zsock_send (), so please consult its documentation for the
details.
"""
return utils.lib.zsock_vsend(self._p, utils.to_bytes(picture), argptr._p)
示例12: recv
def recv(self, picture, ):
"""
Receive a 'picture' message to the socket (or actor). See zsock_send for
the format and meaning of the picture. Returns the picture elements into
a series of pointers as provided by the caller:
i = int * (stores signed integer)
4 = uint32_t * (stores 32-bit unsigned integer)
8 = uint64_t * (stores 64-bit unsigned integer)
s = char ** (allocates new string)
b = byte **, size_t * (2 arguments) (allocates memory)
c = zchunk_t ** (creates zchunk)
f = zframe_t ** (creates zframe)
U = zuuid_t * (creates a zuuid with the data)
h = zhashx_t ** (creates zhashx)
p = void ** (stores pointer)
m = zmsg_t ** (creates a zmsg with the remaing frames)
z = null, asserts empty frame (0 arguments)
u = uint * (stores unsigned integer, deprecated)
Note that zsock_recv creates the returned objects, and the caller must
destroy them when finished with them. The supplied pointers do not need
to be initialized. Returns 0 if successful, or -1 if it failed to recv
a message, in which case the pointers are not modified. When message
frames are truncated (a short message), sets return values to zero/null.
If an argument pointer is NULL, does not store any value (skips it).
An 'n' picture matches an empty frame; if the message does not match,
the method will return -1.
"""
return utils.lib.zsock_recv(self._p, utils.to_bytes(picture), )
示例13: update
def update(self, key, item):
"""
Update item into hash table with specified key and item.
If key is already present, destroys old item and inserts new one.
Use free_fn method to ensure deallocator is properly called on item.
"""
utils.lib.zhash_update(self._p, utils.to_bytes(key), item._p)
示例14: send
def send(self, picture, ):
"""
Send a 'picture' message to the socket (or actor). The picture is a
string that defines the type of each frame. This makes it easy to send
a complex multiframe message in one call. The picture can contain any
of these characters, each corresponding to one or two arguments:
i = int (signed)
1 = uint8_t
2 = uint16_t
4 = uint32_t
8 = uint64_t
s = char *
b = byte *, size_t (2 arguments)
c = zchunk_t *
f = zframe_t *
h = zhashx_t *
U = zuuid_t *
p = void * (sends the pointer value, only meaningful over inproc)
m = zmsg_t * (sends all frames in the zmsg)
z = sends zero-sized frame (0 arguments)
u = uint (deprecated)
Note that s, b, c, and f are encoded the same way and the choice is
offered as a convenience to the sender, which may or may not already
have data in a zchunk or zframe. Does not change or take ownership of
any arguments. Returns 0 if successful, -1 if sending failed for any
reason.
"""
return utils.lib.zsock_send(self._p, utils.to_bytes(picture), )
示例15: insert
def insert(self, key, item):
"""
Insert item into hash table with specified key and item.
If key is already present returns -1 and leaves existing item unchanged
Returns 0 on success.
"""
return utils.lib.zhash_insert(self._p, utils.to_bytes(key), item._p)