Skip to content

Commit

Permalink
add jinja template and many other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
heikoschmidt committed Mar 8, 2024
1 parent 86df6e4 commit d2ade63
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/pypacer/helpers.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions src/pypacer/helpers_test.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions src/pypacer/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function FindProxyForURL(url, host) {
host = host.toLowerCase();
// at this point they are placed exclusions
return "{{ default }}";
}

0 comments on commit d2ade63

Please sign in to comment.