<s> import logging <EOL> import os <EOL> import struct <EOL> from google . appengine . ext import webapp <EOL> from google . appengine . ext . webapp import util <EOL> import filestorage <EOL> class GetMessageNoncesByToken ( webapp . RequestHandler ) : <EOL> def post ( self ) : <EOL> minlen = <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:20> <EOL> STR_VERSERVER = '<STR_LIT>' <EOL> INT_VERCLIENT = <NUM_LIT> <EOL> STR_VERCLIENT = '<STR_LIT>' <EOL> if not os . environ . has_key ( '<STR_LIT>' ) : <EOL> self . resp_simple ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> return <EOL> if not os . environ . has_key ( '<STR_LIT>' ) : <EOL> self . resp_simple ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> return <EOL> HTTPS = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> CURRENT_VERSION_ID = os . environ . get ( '<STR_LIT>' , STR_VERSERVER ) <EOL> if HTTPS . __str__ ( ) != '<STR_LIT>' : <EOL> self . resp_simple ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> return <EOL> self . response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> data = self . request . body <EOL> size = str . __len__ ( data ) <EOL> if size < minlen : <EOL> logging . debug ( "<STR_LIT>" % data ) <EOL> logging . debug ( "<STR_LIT>" % size ) <EOL> self . resp_simple ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> return <EOL> client = ( struct . unpack ( "<STR_LIT>" , data [ <NUM_LIT:0> : <NUM_LIT:4> ] ) ) [ <NUM_LIT:0> ] <EOL> data = data [ <NUM_LIT:4> : ] <EOL> if client < INT_VERCLIENT : <EOL> self . resp_simple ( <NUM_LIT:0> , ( '<STR_LIT>' % STR_VERCLIENT ) ) <EOL> return <EOL> server = int ( CURRENT_VERSION_ID [ <NUM_LIT:0> : <NUM_LIT:8> ] , <NUM_LIT:16> ) <EOL> pos = <NUM_LIT:0> <EOL> lenrtok = ( struct . unpack ( "<STR_LIT>" , data [ pos : ( pos + <NUM_LIT:4> ) ] ) ) [ <NUM_LIT:0> ] <EOL> pos = pos + <NUM_LIT:4> <EOL> recipientToken = str ( data [ pos : ( pos + lenrtok ) ] ) <EOL> pos = pos + lenrtok <EOL> numquery = ( struct . unpack ( "<STR_LIT>" , data [ pos : ( pos + <NUM_LIT:4> ) ] ) ) [ <NUM_LIT:0> ] <EOL> pos = pos + <NUM_LIT:4> <EOL> query = filestorage . FileStorage . all ( ) <EOL> downloaded = False <EOL> query . filter ( '<STR_LIT>' , recipientToken ) . filter ( '<STR_LIT>' , downloaded ) <EOL> num = query . count ( ) <EOL> items = query . fetch ( num ) <EOL> lenArray = [ ] <EOL> nonceArray = [ ] <EOL> num = <NUM_LIT:0> <EOL> for item in items : <EOL> msgId = item . id <EOL> lenid = str . __len__ ( msgId ) <EOL> lenArray . append ( lenid ) <EOL> nonceArray . append ( msgId ) <EOL> num = num + <NUM_LIT:1> <EOL> if num == <NUM_LIT:0> : <EOL> self . response . out . write ( '<STR_LIT:%s>' % struct . pack ( '<STR_LIT>' , server ) ) <EOL> self . response . out . write ( '<STR_LIT:%s>' % ( struct . pack ( '<STR_LIT>' , <NUM_LIT:1> ) ) ) <EOL> self . response . out . write ( '<STR_LIT:%s>' % struct . pack ( '<STR_LIT>' , num ) ) <EOL> return <EOL> else : <EOL> self . response . out . write ( '<STR_LIT:%s>' % struct . pack ( '<STR_LIT>' , server ) ) <EOL> self . response . out . write ( '<STR_LIT:%s>' % ( struct . pack ( '<STR_LIT>' , <NUM_LIT:1> ) ) ) <EOL> self . response . out . write ( '<STR_LIT:%s>' % struct . pack ( '<STR_LIT>' , num ) ) <EOL> idx = <NUM_LIT:0> <EOL> for nonce in nonceArray : <EOL> self . response . out . write ( '<STR_LIT>' % ( struct . pack ( '<STR_LIT>' , lenArray [ idx ] ) , nonce ) ) <EOL> idx = idx + <NUM_LIT:1> <EOL> def resp_simple ( self , code , msg ) : <EOL> self . response . out . write ( '<STR_LIT>' % ( struct . pack ( '<STR_LIT>' , code ) , msg ) ) <EOL> if code == <NUM_LIT:0> : <EOL> logging . error ( msg ) <EOL> def main ( ) : <EOL> STR_VERSERVER = '<STR_LIT>' <EOL> CURRENT_VERSION_ID = os . environ . get ( '<STR_LIT>' , STR_VERSERVER ) <EOL> isProd = CURRENT_VERSION_ID [ <NUM_LIT:8> : <NUM_LIT:9> ] == '<STR_LIT:p>' <EOL> if isProd : <EOL> logging . getLogger ( ) . setLevel ( logging . INFO ) <EOL> else : <EOL> logging . getLogger ( ) . setLevel ( logging . DEBUG ) <EOL> application = webapp . WSGIApplication ( [ ( '<STR_LIT>' , GetMessageNoncesByToken ) ] , <EOL> debug = True ) <EOL> util . run_wsgi_app ( application ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
