问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

pyodbc哪个版本支持python3

发布网友 发布时间:2022-05-02 07:05

我来回答

3个回答

懂视网 时间:2022-05-02 11:26

class SSDB_Response(object): def __init__(self, code=‘‘, data_or_message=None): self.type = ‘none‘ self.code = code self.data = None self.message = None self.set(code, data_or_message) def set(self, code, data_or_message=None): self.code = code if code == ‘ok‘: self.data = data_or_message else: if isinstance(data_or_message, list): if len(data_or_message) > 0: self.message = data_or_message[0] else: self.message = data_or_message def __repr__(self): return ((((str(self.code) + ‘ ‘) + str(self.message)) + ‘ ‘) + str(self.data)) def ok(self): return self.code == ‘ok‘ def not_found(self): return self.code == ‘not_found‘ def str_resp(self, resp): self.type = ‘val‘ if resp[0] == ‘ok‘: if len(resp) == 2: self.set(‘ok‘, resp[1]) else: self.set(‘server_error‘, ‘Invalid response‘) else: self.set(resp[0], resp[1:]) return self def str_resp(self, resp): self.type = ‘val‘ if resp[0] == ‘ok‘: if len(resp) == 2: self.set(‘ok‘, resp[1]) else: self.set(‘server_error‘, ‘Invalid response‘) else: self.set(resp[0], resp[1:]) return self def int_resp(self, resp): self.type = ‘val‘ if resp[0] == ‘ok‘: if len(resp) == 2: try: val = int(resp[1]) self.set(‘ok‘, val) except Exception as e: self.set(‘server_error‘, ‘Invalid response‘) else: self.set(‘server_error‘, ‘Invalid response‘) else: pass self.set(resp[0], resp[1:]) return self def float_resp(self, resp): self.type = ‘val‘ if resp[0] == ‘ok‘: if len(resp) == 2: try: val = float(resp[1]) self.set(‘ok‘, val) except Exception as e: self.set(‘server_error‘, ‘Invalid response‘) else: self.set(‘server_error‘, ‘Invalid response‘) else: self.set(resp[0], resp[1:]) return self def list_resp(self, resp): self.type = ‘list‘ self.set(resp[0], resp[1:]) return self def int_map_resp(self, resp): self.type = ‘map‘ if resp[0] == ‘ok‘: if len(resp) % 2 == 1: data = {‘index‘: [], ‘items‘: {}, } i = 1 while i < len(resp): k = resp[i] v = resp[(i + 1)] try: v = int(v) except Exception as e: v = - (1) data[‘index‘].append(k) data[‘items‘][k] = v i += 2 self.set(‘ok‘, data) else: self.set(‘server_error‘, ‘Invalid response‘) else: self.set(resp[0], resp[1:]) return self def str_map_resp(self, resp): self.type = ‘map‘ if resp[0] == ‘ok‘: if len(resp) % 2 == 1: data = {‘index‘: [], ‘items‘: {}, } i = 1 while i < len(resp): k = resp[i] v = resp[(i + 1)] data[‘index‘].append(k) data[‘items‘][k] = v i += 2 self.set(‘ok‘, data) else: self.set(‘server_error‘, ‘Invalid response‘) else: self.set(resp[0], resp[1:]) return self class SSDB(object): def __init__(self, host, port): self.recv_buf = ‘‘ self._closed = False self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect(tuple([host, port])) self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) def close(self): if not (self._closed): self.sock.close() self._closed = True def closed(self): pass return self._closed def request(self, cmd, params=None): pass if params is None: params = [] params = ([cmd] + params) self.send(params) resp = self.recv() if resp is None: return SSDB_Response(‘error‘, ‘Unknown error‘) if len(resp) == 0: return SSDB_Response(‘disconnected‘, ‘Connection closed‘) ret = SSDB_Response() # {{{ switch: cmd _continue_1 = False while True: if False or ((cmd) == ‘ping‘) or ((cmd) == ‘set‘) or ((cmd) == ‘del‘) or ((cmd) == ‘qset‘) or ( (cmd) == ‘zset‘) or ((cmd) == ‘hset‘) or ((cmd) == ‘qpush‘) or ((cmd) == ‘qpush_front‘) or ( (cmd) == ‘qpush_back‘) or ((cmd) == ‘zdel‘) or ((cmd) == ‘hdel‘) or ((cmd) == ‘multi_set‘) or ( (cmd) == ‘multi_del‘) or ((cmd) == ‘multi_hset‘) or ((cmd) == ‘multi_hdel‘) or ( (cmd) == ‘multi_zset‘) or ((cmd) == ‘multi_zdel‘): if len(resp) > 1: return ret.int_resp(resp) else: return SSDB_Response(resp[0], None) break if False or ((cmd) == ‘version‘) or ((cmd) == ‘substr‘) or ((cmd) == ‘get‘) or ((cmd) == ‘getset‘) or ( (cmd) == ‘hget‘) or ((cmd) == ‘qfront‘) or ((cmd) == ‘qback‘) or ((cmd) == ‘qget‘): pass return ret.str_resp(resp) break if False or ((cmd) == ‘qpop‘) or ((cmd) == ‘qpop_front‘) or ((cmd) == ‘qpop_back‘): size = 1 try: size = int(params[2]) except Exception as e: pass if size == 1: return ret.str_resp(resp) else: return ret.list_resp(resp) break if False or ((cmd) == ‘dbsize‘) or ((cmd) == ‘getbit‘) or ((cmd) == ‘setbit‘) or ((cmd) == ‘countbit‘) or ( (cmd) == ‘bitcount‘) or ((cmd) == ‘strlen‘) or ((cmd) == ‘ttl‘) or ((cmd) == ‘expire‘) or ( (cmd) == ‘setnx‘) or ((cmd) == ‘incr‘) or ((cmd) == ‘decr‘) or ((cmd) == ‘zincr‘) or ( (cmd) == ‘zdecr‘) or ((cmd) == ‘hincr‘) or ((cmd) == ‘hdecr‘) or ((cmd) == ‘hsize‘) or ( (cmd) == ‘zsize‘) or ((cmd) == ‘qsize‘) or ((cmd) == ‘zget‘) or ((cmd) == ‘zrank‘) or ( (cmd) == ‘zrrank‘) or ((cmd) == ‘zsum‘) or ((cmd) == ‘zcount‘) or ((cmd) == ‘zremrangebyrank‘) or ( (cmd) == ‘zremrangebyscore‘) or ((cmd) == ‘hclear‘) or ((cmd) == ‘zclear‘) or ((cmd) == ‘qclear‘) or ( (cmd) == ‘qpush‘) or ((cmd) == ‘qpush_front‘) or ((cmd) == ‘qpush_back‘) or ( (cmd) == ‘qtrim_front‘) or ((cmd) == ‘qtrim_back‘): pass return ret.int_resp(resp) break if False or ((cmd) == ‘zavg‘): pass return ret.float_resp(resp) break if False or ((cmd) == ‘keys‘) or ((cmd) == ‘rkeys‘) or ((cmd) == ‘zkeys‘) or ((cmd) == ‘zrkeys‘) or ( (cmd) == ‘hkeys‘) or ((cmd) == ‘hrkeys‘) or ((cmd) == ‘list‘) or ((cmd) == ‘hlist‘) or ( (cmd) == ‘hrlist‘) or ((cmd) == ‘zlist‘) or ((cmd) == ‘zrlist‘): pass return ret.list_resp(resp) break if False or ((cmd) == ‘scan‘) or ((cmd) == ‘rscan‘) or ((cmd) == ‘hgetall‘) or ((cmd) == ‘hscan‘) or ( (cmd) == ‘hrscan‘): pass return ret.str_map_resp(resp) break if False or ((cmd) == ‘zscan‘) or ((cmd) == ‘zrscan‘) or ((cmd) == ‘zrange‘) or ((cmd) == ‘zrrange‘) or ( (cmd) == ‘zpop_front‘) or ((cmd) == ‘zpop_back‘): pass return ret.int_map_resp(resp) break if False or ((cmd) == ‘auth‘) or ((cmd) == ‘exists‘) or ((cmd) == ‘hexists‘) or ((cmd) == ‘zexists‘): pass return ret.int_resp(resp) break if False or ((cmd) == ‘multi_exists‘) or ((cmd) == ‘multi_hexists‘) or ((cmd) == ‘multi_zexists‘): pass return ret.int_map_resp(resp) break if False or ((cmd) == ‘multi_get‘) or ((cmd) == ‘multi_hget‘): pass return ret.str_map_resp(resp) break if False or ((cmd) == ‘multi_hsize‘) or ((cmd) == ‘multi_zsize‘) or ((cmd) == ‘multi_zget‘): pass return ret.int_map_resp(resp) break ### default return ret.list_resp(resp) break break if _continue_1: continue # }}} switch return SSDB_Response(‘error‘, ‘Unknown error‘) def send(self, data): pass ps = [] _cpy_r_0 = _cpy_l_1 = data if type(_cpy_r_0).__name__ == ‘dict‘: _cpy_b_3 = True; _cpy_l_1 = _cpy_r_0.iterkeys() else: _cpy_b_3 = False; for _cpy_k_2 in _cpy_l_1: if _cpy_b_3: p = _cpy_r_0[_cpy_k_2] else: p = _cpy_k_2 pass p = str(p) ps.append(str(len(p))) ps.append(p) nl = ‘ ‘ s = (nl.join(ps) + ‘ ‘) try: while True: ret = self.sock.send(s.encode()) if ret == 0: return - (1) s = s[ret:] if len(s) == 0: break except socket.error as e: return -(1) return ret def net_read(self): try: data = self.sock.recv(1024 * 8) except Exception as e: data = ‘‘ if data == ‘‘: self.close() return 0 self.recv_buf += str(data,encoding = "ascii") return len(data) def recv(self): while True: ret = self.parse() if ret is None: if self.net_read() == 0: return [] else: return ret def parse(self): pass ret = [] spos = 0 epos = 0 while True: spos = epos epos = self.recv_buf.find(‘ ‘, spos) if epos == - (1): break epos += 1 line = self.recv_buf[spos: epos] spos = epos if line.strip() == ‘‘: if len(ret) == 0: continue else: self.recv_buf = self.recv_buf[spos:] return ret try: num = int(line) except Exception as e: return [] epos = (spos + num) if epos > len(self.recv_buf): break data = self.recv_buf[spos: epos] ret.append(data) spos = epos epos = self.recv_buf.find(‘ ‘, spos) if epos == - (1): break epos += 1 return None

测试程序

from SSDB import SSDB

ssdb = SSDB(‘192.168.1.250‘, 8888)

l = []
l.append(‘person_1‘)
l.append(‘a‘)
l.append(‘1111‘)
l.append(‘b‘)
l.append(‘2222‘)

print(ssdb.request(‘multi_hset‘, l))

‘‘‘
print(ssdb.request(‘set‘, [‘test‘, ‘123‘]))
print(ssdb.request(‘get‘, [‘test‘]))
print(ssdb.request(‘incr‘, [‘test‘, ‘1‘]))
print(ssdb.request(‘decr‘, [‘test‘, ‘1‘]))
print(ssdb.request(‘scan‘, [‘a‘, ‘z‘, 10]))
print(ssdb.request(‘rscan‘, [‘z‘, ‘a‘, 10]))
print(ssdb.request(‘keys‘, [‘a‘, ‘z‘, 10]))
print(ssdb.request(‘del‘, [‘test‘]))
print(ssdb.request(‘get‘, [‘test‘]))
print("
")
print(ssdb.request(‘zset‘, [‘test‘, ‘a‘, 20]))
print(ssdb.request(‘zget‘, [‘test‘, ‘a‘]))
print(ssdb.request(‘zincr‘, [‘test‘, ‘a‘, 20]))
print(ssdb.request(‘zdecr‘, [‘test‘, ‘a‘, 20]))
print(ssdb.request(‘zscan‘, [‘test‘, ‘a‘, 0, 100, 10]))
print(ssdb.request(‘zrscan‘, [‘test‘, ‘a‘, 100, 0, 10]))
print(ssdb.request(‘zkeys‘, [‘test‘, ‘a‘, 0, 100, 10]))
print(ssdb.request(‘zdel‘, [‘test‘, ‘a‘]))
print(ssdb.request(‘zget‘, [‘test‘, ‘a‘]))
print("
")
print(ssdb.request(‘hset‘, [‘test‘, ‘a‘, 20]))
print(ssdb.request(‘hget‘, [‘test‘, ‘a‘]))
print(ssdb.request(‘hincr‘, [‘test‘, ‘a‘, 20]))
print(ssdb.request(‘hdecr‘, [‘test‘, ‘a‘, 20]))
print(ssdb.request(‘hscan‘, [‘test‘, ‘0‘, ‘z‘, 10]))
print(ssdb.request(‘hrscan‘, [‘test‘, ‘z‘, ‘0‘, 10]))
print(ssdb.request(‘hkeys‘, [‘test‘, ‘0‘, ‘z‘, 10]))
print(ssdb.request(‘hdel‘, [‘test‘, ‘a‘]))
print(ssdb.request(‘hget‘, [‘test‘, ‘a‘]))
print("
")
‘‘‘

 

兼容python3的SSDB客户端

标签:multi   message   hsi   erro   host   else   ==   enc   app   

热心网友 时间:2022-05-02 08:34

如果是win10而且是64位的系统,最好安装python3.7和pyodbc-4.0.27-cp37-cp37m-win_amd64,最新版本的python3.8和很多组件都不兼容。

热心网友 时间:2022-05-02 09:52

pip般用于DOS命令安装库文件; pip所命令:pip install xxx 安装库文件示例:pip install pyodb
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
夫妻养狗狗把谁当主人 两人同养狗认谁当主人 什么蔬菜和水果可以美容祛斑呢? vivox60怎么查看参数配置详情 怎样查看vivo手机的屏幕参数? vivo手机怎么看手机参数 vi##手机怎么看配置? 义乌到湖州没有直达快客???必须到南浔?? 湖州到绍兴的汽车有几班? 注销驾考需要本人吗 C#中怎样把一个字符串转换成字符形数组? 如何将字符串转换为字符串数组 华夏红利基金净值怎样? 华夏债券、华夏回报、中银中国、华夏红利二号基金 华夏红利和南方绩优成长哪个好呢?谢谢 0020011华夏红利基金的市值是多少 华夏红利基金 华夏基金哪个最好呢?我想加入基金定投,目前很多人说华夏回报,华夏红利等比较好,纠结哪个好呢? 2007年买了1万元的华夏红利混合基金,到2014年净值不足6000元,是怎么回事 买一万元华夏红利基金一年能获利多少? vivo y66手机系统经常更新,会有什么损害么? vivo手机y66系统更新好吗,更新不会更占内存吧? ViVOY66的系统版本 vivo66属于什么系统 vivoy66手机最新系统版本更新后为什么看不出有什么区别呢 vivoy66手机什么时候更新道8.0版本系统 vivoy66用什么系统好? vivoy66提示更新,要不要更新? vivo y66是安卓标准版吧? vivoy66手机最新系统版本更新后为什么看不出有什么区别呢? c++怎么将字符串变为字符数组 如何string字符串转换成数组 如何将字符串转成数组 如何将字符串转换为数组 c++中如何将一个字符串转化成数组 养老护理员与护理员的区别 信用卡逾期5个月,已经协商还款了。但是现在在做生意可以去银行贷款吗? 《护工岗位合格证》是哪颁发的?卫校还是*部门(如人社局等)?和《老年护理员》证(*发的)有区别 护工都是有老年护理专业证书的吗? 医疗照护证和养老护理证哪个级别高一点? 养老护理中级结业证书和养老护理资格证有什么区别 车船税使用税有效期什么意思 车船税是什么意思?如何查询车船税更方便? 除了贷款买车,还有什么方式可以低首付的买到车 低首付买车,车型有什么限制吗? 狗身上有蜱虫怎么办 去除 家里的狗狗身上发现蜱虫,应该怎么处理,有什么驱虫的产品可以去除吗? 狗狗身上发现蜱虫怎么办 python 兼容python3 吗 广告学不好就业吗?