-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding lambda support #3
base: master
Are you sure you want to change the base?
Conversation
moxy.py
Outdated
if index != -1: | ||
replace_lambda_value = lambda_with_args(replace_lambda_value, index) | ||
try: | ||
code_object = compile(replace_lambda_value, "<lambda>", "eval") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these compiled lambdas should be cached like compiled regexes are? Also, several lines of duplicated code between replace_lambda_in_dict
and replace_lambda_in_content
, maybe move to a function called by both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great feedback, I will refactor accordingly.
moxy.py
Outdated
- An object (such as a dictionary) that can be dumped as JSON, in which case | ||
it is converted to JSON. | ||
""" | ||
content_type = "application/json" | ||
if isinstance(content, str): | ||
try: | ||
with open(content, "rb") as content_file: | ||
if content.endswith("html"): | ||
if content.endswith(".html"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lack of .
was actually intentional to cover xhtml
, shtml
and such variants, but TBH probably not much of an issue in practice, and xhtml
might need its own type anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context; I'll go ahead and revert this.
I wanted to perform a string substitution that could be more dynamic than what was already supported, so I added support for using lambda functions as replacement arguments.
While implementing my changes, I also made a slight modification to
encode_content
to better handle content passed to it and removed themitmproxy
net
import since it is not necessary since this commit.