Skip to content

Commit

Permalink
Assert that string parameters are to be bytestrings. Closes pika#105.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyg committed Aug 10, 2012
1 parent daac34d commit 4f5bbe9
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
6 changes: 6 additions & 0 deletions codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ def genSingleDecode(prefix, cLvalue, unresolved_domain):
def genSingleEncode(prefix, cValue, unresolved_domain):
type = spec.resolveDomain(unresolved_domain)
if type == 'shortstr':
print prefix + \
"assert isinstance(%s, str), 'A non-bytestring value was supplied for %s'" \
% (cValue, cValue)
print prefix + "pieces.append(struct.pack('B', len(%s)))" % cValue
print prefix + "pieces.append(%s)" % cValue
elif type == 'longstr':
print prefix + \
"assert isinstance(%s, str), 'A non-bytestring value was supplied for %s'" \
% (cValue, cValue)
print prefix + "pieces.append(struct.pack('>I', len(%s)))" % cValue
print prefix + "pieces.append(%s)" % cValue
elif type == 'octet':
Expand Down
Loading

0 comments on commit 4f5bbe9

Please sign in to comment.