]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
add regexes to idlib to match certain kinds of base32-encoded values
authorZooko O'Whielacronx <zooko@zooko.com>
Thu, 3 Jan 2008 23:44:46 +0000 (16:44 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Thu, 3 Jan 2008 23:44:46 +0000 (16:44 -0700)
src/allmydata/util/idlib.py

index 8432f5801d3e3cf3224d645c7e8d67c8a3486385..202f1c272ed379b76e7ea824b61a28a58febbc57 100644 (file)
@@ -34,6 +34,17 @@ def get_trailing_chars_without_lsbs(N):
     d = {}
     return ''.join(_get_trailing_chars_without_lsbs(N, d=d))
 
+ZBASE32CHAR = '['+get_trailing_chars_without_lsbs(0)+']'
+ZBASE32CHAR_4bits = '['+get_trailing_chars_without_lsbs(1)+']'
+ZBASE32CHAR_3bits = '['+get_trailing_chars_without_lsbs(2)+']'
+ZBASE32CHAR_2bits = '['+get_trailing_chars_without_lsbs(3)+']'
+ZBASE32CHAR_1bits = '['+get_trailing_chars_without_lsbs(4)+']'
+ZBASE32STR_1byte = ZBASE32CHAR+ZBASE32CHAR_3bits
+ZBASE32STR_2bytes = ZBASE32CHAR+'{3}'+ZBASE32CHAR_1bits
+ZBASE32STR_3bytes = ZBASE32CHAR+'{4}'+ZBASE32CHAR_4bits
+ZBASE32STR_4bytes = ZBASE32CHAR+'{6}'+ZBASE32CHAR_2bits
+ZBASE32STR_anybytes = '((?:%s{8})*' % (ZBASE32CHAR,) + "(?:|%s|%s|%s|%s))" % (ZBASE32STR_1byte, ZBASE32STR_2bytes, ZBASE32STR_3bytes, ZBASE32STR_4bytes)
+
 def b2a(os):
     """
     @param os the data to be encoded (a string)