Skip to content

Commit 19f1825

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2eefcb3 commit 19f1825

File tree

11 files changed

+93
-78
lines changed

11 files changed

+93
-78
lines changed

_test/lib/canonical.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ def scan_tag(self):
141141
' ': ' ',
142142
'a': '\x07',
143143
'b': '\x08',
144-
'e': '\x1B',
145-
'f': '\x0C',
146-
'n': '\x0A',
147-
'r': '\x0D',
144+
'e': '\x1b',
145+
'f': '\x0c',
146+
'n': '\x0a',
147+
'r': '\x0d',
148148
't': '\x09',
149-
'v': '\x0B',
149+
'v': '\x0b',
150150
'N': '\u0085',
151151
'L': '\u2028',
152152
'P': '\u2029',

_test/test_issues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
# cannot do "from .roundtrip" because of pytest, so mypy cannot find this
88
from roundtrip import ( # type: ignore
9+
YAML,
910
dedent,
1011
na_round_trip,
1112
round_trip,
1213
round_trip_dump,
1314
round_trip_load,
1415
save_and_run,
15-
YAML,
1616
)
1717

1818

_test/test_z_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf-8
22

3-
import sys
43
import os
4+
import sys
55
import warnings # NOQA
66
from pathlib import Path
77
from typing import Any, List, Optional, Tuple

lib/ruyaml/comments.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,9 @@ def __init__(self, *args: Any, **kw: Any) -> None:
10611061
except TypeError:
10621062
raise
10631063

1064-
__delitem__ = (
1065-
__setitem__
1066-
) = clear = pop = popitem = setdefault = update = raise_immutable
1064+
__delitem__ = __setitem__ = clear = pop = popitem = setdefault = update = (
1065+
raise_immutable
1066+
)
10671067

10681068
# need to implement __getitem__, __iter__ and __len__
10691069
def __getitem__(self, index: Any) -> Any:

lib/ruyaml/compat.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ def fp(self, mode: str = 'a') -> Any:
159159

160160

161161
def check_namespace_char(ch: Any) -> bool:
162-
if '\x21' <= ch <= '\x7E': # ! to ~
162+
if '\x21' <= ch <= '\x7e': # ! to ~
163163
return True
164-
if '\xA0' <= ch <= '\uD7FF':
164+
if '\xa0' <= ch <= '\ud7ff':
165165
return True
166-
if ('\uE000' <= ch <= '\uFFFD') and ch != '\uFEFF': # excl. byte order mark
166+
if ('\ue000' <= ch <= '\ufffd') and ch != '\ufeff': # excl. byte order mark
167167
return True
168-
if '\U00010000' <= ch <= '\U0010FFFF':
168+
if '\U00010000' <= ch <= '\U0010ffff':
169169
return True
170170
return False
171171

lib/ruyaml/composer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from ruyaml.error import MarkedYAMLError, ReusedAnchorWarning
88
from ruyaml.events import (
99
AliasEvent,
10-
MappingStartEvent,
1110
MappingEndEvent,
11+
MappingStartEvent,
1212
ScalarEvent,
13-
SequenceStartEvent,
1413
SequenceEndEvent,
15-
StreamStartEvent,
14+
SequenceStartEvent,
1615
StreamEndEvent,
16+
StreamStartEvent,
1717
)
1818
from ruyaml.nodes import MappingNode, ScalarNode, SequenceNode
1919

lib/ruyaml/constructor.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,45 @@
88
from collections.abc import Hashable, MutableMapping, MutableSequence # type: ignore
99
from datetime import timedelta as TimeDelta
1010

11-
# fmt: off
12-
from ruyaml.error import (MarkedYAMLError, MarkedYAMLFutureWarning,
13-
MantissaNoDotYAML1_1Warning)
14-
from ruyaml.nodes import * # NOQA
15-
from ruyaml.nodes import (SequenceNode, MappingNode, ScalarNode)
16-
from ruyaml.compat import (builtins_module, # NOQA
17-
nprint, nprintf, version_tnf)
18-
from ruyaml.compat import ordereddict
11+
from ruyaml.comments import * # NOQA
12+
from ruyaml.comments import (
13+
C_KEY_EOL,
14+
C_KEY_POST,
15+
C_KEY_PRE,
16+
C_VALUE_EOL,
17+
C_VALUE_POST,
18+
C_VALUE_PRE,
19+
CommentedKeyMap,
20+
CommentedKeySeq,
21+
CommentedMap,
22+
CommentedOrderedMap,
23+
CommentedSeq,
24+
CommentedSet,
25+
TaggedScalar,
26+
)
27+
from ruyaml.compat import builtins_module # NOQA
28+
from ruyaml.compat import nprint, nprintf, ordereddict, version_tnf
1929

20-
from ruyaml.tag import Tag
21-
from ruyaml.comments import * # NOQA
22-
from ruyaml.comments import (CommentedMap, CommentedOrderedMap, CommentedSet,
23-
CommentedKeySeq, CommentedSeq, TaggedScalar,
24-
CommentedKeyMap,
25-
C_KEY_PRE, C_KEY_EOL, C_KEY_POST,
26-
C_VALUE_PRE, C_VALUE_EOL, C_VALUE_POST,
27-
)
28-
from ruyaml.scalarstring import (SingleQuotedScalarString, DoubleQuotedScalarString,
29-
LiteralScalarString, FoldedScalarString,
30-
PlainScalarString, ScalarString)
31-
from ruyaml.scalarint import ScalarInt, BinaryInt, OctalInt, HexInt, HexCapsInt
32-
from ruyaml.scalarfloat import ScalarFloat
30+
# fmt: off
31+
from ruyaml.error import (
32+
MantissaNoDotYAML1_1Warning,
33+
MarkedYAMLError,
34+
MarkedYAMLFutureWarning,
35+
)
36+
from ruyaml.nodes import * # NOQA
37+
from ruyaml.nodes import MappingNode, ScalarNode, SequenceNode
3338
from ruyaml.scalarbool import ScalarBoolean
39+
from ruyaml.scalarfloat import ScalarFloat
40+
from ruyaml.scalarint import BinaryInt, HexCapsInt, HexInt, OctalInt, ScalarInt
41+
from ruyaml.scalarstring import (
42+
DoubleQuotedScalarString,
43+
FoldedScalarString,
44+
LiteralScalarString,
45+
PlainScalarString,
46+
ScalarString,
47+
SingleQuotedScalarString,
48+
)
49+
from ruyaml.tag import Tag
3450
from ruyaml.timestamp import TimeStamp
3551
from ruyaml.util import create_timestamp, timestamp_regexp
3652

lib/ruyaml/emitter.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,16 +1155,16 @@ def analyze_scalar(self, scalar: Any) -> Any:
11551155
# Check for line breaks, special, and unicode characters.
11561156
if ch in '\n\x85\u2028\u2029':
11571157
line_breaks = True
1158-
if not (ch == '\n' or '\x20' <= ch <= '\x7E'):
1158+
if not (ch == '\n' or '\x20' <= ch <= '\x7e'):
11591159
if (
11601160
ch == '\x85'
1161-
or '\xA0' <= ch <= '\uD7FF'
1162-
or '\uE000' <= ch <= '\uFFFD'
1161+
or '\xa0' <= ch <= '\ud7ff'
1162+
or '\ue000' <= ch <= '\ufffd'
11631163
or (
11641164
self.unicode_supplementary
1165-
and ('\U00010000' <= ch <= '\U0010FFFF')
1165+
and ('\U00010000' <= ch <= '\U0010ffff')
11661166
)
1167-
) and ch != '\uFEFF':
1167+
) and ch != '\ufeff':
11681168
# unicode_characters = True
11691169
if not self.allow_unicode:
11701170
special_characters = True
@@ -1225,9 +1225,9 @@ def analyze_scalar(self, scalar: Any) -> Any:
12251225
# Spaces followed by breaks, as well as special character are only
12261226
# allowed for double quoted scalars.
12271227
if special_characters:
1228-
allow_flow_plain = (
1229-
allow_block_plain
1230-
) = allow_single_quoted = allow_block = False
1228+
allow_flow_plain = allow_block_plain = allow_single_quoted = allow_block = (
1229+
False
1230+
)
12311231
elif space_break:
12321232
allow_flow_plain = allow_block_plain = allow_single_quoted = False
12331233
if not self.allow_space_break:
@@ -1266,7 +1266,7 @@ def flush_stream(self) -> None:
12661266
def write_stream_start(self) -> None:
12671267
# Write BOM if needed.
12681268
if self.encoding and self.encoding.startswith('utf-16'):
1269-
self.stream.write('\uFEFF'.encode(self.encoding))
1269+
self.stream.write('\ufeff'.encode(self.encoding))
12701270

12711271
def write_stream_end(self) -> None:
12721272
self.flush_stream()
@@ -1405,15 +1405,15 @@ def write_single_quoted(self, text: Any, split: Any = True) -> None:
14051405
'\x07': 'a',
14061406
'\x08': 'b',
14071407
'\x09': 't',
1408-
'\x0A': 'n',
1409-
'\x0B': 'v',
1410-
'\x0C': 'f',
1411-
'\x0D': 'r',
1412-
'\x1B': 'e',
1408+
'\x0a': 'n',
1409+
'\x0b': 'v',
1410+
'\x0c': 'f',
1411+
'\x0d': 'r',
1412+
'\x1b': 'e',
14131413
'"': '"',
14141414
'\\': '\\',
14151415
'\x85': 'N',
1416-
'\xA0': '_',
1416+
'\xa0': '_',
14171417
'\u2028': 'L',
14181418
'\u2029': 'P',
14191419
}
@@ -1436,15 +1436,15 @@ def write_double_quoted(self, text: Any, split: Any = True) -> None:
14361436
ch = text[end]
14371437
if (
14381438
ch is None
1439-
or ch in '"\\\x85\u2028\u2029\uFEFF'
1439+
or ch in '"\\\x85\u2028\u2029\ufeff'
14401440
or not (
1441-
'\x20' <= ch <= '\x7E'
1441+
'\x20' <= ch <= '\x7e'
14421442
or (
14431443
self.allow_unicode
14441444
and (
1445-
('\xA0' <= ch <= '\uD7FF')
1446-
or ('\uE000' <= ch <= '\uFFFD')
1447-
or ('\U00010000' <= ch <= '\U0010FFFF')
1445+
('\xa0' <= ch <= '\ud7ff')
1446+
or ('\ue000' <= ch <= '\ufffd')
1447+
or ('\U00010000' <= ch <= '\U0010ffff')
14481448
)
14491449
)
14501450
)
@@ -1459,9 +1459,9 @@ def write_double_quoted(self, text: Any, split: Any = True) -> None:
14591459
if ch is not None:
14601460
if ch in self.ESCAPE_REPLACEMENTS:
14611461
data = '\\' + self.ESCAPE_REPLACEMENTS[ch]
1462-
elif ch <= '\xFF':
1462+
elif ch <= '\xff':
14631463
data = '\\x%02X' % ord(ch)
1464-
elif ch <= '\uFFFF':
1464+
elif ch <= '\uffff':
14651465
data = '\\u%04X' % ord(ch)
14661466
else:
14671467
data = '\\U%08X' % ord(ch)

lib/ruyaml/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

33
import glob
4+
import warnings
45
from importlib import import_module
56
from io import BytesIO, StringIO
67
from typing import TYPE_CHECKING, Any, List, Optional, Text, Union
7-
import warnings
88

99
import ruyaml
1010
from ruyaml.comments import C_PRE, CommentedMap, CommentedSeq
@@ -21,7 +21,6 @@
2121
from ruyaml.events import * # NOQA
2222
from ruyaml.loader import BaseLoader # NOQA
2323
from ruyaml.loader import Loader # NOQA
24-
from ruyaml.loader import Loader as UnsafeLoader
2524
from ruyaml.loader import RoundTripLoader, SafeLoader # NOQA
2625
from ruyaml.nodes import * # NOQA
2726
from ruyaml.representer import (

lib/ruyaml/reader.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def forward_1_1(self, length: int = 1) -> None:
149149
):
150150
self.line += 1
151151
self.column = 0
152-
elif ch != '\uFEFF':
152+
elif ch != '\ufeff':
153153
self.column += 1
154154
length -= 1
155155

@@ -163,7 +163,7 @@ def forward(self, length: int = 1) -> None:
163163
if ch == '\n' or (ch == '\r' and self.buffer[self.pointer] != '\n'):
164164
self.line += 1
165165
self.column = 0
166-
elif ch != '\uFEFF':
166+
elif ch != '\ufeff':
167167
self.column += 1
168168
length -= 1
169169

@@ -196,14 +196,14 @@ def determine_encoding(self) -> None:
196196
self.update(1)
197197

198198
NON_PRINTABLE = RegExp(
199-
'[^\x09\x0A\x0D\x20-\x7E\x85'
200-
'\xA0-\uD7FF'
201-
'\uE000-\uFFFD'
202-
'\U00010000-\U0010FFFF'
199+
'[^\x09\x0a\x0d\x20-\x7e\x85'
200+
'\xa0-\ud7ff'
201+
'\ue000-\ufffd'
202+
'\U00010000-\U0010ffff'
203203
']' # NOQA
204204
)
205205

206-
_printable_ascii = ('\x09\x0A\x0D' + "".join(map(chr, range(0x20, 0x7F)))).encode(
206+
_printable_ascii = ('\x09\x0a\x0d' + "".join(map(chr, range(0x20, 0x7F)))).encode(
207207
'ascii'
208208
)
209209

0 commit comments

Comments
 (0)