clean up ambiguous or sloppy use of . delimiter

workspace
Brendan Howell 8 years ago
parent 37f6c1cfc3
commit 85438784f8

@ -10,6 +10,7 @@ import textwrap
import threading
import time
import lmdb
import zmq
from mako.template import Template
@ -83,6 +84,16 @@ class Bureau(object):
self.config = configparser.ConfigParser()
self.load_config()
# setup a dir to store files and data
self.datadir = os.path.join(basepath, self.prefix)
if not os.path.exists(self.datadir):
os.mkdir(self.datadir)
# set up a basic key-value store with LMDB - max 10 sub-dbs
# if a bureau needs more then just import lmdb and roll your own
dbfile = os.path.join(self.datadir, self.prefix + ".lmdb")
self.dbenv = lmdb.open(dbfile, max_dbs=10)
self.context = zmq.Context()
self._recv = self.context.socket(zmq.REP)
self._recv.bind("ipc://" + self.prefix + ".ipc")
@ -112,7 +123,11 @@ class Bureau(object):
returns either empty string, text or a json object
"""
message += "."
# clean up for sloppy offices
message = message.strip()
if not message.endswith("."):
message += "."
if data:
message += json.dumps(data)
sender = self.context.socket(zmq.REQ)
@ -274,9 +289,12 @@ class Bureau(object):
time.sleep(0.05) # don't waste CPU
continue
try:
print("got message:", msg)
dot = msg.find(".")
ref = msg[:dot]
if (dot < len(msg) - 1) and (dot > 0):
print("msg length:", len(msg))
print("dot at", dot)
data = msg[dot + 1:]
else:
data = None

Loading…
Cancel
Save