Skip to content

Commit

Permalink
Bugfixes; file_md5 was type bytes vs str, reply() needed argument def…
Browse files Browse the repository at this point in the history
…ault, use get_argument() instead of request.arguments[], json to str lambda to ease schema encoding, true => True in python
  • Loading branch information
kueblc committed Jul 3, 2019
1 parent 3995407 commit da1966a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions scripts/fake-registration-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import hashlib
import json
jsonstr = lambda j : json.dumps(j, separators=(',', ':'))

def file_as_bytes(file_name):
with open(file_name, 'rb') as file:
Expand All @@ -23,7 +24,7 @@ def get_file_stats(file_name):
global file_md5
global file_len
file = file_as_bytes(file_name)
file_md5 = hashlib.md5(file).hexdigest().encode('utf-8')
file_md5 = hashlib.md5(file).hexdigest()
file_len = str(os.path.getsize(file_name))

from time import time
Expand All @@ -49,23 +50,23 @@ def get(self):
print('\n')
print('URI:'+str(self.request.uri))
self.write('Hello Human, Do you have IOT?')
def reply(self, result):
def reply(self, result=None):
answer = {
't': timestamp(),
'e': False,
'success': True }
if result:
answer['result'] = result
answer = json.dumps(answer, separators=(',', ':'))
answer = jsonstr(answer)
self.set_header("Content-Type", "application/json;charset=UTF-8")
self.set_header('Content-Length', str(len(answer)))
self.set_header('Content-Language', 'zh-CN')
self.write(answer)
def post(self):
print('\n')
uri = str(self.request.uri)
a = str(self.request.arguments['a'])
gwId = str(self.request.arguments['gwId'])
a = str(self.get_argument('a'))
gwId = str(self.get_argument('gwId'))
print('URI:'+uri)

if(a == "s.gw.token.get"):
Expand All @@ -85,12 +86,12 @@ def post(self):
elif(".active" in a):
print("Answer s.gw.dev.pk.active")
answer = {
"schema": [{
"schema": jsonstr([{
"mode": "rw",
"property": {
"type": "bool" },
"id": 1,
"type": "obj" }],
"type": "obj" }]),
"uid": "00000000000000000000",
"devEtag": "0000000000",
"secKey": "0000000000000000",
Expand All @@ -107,7 +108,7 @@ def post(self):
elif(".device.upgrade" in a):
print("Answer tuya.device.upgrade.get")
answer = {
"auto": true,
"auto": True,
"type": 0,
"size": file_len,
"version": "9.0.0",
Expand Down

0 comments on commit da1966a

Please sign in to comment.