#NEWLINE# def __init__( self , address , generate = True , override_quota = False ) : #NEWLINE# #INDENT# self . address = address #NEWLINE# if generate : #NEWLINE# #INDENT# self . token = memcache . get ( ( 'token_%s' % self . address ) ) #NEWLINE# if ( self . token is None ) : #NEWLINE# #INDENT# device = models . getDevice ( self . address ) #NEWLINE# if ( device . token and device . tokenValid ( ) ) : #NEWLINE# #INDENT# self . token = device . token #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( models . getQuota ( ) . amount > models . getStats ( 'channels' ) . count ) or override_quota ) : #NEWLINE# #INDENT# self . token = channel . create_channel ( self . address ) #NEWLINE# stats . record ( 'channel_created' , simplejson . dumps ( { #NEWLINE# #INDENT# 'channel' : device . address , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# self . cached = False #NEWLINE# device . updateToken ( self . token ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise OverQuotaError ( ) #NEWLINE# return False #NEWLINE# #UNINDENT# #UNINDENT# memcache . set ( ( 'token_%s' % self . address ) , self . token , time = 7200 )