2 # vim:fileencoding=utf-8
9 from google
.appengine
.api
import memcache
11 timeParser
= re
.compile(r
'^(\d+)([smhd])?$')
12 linkre
= re
.compile(r
' <https?://(?!i.imgur.com/)[^>]+>')
13 linkjsre
= re
.compile(r
' <javascript:[^>]+>')
23 '''将 数字 转化为 xxKiB 的形式'''
27 while left
> 1100 and unit
< 3:
35 return '%.1f%siB' % (left
, units
[unit
])
37 def strftime(time
, timezone
, show_date
=False):
38 '''将时间转换为字符串,考虑时区,可能带日期'''
42 format
= '%m-%d %H:%M:%S'
43 return (time
+ timezone
).strftime(format
)
46 '''将 3s,5d,1h,6m 等转换成秒数'''
47 m
= timeParser
.match(s
)
49 raise ValueError('not a time')
55 return n
* timeUnitMap
[u
]
59 if len(nick
.encode('utf-8')) > config
.nick_maxlen
:
62 if not unicodedata
.category(i
).startswith('L') and i
not in config
.allowedSymbolInNick
:
68 links
= linkre
.findall(msg
)
70 msg
= linkre
.sub('', msg
)
71 msg
= linkjsre
.sub('', msg
)
75 def __init__(self
, name
):
79 while memcache
.get(self
.name
):
81 memcache
.set(self
.name
, True)
84 memcache
.set(self
.name
, False)