From 7e224ba5af86fa7febe7dd5d9c662942e4efa960 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 17 May 2018 08:40:02 +0200 Subject: [PATCH] Modernize vnpy/api/k* --- vnpy/api/ksgold/__init__.py | 5 +++-- vnpy/api/ksgold/pyscript/generate_data_type.py | 13 +++++++------ vnpy/api/ksgold/pyscript/generate_struct.py | 3 ++- vnpy/api/ksotp/__init__.py | 7 ++++--- vnpy/api/ksotp/pyscript/generate_data_type.py | 5 +++-- vnpy/api/ksotp/pyscript/generate_struct.py | 7 ++++--- vnpy/api/ksotp/vnksotpmd/test/mdtest.py | 9 +++++---- vnpy/api/ksotp/vnksotptd/test/tdtest.py | 13 +++++++------ 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/vnpy/api/ksgold/__init__.py b/vnpy/api/ksgold/__init__.py index c57e3924..a7a7a59e 100644 --- a/vnpy/api/ksgold/__init__.py +++ b/vnpy/api/ksgold/__init__.py @@ -1,4 +1,5 @@ # encoding: UTF-8 -from vnksgoldtd import TdApi -from ksgold_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnksgoldtd import TdApi +from .ksgold_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/ksgold/pyscript/generate_data_type.py b/vnpy/api/ksgold/pyscript/generate_data_type.py index 477d5288..e833bad2 100644 --- a/vnpy/api/ksgold/pyscript/generate_data_type.py +++ b/vnpy/api/ksgold/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -48,7 +49,7 @@ def process_typedef(line): else: keyword = content[-1] keyword = keyword.replace(';\n', '') - print content, keyword + print(content, keyword) if '[' in keyword: i = keyword.index('[') @@ -91,15 +92,15 @@ def main(): py_line = process_line(line) if py_line: fpy.write(py_line.decode('gbk').encode('utf-8')) - print n + print(n) fcpp.close() fpy.close() - print u'data_type.py生成过程完成' - except Exception, e: - print u'data_type.py生成过程出错' - print e + print(u'data_type.py生成过程完成') + except Exception as e: + print(u'data_type.py生成过程出错') + print(e) if __name__ == '__main__': diff --git a/vnpy/api/ksgold/pyscript/generate_struct.py b/vnpy/api/ksgold/pyscript/generate_struct.py index df86652b..60f9662b 100644 --- a/vnpy/api/ksgold/pyscript/generate_struct.py +++ b/vnpy/api/ksgold/pyscript/generate_struct.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from ksgold_data_type import * @@ -47,7 +48,7 @@ def main(): n = line.index('//') line = line[:n] - print no, ':', line + print(no, ':', line) content = line.split('\t') diff --git a/vnpy/api/ksotp/__init__.py b/vnpy/api/ksotp/__init__.py index c4295cbe..d2d3e92f 100644 --- a/vnpy/api/ksotp/__init__.py +++ b/vnpy/api/ksotp/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 -from vnksotpmd import MdApi -from vnksotptd import TdApi -from ksotp_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnksotpmd import MdApi +from .vnksotptd import TdApi +from .ksotp_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/ksotp/pyscript/generate_data_type.py b/vnpy/api/ksotp/pyscript/generate_data_type.py index 58fb009d..a34f38a8 100644 --- a/vnpy/api/ksotp/pyscript/generate_data_type.py +++ b/vnpy/api/ksotp/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -88,9 +89,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/ksotp/pyscript/generate_struct.py b/vnpy/api/ksotp/pyscript/generate_struct.py index 1e71da16..4018e530 100644 --- a/vnpy/api/ksotp/pyscript/generate_struct.py +++ b/vnpy/api/ksotp/pyscript/generate_struct.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from ksotp_data_type import * @@ -15,7 +16,7 @@ def main(): fpy.write('\n') for n, line in enumerate(fcpp): - print n + print(n) # 结构体申明注释 if '///' in line and '\t' not in line: py_line = '#' + line[3:] @@ -38,8 +39,8 @@ def main(): try: type_ = typedefDict[typedef] except KeyError: - print content - print typedef + print(content) + print(typedef) variable = content[2].replace(';\n', "") py_line = '%s["%s"] = "%s"\n' % (name, variable, type_) diff --git a/vnpy/api/ksotp/vnksotpmd/test/mdtest.py b/vnpy/api/ksotp/vnksotpmd/test/mdtest.py index 81f3cea0..d071b51d 100644 --- a/vnpy/api/ksotp/vnksotpmd/test/mdtest.py +++ b/vnpy/api/ksotp/vnksotpmd/test/mdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -12,15 +13,15 @@ from vnksotpmd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -44,7 +45,7 @@ class TestMdApi(MdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log diff --git a/vnpy/api/ksotp/vnksotptd/test/tdtest.py b/vnpy/api/ksotp/vnksotptd/test/tdtest.py index 7a06c057..e2cb98ef 100644 --- a/vnpy/api/ksotp/vnksotptd/test/tdtest.py +++ b/vnpy/api/ksotp/vnksotptd/test/tdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -11,15 +12,15 @@ from vnksotptd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -43,7 +44,7 @@ class TestTdApi(TdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log @@ -89,8 +90,8 @@ class TestTdApi(TdApi): """查询合约回报""" print_dict(data) print_dict(error) - print n - print last + print(n) + print(last) #----------------------------------------------------------------------