From 74475e27c14d79ab2f040c2d33043e928ee1e802 Mon Sep 17 00:00:00 2001 From: Will Dean Date: Fri, 29 Oct 2021 08:34:11 -0500 Subject: [PATCH 1/2] support for pathlib object --- branca/element.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/branca/element.py b/branca/element.py index 36a661c..63e8315 100644 --- a/branca/element.py +++ b/branca/element.py @@ -14,6 +14,7 @@ from urllib.request import urlopen from binascii import hexlify from os import urandom +from pathlib import PosixPath from jinja2 import Environment, PackageLoader, Template @@ -159,7 +160,7 @@ def save(self, outfile, close_file=True, **kwargs): close_file : bool, default True Whether the file has to be closed after write. """ - if isinstance(outfile, str) or isinstance(outfile, bytes): + if isinstance(outfile, (str, bytes, PosixPath)): fid = open(outfile, 'wb') else: fid = outfile From d1fabd036eafb3a0d210adf80b59769376415233 Mon Sep 17 00:00:00 2001 From: Will Date: Mon, 14 Feb 2022 15:38:35 -0600 Subject: [PATCH 2/2] Path is the parent for Windows Path and non-Windows Path objects --- branca/element.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/branca/element.py b/branca/element.py index 63e8315..0924af4 100644 --- a/branca/element.py +++ b/branca/element.py @@ -14,7 +14,7 @@ from urllib.request import urlopen from binascii import hexlify from os import urandom -from pathlib import PosixPath +from pathlib import Path from jinja2 import Environment, PackageLoader, Template @@ -160,7 +160,7 @@ def save(self, outfile, close_file=True, **kwargs): close_file : bool, default True Whether the file has to be closed after write. """ - if isinstance(outfile, (str, bytes, PosixPath)): + if isinstance(outfile, (str, bytes, Path)): fid = open(outfile, 'wb') else: fid = outfile