Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle isInNet() being given non-str args. #69

Merged
merged 5 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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