never forget to do svn commit from the root directory of the project ;>

This commit is contained in:
phear 2005-09-06 19:05:10 +00:00
parent f1082743de
commit 81fea29c24
3 changed files with 37 additions and 18 deletions

View file

@ -92,21 +92,7 @@ def display_goban(goban):
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)
def process_form(goban):
@ -123,7 +109,7 @@ def process_form(goban):
if form.keys() != []:
#cut out the name of the clicked button
namestring = string.split(form.keys()[0],".x")[0]
position = string_to_tuple(namestring)
position = helper.string_to_tuple(namestring)
ret = set_stone(goban, position)
if (type(ret) == type("")):
return (goban,ret) #return old goban and error string

View file

@ -35,4 +35,20 @@ def check_for_int(data):
ret = int(data)
else:
ret = data
return ret
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)

19
psql.py
View file

@ -68,6 +68,23 @@ def create_goban_table(size):
gets:size of goban.
creates postgresql table containing goban data.
returns: name of created table.
the table looks like this:
line x1 x2 x3 x4 ... x(size)
y1
y2
y3
...
y(size)
turn_number
size
name
and the meaning of these fields:
(xn,yn) is a field of the goban,
(turn_number,x1) is the current turn,
(size,x1) is the length of a side of the goban,
(name,x1) is the name of this goban.
"""
tablename="test"
data="line varchar(15)"
@ -188,7 +205,7 @@ def set_user_timeout(username):
gets username, sets timeout to time.time + 30min
"""
import time
timeout = int(time.time()) + 1800 #current time in seconds + seconds for session
timeout = int(time.time()) + 900 #current time in seconds + seconds for session
executestring ="UPDATE users SET timeout = '%s' WHERE username = '%s'" %(timeout, username)
sql_one_liner(executestring)