-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add jinja template and many other improvements
- Loading branch information
heikoschmidt
committed
Mar 8, 2024
1 parent
86df6e4
commit d2ade63
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}"; | ||
} |