diff --git a/src/pypacer/helpers.py b/src/pypacer/helpers.py new file mode 100644 index 0000000..2ca8c67 --- /dev/null +++ b/src/pypacer/helpers.py @@ -0,0 +1,22 @@ +import os +import re +from enum import Enum + +location = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) + + +class TargetType(Enum): + IP_MASK = 1 # isInNet + IP = 2 + HOST = 3 # for localHostOrDomainIs + HOSTS = 4 # for dnsDomainIs + + +def get_target_type(target: str) -> TargetType: + if re.fullmatch(r"[0-9.]+", target): + return TargetType.IP + elif re.fullmatch(r"[0-9./]+", target): + return TargetType.IP_MASK + elif target.startswith("."): + return TargetType.HOSTS + return TargetType.HOST diff --git a/src/pypacer/helpers_test.py b/src/pypacer/helpers_test.py new file mode 100644 index 0000000..f2e786c --- /dev/null +++ b/src/pypacer/helpers_test.py @@ -0,0 +1,18 @@ +import unittest + +from pypacer.helpers import get_target_type, TargetType + + +class TestHelpers(unittest.TestCase): + + def test_target_type_ip_mask(self): + self.assertEqual(get_target_type("127.0.0.0/24"), TargetType.IP_MASK) + + def test_target_type_ip(self): + self.assertEqual(get_target_type("127.0.0.1"), TargetType.IP) + + def test_target_type_hosts(self): + self.assertEqual(get_target_type(".example.com"), TargetType.HOSTS) + + def test_target_type_host(self): + self.assertEqual(get_target_type("example.com"), TargetType.HOST) diff --git a/src/pypacer/template.js b/src/pypacer/template.js new file mode 100644 index 0000000..fef6745 --- /dev/null +++ b/src/pypacer/template.js @@ -0,0 +1,5 @@ +function FindProxyForURL(url, host) { + host = host.toLowerCase(); + // at this point they are placed exclusions + return "{{ default }}"; +}