luckylucy.utils.encoding 1.85rc1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# /// script
|
|
3
|
+
# requires-python = ">=2.7"
|
|
4
|
+
# dependencies = []
|
|
5
|
+
#
|
|
6
|
+
# [tool.luckylucy]
|
|
7
|
+
# module = true
|
|
8
|
+
# ///
|
|
9
|
+
from __future__ import unicode_literals
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
__author__ = 'luckydonald'
|
|
13
|
+
|
|
14
|
+
if sys.version < '3': # python 2.7
|
|
15
|
+
# noinspection PyUnresolvedReferences
|
|
16
|
+
text_type = unicode
|
|
17
|
+
binary_type = str
|
|
18
|
+
native_type = binary_type
|
|
19
|
+
unicode_type = text_type # because I can't remember to use text_type
|
|
20
|
+
# noinspection PyUnresolvedReferences
|
|
21
|
+
long_int = long
|
|
22
|
+
|
|
23
|
+
def to_native(x):
|
|
24
|
+
return to_binary(x)
|
|
25
|
+
# end def
|
|
26
|
+
else: # python 3
|
|
27
|
+
text_type = str
|
|
28
|
+
binary_type = bytes
|
|
29
|
+
native_type = text_type
|
|
30
|
+
unicode_type = text_type
|
|
31
|
+
long_int = int
|
|
32
|
+
|
|
33
|
+
def to_native(x):
|
|
34
|
+
return to_unicode(x)
|
|
35
|
+
# end def
|
|
36
|
+
# end if
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def to_binary(x):
|
|
40
|
+
if isinstance(x, text_type):
|
|
41
|
+
return x.encode("utf-8")
|
|
42
|
+
elif isinstance(x, binary_type):
|
|
43
|
+
return x
|
|
44
|
+
else:
|
|
45
|
+
return to_binary(str(x)) # str() can fail. # do i need bytes() here with py3 (because ascii and stuff?) ?
|
|
46
|
+
# end if
|
|
47
|
+
# end def
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def to_unicode(x):
|
|
51
|
+
if isinstance(x, binary_type):
|
|
52
|
+
return x.decode("utf-8")
|
|
53
|
+
elif isinstance(x, text_type):
|
|
54
|
+
return x
|
|
55
|
+
else:
|
|
56
|
+
return to_unicode(str(x)) # str() can fail.
|
|
57
|
+
# end if
|
|
58
|
+
# end def
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: luckylucy.utils.encoding
|
|
3
|
+
Version: 1.85.pre1
|
|
4
|
+
Summary: A collection of utilities I use across different projects (luckylucy.utils.encoding)
|
|
5
|
+
Project-URL: Homepage, https://github.com/luckydonald/luckylucy.utils
|
|
6
|
+
Author-email: luckylucy <luckylucy.utils._.code@luckydonald.de>
|
|
7
|
+
License-Expression: GPL-2.0-or-later
|
|
8
|
+
Requires-Python: >=2.7
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
luckylucy/utils/encoding.py,sha256=SJEVBC5nKucbecFyNeIYVbu535i7hUjlV-NXWAfw_18,1292
|
|
2
|
+
luckylucy_utils_encoding-1.85rc1.dist-info/METADATA,sha256=hYd0uQqS8morrBj2BMVfxF3GIC9h7QA5EqHWyrZ_hrs,360
|
|
3
|
+
luckylucy_utils_encoding-1.85rc1.dist-info/WHEEL,sha256=DnXx7cBEyVTTMvhePCuz2Now68IkDfyaQ4wNff8GnEk,105
|
|
4
|
+
luckylucy_utils_encoding-1.85rc1.dist-info/RECORD,,
|