Projects
openEuler:Mainline
python-pytoml
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
_service:tar_scm:python-pytoml.spec
Changed
@@ -1,47 +1,81 @@ +%global _empty_manifest_terminate_build 0 %global github_name pytoml - -Name: python-%{github_name} -Version: 0.1.18 -Release: 3 -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 -BuildArch: noarch - %global my_description \ This package aims at being a specs-conforming and\ strict parser and writer for TOML files. +Name: python-pytoml +Version: 0.1.21 +Release: 1 +Summary: Parser for TOML +License: MIT +URL: https://github.com/avakar/%{github_name} +Source0: https://files.pythonhosted.org/packages/f4/ba/98ee2054a2d7b8bebd367d442e089489250b6dc2aee558b000e961467212/pytoml-%{version}.tar.gz +BuildArch: noarch + %description %{my_description} -%package -n python3-%{github_name} -Summary: %{summary} -BuildArch: noarch -BuildRequires: python3-devel -BuildRequires: python3-setuptools -%{?python_provide:%python_provide python3-%{github_name}} +%package -n python3-pytoml +Summary: Parser for TOML +Provides: python-pytoml = %{version}-%{release} +BuildRequires: python3-devel +BuildRequires: python3-setuptools +%description -n python3-pytoml +%{my_description} -%description -n python3-%{github_name} +%package help +Summary: Development documents and examples for pytoml +Provides: python3-pytoml-doc +%description help %{my_description} %prep -%autosetup -p1 -n %{github_name}-%{version} +%autosetup -n pytoml-%{version} %build %py3_build %install %py3_install +install -d -m644 %{buildroot}/%{_pkgdocdir} +if -d doc ; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if -d docs ; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if -d example ; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if -d examples ; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if -d usr/lib ; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if -d usr/lib64 ; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if -d usr/bin ; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if -d usr/sbin ; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if -d usr/share/man ; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-pytoml -f filelist.lst +%dir %{python3_sitelib}/* -%files -n python3-%{github_name} +%files help -f doclist.lst +%{_docdir}/* %doc README.md %license LICENSE -%{python3_sitelib}/%{github_name}-%{version}*-py%{python3_version}.egg-info/ -%{python3_sitelib}/%{github_name}/ %changelog +* Mon Nov 28 2022 wangjunqi <wangjunqi@kylinos.cn> - 0.1.21-1 +- Update package to version 0.1.21 + * Thu Oct 22 2020 wutao <wutao61@huawei.com> - 0.1.18-3 - delete python2 modules
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="scm">git</param> <param name="url">git@gitee.com:src-openeuler/python-pytoml.git</param> - <param name="revision">9ecb13a79fcd2404a3a70dc72e9cbd0628c021ca</param> + <param name="revision">master</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/.gitignore
Deleted
@@ -1,9 +0,0 @@ -build/ -dist/ -pytoml.egg-info/ -venv/ -.idea/ -__pycache__/ -.tox/ -*.pyc -.cache/
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/.gitmodules
Deleted
@@ -1,3 +0,0 @@ -submodule "test/toml-test" - path = test/toml-test - url = https://github.com/avakar/toml-test.git
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/.travis.yml
Deleted
@@ -1,10 +0,0 @@ -sudo: false -language: python -python: - - "2.6" - - "2.7" - - "3.4" - - "3.5" - - "3.6" -install: pip install tox-travis -script: tox
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/dev-requirements.txt
Deleted
@@ -1,1 +0,0 @@ -pytest==3.0.7
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/test/toml-test
Deleted
-(directory)
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/tox.ini
Deleted
@@ -1,7 +0,0 @@ -tox -envlist = py26,py27,py34,py35,py36 -testenv -deps = -r{toxinidir}/dev-requirements.txt -commands= - python ./test/test.py - py.test test
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/LICENSE -> _service:tar_scm:pytoml-0.1.21.tar.gz/LICENSE
Changed
@@ -1,16 +1,16 @@ -No-notice MIT License - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +No-notice MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/MANIFEST.in -> _service:tar_scm:pytoml-0.1.21.tar.gz/MANIFEST.in
Changed
@@ -1,2 +1,2 @@ -include LICENSE -include README.md +include LICENSE +include README.md
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/PKG-INFO
Added
@@ -0,0 +1,67 @@ +Metadata-Version: 2.1 +Name: pytoml +Version: 0.1.21 +Summary: A parser for TOML-0.4.0 +Home-page: https://github.com/avakar/pytoml +Author: Martin Vejnár +Author-email: vejnar.martin@gmail.com +License: MIT +Description: !PyPI(https://img.shields.io/pypi/v/pytoml.svg)(https://pypi.python.org/pypi/pytoml) + !Build Status(https://travis-ci.org/avakar/pytoml.svg?branch=master)(https://travis-ci.org/avakar/pytoml) + + # Deprecated + + The pytoml project is no longer being actively maintained. Consider using the + toml(https://github.com/uiri/toml) package instead. + + # pytoml + + This project aims at being a specs-conforming and strict parser and writer for TOML1 files. + The library currently supports version 0.4.02 of the specs and runs with Python 2.7+ and 3.5+. + + Install: + + pip install pytoml + + The interface is the same as for the standard `json` package. + + >>> import pytoml as toml + >>> toml.loads('a = 1') + {'a': 1} + >>> with open('file.toml', 'rb') as fin: + ... obj = toml.load(fin) + >>> obj + {'a': 1} + + The `loads` function accepts either a bytes object + (that gets decoded as UTF-8 with no BOM allowed), + or a unicode object. + + Use `dump` or `dumps` to serialize a dict into TOML. + + >>> print toml.dumps(obj) + a = 1 + + ## tests + + To run the tests update the `toml-test` submodule: + + git submodule update --init --recursive + + Then run the tests: + + python test/test.py + + 1: https://github.com/toml-lang/toml + 2: https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md + +Platform: UNKNOWN +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: License :: OSI Approved :: MIT License +Classifier: Topic :: Software Development :: Libraries +Description-Content-Type: text/markdown
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/README.md -> _service:tar_scm:pytoml-0.1.21.tar.gz/README.md
Changed
@@ -1,43 +1,48 @@ -!PyPI(https://img.shields.io/pypi/v/pytoml.svg)(https://pypi.python.org/pypi/pytoml) -!Build Status(https://travis-ci.org/avakar/pytoml.svg?branch=master)(https://travis-ci.org/avakar/pytoml) - -# pytoml - -This project aims at being a specs-conforming and strict parser and writer for TOML1 files. -The library currently supports version 0.4.02 of the specs and runs with Python 2.6+ and 3.4+. - -Install: - - pip install pytoml - -The interface is the same as for the standard `json` package. - - >>> import pytoml as toml - >>> toml.loads('a = 1') - {'a': 1} - >>> with open('file.toml', 'rb') as fin: - ... obj = toml.load(fin) - >>> obj - {'a': 1} - -The `loads` function accepts either a bytes object -(that gets decoded as UTF-8 with no BOM allowed), -or a unicode object. - -Use `dump` or `dumps` to serialize a dict into TOML. - - >>> print toml.dumps(obj) - a = 1 - -## tests - -To run the tests update the `toml-test` submodule: - - git submodule update --init --recursive - -Then run the tests: - - python test/test.py - - 1: https://github.com/toml-lang/toml - 2: https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md +!PyPI(https://img.shields.io/pypi/v/pytoml.svg)(https://pypi.python.org/pypi/pytoml) +!Build Status(https://travis-ci.org/avakar/pytoml.svg?branch=master)(https://travis-ci.org/avakar/pytoml) + +# Deprecated + +The pytoml project is no longer being actively maintained. Consider using the +toml(https://github.com/uiri/toml) package instead. + +# pytoml + +This project aims at being a specs-conforming and strict parser and writer for TOML1 files. +The library currently supports version 0.4.02 of the specs and runs with Python 2.7+ and 3.5+. + +Install: + + pip install pytoml + +The interface is the same as for the standard `json` package. + + >>> import pytoml as toml + >>> toml.loads('a = 1') + {'a': 1} + >>> with open('file.toml', 'rb') as fin: + ... obj = toml.load(fin) + >>> obj + {'a': 1} + +The `loads` function accepts either a bytes object +(that gets decoded as UTF-8 with no BOM allowed), +or a unicode object. + +Use `dump` or `dumps` to serialize a dict into TOML. + + >>> print toml.dumps(obj) + a = 1 + +## tests + +To run the tests update the `toml-test` submodule: + + git submodule update --init --recursive + +Then run the tests: + + python test/test.py + + 1: https://github.com/toml-lang/toml + 2: https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/pytoml.egg-info
Added
+(directory)
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/pytoml.egg-info/PKG-INFO
Added
@@ -0,0 +1,67 @@ +Metadata-Version: 2.1 +Name: pytoml +Version: 0.1.21 +Summary: A parser for TOML-0.4.0 +Home-page: https://github.com/avakar/pytoml +Author: Martin Vejnár +Author-email: vejnar.martin@gmail.com +License: MIT +Description: !PyPI(https://img.shields.io/pypi/v/pytoml.svg)(https://pypi.python.org/pypi/pytoml) + !Build Status(https://travis-ci.org/avakar/pytoml.svg?branch=master)(https://travis-ci.org/avakar/pytoml) + + # Deprecated + + The pytoml project is no longer being actively maintained. Consider using the + toml(https://github.com/uiri/toml) package instead. + + # pytoml + + This project aims at being a specs-conforming and strict parser and writer for TOML1 files. + The library currently supports version 0.4.02 of the specs and runs with Python 2.7+ and 3.5+. + + Install: + + pip install pytoml + + The interface is the same as for the standard `json` package. + + >>> import pytoml as toml + >>> toml.loads('a = 1') + {'a': 1} + >>> with open('file.toml', 'rb') as fin: + ... obj = toml.load(fin) + >>> obj + {'a': 1} + + The `loads` function accepts either a bytes object + (that gets decoded as UTF-8 with no BOM allowed), + or a unicode object. + + Use `dump` or `dumps` to serialize a dict into TOML. + + >>> print toml.dumps(obj) + a = 1 + + ## tests + + To run the tests update the `toml-test` submodule: + + git submodule update --init --recursive + + Then run the tests: + + python test/test.py + + 1: https://github.com/toml-lang/toml + 2: https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md + +Platform: UNKNOWN +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: License :: OSI Approved :: MIT License +Classifier: Topic :: Software Development :: Libraries +Description-Content-Type: text/markdown
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/pytoml.egg-info/SOURCES.txt
Added
@@ -0,0 +1,18 @@ +LICENSE +MANIFEST.in +README.md +setup.cfg +setup.py +pytoml/__init__.py +pytoml/core.py +pytoml/parser.py +pytoml/test.py +pytoml/utils.py +pytoml/writer.py +pytoml.egg-info/PKG-INFO +pytoml.egg-info/SOURCES.txt +pytoml.egg-info/dependency_links.txt +pytoml.egg-info/top_level.txt +test/test.py +test/test_parser.py +test/test_writer.py \ No newline at end of file
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/pytoml.egg-info/dependency_links.txt
Added
@@ -0,0 +1,1 @@ +
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/pytoml.egg-info/top_level.txt
Added
@@ -0,0 +1,1 @@ +pytoml
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/pytoml/__init__.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/pytoml/__init__.py
Changed
@@ -1,3 +1,4 @@ -from .core import TomlError -from .parser import load, loads -from .writer import dump, dumps +from .core import TomlError +from .parser import load, loads +from .test import translate_to_test +from .writer import dump, dumps \ No newline at end of file
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/pytoml/core.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/pytoml/core.py
Changed
@@ -1,13 +1,13 @@ -class TomlError(RuntimeError): - def __init__(self, message, line, col, filename): - RuntimeError.__init__(self, message, line, col, filename) - self.message = message - self.line = line - self.col = col - self.filename = filename - - def __str__(self): - return '{}({}, {}): {}'.format(self.filename, self.line, self.col, self.message) - - def __repr__(self): - return 'TomlError({!r}, {!r}, {!r}, {!r})'.format(self.message, self.line, self.col, self.filename) +class TomlError(RuntimeError): + def __init__(self, message, line, col, filename): + RuntimeError.__init__(self, message, line, col, filename) + self.message = message + self.line = line + self.col = col + self.filename = filename + + def __str__(self): + return '{}({}, {}): {}'.format(self.filename, self.line, self.col, self.message) + + def __repr__(self): + return 'TomlError({!r}, {!r}, {!r}, {!r})'.format(self.message, self.line, self.col, self.filename)
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/pytoml/parser.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/pytoml/parser.py
Changed
@@ -1,374 +1,342 @@ -import string, re, sys, datetime -from .core import TomlError - -if sys.version_info0 == 2: - _chr = unichr -else: - _chr = chr - -def load(fin, translate=lambda t, x, v: v, object_pairs_hook=dict): - return loads(fin.read(), translate=translate, object_pairs_hook=object_pairs_hook, filename=getattr(fin, 'name', repr(fin))) - -def loads(s, filename='<string>', translate=lambda t, x, v: v, object_pairs_hook=dict): - if isinstance(s, bytes): - s = s.decode('utf-8') - - s = s.replace('\r\n', '\n') - - root = object_pairs_hook() - tables = object_pairs_hook() - scope = root - - src = _Source(s, filename=filename) - ast = _p_toml(src, object_pairs_hook=object_pairs_hook) - - def error(msg): - raise TomlError(msg, pos0, pos1, filename) - - def process_value(v, object_pairs_hook): - kind, text, value, pos = v - if kind == 'str' and value.startswith('\n'): - value = value1: - if kind == 'array': - if value and any(k != value00 for k, t, v, p in value1:): - error('array-type-mismatch') - value = process_value(item, object_pairs_hook=object_pairs_hook) for item in value - elif kind == 'table': - value = object_pairs_hook((k, process_value(valuek, object_pairs_hook=object_pairs_hook)) for k in value) - return translate(kind, text, value) - - for kind, value, pos in ast: - if kind == 'kv': - k, v = value - if k in scope: - error('duplicate_keys. Key "{0}" was used more than once.'.format(k)) - scopek = process_value(v, object_pairs_hook=object_pairs_hook) - else: - is_table_array = (kind == 'table_array') - cur = tables - for name in value:-1: - if isinstance(cur.get(name), list): - d, cur = curname-1 - else: - d, cur = cur.setdefault(name, (None, object_pairs_hook())) - - scope = object_pairs_hook() - name = value-1 - if name not in cur: - if is_table_array: - curname = (scope, object_pairs_hook()) - else: - curname = (scope, object_pairs_hook()) - elif isinstance(curname, list): - if not is_table_array: - error('table_type_mismatch') - curname.append((scope, object_pairs_hook())) - else: - if is_table_array: - error('table_type_mismatch') - old_scope, next_table = curname - if old_scope is not None: - error('duplicate_tables') - curname = (scope, next_table) - - def merge_tables(scope, tables): - if scope is None: - scope = object_pairs_hook() - for k in tables: - if k in scope: - error('key_table_conflict') - v = tablesk - if isinstance(v, list): - scopek = merge_tables(sc, tbl) for sc, tbl in v - else: - scopek = merge_tables(v0, v1) - return scope - - return merge_tables(root, tables) - -class _Source: - def __init__(self, s, filename=None): - self.s = s - self._pos = (1, 1) - self._last = None - self._filename = filename - self.backtrack_stack = - - def last(self): - return self._last - - def pos(self): - return self._pos - - def fail(self): - return self._expect(None) - - def consume_dot(self): - if self.s: - self._last = self.s0 - self.s = self1: - self._advance(self._last) - return self._last - return None - - def expect_dot(self): - return self._expect(self.consume_dot()) - - def consume_eof(self): - if not self.s: - self._last = '' - return True - return False - - def expect_eof(self): - return self._expect(self.consume_eof()) - - def consume(self, s): - if self.s.startswith(s): - self.s = self.slen(s): - self._last = s - self._advance(s) - return True - return False - - def expect(self, s): - return self._expect(self.consume(s)) - - def consume_re(self, re): - m = re.match(self.s) - if m: - self.s = self.slen(m.group(0)): - self._last = m - self._advance(m.group(0)) - return m - return None - - def expect_re(self, re): - return self._expect(self.consume_re(re)) - - def __enter__(self): - self.backtrack_stack.append((self.s, self._pos)) - - def __exit__(self, type, value, traceback): - if type is None: - self.backtrack_stack.pop() - else: - self.s, self._pos = self.backtrack_stack.pop() - return type == TomlError - - def commit(self): - self.backtrack_stack-1 = (self.s, self._pos) - - def _expect(self, r): - if not r: - raise TomlError('msg', self._pos0, self._pos1, self._filename) - return r - - def _advance(self, s): - suffix_pos = s.rfind('\n') - if suffix_pos == -1: - self._pos = (self._pos0, self._pos1 + len(s)) - else: - self._pos = (self._pos0 + s.count('\n'), len(s) - suffix_pos) - -_ews_re = re.compile(r'(?: \t|#^\n*\n|#^\n*\Z|\n)*') -def _p_ews(s): - s.expect_re(_ews_re) - -_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' } - -_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') -_newline_esc_re = re.compile('\n \t\n*') -def _p_basicstr_content(s, content=_basicstr_re): - res = - while True: - res.append(s.expect_re(content).group(0)) - if not s.consume('\\'): - break - if s.consume_re(_newline_esc_re): - pass - elif s.consume_re(_short_uni_re) or s.consume_re(_long_uni_re): - res.append(_chr(int(s.last().group(1), 16)))
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/pytoml/test.py
Added
@@ -0,0 +1,30 @@ +import datetime +from .utils import format_rfc3339 + +try: + _string_types = (str, unicode) + _int_types = (int, long) +except NameError: + _string_types = str + _int_types = int + +def translate_to_test(v): + if isinstance(v, dict): + return { k: translate_to_test(v) for k, v in v.items() } + if isinstance(v, list): + a = translate_to_test(x) for x in v + if v and isinstance(v0, dict): + return a + else: + return {'type': 'array', 'value': a} + if isinstance(v, datetime.datetime): + return {'type': 'datetime', 'value': format_rfc3339(v)} + if isinstance(v, bool): + return {'type': 'bool', 'value': 'true' if v else 'false'} + if isinstance(v, _int_types): + return {'type': 'integer', 'value': str(v)} + if isinstance(v, float): + return {'type': 'float', 'value': '{:.17}'.format(v)} + if isinstance(v, _string_types): + return {'type': 'string', 'value': v} + raise RuntimeError('unexpected value: {!r}'.format(v))
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/pytoml/utils.py
Added
@@ -0,0 +1,67 @@ +import datetime +import re + +rfc3339_re = re.compile(r'(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(?:Z|(+-\d{2}):(\d{2}))') + +def parse_rfc3339(v): + m = rfc3339_re.match(v) + if not m or m.group(0) != v: + return None + return parse_rfc3339_re(m) + +def parse_rfc3339_re(m): + r = map(int, m.groups():6) + if m.group(7): + micro = float(m.group(7)) + else: + micro = 0 + + if m.group(8): + g = int(m.group(8), 10) * 60 + int(m.group(9), 10) + tz = _TimeZone(datetime.timedelta(0, g * 60)) + else: + tz = _TimeZone(datetime.timedelta(0, 0)) + + y, m, d, H, M, S = r + return datetime.datetime(y, m, d, H, M, S, int(micro * 1000000), tz) + + +def format_rfc3339(v): + offs = v.utcoffset() + offs = int(offs.total_seconds()) // 60 if offs is not None else 0 + + if offs == 0: + suffix = 'Z' + else: + if offs > 0: + suffix = '+' + else: + suffix = '-' + offs = -offs + 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 + else: + return v.strftime('%Y-%m-%dT%H:%M:%S') + suffix + +class _TimeZone(datetime.tzinfo): + def __init__(self, offset): + self._offset = offset + + def utcoffset(self, dt): + return self._offset + + def dst(self, dt): + return None + + def tzname(self, dt): + m = self._offset.total_seconds() // 60 + if m < 0: + res = '-' + m = -m + else: + res = '+' + h = m // 60 + m = m - h * 60 + return '{}{:.02}{:.02}'.format(res, h, m)
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/pytoml/writer.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/pytoml/writer.py
Changed
@@ -1,127 +1,114 @@ -from __future__ import unicode_literals -import io, datetime, math, sys - -if sys.version_info0 == 3: - long = int - unicode = str - - -def dumps(obj, sort_keys=False): - fout = io.StringIO() - dump(obj, fout, sort_keys=sort_keys) - return fout.getvalue() - - -_escapes = {'\n': 'n', '\r': 'r', '\\': '\\', '\t': 't', '\b': 'b', '\f': 'f', '"': '"'} - - -def _escape_string(s): - res = - start = 0 - - def flush(): - if start != i: - res.append(sstart:i) - return i + 1 - - i = 0 - while i < len(s): - c = si - if c in '"\\\n\r\t\b\f': - start = flush() - res.append('\\' + _escapesc) - elif ord(c) < 0x20: - start = flush() - res.append('\\u%04x' % ord(c)) - i += 1 - - flush() - return '"' + ''.join(res) + '"' - - -def _escape_id(s): - if any(not c.isalnum() and c not in '-_' for c in s): - return _escape_string(s) - return 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' - if isinstance(v, int) or isinstance(v, long): - return unicode(v) - if isinstance(v, float): - if math.isnan(v) or math.isinf(v): - raise ValueError("{0} is not a valid TOML value".format(v)) - else: - return repr(v) - elif isinstance(v, unicode) or isinstance(v, bytes): - return _escape_string(v) - elif isinstance(v, datetime.datetime): - offs = v.utcoffset() - offs = _total_seconds(offs) // 60 if offs is not None else 0 - - if offs == 0: - suffix = 'Z' - else: - if offs > 0: - suffix = '+' - else: - suffix = '-' - offs = -offs - 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 - else: - return v.strftime('%Y-%m-%dT%H:%M:%S') + suffix - elif isinstance(v, list): - return _format_list(v) - else: - raise RuntimeError(v) - - -def dump(obj, fout, sort_keys=False): - tables = ((), obj, False) - - while tables: - name, table, is_array = tables.pop() - if name: - section_name = '.'.join(_escape_id(c) for c in name) - if is_array: - fout.write('{0}\n'.format(section_name)) - else: - fout.write('{0}\n'.format(section_name)) - - table_keys = sorted(table.keys()) if sort_keys else table.keys() - new_tables = - has_kv = False - for k in table_keys: - v = tablek - if isinstance(v, dict): - new_tables.append((name + (k,), v, False)) - elif isinstance(v, list) and v and all(isinstance(o, dict) for o in v): - new_tables.extend((name + (k,), d, True) for d in v) - elif v is None: - # based on mojombo's comment: https://github.com/toml-lang/toml/issues/146#issuecomment-25019344 - fout.write( - '#{} = null # To use: uncomment and replace null with value\n'.format(_escape_id(k))) - has_kv = True - else: - fout.write('{0} = {1}\n'.format(_escape_id(k), _format_value(v))) - has_kv = True - - tables.extend(reversed(new_tables)) - - if (name or has_kv) and tables: - fout.write('\n') +from __future__ import unicode_literals +import io, datetime, math, string, sys + +from .utils import format_rfc3339 + +try: + from pathlib import PurePath as _path_types +except ImportError: + _path_types = () + + +if sys.version_info0 == 3: + long = int + unicode = str + + +def dumps(obj, sort_keys=False): + fout = io.StringIO() + dump(obj, fout, sort_keys=sort_keys) + return fout.getvalue() + + +_escapes = {'\n': 'n', '\r': 'r', '\\': '\\', '\t': 't', '\b': 'b', '\f': 'f', '"': '"'} + + +def _escape_string(s): + res = + start = 0 + + def flush(): + if start != i: + res.append(sstart:i) + return i + 1 + + i = 0 + while i < len(s): + c = si + if c in '"\\\n\r\t\b\f': + start = flush() + res.append('\\' + _escapesc) + elif ord(c) < 0x20: + start = flush() + res.append('\\u%04x' % ord(c)) + i += 1 + + flush() + return '"' + ''.join(res) + '"' + + +_key_chars = string.digits + string.ascii_letters + '-_' +def _escape_id(s): + if any(c not in _key_chars for c in s): + return _escape_string(s) + return s + + +def _format_value(v): + if isinstance(v, bool): + return 'true' if v else 'false' + if isinstance(v, int) or isinstance(v, long): + return unicode(v) + if isinstance(v, float): + if math.isnan(v) or math.isinf(v): + raise ValueError("{0} is not a valid TOML value".format(v)) + else: + return repr(v) + elif isinstance(v, unicode) or isinstance(v, bytes): + return _escape_string(v) + elif isinstance(v, datetime.datetime): + return format_rfc3339(v) + elif isinstance(v, list): + return '{0}'.format(', '.join(_format_value(obj) for obj in v))
View file
_service:tar_scm:pytoml-0.1.21.tar.gz/setup.cfg
Added
@@ -0,0 +1,10 @@ +bdist_wheel +universal = 1 + +metadata +license_file = LICENSE + +egg_info +tag_build = +tag_date = 0 +
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/setup.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/setup.py
Changed
@@ -1,39 +1,37 @@ -#!/usr/bin/env python -# coding: utf-8 - -from setuptools import setup - -with open('README.md', 'r') as fin: - long_description = fin.read() - -setup( - name='pytoml', - version='0.1.18', - - description='A parser for TOML-0.4.0', - long_description=long_description, - long_description_content_type='text/markdown', - - author='Martin Vejnár', - author_email='vejnar.martin@gmail.com', - url='https://github.com/avakar/pytoml', - license='MIT', - packages='pytoml', - classifiers= - # Supported python versions - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - - # License - 'License :: OSI Approved :: MIT License', - - # Topics - 'Topic :: Software Development :: Libraries', - -) +#!/usr/bin/env python +# coding: utf-8 + +from setuptools import setup + +with open('README.md', 'r') as fin: + long_description = fin.read() + +setup( + name='pytoml', + version='0.1.21', + + description='A parser for TOML-0.4.0', + long_description=long_description, + long_description_content_type='text/markdown', + + author='Martin Vejnár', + author_email='vejnar.martin@gmail.com', + url='https://github.com/avakar/pytoml', + license='MIT', + packages='pytoml', + classifiers= + # Supported python versions + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + + # License + 'License :: OSI Approved :: MIT License', + + # Topics + 'Topic :: Software Development :: Libraries', + +)
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/test/test.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/test/test.py
Changed
@@ -1,106 +1,99 @@ -import os, json, sys, io, traceback, argparse -import pytoml as toml - -# 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 _testbench_literal(type, text, value): - if type == 'table': - return value - if type == 'array': - return { 'type': 'array', 'value': value } - if type == 'datetime': - offs = _total_seconds(value.tzinfo.utcoffset(value)) // 60 - offs = 'Z' if offs == 0 else '{}{}:{}'.format('-' if offs < 0 else '-', abs(offs) // 60, abs(offs) % 60) - v = '{0:04}-{1:02}-{2:02}T{3:02}:{4:02}:{5:02}{6}'.format(value.year, value.month, value.day, value.hour, value.minute, value.second, offs) - return { 'type': 'datetime', 'value': v } - if type == 'bool': - return { 'type': 'bool', 'value': 'true' if value else 'false' } - if type == 'float': - return { 'type': 'float', 'value': value } - if type == 'str': - return { 'type': 'string', 'value': value } - if type == 'int': - return { 'type': 'integer', 'value': str(value) } - -def adjust_bench(v): - if isinstance(v, dict): - if v.get('type') == 'float': - v'value' = float(v'value') - return v - return dict((k, adjust_bench(vk)) for k in v) - if isinstance(v, list): - return adjust_bench(v) for v in v - return v - -def _main(): - ap = argparse.ArgumentParser() - ap.add_argument('-d', '--dir', action='append') - ap.add_argument('testcase', nargs='*') - args = ap.parse_args() - - if not args.dir: - args.dir = os.path.join(os.path.split(__file__)0, 'toml-test/tests') - - succeeded = - failed = - - for path in args.dir: - if not os.path.isdir(path): - print('error: not a dir: {0}'.format(path)) - return 2 - for top, dirnames, fnames in os.walk(path): - for fname in fnames: - if not fname.endswith('.toml'): - continue - - if args.testcase and not any(arg in fname for arg in args.testcase): - continue - - parse_error = None - try: - with open(os.path.join(top, fname), 'rb') as fin: - parsed = toml.load(fin) - except toml.TomlError: - parsed = None - parse_error = sys.exc_info() - else: - dumped = toml.dumps(parsed, sort_keys=False) - dumped_sorted = toml.dumps(parsed, sort_keys=True) - parsed2 = toml.loads(dumped) - parsed2_sorted = toml.loads(dumped_sorted) - if parsed != parsed2 or parsed != parsed2_sorted: - failed.append((fname, parsed, parsed2, parsed2_sorted, None)) - continue - - with open(os.path.join(top, fname), 'rb') as fin: - parsed = toml.load(fin, translate=_testbench_literal) - - try: - with io.open(os.path.join(top, fname:-5 + '.json'), 'rt', encoding='utf-8') as fin: - bench = json.load(fin) - except IOError: - bench = None - - if parsed != adjust_bench(bench): - failed.append((fname, parsed, bench, parse_error)) - else: - succeeded.append(fname) - - for f, parsed, bench, e in failed: - try: - print('failed: {}\n{}\n{}'.format(f, json.dumps(parsed, indent=4), json.dumps(bench, indent=4))) - except TypeError: - print('failed: {}\n{}\n{}'.format(f, parsed, bench)) - - if e: - traceback.print_exception(*e) - print('succeeded: {0}'.format(len(succeeded))) - return 1 if failed or not succeeded else 0 - -if __name__ == '__main__': - sys.exit(_main()) +import os, json, sys, io, traceback, argparse +import pytoml as toml +from pytoml.utils import parse_rfc3339 + +def is_bench_equal(a, b): + if isinstance(a, dict): + if 'type' in a: + if b.get('type') != a'type': + return False + + if a'type' == 'float': + return float(a'value') == float(b'value') + if a'type' == 'datetime': + x = parse_rfc3339(a'value') + y = parse_rfc3339(b'value') + return x == y + if a'type' == 'array': + return is_bench_equal(a'value', b'value') + return a'value' == b'value' + + return (isinstance(b, dict) and len(a) == len(b) + and all(k in b and is_bench_equal(ak, bk) for k in a)) + + if isinstance(a, list): + return (isinstance(b, list) and len(a) == len(b) + and all(is_bench_equal(x, y) for x, y in zip(a, b))) + + raise RuntimeError('Invalid data in the bench JSON') + +def _main(): + ap = argparse.ArgumentParser() + ap.add_argument('-d', '--dir', action='append') + ap.add_argument('testcase', nargs='*') + args = ap.parse_args() + + if not args.dir: + args.dir = os.path.join(os.path.split(__file__)0, 'toml-test/tests') + + succeeded = + failed = + + for path in args.dir: + if not os.path.isdir(path): + print('error: not a dir: {0}'.format(path)) + return 2 + for top, dirnames, fnames in os.walk(path): + for fname in fnames: + if not fname.endswith('.toml'): + continue + + if args.testcase and not any(arg in fname for arg in args.testcase): + continue + + parse_error = None + try: + with open(os.path.join(top, fname), 'rb') as fin: + parsed = toml.load(fin) + except toml.TomlError: + parsed = None + parse_error = sys.exc_info() + else: + dumped = toml.dumps(parsed, sort_keys=False) + dumped_sorted = toml.dumps(parsed, sort_keys=True) + parsed2 = toml.loads(dumped) + parsed2_sorted = toml.loads(dumped_sorted) + if parsed != parsed2 or parsed != parsed2_sorted: + failed.append((fname, parsed, parsed2, parsed2_sorted, None)) + continue + + with open(os.path.join(top, fname), 'rb') as fin: + parsed = toml.load(fin) + parsed = toml.translate_to_test(parsed) + + try: + with io.open(os.path.join(top, fname:-5 + '.json'), 'rt', encoding='utf-8') as fin: + bench = json.load(fin) + except IOError: + bench = None + + 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) + + for f, parsed, bench, e in failed: + try: + print('failed: {}\n{}\n{}'.format(f, json.dumps(parsed, indent=4), json.dumps(bench, indent=4))) + except TypeError: + print('failed: {}\n{}\n{}'.format(f, parsed, bench)) + + if e: + traceback.print_exception(*e) + print('succeeded: {0}'.format(len(succeeded)))
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/test/test_parser.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/test/test_parser.py
Changed
@@ -1,37 +1,37 @@ -from __future__ import unicode_literals - -import collections -import sys -if sys.version_info < (2, 7): - from StringIO import StringIO -else: - from io import StringIO - -import pytest - -import pytoml as toml - - -def test_name_of_fileobj_is_used_in_errors(): - source = StringIO("") - source.name = "<source>" - error = pytest.raises(toml.TomlError, lambda: toml.load(source)) - assert error.value.filename == "<source>" - - -def test_when_fileobj_has_no_name_attr_then_repr_of_fileobj_is_used_in_errors(): - source = StringIO("") - error = pytest.raises(toml.TomlError, lambda: toml.load(source)) - assert error.value.filename == repr(source) - - -def test_object_pairs_hook(): - source = StringIO(u"""\ - x.a - x.b - x.c - """) - - d = toml.load(source, object_pairs_hook=collections.defaultdict) - assert isinstance(d, collections.defaultdict) - assert isinstance(d'x', collections.defaultdict) +from __future__ import unicode_literals + +import collections +import sys +if sys.version_info < (2, 7): + from StringIO import StringIO +else: + from io import StringIO + +import pytest + +import pytoml as toml + + +def test_name_of_fileobj_is_used_in_errors(): + source = StringIO("") + source.name = "<source>" + error = pytest.raises(toml.TomlError, lambda: toml.load(source)) + assert error.value.filename == "<source>" + + +def test_when_fileobj_has_no_name_attr_then_repr_of_fileobj_is_used_in_errors(): + source = StringIO("") + error = pytest.raises(toml.TomlError, lambda: toml.load(source)) + assert error.value.filename == repr(source) + + +def test_object_pairs_hook(): + source = StringIO(u"""\ + x.a + x.b + x.c + """) + + d = toml.load(source, object_pairs_hook=collections.defaultdict) + assert isinstance(d, collections.defaultdict) + assert isinstance(d'x', collections.defaultdict)
View file
_service:tar_scm:pytoml-0.1.18.tar.gz/test/test_writer.py -> _service:tar_scm:pytoml-0.1.21.tar.gz/test/test_writer.py
Changed
@@ -1,15 +1,33 @@ -from __future__ import unicode_literals - -import pytest - -import pytoml as toml - - -@pytest.mark.parametrize("value", - float("NaN"), - float("Inf"), - -float("Inf"), -) -def test_attempting_to_write_non_number_floats_raises_error(value): - error = pytest.raises(ValueError, lambda: toml.dumps({"value": value})) - assert str(error.value) == "{0} is not a valid TOML value".format(value) +from __future__ import unicode_literals + +import pytest + +import pytoml as toml + + +@pytest.mark.parametrize("value", + float("NaN"), + float("Inf"), + -float("Inf"), +) +def test_attempting_to_write_non_number_floats_raises_error(value): + error = pytest.raises(ValueError, lambda: toml.dumps({"value": value})) + assert str(error.value) == "{0} is not a valid TOML value".format(value) + + +def test_pathlib_path_objects_are_written_as_strings(): + pathlib = pytest.importorskip("pathlib") + path_value = toml.dumps({"value": pathlib.Path("test-path")}) + assert path_value == 'value = "test-path"\n' + + +def test_pathlib_purepath_objects_are_written_as_strings(): + pathlib = pytest.importorskip("pathlib") + path_value = toml.dumps({"value": pathlib.PurePath("test-path")}) + assert path_value == 'value = "test-path"\n' + + +def test_pathlib_purepath_objects_contents_are_escaped(): + pathlib = pytest.importorskip("pathlib") + path_value = toml.dumps({"value": pathlib.PurePath('C:\\Escape\"this string"')}) + assert path_value == 'value = "C:\\\\Escape\\"this string\\""\n'
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2