Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
138601d679
!20 Add a decoder implementing the toml-test protocol
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-12-27 10:05:19 +00:00
fandehui
72948f9230 Add a decoder implementing the toml-test protocol
Signed-off-by: fandehui <fandehui@xfusion.com>
2023-12-27 14:50:26 +08:00
openeuler-ci-bot
f2653aeaad
!14 Avoid annoying SystemExit breaks in vscode
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-12-11 06:31:01 +00:00
openeuler-ci-bot
e585618802
!13 Reject invalid escapes in strings
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-11-24 06:30:14 +00:00
openeuler-ci-bot
8febf1e145
!8 Fix datetime serialization
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-11-15 02:23:12 +00:00
openeuler-ci-bot
da2c4f67fc
!7 Add .vscode and .pytest_cache to .gitignore
From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
2023-11-03 07:27:19 +00:00
linker99
ee9bab3f17 Avoid annoying SystemExit breaks in vscode
Signed-off-by: linker99 <fandehui@xfusion.com>
2023-11-01 05:30:52 +08:00
linker99
9aaea03625 Reject invalid escapes in strings
Fixes `invalid-escape` test.
2023-10-31 22:03:05 +08:00
linker99
5857ce352d Fix datetime serialization 2023-10-31 10:10:19 +08:00
fandehui
b0d081916b Add .vscode and .pytest_cache to .gitignore 2023-10-27 20:50:54 +08:00
7 changed files with 215 additions and 1 deletions

View File

@ -0,0 +1,22 @@
From 1519a4f917aed4ad3a1f975e4451791ea84f1b32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sun, 9 Sep 2018 14:07:30 +0200
Subject: [PATCH] Add .vscode and .pytest_cache to .gitignore
---
.gitignore | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore
index 6317d70..ae02791 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@ __pycache__/
.tox/
*.pyc
.cache/
+.vscode/
+.pytest_cache/
--
2.27.0

View File

@ -0,0 +1,41 @@
From f527cd48a3e6232ace55a3e76a2f413eeca04242 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sun, 28 Oct 2018 13:29:01 +0100
Subject: [PATCH] Add a decoder implementing the `toml-test` protocol
---
test/decoder.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 test/decoder.py
diff --git a/test/decoder.py b/test/decoder.py
new file mode 100644
index 0000000..26efe79
--- /dev/null
+++ b/test/decoder.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import argparse
+import json
+import pytoml
+import sys
+
+def _main():
+ ap = argparse.ArgumentParser()
+ ap.add_argument('-i', '--input', type=argparse.FileType('r', encoding='utf-8'))
+ ap.add_argument('-o', '--output', type=argparse.FileType('w', encoding='utf-8'), default='-')
+ args = ap.parse_args()
+
+ if not args.input:
+ args.input = sys.stdin.buffer
+
+ v = pytoml.load(args.input)
+ translated = pytoml.translate_to_test(v)
+ json.dump(translated, args.output)
+
+if __name__ == '__main__':
+ _main()
--
2.42.0.windows.2

View File

@ -0,0 +1,24 @@
From 056ef47a8797334d2af737c910527e4bdf6746ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sun, 28 Oct 2018 13:37:00 +0100
Subject: [PATCH] Avoid annoying SystemExit breaks in vscode
---
test/test.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/test.py b/test/test.py
index 0884253..21bffd8 100644
--- a/test/test.py
+++ b/test/test.py
@@ -94,4 +94,6 @@ def _main():
return 1 if failed or not succeeded else 0
if __name__ == '__main__':
- sys.exit(_main())
+ r = _main()
+ if r:
+ sys.exit(r)
--
2.27.0

View File

@ -0,0 +1,48 @@
From dffef385459c3bd49c33fd69b759485016a7f0b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sat, 27 Oct 2018 21:47:28 +0200
Subject: [PATCH] Fix datetime serialization
---
pytoml/writer.py | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/pytoml/writer.py b/pytoml/writer.py
index 6eaf5d7..2d8afb5 100644
--- a/pytoml/writer.py
+++ b/pytoml/writer.py
@@ -48,13 +48,6 @@ def _escape_id(s):
def _format_list(v):
return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))
-# Formula from:
-# https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
-# Once support for py26 is dropped, this can be replaced by td.total_seconds()
-def _total_seconds(td):
- return ((td.microseconds
- + (td.seconds + td.days * 24 * 3600) * 10**6) / 10.0**6)
-
def _format_value(v):
if isinstance(v, bool):
return 'true' if v else 'false'
@@ -69,7 +62,7 @@ def _format_value(v):
return _escape_string(v)
elif isinstance(v, datetime.datetime):
offs = v.utcoffset()
- offs = _total_seconds(offs) // 60 if offs is not None else 0
+ offs = int(offs.total_seconds()) // 60 if offs is not None else 0
if offs == 0:
suffix = 'Z'
@@ -79,7 +72,7 @@ def _format_value(v):
else:
suffix = '-'
offs = -offs
- suffix = '{0}{1:.02}{2:.02}'.format(suffix, offs // 60, offs % 60)
+ suffix = '{0}{1:02}:{2:02}'.format(suffix, offs // 60, offs % 60)
if v.microsecond:
return v.strftime('%Y-%m-%dT%H:%M:%S.%f') + suffix
--
2.27.0

View File

@ -0,0 +1,25 @@
From 611d33bf15b55f61b0806a3e234848623323a6d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sun, 28 Oct 2018 13:57:11 +0100
Subject: [PATCH] Fix handling of parser errors in the test suite
---
test/test.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test.py b/test/test.py
index 21bffd8..3c3ed1e 100644
--- a/test/test.py
+++ b/test/test.py
@@ -77,7 +77,7 @@ def _main():
except IOError:
bench = None
- if parsed is None != bench is None or (parsed is not None and not is_bench_equal(parsed, bench)):
+ if (parsed is None) != (bench is None) or (parsed is not None and not is_bench_equal(parsed, bench)):
failed.append((fname, parsed, bench, parse_error))
else:
succeeded.append(fname)
--
2.27.0

View File

@ -0,0 +1,34 @@
From 09b300acf1142fec5de429d3521c09afad0832c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sat, 27 Oct 2018 21:57:01 +0200
Subject: [PATCH] Reject invalid escapes in strings
Fixes `invalid-escape` test.
---
pytoml/parser.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pytoml/parser.py b/pytoml/parser.py
index 6d4d483..b4f7646 100644
--- a/pytoml/parser.py
+++ b/pytoml/parser.py
@@ -180,13 +180,13 @@ _ws_re = re.compile(r'[ \t]*')
def _p_ws(s):
s.expect_re(_ws_re)
-_escapes = { 'b': '\b', 'n': '\n', 'r': '\r', 't': '\t', '"': '"', '\'': '\'',
- '\\': '\\', '/': '/', 'f': '\f' }
+_escapes = { 'b': '\b', 'n': '\n', 'r': '\r', 't': '\t', '"': '"',
+ '\\': '\\', 'f': '\f' }
_basicstr_re = re.compile(r'[^"\\\000-\037]*')
_short_uni_re = re.compile(r'u([0-9a-fA-F]{4})')
_long_uni_re = re.compile(r'U([0-9a-fA-F]{8})')
-_escapes_re = re.compile('[bnrt"\'\\\\/f]')
+_escapes_re = re.compile(r'[btnfr\"\\]')
_newline_esc_re = re.compile('\n[ \t\n]*')
def _p_basicstr_content(s, content=_basicstr_re):
res = []
--
2.27.0

View File

@ -2,11 +2,16 @@
Name: python-%{github_name}
Version: 0.1.18
Release: 2
Release: 7
Summary: Parser for TOML
License: MIT
URL: https://github.com/avakar/%{github_name}
Source0: https://github.com/avakar/%{github_name}/archive/v%{version}/%{github_name}-%{version}.tar.gz
Patch0: Add-.vscode-and-.pytest_cache-to-.gitignore.patch
Patch1: Fix-datetime-serialization.patch
Patch2: Reject-invalid-escapes-in-strings.patch
Patch3: Avoid-annoying-SystemExit-breaks-in-vscode.patch
Patch4: Add-a-decoder-implementing-the-toml-test-protocol.patch
BuildArch: noarch
%global my_description \
@ -60,5 +65,20 @@ BuildRequires: python3-setuptools
%{python3_sitelib}/%{github_name}/
%changelog
* Wed Dec 27 2023 fandehui <fandehui@xfusion.com> - 0.1.18-7
- Add a decoder implementing the `toml-test` protocol
* Mon Dec 11 2023 fandehui <fandehui@xfusion.com> - 0.1.18-6
- Avoid annoying SystemExit breaks in vscode
* Fri Nov 24 2023 fandehui <fandehui@xfusion.com> - 0.1.18-5
- Fixes `invalid-escape` test.
* Tue Nov 14 2023 fandehui <fandehui@xfusion.com> - 0.1.18-4
- Fix-datetime-serialization.patch
* Fri Nov 3 2023 fandehui <fandehui@xfusion.com> - 0.1.18-3
- Add .vscode and .pytest_cache to .gitignore
* Tue Dec 3 2019 mengxian <mengxian@huawei.com> - 0.1.18-2
- Package init