<s> import rsa <EOL> from base64 import b64decode <EOL> from flask import Blueprint , request , jsonify <EOL> from utils import has_uuid , Error <EOL> from models import Gcm <EOL> from shared import db <EOL> gcm = Blueprint ( '<STR_LIT>' , __name__ ) <EOL> @ gcm . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" ] ) <EOL> @ has_uuid <EOL> def gcm_register ( client ) : <EOL> registration = request . form . get ( '<STR_LIT>' , False ) or request . form . get ( '<STR_LIT>' , False ) <EOL> pubkey_b64 = request . form . get ( '<STR_LIT>' , None ) <EOL> if pubkey_b64 : <EOL> try : <EOL> rsa . PublicKey . load_pkcs1 ( b64decode ( pubkey_b64 ) , '<STR_LIT>' ) <EOL> except : <EOL> return jsonify ( Error . INVALID_PUBKEY ) <EOL> if not registration : <EOL> return Error . ARGUMENT_MISSING ( '<STR_LIT>' ) <EOL> regs = Gcm . query . filter_by ( uuid = client ) . all ( ) <EOL> for u in regs : <EOL> db . session . delete ( u ) <EOL> reg = Gcm ( client , registration , pubkey_b64 ) <EOL> db . session . add ( reg ) <EOL> db . session . commit ( ) <EOL> return jsonify ( Error . NONE ) <EOL> @ gcm . route ( "<STR_LIT>" , methods = [ "<STR_LIT>" ] ) <EOL> @ has_uuid <EOL> def gcm_unregister ( client ) : <EOL> regs = Gcm . query . filter_by ( uuid = client ) . all ( ) <EOL> for u in regs : <EOL> db . session . delete ( u ) <EOL> db . session . commit ( ) <EOL> return jsonify ( Error . NONE ) </s>
