Skip to content

Commit

Permalink
Support for passing filenames as Path objects
Browse files Browse the repository at this point in the history
Added support for passing filenames as Path objects.
  • Loading branch information
WouldYouKindly authored May 12, 2018
1 parent 2704344 commit 3863f98
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def tohex(data):
if sys.hexversion < 0x2070000:
memoryview = lambda x: x # noqa

try:
from pathlib import Path
_have_pathlib = True
except ImportError:
_have_pathlib = False

__version__ = '3.0'

# export only interesting items
Expand Down Expand Up @@ -655,7 +661,11 @@ def __init__(self, rarfile, mode="r", charset=None, info_callback=None,
Either "stop" to quietly stop parsing on errors,
or "strict" to raise errors. Default is "stop".
"""
self._rarfile = rarfile
if _have_pathlib and isinstance(rarfile, Path):
self._rarfile = str(rarfile)
else:
self._rarfile = rarfile

self._charset = charset or DEFAULT_CHARSET
self._info_callback = info_callback
self._crc_check = crc_check
Expand Down

0 comments on commit 3863f98

Please sign in to comment.