def xsrf_required(method):
 def xsrf_required_decorator(self):
  expected_token = get_xsrf_token()
  actual_token = self.request.get('xsrf_token')
  if (actual_token != expected_token):
   self.response.set_status(403, 'Invalid XSRF token')
   self.response.out.write((('<h1>Invalid XSRF token</h1>\n' + '<p>Please reload the form page</n>\n') + (' ' * 512)))
  else:
   method(self)
 return xsrf_required_decorator

def xsrf_required ( method ) : def xsrf_required_decorator ( self ) : expected_token = get_xsrf_token ( ) actual_token = self . request . get ( 'xsrf_token' ) if ( actual_token != expected_token ) : self . response . set_status ( 403 , 'Invalid XSRF token' ) self . response . out . write ( ( ( '<h1>Invalid XSRF token</h1>\n' + '<p>Please reload the form page</n>\n' ) + ( ' ' * 512 ) ) ) else : method ( self ) return xsrf_required_decorator
decorator to protect post() handlers against xsrf attacks .