Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def api_json_to_worksheet(sheet_json):
sheet_values = jsonlib.loads(sheet_json)
worksheet = Worksheet()
worksheet.name = sheet_values.get('name', 'Untitled')
for key, value in sheet_values.iteritems():
if key == "usercode_error":
worksheet._usercode_error = value
elif isinstance(value, dict):
rows = value
col = int(key)
for row, value in rows.iteritems():
row = int(row)
worksheet[col, row].value = value
return worksheet
def _parse_response(self, response, method, format=None):
"""Parses the response according to the given (optional) format, which should be either 'JSON' or 'XML'."""
if not format:
format = RESPONSE_FORMAT
if format == 'JSON':
result = simplejson.loads(response)
self._check_error(result)
elif format == 'XML':
dom = minidom.parseString(response)
result = self._parse_response_item(dom)
dom.unlink()
if 'error_response' in result:
self._check_error(result['error_response'])
result = result[method[9:].replace('.', '_') + '_response']
else:
raise RuntimeError('Invalid format specified.')
return result
# -*- coding: UTF-8 -*-
"""
Picka is a data generation and randomization module which aims to increase
coverage by increasing the amount of tests you _dont_ have to write
by hand.
By: Anthony Long
"""
import os
import random
import string
import jsonlib as json
__docformat__ = "restructuredtext en"
albanian_names = json.loads(open(os.path.join(os.path.dirname(__file__), 'albanian.json')).read())['albanian']
def age(min=1, max=99):
return random.randint(min, max + 1)
def apartment_number():
return ' '.join([random.choice(["apartament", "pas", "dhomë"]), str(random.randint(1, 100))])
def business_title():
pass
def calling_code():
pass
def _prepare_response(self, code, data):
msg = self._get_msg(code)
if data:
try:
data = simplejson.loads(data)
except ValueError:
pass
return {'status': code, 'body': data or {}, 'msg': msg}
def _parse_response(self, response, method, format=None):
"""Parses the response according to the given (optional) format, which should be either 'JSON' or 'XML'."""
if not format:
format = RESPONSE_FORMAT
if format == 'JSON':
result = simplejson.loads(response)
print 'result: ', result
self._check_error(result)
elif format == 'XML':
dom = minidom.parseString(response)
result = self._parse_response_item(dom)
dom.unlink()
if 'error_response' in result:
self._check_error(result['error_response'])
result = result[method[9:].replace('.', '_') + '_response']
else:
raise RuntimeError('Invalid format specified.')
return result
def _parse_response(self, response, method, format=None):
"""Parses the response according to the given (optional) format, which should be either 'JSON' or 'XML'."""
if not format:
format = RESPONSE_FORMAT
if format == 'JSON':
result = simplejson.loads(response)
self._check_error(result)
elif format == 'XML':
dom = minidom.parseString(response)
result = self._parse_response_item(dom)
dom.unlink()
if 'error_response' in result:
self._check_error(result['error_response'])
result = result[method[9:].replace('.', '_') + '_response']
else:
raise RuntimeError('Invalid format specified.')
return result