Skip to content

Navigation Menu

Sign in
Sign up

Commit 0081f32

Browse files
更新工具类
1 parent 98aedaa commit 0081f32

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎tools/convert.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def test_unescape():
2525
# unicode编码后的汉字的解析
2626
str_xx = '加入到"我的书目选单"中'
2727
str_xx = '\xe5\xbd\x93\xe5\x89\x8d\xe5\xb7\xb2\xe8\xbe\xbe\xe5\x88\xb0\xe6\x8a\x93\xe5\x8f\x96\xe9\x85\x8d\xe7\xbd\xae\xe7\x9a\x84\xe6\x9c\x80\xe5\xa4\xa7\xe9\xa1\xb5\xe7\xa0\x81'
28+
str_xx = '\xe9\xaa\x8c\xe8\xaf\x81\xe7\xa0\x81\xe8\xbe\x93\xe5\x85\xa5\xe9\x94\x99\xe8\xaf\xaf, \xe8\xaf\xb7\xe9\x87\x8d\xe6\x96\xb0\xe8\xbe\x93\xe5\x85\xa5\xef\xbc\x81'
29+
str_xx = '\xe6\x9c\xaa\xe7\x9f\xa5\xe8\xae\xbf\xe9\x97\xae\xe6\x9d\xa5\xe6\xba\x90'
2830
from HTMLParser import HTMLParser
2931
h = HTMLParser()
3032
print h.unescape(str_xx)
@@ -76,10 +78,10 @@ def test():
7678

7779
if __name__ == "__main__":
7880
test()
79-
print system_to_decimal('000000001b2025f6', 16)
80-
print system_to_decimal('0001000100010001', 2)
81-
test_unescape()
82-
test_unicode()
81+
# print system_to_decimal('000000001b2025f6', 16)
82+
# print system_to_decimal('0001000100010001', 2)
83+
# test_unescape()
84+
# test_unicode()
8385

8486

8587
"""

‎tools/date.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,16 @@ def test():
203203
time模块的官方文档
204204
https://docs.python.org/2/library/time.html
205205
206+
207+
模拟 http response header Date 时间格式:
208+
209+
格林威治时间
210+
In [4]: time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
211+
Out[4]: '2017年12月11日 12:04:25 GMT'
212+
213+
本地时区时间
214+
In [5]: time.strftime("%a, %d %b %Y %H:%M:%S %Z")
215+
Out[5]: '2017年12月11日 20:04:45 CST'
216+
217+
206218
"""

‎tools/redis_pub_sub.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,28 @@ def sub_not_loop(self, k):
7979

8080

8181
def test_pub():
82-
q = RedisPubSub('test:aa')
83-
q.pub('hh', '123')
82+
q = RedisPubSub('test:aa', password='123456')
83+
q.pub('hh', '123') # 字符串
84+
q.pub('hh', {'a': False}) # 字典
85+
q.pub('hh', json.dumps({'a': False})) # JSON
8486

8587

8688
def test_sub():
87-
q = RedisPubSub('test:aa')
89+
q = RedisPubSub('test:aa', password='123456')
8890
r = q.sub('hh')
8991
for i in r:
9092
print i
9193

9294

9395
def test_p_sub():
94-
q = RedisPubSub('test:*')
96+
q = RedisPubSub('test:*', password='123456')
9597
r = q.p_sub('hh')
9698
for i in r:
9799
print i
98100

99101

100102
def test_sub_not_loop():
101-
q = RedisPubSub('test')
103+
q = RedisPubSub('test:aa', password='123456')
102104
r = q.sub_not_loop('hh')
103105
print r
104106

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /