Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def writeField(self, field):
self.transport.write(str(field) + self.delimiter)
def writeFields(self, fields):
assert fields, 'Cannot write zero count fields.'
self.transport.write(self.delimiter.join(map(str, fields)) + self.delimiter)
def writeMessage(self, msg):
self.transport.write(msg)
ZMQ_OK_RESPONSE = 'OK'
ZMQ_ERR_RESPONSE = 'ERR'
ZMQ_OOB_PREFIX = 'OOB'
class ZmqRequests(ZmqREPConnection):
_twsprotocol = None
def setTWSProtocol(self, protocol):
self._twsprotocol = protocol
def gotMessage(self, messageid, msg):
# Handle OOB messages.
if msg.startswith(ZMQ_OOB_PREFIX + '\0'):
fields = msg.split('\0')
if fields[1] == 'NOP':
log.debug('Sending NOP response.')
self.reply_ok(messageid)
else:
log.error('Unrecognized out-of-band message {0}.'.format(msg))
self.reply_err(messageid)
else:
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from txzmq import ZmqFactory, ZmqEndpoint, ZmqEndpointType, ZmqREPConnection
import logging
import json
import time
import sqlite3
from util import Identity
import qasino_table
class ZmqReceiver(ZmqREPConnection):
def __init__(self, port, zmq_factory, data_manager):
self.data_manager = data_manager
endpoint = ZmqEndpoint(ZmqEndpointType.bind, "tcp://*:%d" % port)
ZmqREPConnection.__init__(self, zmq_factory, endpoint)
def gotMessage(self, messageId, *messageParts):
try:
obj = json.loads(messageParts[0])
except Exception as e:
logging.info("ZmqReceiver: ERROR failed to get/parse content of POST: %s", str(e))
response_meta = { "response_op" : "error", "error_message" : "Failed to parse JSON message: %s" % str(e), "identity" : Identity.get_identity() }
def __init__(self, core):
self._core = core
def startService(self):
zf = ZmqFactory()
e = ZmqEndpoint(ZmqEndpointType.bind, ENDPOINT)
self._conn = _DispatcherREPConnection(zf, e, self._core)
reactor.callWhenRunning(self._conn.do_greet)
service.Service.startService(self)
def stopService(self):
service.Service.stopService(self)
class _DispatcherREPConnection(ZmqREPConnection):
def __init__(self, zf, e, core):
ZmqREPConnection.__init__(self, zf, e)
self.dispatcher = CommandDispatcher(core)
def gotMessage(self, msgId, *parts):
r = self.dispatcher.dispatch(parts)
r.addCallback(self.defer_reply, msgId)
def defer_reply(self, response, msgId):
reactor.callLater(0, self.reply, msgId, str(response))
def log_err(self, failure, msgId):
log.failure('Error on dispatcher')
self.defer_reply("ERROR: %r" % failure, msgId)