本文整理汇总了Python中utils.to_bytes函数的典型用法代码示例。如果您正苦于以下问题:Python to_bytes函数的具体用法?Python to_bytes怎么用?Python to_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_bytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:evoskuil,项目名称:czmq,代码行数:9,代码来源:Zsys.py
示例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)
开发者ID:evoskuil,项目名称:czmq,代码行数:12,代码来源:ZdirPatch.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)
开发者ID:evoskuil,项目名称:czmq,代码行数:14,代码来源:Zdir.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
开发者ID:capybala,项目名称:find-ebook-edition-backend,代码行数:7,代码来源:kindle_version_cache.py
示例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)
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Ztrie.py
示例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))
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Ztrie.py
示例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))
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zframe.py
示例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)
开发者ID:evoskuil,项目名称:czmq,代码行数:16,代码来源:Zfile.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), )
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zsys.py
示例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))
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zsys.py
示例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)
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zsock.py
示例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), )
开发者ID:evoskuil,项目名称:czmq,代码行数:30,代码来源:Zsock.py
示例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)
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zhash.py
示例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), )
开发者ID:evoskuil,项目名称:czmq,代码行数:30,代码来源:Zsock.py
示例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)
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zhash.py
示例16: load
def load(self, filename):
"""
Load hash table from a text file in name=value format; hash table must
already exist. Hash values must printable strings; keys may not contain
'=' character. Returns 0 if OK, else -1 if a file was not readable.
"""
return utils.lib.zhash_load(self._p, utils.to_bytes(filename))
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zhash.py
示例17: save
def save(self, filename):
"""
Save hash table to a text file in name=value format. Hash values must be
printable strings; keys may not contain '=' character. Returns 0 if OK,
else -1 if a file error occurred.
"""
return utils.lib.zhash_save(self._p, utils.to_bytes(filename))
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zhash.py
示例18: param_lookupx
def param_lookupx(self, keys, ):
"""
Return value of named parameter(s), NULL if no given parameter has
been specified, or special value for wich zargs_param_empty ()
returns true.
"""
return utils.lib.zargs_param_lookupx(self._p, utils.to_bytes(keys), )
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zargs.py
示例19: close
def close(handle, filename, line_nbr):
"""
Destroy/close a ZMQ socket. You should call this for every socket you
create using zsys_socket().
*** This is for CZMQ internal use only and may change arbitrarily ***
"""
return utils.lib.zsys_close(handle._p, utils.to_bytes(filename), line_nbr)
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zsys.py
示例20: file_mode
def file_mode(filename):
"""
Return file mode; provides at least support for the POSIX S_ISREG(m)
and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes.
Returns a mode_t cast to int, or -1 in case of error.
"""
return utils.lib.zsys_file_mode(utils.to_bytes(filename))
开发者ID:evoskuil,项目名称:czmq,代码行数:7,代码来源:Zsys.py
注:本文中的utils.to_bytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论