File: python_utilities.py

package info (click to toggle)
python-caldav 1.3.9-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 636 kB
  • sloc: python: 6,824; makefile: 91; sh: 7
file content (38 lines) | stat: -rw-r--r-- 798 bytes parent folder | download | duplicates (2)
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
def to_wire(text):
    if text is None:
        return None
    if isinstance(text, str):
        text = bytes(text, "utf-8")
    text = text.replace(b"\n", b"\r\n")
    text = text.replace(b"\r\r\n", b"\r\n")
    return text


def to_local(text):
    if text is None:
        return None
    if not isinstance(text, str):
        text = text.decode("utf-8")
    text = text.replace("\r\n", "\n")
    return text


to_str = to_local


def to_normal_str(text):
    """
    Make sure we return a normal string
    """
    if text is None:
        return text
    if not isinstance(text, str):
        text = text.decode("utf-8")
    text = text.replace("\r\n", "\n")
    return text


def to_unicode(text):
    if text and isinstance(text, bytes):
        return text.decode("utf-8")
    return text