Skip to content

Commit

Permalink
+ Version 1.4.1
Browse files Browse the repository at this point in the history
+ Cleaned some stuff
  • Loading branch information
Genarito committed Aug 1, 2021
1 parent f9cf680 commit 12c1577
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions gura/GuraParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,7 @@ def literal_string(self) -> MatchResult:

return MatchResult(MatchResultType.PRIMITIVE, ''.join(chars))

@staticmethod
def dumps(value: Dict) -> str:
def dumps(self, value: Dict) -> str:
"""
Generates a Gura string from a dictionary (aka. stringify). Takes a value, check its type and returns its
correct value in a recursive way
Expand Down Expand Up @@ -731,7 +730,7 @@ def dumps(value: Dict) -> str:
# If the value is an object, splits the stringified value by
# newline and indents each line before adding it to the result
if type(dict_value) == dict:
stringified_value = dumps(dict_value).rstrip()
stringified_value = self.dumps(dict_value).rstrip()
if len(dict_value) > 0:
result += '\n'

Expand All @@ -742,21 +741,21 @@ def dumps(value: Dict) -> str:
result += ' ' + stringified_value + '\n'
# Otherwise adds the stringified value
else:
result += f' {dumps(dict_value)}\n'
result += f' {self.dumps(dict_value)}\n'

return result
if value_type == list:
should_multiline = any((type(e) == dict or type(e) == list) and len(e) > 0 for e in value)

if not should_multiline:
stringify_values = list(map(dumps, value))
stringify_values = list(map(self.dumps, value))
return f'[{", ".join(stringify_values)}]'

result = '['

last_idx = len(value) - 1
for idx, entry in enumerate(value):
stringified_value = dumps(entry).rstrip()
stringified_value = self.dumps(entry).rstrip()

result += '\n'

Expand Down
2 changes: 1 addition & 1 deletion gura/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
VariableNotDefinedError, DuplicatedImportError, loads, dumps
from gura.Parser import ParseError

__version__ = "1.4.0"
__version__ = "1.4.1"

loads = loads
dumps = dumps
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
author='JWare',
author_email='[email protected]',
url='https://github.com/gura-conf/gura-python-parser',
download_url='https://github.com/gura-conf/gura-python-parser/archive/refs/tags/1.4.0.tar.gz',
download_url='https://github.com/gura-conf/gura-python-parser/archive/refs/tags/1.4.1.tar.gz',
keywords=['Gura', 'parser', 'loads', 'dumps', 'encode', 'decode'],
install_requires=[
'wheel'
Expand Down

0 comments on commit 12c1577

Please sign in to comment.