def unserialize_(apistr): ''' Unserializes a string :param apistr: The serialized string :return: the unserialized array on success or false on failure ''' apistr = unserialize(apistr) if not apistr: apistr = unserialize(apistr) if not apistr: return False else: return apistr
def get_rest_gallery_img(self, id): query = """SELECT m1.meta_value FROM wp_posts AS p LEFT JOIN wp_postmeta AS m1 ON m1.post_id = p.ID AND m1.meta_key = '_wp_attachment_metadata' WHERE p.post_type ='attachment' AND p.post_mime_type LIKE '%%%%image%%%%' AND p.post_parent = %d""" % int(id) cursor = self.db.cursor() cursor.execute(query) result = self.dictfetchall(cursor) img_l = [] img_m = [] for img in result: condition = (img['meta_value'] is not None and img['meta_value'].strip() is not '') if(condition): try: meta = unserialize(img['meta_value']) path = re.sub(r'.[^\/]*$', '', meta['file']) m = "%s/%s/%s" % ( self.cdn, path, meta['sizes']['M']['file']) l = "%s/%s/%s" % ( self.cdn, path, meta['sizes']['L']['file']) img_l.append(l) img_m.append(m) except ValueError: pass return [img_m, img_l]
def get_rest_featured_img(self, id): query = """SELECT m2.meta_value FROM wp_postmeta AS m1 LEFT JOIN wp_postmeta AS m2 ON m2.post_id = m1.meta_value AND m2.meta_key = '_wp_attachment_metadata' WHERE m1.post_id = %d AND m1.meta_key = '_thumbnail_id' LIMIT 0,1""" % int(id) cursor = self.db.cursor() cursor.execute(query) result = self.dictfetchall(cursor) img = [] try: meta = unserialize(result[0]['meta_value']) path = re.sub(r'.[^\/]*$', '', meta['file']) s = "%s/%s/%s" % (self.cdn, path, meta['sizes']['S']['file']) l = "%s/%s/%s" % (self.cdn, path, meta['sizes']['L']['file']) img.append(s) img.append(l) except: pass return img
def _transform(record): """ Converts the record into a 2 sized list of email id, language and coupon data :param record: :return: """ res = record[:2] # [email, language] cdata = record[2:] # [ 0:code, 1:currency, 2:discount type, 3:amount, 4:percentage, 5:conditions currency = cdata[1] try: coupon_condition = unserialize(cdata[5]) subtotal = _sanitize(coupon_condition['Subtotal']) + " " + str(currency) except: print "Transformation, dropping 1" return [] discount_type = cdata[2] if discount_type == 'fixed': amt = _sanitize(cdata[3]) + " " + str(currency) else: amt = _sanitize(cdata[4]) + "%" res.append({ 'code': cdata[0], 'amount': amt, 'total': subtotal }) return res
def build_sensor_url(sensor_name): host = cfg['farmos']['host'] sensor_sql = """ SELECT settings FROM farm_asset INNER JOIN farm_sensor ON farm_asset.id = farm_sensor.id WHERE farm_asset.type = 'sensor' AND name LIKE '%%%s%%' """ % sensor_name sensor_db_cur = dbcx.cursor() sensor_db_cur.execute(sensor_sql) sensor_res = sensor_db_cur.fetchall() sensor_settings = {} if len(sensor_res) > 1: print("More than one matching sensor found") elif len(sensor_res) == 0: print("No devices matching %s found in database" % sensor_name) print("Query was: %s" % sensor_sql) else: sensor_settings = convert( phpserialize.unserialize(sensor_res[0][0].encode())) url = "%s/farm/sensor/listener/%s?private_key=%s" % ( host, sensor_settings['public_key'], sensor_settings['private_key']) return url
def get_rest_meta(self, id, key): query = """SELECT m.meta_value FROM wp_postmeta AS m WHERE m.post_id = %d AND m.meta_key = '%s'""" % (int(id), key) cursor = self.db.cursor() cursor.execute(query) result = self.dictfetchall(cursor) meta_value = '' try: condition = (result[0]['meta_value'] is not None and result[0]['meta_value'].strip() is not '') if(condition): meta_value = result[0]['meta_value'] try: meta_value = unserialize(meta_value) meta_value = meta_value[0] except ValueError: pass except IndexError: pass return meta_value
def parse_out_wanted_data(self, data): """ Parse out wanted data: company_name and domain company_name = "rdf-schema#label.en", "rdf-schema#label" website = "common.topic.official_website" @return [dict] """ if not data: return False if type(data) is not tuple: return False fb_id = data[0] wants = ('business', 'company', 'companies', 'corporation', 'corporated') if any(needle in data[1].lower() for needle in wants): try: udata = unserialize(data[1]) except: return False good_data = {} if 'rdf-schema#label.en' in udata: good_data['company_name'] = udata['rdf-schema#label.en'] elif 'rdf-schema#label' in udata: good_data[ 'company_name' ] = udata[ 'rdf-schema#label' ] if 'common.topic.official_website' in udata: good_data[ 'website' ] = udata[ 'common.topic.official_website' ][0] if 'website' in good_data: good_data['fb_id'] = fb_id return good_data else: return False
def unPHP( self, raw ): """ Convert softaculous PHP serialization to Python object. """ from phpserialize import unserialize aldente = raw.strip() return unserialize( aldente )
def to_python(self, value): # object case if value is None: return None if isinstance(value, dict): return StatsDict(value) # string case if value and value[0] in '[{': # JSON try: d = json.loads(value) except ValueError: d = None else: # phpserialize data try: if isinstance(value, unicode): value = value.encode('utf8') d = php.unserialize(value, decode_strings=True) except ValueError: d = None if isinstance(d, dict): return StatsDict(d) return None
def get_drupal_sitename(self): """Get the Drupal installation version. """ sitename = "[Unknown sitename]" result = None try: # Returns a tuple of dictionary objects result = self.query( "SELECT value FROM variable WHERE name='site_name';" ) except mdb.ProgrammingError as ex: self._logger.error( "Couldn't get site name. " "Perhaps your variable table is missing." ) # We expect the 'value' dictionary object as the first item if result: variable_row = result[0] variable_info = variable_row['value'] # The variable info in Drupal is stored as a serialized string try: sitename = unserialize(variable_info.encode('utf8')) except Exception as ex: self._logger.error( "Could not unserialize site name. Unknonw encoding?" ) sitename = variable_info raise return sitename
def __init__(self, options) : #set arguments if options.extension != None : self._extension = options.extension.split(',') self._showlinenumbers = options.linenumbers if options.directory != None : self._directory = options.directory if options.dateformat != None : self._dateformat = options.dateformat if options.format != None : self._report_format = options.format self._remotefingerprint = options.remote if (self._remotefingerprint == True) : url = 'https://raw.github.com/emposha/PHP-Shell-Detector/master/shelldetect.db' self._fingerprints = urllib2(url).read() self._fingerprints = base64.b64decode(bytes(self._fingerprints)) else : if(os.path.isfile("shelldetect.db")) : try : self._fingerprints = base64.encodestring(str(open('shelldetect.db', 'r').read())); self._fingerprints = unserialize(str(self._fingerprints)) except IOError as e : print("({})".format(e))
def recursive_unserialize_replace(search, replace, data, serialized = False): try: recursive_unserialize_replace(search, replace, unserialize(data), True) except Exception, e: #HANDLE THE ERROR REPORT HERE if e.message.find('unexpected opcode') >= 0: pass # print 'this is not serialized data' # print data elif e.message.find('failed expectation') >= 0: print 'You have a badly encoded serialized data in' pprint.pprint(data) # THIS IS EITHER A CORRUPT SERIALIZED DATA OR NOT A SERIALIZED DATA # DO THE STANDARD WORK. tmpDict = {} if (type(data) in (dict, list, tuple)): for key, value in dict.iteritems(data): tmpDict[key.replace(search, replace)] = recursive_unserialize_replace(search, replace, value, False) data = tmpDict elif(type(data) == str): data = data.replace(search, replace) if serialized == True: return serialize(data) else: return data
def get_drupal_sitename(self): """Get the Drupal installation version. """ sitename = "[Unknown sitename]" result = None try: # Returns a tuple of dictionary objects result = self.query( "SELECT value FROM variable WHERE name='site_name';") except mdb.ProgrammingError as ex: self._logger.error("Couldn't get site name. " "Perhaps your variable table is missing.") # We expect the 'value' dictionary object as the first item if result: variable_row = result[0] variable_info = variable_row['value'] # The variable info in Drupal is stored as a serialized string try: sitename = unserialize(variable_info.encode('utf8')) except Exception as ex: self._logger.error( "Could not unserialize site name. Unknonw encoding?") sitename = variable_info raise return sitename
def serialize_unserialize_php(request): try: input_value = request.POST.get("inputValue") output_value = "input invalid" data_result = { "input_value": output_value, "output_value": "input invalid" } print "kq ", request.POST try: if "serialize" in request.POST and input_value is not None: serialize_output = serialize(input_value) data_result = { "input_value": input_value, "output_value": serialize_output } elif "unserialize" in request.POST and input_value is not None: print "vao" unserialize_output = unserialize(input_value) data_result = { "input_value": input_value, "output_value": unserialize_output } except: data_result = {"input_value": "", "output_value": "input invalid"} return render(request, "serialize_unserialize_php.html", {"post": data_result}) except: return render(request, "page404.html")
def newjobs(i): if i == "NULL": return "" else: old_jobs_un = unserialize(i) old_jobs_un_trimmed = old_jobs_un['jobs'] new_jobs_se = serialize(old_jobs_un_trimmed) return new_jobs_se
def unserializeEntry(self, serialized_entry, method='python_repr'): """Unserialize a serialized entry. See :meth:`serializeEntry`.""" if method=='python_repr': return bBase.entry(eval(serialized_entry)) elif method=='php_serialize': import phpserialize return phpserialize.unserialize(serialized_entry, decode_strings=True) else: raise NotImplementedError()
def setMeta(self, text): assert self.sz_meta is None self.sz_meta = DokuMeta(self, len(text)) try: self.meta = unserialize(text.encode(), decode_strings=True) logging.info(repr(self.meta)) except Exception as e: logging.error(e) logging.info(text) self.meta = text raise e
def get_aligned_user_list(self, column_names, column_values, extra_vars, ban_list, user_list): result = [] header = [] #기본필드 머리 삽입 for i in range(len(column_names[:-1])): if column_values[i].get(): header.append(column_names[i]) #확장필드 머리 삽입 if column_values[-1].get(): for i in range(len(extra_vars)): #확장변수 밴 리스트에 있으면 아무것도 안함 if (extra_vars[i][1] in ban_list) or (extra_vars[i][2] in ban_list): pass else: header.append(extra_vars[i][2]) result.append(header) #몸통 삽입 for i in range(len(user_list)): body = [] #기본필드 몸통 삽입 for j in range(len(user_list[i][:-1])): if column_values[j].get(): body.append(user_list[i][j]) #확장필드 몸통 삽입 if column_values[-1].get(): extra_var = unserialize(user_list[i][-1].encode(), decode_strings=True, object_hook=phpobject)._asdict() for j in range(len(extra_vars)): #확장변수 밴 리스트에 있으면 아무것도 안함 if (extra_vars[j][1] in ban_list) or (extra_vars[j][2] in ban_list): pass else: #확장필드가 주소 형태라면 if re.match(r'.*zip$', extra_vars[j][0]) is not None: body.append(extra_var[extra_vars[j][1]][1] + ' ' + extra_var[extra_vars[j][1]][2] + ' ' + extra_var[extra_vars[j][1]][4] + ' ' + extra_var[extra_vars[j][1]][3] if ( extra_vars[j][1] in extra_var ) else '') #주소 이외의 다른 형태라면 else: body.append(extra_var[extra_vars[j][1]] if ( extra_vars[j][1] in extra_var) else '') result.append(body) return result
def __decode_response(self, response): """Devuelve un objeto con los datos de la respuesta de Pagadito. :param response Cadena contenedora de la estructura a ser decodificada. :return :type object """ if self.format_return == "php": return unserialize(response) elif self.format_return == "xml": return ET.fromstring(response) elif self.format_return == "json": return json.loads(response) else: return json.loads(response)
def getAcl(self, user_id): res = self.DBSession.query( GroupTable.group_access).join(UserTable).filter( UserTable.user_id == user_id).first() group_access = bytes(res.group_access, 'utf-8') group_access = unserialize(group_access) acl_list = [] for i in group_access: acl_list.append(group_access[i].decode("utf-8")) return acl_list
def check(self): for i in range(0, 100): if self._true: print 'Analysis Total >> Ending!' return data = self.getList() if data == None: print 'Data is Null' return Msg = BabyMQ.redis.hget('baby:message', '1') if Msg == None: print '微信消息提醒模板没有 请到MT后台添加模板' return Msg = phpserialize.unserialize(Msg) content = Msg['wechat_content'] for i in data: _data = json.loads(i['data']) if (_data.has_key('hash')): num = BabyMQ.redis.hget("Activity:geoHash", _data['hash']) if num != None: num = int(num) - 1; BabyMQ.redis.hset("Activity:geoHash", _data['hash'], num) sql = "UPDATE sed_new_activity_member SET `is_delete`=1 WHERE id=%s" % (i['id']) r1 = self.mysql.insert(sql) sql = "UPDATE sed_new_activity SET `amount`= `amount` + 1 WHERE id=%s" % (i['activity_id']) r = self.mysql.insert(sql) if r1 == 0 and i['open_id']: order_no = i['order_no'] order = self.getOrder(order_no) sql = "UPDATE sed_order_header SET `is_deleted`=1 WHERE id=%s" % (order['id']) r = self.mysql.insert(sql) pay_money = "%.2f" % order['pay_money'] product_name = order['product_name'] to_address = order['to_address'] Msg['wechat_url'] = Msg['wechat_url'].replace('{site_url}', wechatConfig['site_url']).replace("{orderNum}", order_no.encode("utf-8")) Msg['content'] = content.replace("{money}", pay_money).replace("{goodsInfo}", product_name.encode("utf-8")).replace("{deliveryInfo}", to_address.encode("utf-8")).replace("{orderNum}", order_no.encode("utf-8")) _Msg = {} _Msg['openid'] = order['member_openid'] _Msg['content'] = Msg['content'] _Msg['title'] = Msg['name'] _Msg['url'] = Msg['wechat_url'] _Msg['type'] = 'news' BabyMQ.add('WechatMessage', json.dumps(_Msg)) return
def _parse_unserialize(data: bytes): if len(data) > 0: output_data = unserialize( data, object_hook=ChainMap, ) # ====================================== # print("\n", output_data, "\n") # ====================================== output_data = convert(output_data) # ====================================== # print("\n", output_data, "\n") # ====================================== return output_data
def convert_param(value): result = {} try: a = unserialize(value.encode('utf-8')) except ValueError: return False for key, value in a.items(): if not key.startswith('Unit=') and _clean_text(key) and _clean_text(value): if not _clean_text(value.keys()[0]): continue result[_clean_text(key)] = _clean_text(value.keys()[0]) if len(value.keys()) == 1 else\ [_clean_text(p) for p in value.keys()] return result
def awsConnection(self): db = MySQLdb.connect(host="localhost", user="******", passwd="database_password", db="database_name") cur = db.cursor() cur.execute("SELECT * FROM aws_credential WHERE id = 1") row = cur.fetchone() unserializedData = unserialize(row[2]) awsaccesskeyid = unserializedData['aws_access_key_id'] awssecretaccesskey = unserializedData['aws_secret_access_key'] session = boto3.Session(aws_access_key_id=awsaccesskeyid, aws_secret_access_key=awssecretaccesskey) return session
def convert_param(value): result = {} try: a = unserialize(value.encode('utf-8')) except ValueError: return False for key, value in a.items(): if not key.startswith('Unit=') and _clean_text(key) and _clean_text( value): if not _clean_text(value.keys()[0]): continue result[_clean_text(key)] = _clean_text(value.keys()[0]) if len(value.keys()) == 1 else\ [_clean_text(p) for p in value.keys()] return result
def to_python(self, value): # object case if value is None: return None if isinstance(value, dict): return StatsDict(value) # string case try: d = php.unserialize(value) except ValueError: d = None if isinstance(d, dict): return StatsDict(d) return None
def process_request(self, request): request.xf_session_id = request.COOKIES.get(settings.XENFORO_COOKIE_PREFIX + 'session', None) request.xf_session = None if not request.xf_session_id: return # TODO: pluggable SessionStores cursor = connections[settings.XENFORO_DATABASE].cursor() cursor.execute("SELECT session_id, session_data, expiry_date FROM " + settings.XENFORO_TABLE_PREFIX + "session WHERE session_id = %s AND expiry_date >= %s", [request.xf_session_id, int(time())]) row = cursor.fetchone() cursor.close() if row: request.xf_session = phpserialize.unserialize(row[1], decode_strings=True)
def php_unmarshal( self, step, utdata ): flag, params = dh.param_rebuild( step.execute.params, utdata.vars ) if not flag: return None, "解析参数过程失败" data = params.get("data") try: data = unserialize( data ) except ValueError: try: data = loads( data, object_hook=phpobject ) except: data = pimpv.loads( data.replace("O:8\"stdClass\"", "a"), object_hook=phpobject ) except: return False, "提供的数据无法使用php方式解序列化" return True, data
def token_decrypt(pwd, token): key = 'key' iv = 'iv' encrypted = base64.b64decode(unquote(token).decode('utf8')) cipher = AES.new(key,AES.MODE_CBC, iv) decrypted = cipher.decrypt(encrypted) userData = (unserialize(base64.b64decode(decrypted))) hash_object = userData['uuid'] + str(userData['timestamp']) result = hashlib.sha512(hash_object.encode()).hexdigest() res = pwd == result tab = dict() tab['auth'] = res tab['userData'] = userData return tab
def get_drupal_version(self): """Get the Drupal installation version. """ version = None result = None try: # Returns a tuple of dictionary objects result = self.query("SELECT info FROM system WHERE name='system'") except mdb.ProgrammingError as ex: print "Couldn't get the version number. Perhaps your system table is missing." if result: # We expect the 'info' dictionary object as the first item system_row = result[0] system_info = system_row['info'] # The system info in Drupal is stored as a serialized string system_info_dict = unserialize(system_info) version = system_info_dict['version'] return version
def edit_rec(self, _r): ''' scan and edit each record if appropriate''' #import pdb; pdb.set_trace() _sep = "\\', " #save the end char & split the rec into a list _end = _r[:-1] #re.split parses the sql correctly, where str.split does # not handle escaped ' correctly self._rlist = re.split(r"\\\'\, ", _r) for i, _s in enumerate(self._rlist): #try unserialize, else just use it if self.scan_for_old_strings(_s): try: add_quotes = False if _s[1:3] == 'a:': _s = _s.strip("'") add_quotes = True _s = phpserialize.unserialize(_s, array_hook=OrderedDict) _s = self.iterate_data(_s) _ss = phpserialize.serialize(_s) #add back single quotes if add_quotes: self._rlist[i] = "'{}'".format(_ss) add_quotes = False except Exception as e: self._rlist[i] = self.replace_strings(_s) if _s[0:2] == 'a:': print('\n**serialization failed: {}\n{}'.format( self._rlist[0], self._rlist[i])) print('**', e) #print('***',a) self.ser_err_cnt += 1 #put the pieces back together _t = _sep.join(self._rlist) if _end == ',' and _t[-1] != ',': _t += ',' return _t
def edit_rec(self,_r): ''' scan and edit each record if appropriate''' #import pdb; pdb.set_trace() _sep = "\\', " #save the end char & split the rec into a list _end = _r[:-1] #re.split parses the sql correctly, where str.split does # not handle escaped ' correctly self._rlist = re.split(r"\\\'\, ",_r) for i,_s in enumerate(self._rlist): #try unserialize, else just use it if self.scan_for_old_strings(_s): try: add_quotes = False if _s[1:3] == 'a:': _s = _s.strip("'") add_quotes = True _s = phpserialize.unserialize(_s,array_hook=OrderedDict) _s = self.iterate_data(_s) _ss = phpserialize.serialize(_s) #add back single quotes if add_quotes: self._rlist[i] = "'{}'".format(_ss) add_quotes = False except Exception as e: self._rlist[i] = self.replace_strings(_s) if _s[0:2] == 'a:': print('\n**serialization failed: {}\n{}'.format(self._rlist[0],self._rlist[i])) print('**',e) #print('***',a) self.ser_err_cnt += 1 #put the pieces back together _t = _sep.join(self._rlist) if _end == ',' and _t[-1] != ',': _t += ',' return _t
def checkOrder(self): for i in range(0, 100): if self._true1: print 'Analysis Total >> Ending!' return data = self.getOrderList() if data == None: print 'Data is Null' return Msg = BabyMQ.redis.hget('baby:message', '1') if Msg == None: print '微信消息提醒模板没有 请到MT后台添加模板' return Msg = phpserialize.unserialize(Msg) content = Msg['wechat_content'] for i in data: order_no = i['orderId'] order = self.getOrder(order_no) if order == 1:continue sql = "UPDATE sed_order_header SET `is_deleted`=1 WHERE id=%s" % (i['id']) r = self.mysql.insert(sql) pay_money = "%.2f" % order['pay_money'] product_name = order['product_name'] to_address = order['to_address'] Msg['wechat_url'] = Msg['wechat_url'].replace('{site_url}', wechatConfig['site_url']).replace("{orderNum}", order_no.encode("utf-8")) Msg['content'] = content.replace("{money}", pay_money).replace("{goodsInfo}", product_name.encode("utf-8")).replace("{deliveryInfo}", to_address.encode("utf-8")).replace("{orderNum}", order_no.encode("utf-8")) _Msg = {} _Msg['openid'] = order['member_openid'] _Msg['content'] = Msg['content'] _Msg['title'] = Msg['name'] _Msg['url'] = Msg['wechat_url'] _Msg['type'] = 'news' BabyMQ.add('WechatMessage', json.dumps(_Msg)) print order_no return return ''
def get_drupal_version(self): """Get the Drupal installation version. """ version = None result = None try: # Returns a tuple of dictionary objects result = self.query("SELECT info FROM system WHERE name='system'") except mdb.ProgrammingError as ex: self._logger.error( "Couldn't get the version number. " "Perhaps your system table is missing." ) if result: # We expect the 'info' dictionary object as the first item system_row = result[0] system_info = system_row['info'] # The system info in Drupal is stored as a serialized string system_info_dict = unserialize(system_info) version = system_info_dict['version'] return version
def awsConnection(self): db = MySQLdb.connect(host="localhost", user="******", passwd="password", db="database") cur = db.cursor() cur.execute("SELECT * FROM aws_credential WHERE id = 1") row = cur.fetchone() unserializedData = unserialize(row[2]) awsaccesskeyid = unserializedData['aws_access_key_id'] awssecretaccesskey = unserializedData['aws_secret_access_key'] session = boto3.Session(aws_access_key_id=awsaccesskeyid, aws_secret_access_key=awssecretaccesskey, region_name='us-east-1') s3 = boto3.resource('s3', aws_access_key_id=awsaccesskeyid, aws_secret_access_key=awssecretaccesskey, region_name='us-east-1') client = boto3.resource('ec2', aws_access_key_id=awsaccesskeyid, aws_secret_access_key=awssecretaccesskey, region_name='us-east-1') ec2 = session.resource('ec2', region_name='us-east-1') return client
def GetUnserializedData(serializeData): return unserialize(serializeData)
import pickle import json from phpserialize import serialize, unserialize df = 'a:2:{i:0;a:2:{s:3:"qty";i:1;s:5:"price";s:4:"0.39";}i:1;a:2:{s:3:"qty";i:3;s:5:"price";s:4:"0.33";}}' data = serialize("wow") b = bytes(df, 'utf-8') data = unserialize(b) print(data)
def assertUnserialize(self, obj, serialized): self.assertEqual(obj, unserialize(serialized))
#template_report_desc = re.search("<description>(.+)</description>", str(template_contents)) sc_template_file.close() # replace def with tag to be substituted later new_sc_template = re.sub( "<definition>(.+)</definition>", "<definition>{{ report_output }}</definition>", str(template_contents)) sc_working_template_file = open('/templates/sc_working_template.txt', "w") sc_working_template_file.write(new_sc_template) sc_working_template_file.close() # Let's put the encoded report def into a format we can work with template_def = base64.b64decode(template_def.group(1)) template_def = unserialize(template_def, decode_strings=True) # Replace the CVE placeholder with something we can swap out later template_def = str(template_def).replace("CVE-1990-0000", "{{ cve_list }}") # Write this definition template to a file template_def_file = open("/templates/definition.txt", "w") template_def_file.write(template_def) template_def_file.close() if arc_request is True: sc_arcs = sc.get('arc').text sc_arcs = json.loads(sc_arcs) arc_name = feed + " Advisory Alerts" if os.path.isfile('/templates/custom_arc_report.xml'): arc_template_path = '/templates/custom_arc_report.xml'
def blob_to_array(self, blob): return phpserialize.unserialize(zlib.decompress(blob))
def get_paranoia(self): return dict_to_list(unserialize(bytes(str(self.paranoia), 'utf-8')))
def _parse_raw_licence(self, data): seed = md5(self.secret_string).hexdigest() data = decrypt(base64.decodestring(data), seed) info = unserialize(data) return info
def php_unserialize(cadena): dicc = unserialize(cadena) return dicc
def de_serialized(encoded_array): #df='a:2:{i:0;a:2:{s:3:"qty";i:1;s:5:"price";s:4:"0.39";}i:1;a:2:{s:3:"qty";i:3;s:5:"price";s:4:"0.33";}}' b = bytes(encoded_array, 'utf-8') data = unserialize(b) print(data) return data
def blob_to_array(self, blob): try: return phpserialize.unserialize(zlib.decompress(blob)) except: return phpserialize.unserialize(blob.decode('base64'))
def get_box(box_ser): # a:4:{i:0;a:2:{i:0;i:499;i:1;i:909;}i:1;a:2:{i:0;i:538;i:1;i:909;}i:2;a:2:{i:0;i:538;i:1;i:957;}i:3;a:2:{i:0;i:499;i:1;i:957;}} # {0: {0: 499, 1: 909}, 1: {0: 538, 1: 909}, 2: {0: 538, 1: 957}, 3: {0: 499, 1: 957}} points = phpserialize.unserialize(box_ser) box = [points[0][0], points[0][1], points[2][0], points[2][1]] return box
Evaluation.scoresheet != None, Site.raingarden == 1, Geolocation.latitude != None, Geolocation.latitude > 0)) # serialize SQLA query evaluations as list of dictionaries; # convert scoresheet from php array object to list of dictionaries """ # get php array object of scoresheets as list of dictionaries evals = [{'garden_id': result.garden_id, 'ratingyear': result.ratingyear, 'scoresheet': json.dumps(unserialize(result.scoresheet.replace(' ', '_').lower()))} for result in qEvaluations] table = pd.DataFrame(evals) # Pandas dataframe nourished by consuming SQLAlchemy object: evaluations = pd.read_sql(qEvaluations.statement, qEvaluations.session.bind, columns = list('raingardenratingyear')) sites = pd.read_sql(qSites.statement, qSites.session.bind, columns = list('raingardenratingyear')) elapsed = (time.time() - start) print 'Setup calls time elapsed -> ' + str(elapsed) """TRANSFORM DATA"""
is_natural = int(is_natural) if options: options = options.replace('\\"', '"').replace('""', '"').replace('\\', '"', 2)[:-1] # Clean up csv molested serialize-data f, new = Field.objects.using(database).get_or_create(id=f_id) f.required = required f.help_text = description if is_natural: f.type = 'IntegerField' elif description: f.type = 'CharField' elif ftype == 'dropdown' and options: f.type = 'ChoiceField' try: options = unserialize(options) except ValueError as e: print '[ERROR] unserialize error: %s' % e else: print options.items() f.save() for k, v in options.items(): if v in ['Ja', 'Nej']: f.type = 'BooleanField' print '- Made boolean' break else: FieldChoice.objects.using(database).get_or_create(name=v, field=f) else: f.type = 'CharField' if name:
import fileinput import sys from phpserialize import unserialize errors = 0 # I'm not proud of this code, but it works. for line in fileinput.input(): whole = line[1:-2] whole = whole.replace('\\', '') f = StringIO.StringIO() f.write(whole) f.seek(0) reader = csv.reader(f, delimiter=',', quotechar="'") try: row = reader.next() except: errors += 1 continue filename = row[0] serialized = row[4] try: info = unserialize(serialized) except: errors += 1 continue if info['frameCount'] > 1: print filename sys.stderr.write("Errors: {}\n".format(errors))
def unserialize(str): return phpserialize.unserialize(bytes(str, 'utf-8'), decode_strings=True)
# print "FAIL export of event ", str(event['pc_eid']), err # #print rawtext # items_fail += 1 def _get_key(title): for item in loc_map_keys: if item in title: return loc_map[item] return title eventnode = dom.createElement('event') # process location information locstring = str(event['pc_location']).decode(IN_ENCODING) if "{" in locstring: _locstruct = phpserialize.unserialize(locstring) # cleanup locations details locstruct = {} for key, val in _locstruct.items(): key = _cleanup_textonly(key) val = _cleanup_textonly(val) if not val: continue locstruct[key] = val locstruct['event_datetime'] = '%s %s Europe/Vienna' % ( str(event.get('pc_eventDate')).decode(IN_ENCODING), str(event.get('pc_startTime')).decode(IN_ENCODING) ) if not locstruct.get('event_location', False): # event_location must not be empty continue