2010-08-08 13:27:19 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-08-18 15:40:19 +00:00
|
|
|
#
|
|
|
|
# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
|
|
|
|
# See LICENSE.txt for copyright info
|
2010-08-08 13:27:19 +00:00
|
|
|
|
2011-01-30 01:29:31 +00:00
|
|
|
import re
|
2010-08-18 15:40:19 +00:00
|
|
|
from random import choice
|
2010-08-08 13:27:19 +00:00
|
|
|
|
|
|
|
|
2010-08-18 15:40:19 +00:00
|
|
|
def responseToChallange(kp):
|
2010-08-08 13:27:19 +00:00
|
|
|
if len(kp) != 6:
|
|
|
|
return 'ERROR'
|
|
|
|
aa, bb, cc = int(kp[:2]), int(kp[2:4]), int(kp[4:6])
|
|
|
|
defgh = "%05d" % ((cc+7)*(cc+4)+(bb+1)*(aa+2), )
|
|
|
|
return defgh[3]+defgh[0]+defgh[2]+defgh[4]+defgh[1]
|
|
|
|
|
|
|
|
|
2010-08-18 15:40:19 +00:00
|
|
|
def makeRandomChallange():
|
|
|
|
return ''.join([choice('0123456789') for i in range(6)])
|
|
|
|
|
|
|
|
|
2011-01-30 19:53:34 +00:00
|
|
|
re_tag = re.compile(r"<([A-Z]{1,2})>(.*)</\1>")
|
2010-08-08 13:27:19 +00:00
|
|
|
|
|
|
|
def parseSimpleXML(xml):
|
2011-01-30 01:29:31 +00:00
|
|
|
return dict(re_tag.findall(xml))
|
2010-08-08 13:27:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def formatSimpleXML(elements):
|
|
|
|
if hasattr(elements, 'items'):
|
|
|
|
items = elements.items()
|
|
|
|
else:
|
|
|
|
items = elements
|
2011-04-09 16:30:21 +00:00
|
|
|
return ''.join(["<%s>%s</%s>" % (k.upper().encode('utf8'),v.encode('utf8'),k.upper().encode('utf8')) for k,v in items])
|
2010-08-08 13:27:19 +00:00
|
|
|
|
|
|
|
# vim: set et ai sw=4 ts=4 sts=4:
|