Skip to content

Commit

Permalink
Fixed sonicprobe.helpers.to_yaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Delle Cave committed Jan 28, 2022
1 parent 544fbe8 commit 13a0ccf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
@@ -1,3 +1,9 @@
python-sonicprobe (0.3.45) unstable; urgency=medium

* Fixed sonicprobe.helpers.to_yaml.

-- Adrien DELLE CAVE (Decryptus) <adc@doowan.net> Thu, 27 Jan 2022 05:13:26 +0100

python-sonicprobe (0.3.44) unstable; urgency=medium

* Added xys ienum.
Expand Down
2 changes: 1 addition & 1 deletion RELEASE
@@ -1 +1 @@
0.3.44
0.3.45
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.44
0.3.45
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -44,7 +44,7 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'm2r',
'm2r2',
'sphinx.ext.autodoc',
#'sphinx.ext.napoleon',
]
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
@@ -1,2 +1,2 @@
m2r
m2r2
PyYAML>=3.10
4 changes: 2 additions & 2 deletions setup.yml
Expand Up @@ -4,8 +4,8 @@ description: sonicprobe
author: Adrien Delle Cave
author_email: pypi@doowan.net
copyright: '2022 Adrien Delle Cave'
release: '0.3.44'
version: '0.3.44'
release: '0.3.45'
version: '0.3.45'
license: License GPL-3
url: https://github.com/decryptus/sonicprobe
python_requires:
Expand Down
23 changes: 15 additions & 8 deletions sonicprobe/helpers.py
Expand Up @@ -57,7 +57,7 @@
ALPHANUM = frozenset(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

RE_CRTL_CHARS = re.compile(r'([\x00-\x1f\x7f-\x9f]+)')
RE_CTRL_CHARS = re.compile(r'([\x00-\x1f\x7f-\x9f]+)')
RE_SPACE_CHARS = re.compile(r'\s\s+')
RE_YAML_QSTR = re.compile(r'^(?:\!\![a-z\/]+\s+)?\'(.*)\'$').match

Expand Down Expand Up @@ -101,7 +101,7 @@ def clean_string(value):
return RE_SPACE_CHARS.sub(' ', value.strip())

def raw_string(value):
def repl_crtl_chars(match):
def repl_ctrl_chars(match):
s = match.group()
if PY2 and isinstance(s, str):
return s.encode('string-escape')
Expand All @@ -113,7 +113,7 @@ def repl_crtl_chars(match):

return repr(s)[1:-1]

return RE_CRTL_CHARS.sub(repl_crtl_chars, value)
return RE_CTRL_CHARS.sub(repl_ctrl_chars, value)

def normalize_string(value, case = None):
if not is_print(value):
Expand Down Expand Up @@ -765,11 +765,18 @@ def to_yaml(value, *args, **kwargs):
and RE_YAML_QSTR(value):
has_qstr = True

r = dump_yaml([value],
default_flow_style = None,
default_style = '',
allow_unicode = True,
**kwargs)[1:-2]
if isinstance(value, (dict, list, tuple)):
r = dump_yaml(value,
default_flow_style = None,
default_style = '',
allow_unicode = True,
**kwargs)[0:-1]
else:
r = dump_yaml([value],
default_flow_style = None,
default_style = '',
allow_unicode = True,
**kwargs)[1:-2]

if not has_qstr \
and isinstance(r, (string_types, text_type)):
Expand Down

0 comments on commit 13a0ccf

Please sign in to comment.