From 2a1df6cfc17f189ad75e70d72003884e6ad93b72 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Wed, 8 Sep 2021 17:19:32 -0500 Subject: parseFile and create_diagram methods now accept pathlib.Path arguments --- pyparsing/core.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pyparsing/core.py') diff --git a/pyparsing/core.py b/pyparsing/core.py index a97a59d..b9e63af 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -26,6 +26,7 @@ import types from operator import itemgetter, attrgetter from functools import wraps from threading import RLock +from pathlib import Path from .util import ( _FifoCache, @@ -1766,7 +1767,7 @@ class ParserElement(ABC): def parse_file( self, - file_or_filename: Union[str, TextIO], + file_or_filename: Union[str, Path, TextIO], encoding: str = "utf-8", parse_all: bool = False, *, @@ -2013,7 +2014,7 @@ class ParserElement(ABC): def create_diagram( self, - output_html: Union[TextIO, str], + output_html: Union[TextIO, Path, str], vertical: int = 3, show_results_names: bool = False, **kwargs, @@ -2048,7 +2049,7 @@ class ParserElement(ABC): show_results_names=show_results_names, diagram_kwargs=kwargs, ) - if isinstance(output_html, str): + if isinstance(output_html, (str, Path)): with open(output_html, "w", encoding="utf-8") as diag_file: diag_file.write(railroad_to_html(railroad)) else: -- cgit v1.2.1