Skip to content

Commit

Permalink
Issue #55: mult operator (*) in argument proxies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Oct 13, 2018
1 parent a8ba9a7 commit d320086
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dirhunt/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from dirhunt.exceptions import DirHuntError, catch
from dirhunt.output import output_urls
from dirhunt.sources import SOURCE_CLASSES, get_source_name
from dirhunt.utils import lrange, catch_keyboard_interrupt, force_url, read_file_lines, value_is_file_path, flat_list
from dirhunt.utils import lrange, catch_keyboard_interrupt, force_url, read_file_lines, value_is_file_path, flat_list, \
multiplier_args
from colorama import init

init(autoreset=True)
Expand Down Expand Up @@ -134,6 +135,7 @@ def hunt(urls, threads, exclude_flags, include_flags, interesting_extensions, in
raise BadOptionUsage('--exclude-flags and --include-flags are mutually exclusive.')
welcome()
urls = flat_list(urls)
proxies = multiplier_args(proxies)
if not urls:
click.echo('•_•) OOPS! Add urls to analyze.\nFor example: dirhunt http://domain/path\n\n'
'Need help? Then use dirhunt --help', err=True)
Expand Down
13 changes: 12 additions & 1 deletion dirhunt/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests_mock

from dirhunt.tests._compat import patch, Mock
from dirhunt.utils import force_url, SCHEMES, catch_keyboard_interrupt, flat_list
from dirhunt.utils import force_url, SCHEMES, catch_keyboard_interrupt, flat_list, multiplier_args


class TestForceUrl(unittest.TestCase):
Expand Down Expand Up @@ -49,3 +49,14 @@ def test_without_sublists(self):

def test_with_sublists(self):
self.assertEqual(flat_list([1, [2, 3], 4]), [1, 2, 3, 4])


class TestMultiplierArgs(unittest.TestCase):
def test_without_multiplier(self):
self.assertEqual(multiplier_args(['foo', 'bar']), ['foo', 'bar'])

def test_multiplier(self):
self.assertEqual(multiplier_args(['foo', 'bar*3']), ['foo'] + (['bar'] * 3))

def test_invalid_multiplier(self):
self.assertEqual(multiplier_args(['foo', 'bar*spam']), ['foo', 'bar*spam'])
12 changes: 12 additions & 0 deletions dirhunt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

SCHEMES = ['http', 'https']
DEFAULT_SCHEME = 'http'
ARGUMENT_MULT = re.compile('(.+)\*(\d+)$')


def lrange(start, end):
Expand Down Expand Up @@ -89,3 +90,14 @@ def flat_list(values):
else:
items.append(value)
return items


def multiplier_arg(argument):
matchs = ARGUMENT_MULT.match(argument)
if matchs is None:
return argument
return [matchs.group(1)] * int(matchs.group(2))


def multiplier_args(arguments):
return flat_list([multiplier_arg(argument) for argument in arguments])

0 comments on commit d320086

Please sign in to comment.