<s> import dateutil . parser , datetime <EOL> from bson . objectid import ObjectId <EOL> from gluon . custom_import import track_changes <EOL> from oauth import OAuth2 <EOL> from oauth . storage import web2pyStorage as storage <EOL> from oauth . exceptions import * <EOL> track_changes ( True ) <EOL> CODES = { '<STR_LIT>' : <NUM_LIT:200> } <EOL> MESSAGES = { '<STR_LIT>' : '<STR_LIT:success>' } <EOL> def validate_access_token ( f ) : <EOL> """<STR_LIT>""" <EOL> from oauth . storage import web2pyStorage as storage <EOL> storage = storage ( ) <EOL> storage . connect ( ) <EOL> oauth = OAuth2 ( storage ) <EOL> response . headers [ '<STR_LIT:Content-Type>' ] = json_headers ( ) <EOL> response . view = json_service ( ) <EOL> header = request . env [ '<STR_LIT>' ] <EOL> token = oauth . validate_access_params ( request . get_vars , request . post_vars , <EOL> header ) <EOL> return f <EOL> def parse_to_date ( default , arg ) : <EOL> try : <EOL> if default : <EOL> return dateutil . parser . parse ( default ) if not arg else dateutil . parser . parse ( arg ) <EOL> else : <EOL> return None if not arg else dateutil . parser . parse ( arg ) <EOL> except ValueError : <EOL> return default <EOL> def json_service ( ) : <EOL> return '<STR_LIT>' <EOL> def json_headers ( ) : <EOL> return '<STR_LIT>' <EOL> def encode_model ( obj , recursive = False ) : <EOL> if obj is None : <EOL> return obj <EOL> import bson <EOL> import datetime <EOL> if isinstance ( obj , ( int , float , basestring ) ) : <EOL> out = obj <EOL> elif isinstance ( obj , list ) : <EOL> out = [ encode_model ( item ) for item in obj ] <EOL> elif isinstance ( obj , dict ) : <EOL> out = dict ( [ ( k , encode_model ( v ) ) for ( k , v ) in obj . items ( ) ] ) <EOL> elif isinstance ( obj , ( datetime . datetime , datetime . timedelta ) ) : <EOL> out = str ( obj ) <EOL> elif isinstance ( obj , bson . objectid . ObjectId ) : <EOL> out = { '<STR_LIT>' : str ( obj ) } <EOL> else : <EOL> raise NameError ( "<STR_LIT>" % ( type ( obj ) , str ( obj ) ) ) <EOL> return out </s>
