Skip to content

Commit

Permalink
Merge pull request #20 from 2018-11-27/master
Browse files Browse the repository at this point in the history
1.2.1
  • Loading branch information
2018-11-27 authored Sep 9, 2024
2 parents 4623a9f + 6605279 commit 2405535
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
16 changes: 12 additions & 4 deletions systempath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
────────────────────────────────────────────────────────────────────────────────
Copyright (c) 2022-2024 GQYLPY <http://gqylpy.com>. All rights reserved.
@version: 1.2
@version: 1.2.1
@author: 竹永康 <gqylpy@outlook.com>
@source: https://github.com/gqylpy/systempath
Expand Down Expand Up @@ -1859,8 +1859,8 @@ def __init__(self, file: File, /):

def read(
self,
encoding: Optional[str] = None,
*,
encoding: Optional[str] = None,
defaults: Optional[Mapping[str, str]] = None,
dict_type: Optional[Type[Mapping[str, str]]] = None,
allow_no_value: Optional[bool] = None,
Expand Down Expand Up @@ -1891,8 +1891,8 @@ class CSV:
"w".
@param encoding
Specify the output encoding, usually specified as "UTF-8". The default
encoding is based on the platform, call
Specify the encoding for opening the file, usually specified as "UTF-8".
The default encoding is based on the platform, call
`locale.getpreferredencoding(False)` to get the current locale encoding.
See the `codecs` module for a list of supported encodings.
Expand Down Expand Up @@ -1943,6 +1943,7 @@ def reader(
self,
dialect: Optional[CSVDialectLike] = None,
*,
encoding: Optional[str] = None,
delimiter: Optional[str] = None,
quotechar: Optional[str] = None,
escapechar: Optional[str] = None,
Expand Down Expand Up @@ -2017,6 +2018,12 @@ class JSON:
The Python object you want to convert to JSON format and write to the
file.
@param encoding
Specify the encoding for opening the file, usually specified as "UTF-8".
The default encoding is based on the platform, call
`locale.getpreferredencoding(False)` to get the current locale encoding.
See the `codecs` module for a list of supported encodings.
@param skipkeys
If True (default is False), dictionary keys that are not of a basic
type (str, int, float, bool, None) will be skipped during the encoding
Expand Down Expand Up @@ -2072,6 +2079,7 @@ def dump(
self,
obj: Any,
*,
encoding: Optional[str] = None,
skipkeys: Optional[bool] = None,
ensure_ascii: Optional[bool] = None,
check_circular: Optional[bool] = None,
Expand Down
22 changes: 15 additions & 7 deletions systempath/i systempath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ def __getattr__(self, mode: OpenMode, /) -> Closure:
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{mode}'"
) from None
return self.__pass__(buffer, mode)
return self.__open__(buffer, mode)

def __dir__(self) -> Iterable[str]:
methods = object.__dir__(self)
Expand All @@ -1276,7 +1276,7 @@ def __repr__(self) -> str:
self.file.name if isinstance(self.file, File) else self.file
return f'<{__package__}.{self.__class__.__name__} file={filelink!r}>'

def __pass__(self, buffer: Type[BufferedIOBase], mode: OpenMode) -> Closure:
def __open__(self, buffer: Type[BufferedIOBase], mode: OpenMode) -> Closure:
def init_buffer_instance(
*,
bufsize: int = DEFAULT_BUFFER_SIZE,
Expand Down Expand Up @@ -1573,8 +1573,8 @@ def __init__(self, file: File, /):

def read(
self,
encoding: Optional[str] = None,
*,
encoding: Optional[str] = None,
defaults: Optional[Mapping[str, str]] = None,
dict_type: Type[Mapping[str, str]] = dict,
allow_no_value: bool = False,
Expand Down Expand Up @@ -1617,6 +1617,7 @@ def reader(
self,
dialect: CSVDialectLike = 'excel',
*,
encoding: Optional[str] = None,
delimiter: str = ',',
quotechar: Optional[str] = '"',
escapechar: Optional[str] = None,
Expand All @@ -1627,7 +1628,8 @@ def reader(
strict: bool = False
) -> CSVReader:
return csv.reader(
Open(self.file).r(newline=''), dialect,
Open(self.file).r(encoding=encoding, newline=''),
dialect,
delimiter =delimiter,
quotechar =quotechar,
escapechar =escapechar,
Expand Down Expand Up @@ -1700,6 +1702,7 @@ def dump(
self,
obj: Any,
*,
encoding: Optional[str] = None,
skipkeys: bool = False,
ensure_ascii: bool = True,
check_circular: bool = True,
Expand All @@ -1712,7 +1715,8 @@ def dump(
**kw
) -> None:
return json.dump(
obj, Open(self.file).w(),
obj,
Open(self.file).w(encoding=encoding),
skipkeys =skipkeys,
ensure_ascii =ensure_ascii,
check_circular=check_circular,
Expand Down Expand Up @@ -1763,7 +1767,9 @@ def dump(
sort_keys: bool = True
) -> None:
return yaml.dump_all(
[data], Open(self.file).w(), dumper or yaml.Dumper,
[data],
Open(self.file).w(encoding=encoding),
dumper or yaml.Dumper,
default_style =default_style,
default_flow_style=default_flow_style,
canonical =canonical,
Expand Down Expand Up @@ -1800,7 +1806,9 @@ def dump_all(
sort_keys: bool = True
) -> None:
return yaml.dump_all(
documents, Open(self.file).w(), dumper or yaml.Dumper,
documents,
Open(self.file).w(encoding=encoding),
dumper or yaml.Dumper,
default_style =default_style,
default_flow_style=default_flow_style,
canonical =canonical,
Expand Down

0 comments on commit 2405535

Please sign in to comment.