Skip to content

Commit

Permalink
Merge pull request #60 from BoboTiG/fix-warning-U-mode-py3
Browse files Browse the repository at this point in the history
Fix DeprecationWarning: 'U' mode is deprecated in Python 3
  • Loading branch information
eliben committed Jan 4, 2021
2 parents fef3066 + c39058d commit 4c26b9d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions psslib/driver.py
Expand Up @@ -13,7 +13,7 @@
from .contentmatcher import ContentMatcher
from .defaultpssoutputformatter import DefaultPssOutputFormatter
from .utils import istextfile
from .py3compat import str2bytes
from .py3compat import PY3, str2bytes

TypeSpec = collections.namedtuple('TypeSpec', ['extensions', 'patterns'])

Expand Down Expand Up @@ -299,11 +299,13 @@ def pss_run(roots,
if universal_newlines:
if pattern is None:
pattern = ''
openmode = 'r' if PY3 else 'rU'
else:
if pattern is None:
pattern = b''
else:
pattern = str2bytes(pattern)
openmode = 'rb'

if ( not ignore_case and
(smart_case and not _pattern_has_uppercase(pattern))):
Expand Down Expand Up @@ -337,7 +339,6 @@ def pss_run(roots,
# full work.
#
try:
openmode = 'rU' if universal_newlines else 'rb'
with open(filepath, openmode) as fileobj:
if not istextfile(fileobj):
# istextfile does some reading on fileobj, so rewind it
Expand Down

0 comments on commit 4c26b9d

Please sign in to comment.