-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add custom template option #41
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,10 @@ def take_arguments(): | |
help="Interactive mode: read raw HTTP request from keyboard.") | ||
parser.add_argument( | ||
'--data', '-d', | ||
help='Add the data that you want to send along with the header') | ||
help='Add the data that you want to send along with the header.') | ||
parser.add_argument( | ||
'--custom-template', '-t', | ||
help='Add the path of the custom template you want to provide.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid 'you'. Keep it broad like "Specify path for custom templates." |
||
request_group.add_argument( | ||
'--request', '-r', | ||
help='Input the HTTP request') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
from importlib import import_module | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you move that import after? |
||
import os | ||
import re | ||
import sys | ||
|
||
|
||
# Blindy copied from: https://gist.github.com/mnordhoff/2213179 | ||
|
@@ -7,3 +10,15 @@ | |
re_ipv6_address = re.compile('^(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\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9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){,6}[0-9A-Fa-f]{1,4})?::)$') | ||
# Homebrew | ||
re_domain = re.compile(r'^(?:(?:[A-Z](?:[A-Z-]{0,61}[A-Z])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|)$', re.IGNORECASE) | ||
|
||
DEFAULT_CUSTOM_TEMPLATE_PATH = os.environ.get('DEFAULT_CUSTOM_TEMPLATE_PATH', '~/.config/translator/templates') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point we will need to implement a configuration file for the project. Maybe for later? Should we create an issue for that and add some TODO here like: # TODO: Move it to configuration file (See issue #xxx) What do you think? |
||
DEFAULT_CUSTOM_TEMPLATE_PATH = DEFAULT_CUSTOM_TEMPLATE_PATH.replace('~', os.environ.get('HOME', '')) | ||
|
||
|
||
def exists_global_custom_template(language): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the name of that function. Could you add a docstring as well? |
||
return os.path.exists(os.path.join(DEFAULT_CUSTOM_TEMPLATE_PATH, "{}.py".format(language))) | ||
|
||
|
||
def get_global_custom_template(language): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the name of that function. Could you add a docstring as well for this one? |
||
sys.path.insert(0, DEFAULT_CUSTOM_TEMPLATE_PATH) | ||
return import_module(language) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if there is an exception because of a dodgy template? |
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.
You should add proper name for the custom template option ;)