File: backward2.py

package info (click to toggle)
python-stomp 4.1.19-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 528 kB
  • sloc: python: 3,507; makefile: 219
file content (61 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download
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
51
52
53
54
55
56
57
58
59
60
61
"""
Python2-specific versions of various functions used by stomp.py
"""

NULL = '\x00'


def input_prompt(prompt):
    """
    Get user input

    :rtype: str
    """
    return raw_input(prompt)


def decode(byte_data):
    """
    Decode the byte data to a string - in the case of this Py2 version, we can't really do anything (Py3 differs).

    :param bytes byte_data:

    :rtype: str
    """
    return byte_data  # no way to know if it's unicode or not, so just pass through unmolested


def encode(char_data):
    """
    Encode the parameter as a byte string.

    :param char_data:

    :rtype: bytes
    """
    if type(char_data) is unicode:
        return char_data.encode('utf-8')
    else:
        return char_data


def pack(pieces=()):
    """
    Join a sequence of strings together (note: py3 version differs)

    :param list pieces:

    :rtype: bytes
    """
    return ''.join(encode(p) for p in pieces)


def join(chars=()):
    """
    Join a sequence of characters into a string.

    :param bytes chars:

    :rtype str:
    """
    return ''.join(chars)