Last active
February 12, 2018 21:33
-
-
Save okal/e2b591830f7e029102d574a2246946c4 to your computer and use it in GitHub Desktop.
Static Analysis Adventures in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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