Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
Template
Commits
2cc629c6
Commit
2cc629c6
authored
8 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
- More doctests.
- Updated TODO list.
parent
d4f711a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.rst
+1
-1
1 addition, 1 deletion
README.rst
template/filters.py
+37
-0
37 additions, 0 deletions
template/filters.py
with
38 additions
and
1 deletion
README.rst
+
1
−
1
View file @
2cc629c6
...
...
@@ -78,7 +78,7 @@ at: https://www.shore.co.il/git/.
TODO
----
-
Add
uni
t tests of filters using doctest
.
-
Fix
uni
code strings in Python 2.7 only doctests in :code:`load_json`
.
- Fix combining dictionaries test.
- Fix Travis CI test on Python 3.2 (https://travis-ci.org/adarnimrod/template/jobs/187388235).
- Release on tagged commits to PyPI in Travis CI
...
...
This diff is collapsed.
Click to expand it.
template/filters.py
+
37
−
0
View file @
2cc629c6
#!/usr/bin/env python
from
__future__
import
(
absolute_import
,
division
,
print_function
,
unicode_literals
)
def
to_yaml
(
value
):
...
...
@@ -20,16 +22,51 @@ def to_yaml(value):
def
to_json
(
value
):
'''
Converts given data structure to JSON form.
Examples:
>>>
to_json
([
1
,
2
,
3
])
'
[1, 2, 3]
'
>>>
to_json
({
'
b
'
:
2
})
'
{
"
b
"
: 2}
'
>>>
to_json
(
2
)
'
2
'
>>>
to_json
({
1
:
{
'
a
'
:
[
1
,
2
,
3
]}})
'
{
"
1
"
: {
"
a
"
: [1, 2, 3]}}
'
'''
from
json
import
dumps
return
dumps
(
value
)
def
from_json
(
value
):
'''
Returns native data structure from the given JSON string.
Examples:
>>>
from_json
(
'
[1, 2, 3]
'
)
[
1
,
2
,
3
]
>>>
from_json
(
'"
a
"'
)
u
'
a
'
>>>
from_json
(
'
{
"
1
"
: {
"
a
"
: [1, 2, 3]}}
'
)
{
u
'
1
'
:
{
u
'
a
'
:
[
1
,
2
,
3
]}}
'''
from
json
import
loads
return
loads
(
value
)
def
from_yaml
(
value
):
'''
Returns native data structure from the given YAML string.
Examples:
>>>
from_yaml
(
'
a
'
)
'
a
'
>>>
from_yaml
(
'
[1, 2, 3]
'
)
[
1
,
2
,
3
]
>>>
from_yaml
(
'
{
"
1
"
: {
"
a
"
: [1, 2, 3]}}
'
)
{
'
1
'
:
{
'
a
'
:
[
1
,
2
,
3
]}}
'''
from
yaml
import
safe_load
return
safe_load
(
value
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment