Open the file (with compression options, etc.), and read header information.
(self)
| 1079 | self._open_file() |
| 1080 | |
| 1081 | def _open_file(self) -> None: |
| 1082 | """ |
| 1083 | Open the file (with compression options, etc.), and read header information. |
| 1084 | """ |
| 1085 | if not self._entered: |
| 1086 | warnings.warn( |
| 1087 | "StataReader is being used without using a context manager. " |
| 1088 | "Using StataReader as a context manager is the only supported method.", |
| 1089 | ResourceWarning, |
| 1090 | stacklevel=find_stack_level(), |
| 1091 | ) |
| 1092 | handles = get_handle( |
| 1093 | self._original_path_or_buf, |
| 1094 | "rb", |
| 1095 | storage_options=self._storage_options, |
| 1096 | is_text=False, |
| 1097 | compression=self._compression, |
| 1098 | ) |
| 1099 | if hasattr(handles.handle, "seekable") and handles.handle.seekable(): |
| 1100 | # If the handle is directly seekable, use it without an extra copy. |
| 1101 | self._path_or_buf = handles.handle |
| 1102 | self._close_file = handles.close |
| 1103 | else: |
| 1104 | # Copy to memory, and ensure no encoding. |
| 1105 | with handles: |
| 1106 | self._path_or_buf = BytesIO(handles.handle.read()) |
| 1107 | self._close_file = self._path_or_buf.close |
| 1108 | |
| 1109 | self._read_header() |
| 1110 | self._setup_dtype() |
| 1111 | |
| 1112 | def __enter__(self) -> Self: |
| 1113 | """enter context manager""" |
no test coverage detected