Skip to content

Commit

Permalink
Made pass-through option to set encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Jan 17, 2024
1 parent a917c40 commit 225fe0e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion montepy/input_parser/input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,26 @@ def lineno(self):
"""
pass

def open(self, mode):
def open(self, mode, encoding="ascii"):
"""
Opens the underlying file, and returns self.
This should only ever be completed from within a ``with`` statement.
For this reason, a ``close`` functional is intentionally
not provided.
.. Note::
For different encoding schemes see the available list
`here <https://docs.python.org/3.9/library/codecs.html#standard-encodings>`_.
CP1252 is commonly referred to as "extended-ASCII".
You may have success with this encoding for working with special characters.
:param mode: the mode to open the file in
:type mode: str
:param encoding: The encoding scheme to use.
:type encoding: str
:returns: self
"""
self._fh = open(self.path, mode, encoding="ascii")
Expand Down
11 changes: 10 additions & 1 deletion montepy/input_parser/input_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
from montepy.constants import DEFAULT_VERSION


def read_input(input_file, mcnp_version=DEFAULT_VERSION):
def read_input(input_file, mcnp_version=DEFAULT_VERSION, encoding="ascii"):
"""
Reads the specified MCNP Input file.
The MCNP version must be a three component tuple e.g., (6, 2, 0) and (5, 1, 60).
.. Note::
For different encoding schemes see the available list
`here <https://docs.python.org/3.9/library/codecs.html#standard-encodings>`_.
CP1252 is commonly referred to as "extended-ASCII".
You may have success with this encoding for working with special characters.
:param input_file: the path to the input file to read.
:type input_file: str
:param mcnp_version: The version of MCNP that the input is intended for.
:type mcnp_version: tuple
:returns: The MCNP_Problem instance representing this file.
:param encoding: The encoding scheme to use.
:type encoding: str
:rtype: MCNP_Problem
:raises UnsupportedFeature: If an input format is used that MontePy does not support.
:raises MalformedInputError: If an input has a broken syntax.
Expand Down

0 comments on commit 225fe0e

Please sign in to comment.