restore working with pickle! (can't share data between python versions)

This commit is contained in:
Arturo Hernandez
2018-09-03 17:42:16 -04:00
parent d2c10f31b0
commit e5e6a65f3c
4 changed files with 40 additions and 11 deletions

View File

@@ -109,6 +109,7 @@ class ZK(object):
self.ommit_ping = ommit_ping
self.verbose = verbose
self.encoding = encoding
User.encoding = encoding
self.tcp = False
self.users = 0
self.fingers = 0
@@ -775,14 +776,18 @@ class ZK(object):
return False #some devices doesn't support sound
#raise ZKErrorResponse("can't test voice")
def set_user(self, uid, name, privilege=0, password='', group_id='', user_id='', card=0):
def set_user(self, uid=None, name='', privilege=0, password='', group_id='', user_id='', card=0):
'''
create or update user by uid
'''
command = const.CMD_USER_WRQ
if uid is None:
uid = self.next_uid # keeps uid=0
if not user_id:
user_id = self.next_user_id # else...
if not user_id:
user_id = str(uid) #ZK6 needs uid2 == uid
#uid = chr(uid % 256) + chr(uid >> 8)
#TODO: check what happens if name is missing...
if privilege not in [const.USER_DEFAULT, const.USER_ADMIN]:
privilege = const.USER_DEFAULT
privilege = int(privilege)
@@ -827,8 +832,8 @@ class ZK(object):
raise ZKErrorResponse("Can't find user")
if isinstance(fingers, Finger):
fingers = [fingers]
fpack = ""
table = ""
fpack = b""
table = b""
fnum = 0x10 # possibly flag
tstart = 0
for finger in fingers:

View File

@@ -1,21 +1,25 @@
# -*- coding: utf-8 -*-
from struct import pack #, unpack
class User(object):
encoding = 'UTF-8'
def __init__(self, uid, name, privilege, password='', group_id='', user_id='', card=0):
self.uid = uid
self.name = str(name)
self.privilege = privilege
self.password = str(password)
self.group_id = group_id
self.group_id = str(group_id)
self.user_id = user_id
self.card = card # 64 int to 40 bit int
def repack29(self): # with 02 for zk6 (size 29)
return pack("<BHB5s8sIxBhI", 2, self.uid, self.privilege, self.password, self.name, self.card, int(self.group_id) if self.group_id else 0, 0, int(self.user_id))
return pack("<BHB5s8sIxBhI", 2, self.uid, self.privilege, self.password.encode(User.encoding, errors='ignore'), self.name.encode(User.encoding, errors='ignore'), self.card, int(self.group_id) if self.group_id else 0, 0, int(self.user_id))
def repack73(self): #with 02 for zk8 (size73)
#password 6s + 0x00 + 0x77
# 0,0 => 7sx group id, timezone?
return pack("<BHB8s24sIB7sx24s", 2, self.uid, self.privilege,self.password, self.name, self.card, 1, self.group_id, str(self.user_id))
return pack("<BHB8s24sIB7sx24s", 2, self.uid, self.privilege,self.password.encode(User.encoding, errors='ignore'), self.name.encode(User.encoding, errors='ignore'), self.card, 1, str(self.group_id).encode(User.encoding, errors='ignore'), str(self.user_id).encode(User.encoding, errors='ignore'))
def __str__(self):
return '<User>: [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id)