Skip to content

Instantly share code, notes, and snippets.

@leeclemens
Created July 25, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeclemens/ea5d8bc737819bc9dd0e to your computer and use it in GitHub Desktop.
Save leeclemens/ea5d8bc737819bc9dd0e to your computer and use it in GitHub Desktop.
import dis
class CSPROTO_CLASS(object):
EMPTY = b""
CLOSE = b"<F2B_CLOSE_COMMAND>"
END = b"<F2B_END_COMMAND>"
CLOSE_END = CLOSE + END
class dotdict(dict):
def __getattr__(self, name):
return self[name]
CSPROTO_DOTDICT = dotdict({
"EMPTY": b"",
"END": b"<F2B_END_COMMAND>",
"CLOSE": b"<F2B_CLOSE_COMMAND>"
})
def getter_for_class():
return CSPROTO_CLASS.CLOSE_END
def getter_for_dict():
return CSPROTO_DOTDICT.CLOSE + CSPROTO_DOTDICT.END
dis.dis(getter_for_class)
print("-----------------------------")
dis.dis(getter_for_dict)
"""
24 0 LOAD_GLOBAL 0 (CSPROTO_CLASS)
3 LOAD_ATTR 1 (CLOSE_END)
6 RETURN_VALUE
-----------------------------
28 0 LOAD_GLOBAL 0 (CSPROTO_DOTDICT)
3 LOAD_ATTR 1 (CLOSE)
6 LOAD_GLOBAL 0 (CSPROTO_DOTDICT)
9 LOAD_ATTR 2 (END)
12 BINARY_ADD
13 RETURN_VALUE
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment