1+ import codecs
12import warnings
23from typing import Iterable
34from typing import List
@@ -20,9 +21,9 @@ def _build_parse_stack(
2021) -> List [Middleware ]:
2122 if parse_stack is not None and append_middleware is not None :
2223 raise ValueError (
23- "Provided both parse_stack and append_middleware."
24- "Only one should be provided."
25- "(append_middleware should only be used with the default parse_stack,"
24+ "Provided both parse_stack and append_middleware. "
25+ "Only one should be provided. "
26+ "(append_middleware should only be used with the default parse_stack, "
2627 "i.e., when the passed parse_stack is None.)"
2728 )
2829
@@ -50,10 +51,10 @@ def _build_unparse_stack(
5051) -> List [Middleware ]:
5152 if unparse_stack is not None and prepend_middleware is not None :
5253 raise ValueError (
53- "Provided both parse_stack and append_middleware. "
54- "Only one should be provided."
55- "(prepend_middleware should only be used with the default parse_stack, "
56- "i.e., when the passed parse_stack is None.)"
54+ "Provided both unparse_stack and prepend_middleware. "
55+ "Only one should be provided. "
56+ "(prepend_middleware should only be used with the default unparse_stack, "
57+ "i.e., when the passed unparse_stack is None.)"
5758 )
5859
5960 if unparse_stack is None :
@@ -125,7 +126,13 @@ def parse_file(
125126
126127 :param encoding: Encoding of the .bib file. Default encoding is ``"UTF-8"``.
127128 :return: Library: Parsed BibTeX library
129+ :raises LookupError: If the specified encoding is not recognized.
128130 """
131+ try :
132+ codecs .lookup (encoding )
133+ except LookupError :
134+ raise LookupError (f"Unknown encoding: { encoding !r} " )
135+
129136 with open (path , encoding = encoding ) as f :
130137 bibtex_str = f .read ()
131138 return parse_string (
0 commit comments