You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

54 lines
1.3 KiB

# -*- coding: utf-8 -*-
#
# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
# See LICENSE.txt for copyright info
from HTMLParser import HTMLParser
from random import choice
def responseToChallange(kp):
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]
def makeRandomChallange():
return ''.join([choice('0123456789') for i in range(6)])
class SimpleXMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if not hasattr(self, 'fields'):
self.fields = {}
self.next_field = tag
self.next_data = ''
def handle_data(self, data):
self.next_data += data
def handle_endtag(self, tag):
self.fields[self.next_field] = self.next_data
self.next_field = self.next_data = None
def get_fields(self):
return self.fields
def parseSimpleXML(xml):
p = SimpleXMLParser()
p.feed(xml)
return p.get_fields()
def formatSimpleXML(elements):
if hasattr(elements, 'items'):
items = elements.items()
else:
items = elements
return ''.join(["<%s>%s</%s>" % (k.upper(),v,k.upper()) for k,v in items])
# vim: set et ai sw=4 ts=4 sts=4: