Properly miss when the web api returns 404

main
kaiyou 6 years ago committed by Alexander Graf
parent d2b98ae323
commit 814bb1f36d
No known key found for this signature in database
GPG Key ID: B8A9DC143E075629

@ -81,11 +81,10 @@ class DictProtocol(asyncio.Protocol):
logging.debug("Looking up {}".format(key)) logging.debug("Looking up {}".format(key))
# Priv and shared keys are handled slighlty differently # Priv and shared keys are handled slighlty differently
key_type, key = key.decode("utf8").split("/", 1) key_type, key = key.decode("utf8").split("/", 1)
result = await self.dict.get( try:
key, ns=(self.user if key_type == "priv" else None) result = await self.dict.get(
) key, ns=(self.user if key_type == "priv" else None)
# Handle various response types )
if result is not None:
if type(result) is str: if type(result) is str:
response = result.encode("utf8") response = result.encode("utf8")
elif type(result) is bytes: elif type(result) is bytes:
@ -93,7 +92,7 @@ class DictProtocol(asyncio.Protocol):
else: else:
response = json.dumps(result).encode("ascii") response = json.dumps(result).encode("ascii")
return self.reply(b"O", response) return self.reply(b"O", response)
else: except KeyError:
return self.reply(b"N") return self.reply(b"N")
def process_begin(self, transaction_id): def process_begin(self, transaction_id):

@ -58,6 +58,7 @@ class NetstringProtocol(asyncio.Protocol):
def send_string(self, string): def send_string(self, string):
""" Send a netstring """ Send a netstring
""" """
logging.debug("Replying {}".format(string))
self.transport.write(str(len(string)).encode('ascii')) self.transport.write(str(len(string)).encode('ascii'))
self.transport.write(b':') self.transport.write(b':')
self.transport.write(string) self.transport.write(string)
@ -85,6 +86,7 @@ class SocketmapProtocol(NetstringProtocol):
def string_received(self, string): def string_received(self, string):
# The postfix format contains a space for separating the map name and # The postfix format contains a space for separating the map name and
# the key # the key
logging.debug("Received {}".format(string))
space = string.find(0x20) space = string.find(0x20)
if space != -1: if space != -1:
name = string[:space].decode('ascii') name = string[:space].decode('ascii')

@ -28,6 +28,10 @@ class UrlTable(object):
result = await request.json() result = await request.json()
logging.debug("Table get {} is {}".format(key, result)) logging.debug("Table get {} is {}".format(key, result))
return result return result
elif request.status == 404:
raise KeyError()
else:
raise Exception(request.status)
async def set(self, key, value, ns=None): async def set(self, key, value, ns=None):
""" Set a value for the given key in the provided namespace """ Set a value for the given key in the provided namespace

@ -7,7 +7,7 @@ with open("README.md", "r") as fh:
setup( setup(
name="podop", name="podop",
version="0.2.2", version="0.2.3",
description="Postfix and Dovecot proxy", description="Postfix and Dovecot proxy",
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",

Loading…
Cancel
Save