Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def json_dumps(self, obj, sort_keys=False):
return json.dumps(
obj, default=utils.json_int_dttm_ser, ignore_nan=True, sort_keys=sort_keys
)
def create_zone(self, domain, type='NATIVE', ttl=None, extra=None):
if type == 'master':
type = 'NATIVE'
elif type == 'slave':
type = 'SLAVE'
params = {'name': domain, 'type': type, 'ttl': ttl}
result = self.connection.request(
API_ROOT + '/dns/zone/',
data=json.dumps(params), method='POST').object
extra = {
'soa': result['soa'],
'ns': result['ns']
}
zone = Zone(id=result['id'], domain=domain,
type=type, ttl=ttl, extra=extra, driver=self)
return zone
def signin(self, username=None, password=None):
username = username or self.username
password = password or self.password
url = 'https://api.github.com/authorizations'
auth = 'Basic ' + base64.standard_b64encode(username + ':' + password)
headers = {'Authorization': auth,
'Content-Type': 'application/json'}
data = {'scopes': ['repo'],
'note': __name__.replace('_', '-'),
'note_url': __url__}
request = urllib2.Request(url, headers=headers, data=json.dumps(data))
response = urllib2.urlopen(request)
auth = json.load(response)
assert isinstance(auth, dict)
assert 'token' in auth
def send_request(*args, **kwargs):
req = GitHubRequest(auth['token'], *args, **kwargs)
return urllib2.urlopen(req)
yield send_request
request = GitHubRequest(auth['token'], auth['url'],
headers=headers,
method='DELETE')
response = urllib2.urlopen(request)
assert response.code == 204
def IndexChart(request):
response_dict = {}
model = MLModel.objects.order_by('-time')[0]
response_dict['knn'] = [{'name':u'准确率', 'y':model.knn},{'name':u'误判率', 'y':100 - model.knn}]
response_dict['nb'] = [{'name':u'准确率', 'y':model.nb},{'name':u'误判率', 'y':100 - model.nb}]
response_dict['lr'] = [{'name':u'准确率', 'y':model.lr},{'name':u'误判率', 'y':100 - model.lr}]
response_dict['rf'] = [{'name':u'准确率', 'y':model.rf},{'name':u'误判率', 'y':100 - model.rf}]
response_dict['svm'] = [{'name':u'准确率', 'y':model.svm},{'name':u'误判率', 'y':100 - model.svm}]
return HttpResponse(json.dumps(response_dict),content_type="application/json")
def _format_output(self, output):
# Strip unicode
if type(output) == unicode:
output = output.encode('ascii', 'replace')
# If output is a dict
if type(output) == dict:
return json.dumps(output, indent=2)
# If output is a list of dicts
if type(output) == list and type(output[0]) == dict:
# This gets a little complicated because it potentially means
# nested results, usually because of with_items.
real_output = list()
for index, item in enumerate(output):
copy = item
if type(item) == dict:
for field in FIELDS:
if field in item.keys():
copy[field] = self._format_output(item[field])
real_output.append(copy)
return json.dumps(output, indent=2)
# If output is a list of strings
def validate_dependencies(conn: connection, relation: RelationDescription, tmp_view_name: TempTableName) -> None:
"""
Download the dependencies (usually, based on the temporary view) and compare with table design.
"""
if tmp_view_name.is_late_binding_view:
logger.warning("Dependencies of '%s' cannot be verified because it depends on an external table",
relation.identifier)
return
dependencies = etl.design.bootstrap.fetch_dependencies(conn, tmp_view_name)
# We break with tradition and show the list of dependencies such that they can be copied into a design file.
logger.info("Dependencies of '%s' per catalog: %s", relation.identifier, json.dumps(dependencies))
difference = compare_query_to_design(dependencies, relation.table_design.get("depends_on", []))
if difference:
logger.error("Mismatch in dependencies of '{}': {}".format(relation.identifier, difference))
raise TableDesignValidationError("mismatched dependencies in '%s'" % relation.identifier)
else:
logger.info("Dependencies listing in design file for '%s' matches SQL", relation.identifier)
def serialise(self):
import binascii
import simplejson
return binascii.hexlify(simplejson.dumps(self.get_dict(), sort_keys=True).encode('utf-8')).decode('utf-8')
def run(term=''):
"""
:param str term: Page to request?
:return list: List of titles of elastic hits in response
"""
r = requests.get(str(term).strip())
data = r.json()
return json.dumps([x['_source']['title'] for x in data['hits']['hits']])
ostype = platform.dist()
if(ostype[0] in ['Ubuntu','debian','ubuntu','Debian']):
sysinstaller = 'apt-get'
installer = 'dpkg'
elif(ostype[0] in ['SuSE']):
sysinstaller = 'zypper'
installer = 'rpm'
elif(ostype[0] in ['CentOS', 'centos', 'redhat','RedHat']):
sysinstaller = 'yum'
installer = 'rpm'
machine = platform.machine()
hostname = platform.node()
dist_json = {'os.system':ostype[0], 'os.version':ostype[1], 'os.release':ostype[2], 'os.sysinstall':sysinstaller, 'os.installer':installer, 'os.arch':machine, 'os.hostname':hostname}
return json.dumps(dist_json, sort_keys=False, indent=4, separators=(',', ': '))
#return dist_json
else:
return '{"Exception":"Invalid token"}'
'''
render_json = lambda **kwargs: json.dumps(kwargs)