def convert_variable_table(): """this unserializes (a php thing) the variable table so that python can understand it""" variable = inc.util.Variable('variable', key_field='name', value_field='value') variable.load() #web.transact() u = PHPUnserialize() for v in variable.iteritems(): try: unserialized = u.unserialize(v[1]) variable[v[0]] = unserialized print 'converted',v[0] except: print v[0],'skipped',v[1]
class SodaIdleSodaStatsPanel(BarGraphPanel): sodaStatsPath = "/var/soda/stockcount.psr" unserializer = PHPUnserialize.PHPUnserialize() def __init__(self, parent, ID, pos, size): file = open(self.sodaStatsPath, "r") fcntl.flock(file, fcntl.LOCK_SH) stats = self.unserializer.unserialize(file.read()) fcntl.flock(file, fcntl.LOCK_UN) file.close() stats_keys = filter(lambda x: x != "r10", stats.keys()) stats_list = [(stats[key]["sold"], stats[key]["name"]) for key in stats_keys] stats_list.sort(cmp=lambda x, y: cmp(y, x)) min = stats_list[-1][0] max = stats_list[0][0] BarGraphPanel.__init__(self, parent, ID, pos, size, stats_list, min, max)
#!/usr/bin/python import sys, pprint from PHPUnserialize import * # Unserialize serialized data from STDIN pp = pprint.PrettyPrinter() try: data = sys.stdin.readline() session = PHPUnserialize().session_decode(data) pp.pprint(session) except Exception, e: print e
def __init__(self): self.writer = PHPSerialize.PHPSerialize() self.reader = PHPUnserialize.PHPUnserialize()
#!/usr/bin/python import sys, pprint from PHPUnserialize import * # Unserialize serialized data from STDIN pp = pprint.PrettyPrinter() try: data = sys.stdin.readline() #print data out = PHPUnserialize().unserialize(data) pp.pprint(out) except Exception, e: print e
#Take 1 off the ship count defender_total -= 1 defenders[defid][deftype]['count'] -= 1 fleet_totals[defid] -= 1 if defenders[defid][deftype]['count'] == 0: del defenders[defid][deftype] if fleet_totals[defid] == 0: del defenders[defid] #defenders[defid] = {} #how about rapidfire? stopfiring = True #we are ignoring it #print "-" defenders_before = PHPUnserialize().unserialize(backup) #Next defender fires, so, for each defender. for fleetid,info in defenders_before.iteritems(): #For each of this defenders ships for type,info in defenders_before[fleetid].iteritems(): #For each of this type of ship for n in range (0,info['count']): stopfireing = False while stopfireing == False: #Unless rapidfire, this is the last shot stopfireing = True
import copy from lib.drupy.DrupyPHP import * # # List of tables # tables = ({ 'select': "SELECT system.info, system.name FROM system WHERE system.type = 'theme'", 'update': "UPDATE system SET system.info = '%(info)s' WHERE system.name = '%(name)s'", 'key': 'info' }, ) inc_bootstrap.drupal_bootstrap(inc_bootstrap.DRUPAL_BOOTSTRAP_DATABASE) u = PHPUnserialize.PHPUnserialize() i = 0 for t in tables: s_res = inc_database.db_query(t['select']) while True: s_row = inc_database.db_fetch_assoc(s_res) if not s_row: break try: udata = u.unserialize(s_row[t['key']]) except PHPUnserialize.InvalidObject: continue out = copy.deepcopy(s_row) for ok, ov in out.items(): if ok == t['key']: