cleanup code

This commit is contained in:
Fanani M. Ihsan 2018-12-27 13:57:49 +07:00
parent 0d04f61e1f
commit e4b229886e
3 changed files with 308 additions and 369 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,10 @@ class ZKError(Exception):
pass pass
class ZKErrorConnection(ZKError):
pass
class ZKErrorResponse(ZKError): class ZKErrorResponse(ZKError):
pass pass

View File

@ -1,7 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from struct import pack #, unpack from struct import pack #, unpack
import codecs import codecs
class Finger(object): class Finger(object):
def __init__(self, uid, fid, valid, template): def __init__(self, uid, fid, valid, template):
self.size = len(template) # template only self.size = len(template) # template only
self.uid = int(uid) self.uid = int(uid)
@ -16,6 +19,7 @@ class Finger(object):
def repack_only(self): #only template def repack_only(self): #only template
return pack("H%is" % (self.size), self.size, self.template) return pack("H%is" % (self.size), self.size, self.template)
@staticmethod @staticmethod
def json_unpack(json): def json_unpack(json):
return Finger( return Finger(
@ -24,6 +28,7 @@ class Finger(object):
valid=json['valid'], valid=json['valid'],
template=codecs.decode(json['template'],'hex') template=codecs.decode(json['template'],'hex')
) )
def json_pack(self): #packs for json def json_pack(self): #packs for json
return { return {
"size": self.size, "size": self.size,
@ -44,3 +49,4 @@ class Finger(object):
def dump(self): def dump(self):
return "<Finger> [uid:{:>3}, fid:{}, size:{:>4} v:{} t:{}]".format(self.uid, self.fid, self.size, self.valid, codecs.encode(self.template, 'hex')) return "<Finger> [uid:{:>3}, fid:{}, size:{:>4} v:{} t:{}]".format(self.uid, self.fid, self.size, self.valid, codecs.encode(self.template, 'hex'))