Skip to content

Commit

Permalink
deal with binary delivery tags
Browse files Browse the repository at this point in the history
  • Loading branch information
rhs committed Aug 10, 2011
1 parent 91dfa06 commit 4d6b026
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions filerecv
Expand Up @@ -66,14 +66,23 @@ dir = args[1]
def path(f):
return os.path.join(dir, f)

def HEX(tag):
return "".join(["%02x" % ord(c) for c in tag])
def BIN(tag):
result = ""
while tag:
result += chr(int(tag[:2], 16))
tag = tag[2:]
return result

files = [f for f in os.listdir(dir) if os.path.isfile(path(f))]

unsettled = {}
bytag = {}
for f in files:
if f.endswith(SFX):
name, tag = f.split(":")
tag = tag[:-len(SFX)]
tag = BIN(tag[:-len(SFX)])
unsettled[tag] = ACCEPTED
bytag[tag] = os.path.join(dir, f), name

Expand Down Expand Up @@ -102,7 +111,8 @@ while lnk.pending(block=True):
filename = msg["filename"]
print "RECEIVED", filename
sys.stdout.flush()
tmpname = os.path.join(dir, "%s:%s%s" % (filename, msg.delivery_tag, SFX))
tmpname = os.path.join(dir, "%s:%s%s" % (filename, HEX(msg.delivery_tag),
SFX))
f = open(tmpname, "write")
f.write(msg.content)
f.close()
Expand Down

0 comments on commit 4d6b026

Please sign in to comment.