Added os.path.expanduser() before open() calls with user supplied paths

This commit is contained in:
Matt Weidner 2017-07-22 12:30:15 -05:00
parent 05db6e32c7
commit a2da9b6c02
4 changed files with 4 additions and 1 deletions

View File

@ -518,6 +518,7 @@ def save(opts, path, defaults=False):
Raises OptionsError if the existing data is corrupt.
"""
path = os.path.expanduser(path)
if os.path.exists(path) and os.path.isfile(path):
with open(path, "rt", encoding="utf8") as f:
try:

View File

@ -75,7 +75,7 @@ class RandomGenerator:
class FileGenerator:
def __init__(self, path):
self.path = path
self.path = os.path.expanduser(path)
def __len__(self):
return os.path.getsize(self.path)

View File

@ -208,6 +208,7 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
reqs = []
for r in args.requests:
r = os.path.expanduser(r)
if os.path.isfile(r):
with open(r) as f:
r = f.read()

View File

@ -215,6 +215,7 @@ def args_pathod(argv, stdout_=sys.stdout, stderr_=sys.stderr):
anchors = []
for patt, spec in args.anchors:
spec = os.path.expanduser(spec)
if os.path.isfile(spec):
with open(spec) as f:
data = f.read()