Skip to content

Commit

Permalink
Add SSL Cert verification parameter; version bump (#130)
Browse files Browse the repository at this point in the history
* Add SSL Cert verification parameter; version bump
* add full verify support
  • Loading branch information
barrust committed Jul 28, 2023
1 parent 6f95028 commit b326b64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,9 @@
# MediaWiki Changelog

## Future Release
## Version 0.7.3

* Add `unordered_options` to the `DisambiguationError` to attempt to get options in the order presented on the page; [issue #124](https://github.com/barrust/mediawiki/issues/124)
* Add [verify SSL support](https://requests.readthedocs.io/en/latest/user/advanced/#ssl-cert-verification) by passing info directly to the requests library.

## Version 0.7.2

Expand Down
20 changes: 19 additions & 1 deletion mediawiki/mediawiki.py
Expand Up @@ -25,7 +25,7 @@
from .utilities import memoize

URL = "https://github.com/barrust/mediawiki"
VERSION = "0.7.2"
VERSION = "0.7.3"


class MediaWiki(object):
Expand Down Expand Up @@ -67,6 +67,7 @@ class MediaWiki(object):
"_use_cache",
"_is_logged_in",
"_proxies",
"_verify_ssl",
]

def __init__(
Expand All @@ -81,6 +82,7 @@ def __init__(
username=None,
password=None,
proxies=None,
verify_ssl=True,
):
""" Init Function """
self._version = VERSION
Expand All @@ -94,6 +96,8 @@ def __init__(
self._session = None
self._user_agent = ("python-mediawiki/VERSION-{0}" "/({1})/BOT").format(VERSION, URL)
self._proxies = None
self._verify_ssl = None
self.verify_ssl = verify_ssl
# set libary parameters
if user_agent is not None:
self.user_agent = user_agent
Expand Down Expand Up @@ -227,6 +231,19 @@ def timeout(self, timeout):
return
self._timeout = float(timeout) # allow the exception to be raised

@property
def verify_ssl(self):
""" bool | str: Verify SSL when using requests or path to cert file """
return self._verify_ssl

@verify_ssl.setter
def verify_ssl(self, verify_ssl):
""" Set request verify SSL parameter; defaults to True if issue """
self._verify_ssl = True
if isinstance(verify_ssl, (bool, str)):
self._verify_ssl = verify_ssl
self._reset_session()

@property
def language(self):
""" str: The API URL language, if possible this will update the API \
Expand Down Expand Up @@ -403,6 +420,7 @@ def _reset_session(self):
self._session.headers.update(headers)
if self._proxies is not None:
self._session.proxies.update(self._proxies)
self._session.verify = self._verify_ssl
self._is_logged_in = False

def clear_memoized(self):
Expand Down

0 comments on commit b326b64

Please sign in to comment.