File: utils.py

package info (click to toggle)
czmq 4.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,912 kB
  • sloc: ansic: 30,811; cpp: 19,362; sh: 11,873; python: 11,814; pascal: 11,229; ruby: 8,818; java: 4,363; makefile: 299; perl: 151; javascript: 35
file content (50 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
################################################################################
#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
#  Read the zproject/README.md for information about making permanent changes. #
################################################################################
try:
    from . import native
    lib = native.lib
    ffi = native.ffi
except ImportError:
    from . import dlopen
    lib = dlopen.lib
    ffi = dlopen.ffi

def rebind (_lib, _ffi):
    """Rebind Lib and CompiledFFi objects for given package. Lib object MUST expose all functions
       required by the classes. This is default for zproject based projects"""
    global lib
    global ffi
    lib = _lib
    ffi = _ffi

try:
    text_type = unicode  # Python 2
    binary_type = str
except NameError:
    text_type = str      # Python 3
    binary_type = bytes


def to_bytes(s):
    return s if isinstance(s, binary_type) else text_type(s).encode("utf-8")


def to_unicode(s):
    return s if isinstance(s, text_type) else binary_type(s).decode("utf-8")


def to_strings (s):
    """Convert Python native list types to zlist_t of strings"""
    if issubclass (s.__class__, (list, set, frozenset, tuple)):
        foo = lib.zlist_new ()
        lib.zlist_autofree (foo)
        for item in s:
            lib.zlist_append (foo, to_bytes (item))
        return foo
    return None
################################################################################
#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
#  Read the zproject/README.md for information about making permanent changes. #
################################################################################