2005-09-11 19:11:09 +02:00
|
|
|
import string
|
|
|
|
|
2005-09-06 19:52:46 +02:00
|
|
|
def header():
|
|
|
|
"""return html header"""
|
|
|
|
data = """
|
|
|
|
<html><HEAD>
|
|
|
|
|
|
|
|
</HEAD><body>
|
|
|
|
"""
|
|
|
|
return data
|
|
|
|
|
|
|
|
def footer():
|
|
|
|
"""return html footer"""
|
|
|
|
data = """
|
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
return data
|
|
|
|
|
|
|
|
# create a unique session id
|
|
|
|
def generate_session_id():
|
|
|
|
import md5, time, base64, random, string
|
|
|
|
m = md5.new()
|
|
|
|
m.update(str(time.time()))
|
|
|
|
m.update(str(random.random()))
|
2005-09-12 15:51:18 +02:00
|
|
|
s = string.replace(base64.encodestring(m.digest())[:-3], '/', '$')
|
|
|
|
return s
|
2005-09-06 19:52:46 +02:00
|
|
|
|
2005-09-12 15:51:18 +02:00
|
|
|
def generate_game_name():
|
|
|
|
from whrandom import choice
|
|
|
|
chars = string.letters
|
|
|
|
name = ''
|
|
|
|
for i in range(16):
|
|
|
|
name = name + choice(chars)
|
|
|
|
return name.lower()
|
|
|
|
|
2005-09-06 19:52:46 +02:00
|
|
|
|
|
|
|
def check_for_int(data):
|
|
|
|
"""
|
|
|
|
gets a string. if string is an integer: return integer.
|
|
|
|
else return given string.
|
|
|
|
"""
|
|
|
|
#check if value is int
|
|
|
|
num = [n for n in data if n.isdigit()]
|
|
|
|
tmp = "".join(num)
|
|
|
|
if tmp == data:
|
|
|
|
ret = int(data)
|
|
|
|
else:
|
|
|
|
ret = data
|
2005-09-06 21:05:10 +02:00
|
|
|
return ret
|
|
|
|
|
|
|
|
def string_to_tuple(str):
|
|
|
|
"""
|
|
|
|
gets a string. If the string contains '(',')' and ',', then return
|
|
|
|
a tuple processed from the string. If the partial string is empty, then
|
|
|
|
-1 will be returned for that value.
|
|
|
|
"""
|
|
|
|
if (str[0] =='(') and (str[-1] ==')') and (string.find(str,',')):
|
|
|
|
splitlist = string.split(str[1:-1],",")
|
|
|
|
returnlist = []
|
|
|
|
for item in splitlist:
|
|
|
|
try:
|
|
|
|
returnlist.append(int(item))
|
|
|
|
except: #empty string
|
|
|
|
returnlist.append(-1)
|
|
|
|
return tuple(returnlist)
|