This repository has been archived by the owner on Sep 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtools.py
64 lines (52 loc) · 1.41 KB
/
tools.py
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
62
63
64
# * - coding: utf-8 - *
import sys
def _raw_s(str1):
#decode from utf=8 to unicode
if(isinstance(str1, unicode)):
return str1
if(not isinstance(str1, str)):
str1 = repr(str1)
return str1.decode("utf-8")
# else:
# raise TypeError, u"str1 has Type %s, which doesn't match str or unicode" % type(str1)
def s(*arg):
if(len(arg) == 1):
return _raw_s(arg[0])
return tuple([_raw_s(x) for x in arg])
def us(arg):
if(len(arg) == 1):
return _raw_s(arg[0]).encode("utf-8")
return tuple([_raw_s(x).encode("utf-8") for x in arg])
def getIOLength(readIO):
try:
if readIO.len == None:
raise AttributeError
else:
totalSize = long(readIO.len)
return totalSize
except AttributeError:
pass
try:
if readIO.getheader("Content-Length") == None:
raise AttributeError
else:
totalSize = int(readIO.getheader("Content-Length"))
return totalSize
except AttributeError:
pass
try:
if readIO.length == None:
raise AttributeError
else:
totalSize = readIO.length
return totalSize
except AttributeError:
pass
#raise IOError, "Can't read Length"
return 10485760
def print_(sth):
print sth
def noneThen(sth, sth2):
if sth is not None:
return sth
return sth2