Skip to content

Instantly share code, notes, and snippets.

@okal
Last active February 12, 2018 21:33
Show Gist options
  • Save okal/e2b591830f7e029102d574a2246946c4 to your computer and use it in GitHub Desktop.
Save okal/e2b591830f7e029102d574a2246946c4 to your computer and use it in GitHub Desktop.
Static Analysis Adventures in Python
class Welcome(Handler):
def handle(self, request):
if request.user.is_logged_in:
return request.redirect('Feed')
else:
return request.redirect('SignIn')
class SignIn(Handler):
/* Do stuff here */
next_handler = 'Feed'
class Feed(Handler):
def handle(self, request):
self.display("What's happening")
self.quit()
class LegacySignIn(Handler):
def handle(self, request):
if request.user.has_active_subscription:
return request.redirect('LegacyFeed')
else:
self.display('Please supply your credentials')
class LegacyFeed(Handler):
def handle(self, request):
self.display("What happened back then")
self.quit()
class SomeUtilityClass:
def do_useful_stuff(self):
return self.done()
from ast import parse
def is_handler(ast_node):
# implement introspection
def get_ast(file_path):
with open(file_path) as source_file:
source = source_file.read()
tree = ast.parse(source).body
return tree
def get_handler_nodes(tree):
return filter(is_handler, tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment