diff --git a/app/corpora/CQiWrapper/CQi.py b/app/corpora/CQiWrapper/CQi.py
index 88a57fff..30896494 100644
--- a/app/corpora/CQiWrapper/CQi.py
+++ b/app/corpora/CQiWrapper/CQi.py
@@ -1,16 +1,16 @@
-# ########################################################################### #
-# IMS CQi specification #
-# #
-# Version: 0.1a ;o) #
-# Author: Stefan Evert (evert@ims.uni-stuttgart.de) #
-# Modified by: Patrick Jentsch
#
-# ########################################################################### #
from time import sleep
import socket
import struct
+# ########################################################################### #
+# IMS CQi specification #
+# #
+# Version: 0.1a ;o) #
+# Author: Stefan Evert (evert@ims.uni-stuttgart.de) #
+# Modified by (codestyle): Patrick Jentsch (p.jentsch@uni-bielefeld.de) #
+# Modified date: Thurs Oct 10 #
+# ########################################################################### #
""" 1. padding """
PAD = 0x00
@@ -409,13 +409,24 @@ lookup = {
}
-class Client:
- def __init__(self, host='127.0.0.1', port=4877):
+# ########################################################################### #
+# IMS CQi client #
+# #
+# Version: 0.1a #
+# Author: Patrick Jentsch (p.jentsch@uni-bielefeld.de) #
+# ########################################################################### #
+class APIClient:
+ def __init__(self, host, port=4877):
self.host = host
self.port = port
self.socket = socket.socket()
+
+ def setup(self):
self.socket.connect((self.host, self.port))
+ def teardown(self):
+ self.socket.close()
+
def ctrl_connect(self, username, password):
# INPUT: (STRING username, STRING password)
# OUTPUT: CQI_STATUS_CONNECT_OK, CQI_ERROR_CONNECT_REFUSED
diff --git a/app/corpora/CQiWrapper/CQiWrapper.py b/app/corpora/CQiWrapper/CQiWrapper.py
index dcd5d8f0..981c0e3c 100644
--- a/app/corpora/CQiWrapper/CQiWrapper.py
+++ b/app/corpora/CQiWrapper/CQiWrapper.py
@@ -3,7 +3,7 @@ from . import CQi
import time
-class CQiWrapper(CQi.Client):
+class CQiWrapper(CQi.APIClient):
'''
CQIiWrapper object
@@ -21,7 +21,7 @@ class CQiWrapper(CQi.Client):
def __init__(self, host='127.0.0.1', port=4877, username='anonymous',
password=''):
- super(CQiWrapper, self).__init__(host=host, port=port)
+ super(CQiWrapper, self).__init__(host, port=port)
self.username = username
self.password = password
@@ -32,6 +32,7 @@ class CQiWrapper(CQi.Client):
Connects via socket to the CQP server using the given username and
password from class initiation.
'''
+ super(CQiWrapper, self).setup()
self.ctrl_connect(self.username, self.password)
def __create_attribute_strings(self):
@@ -78,7 +79,7 @@ class CQiWrapper(CQi.Client):
Disconnects from the CQP server. Closes used socket after disconnect.
'''
self.ctrl_bye()
- self.connection.close()
+ super(CQiWrapper, self).teardown()
logger.warning('Disconnected from cqp server.')
def query_subcorpus(self, query, result_subcorpus_name='Query-results'):