Skip to content

Commit

Permalink
Merge pull request #69 from carsonyl/isinnet-bool
Browse files Browse the repository at this point in the history
Handle isInNet() being given non-str args.
  • Loading branch information
carsonyl committed Mar 27, 2023
2 parents 0e403cd + 2290c7c commit 13856db
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 37 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, '3.10', 3.11]
python-version: [2.7, 3.7, 3.8, 3.9, '3.10', 3.11]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dukpy for Windows Python 2.7
if: matrix.os == 'windows-latest' && matrix.python-version == '2.7'
# Pin to final release that still published Python 2.7 binary wheels
run: pip install dukpy==0.2.3
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
Expand Down
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.16.2 (2023-03-26)
-------------------

- Handle boolean args to ``isInNet()``. (#69)
- Remove Python 3.5, 3.6 from CIB test matrix.
- Windows Python 2.7 CIB: Pin to dukpy 0.2.3.


0.16.1 (2022-11-08)
-------------------

Expand Down
57 changes: 31 additions & 26 deletions pypac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
"""
PyPAC: Proxy auto-config for Python
===================================
Copyright 2018 Carson Lam
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from pypac.api import get_pac, collect_pac_urls, download_pac, PACSession, pac_context_for_url


__version__ = "0.16.1"


__all__ = ["get_pac", "collect_pac_urls", "download_pac", "PACSession", "pac_context_for_url"]
"""
PyPAC: Proxy auto-config for Python
===================================
Copyright 2018 Carson Lam
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from pypac.api import (
PACSession,
collect_pac_urls,
download_pac,
get_pac,
pac_context_for_url,
)

__version__ = "0.16.2"


__all__ = ["get_pac", "collect_pac_urls", "download_pac", "PACSession", "pac_context_for_url"]
3 changes: 3 additions & 0 deletions pypac/parser_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def isInNet(host, pattern, mask):
:returns: True iff the IP address of the host matches the specified IP address pattern.
:rtype: bool
"""
host = str(host)
pattern = str(pattern)
mask = str(mask)
host_ip = host if is_ipv4_address(host) else dnsResolve(host)
if not host_ip or not is_ipv4_address(pattern) or not is_ipv4_address(mask):
return False
Expand Down
22 changes: 12 additions & 10 deletions tests/test_parser_functions.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import pytest
from datetime import datetime

import pytest

try:
from unittest.mock import patch
except ImportError:
from mock import patch
from mock import patch # noqa

from pypac.parser_functions import (
alert,
dateRange,
dnsDomainIs,
isResolvable,
isInNet,
dnsResolve,
dnsDomainLevels,
weekdayRange,
myIpAddress,
dnsResolve,
isInNet,
isPlainHostName,
isResolvable,
localHostOrDomainIs,
myIpAddress,
shExpMatch,
timeRange,
localHostOrDomainIs,
dateRange,
alert,
weekdayRange,
)


Expand Down Expand Up @@ -55,6 +56,7 @@ def test_isResolvable(host, expected_value):
("192.168.1.100", "192.168.2.0", "255.255.255.0", False),
("google.com", "0.0.0.0", "0.0.0.0", True),
("google.com", "google.com", "foo", False),
(False, False, False, False),
],
)
def test_isInNet(host, pattern, mask, expected_value):
Expand Down

0 comments on commit 13856db

Please sign in to comment.