forked from jfinkels/flask-restless
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/jfinkels/flask-restless
- Loading branch information
Showing
5 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
flask.ext.restless.helpers | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Helper functions for Flask-Restless. | ||
:copyright: 2012 Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com> | ||
:license: GNU AGPLv3+ or BSD | ||
""" | ||
|
||
|
||
def unicode_keys_to_strings(dictionary): | ||
"""Returns a new dictionary with the same mappings as `dictionary`, but | ||
with each of the keys coerced to a string (by calling :func:`str(key)`). | ||
This function is intended to be used for Python 2.5 compatibility when | ||
unpacking a dictionary to provide keyword arguments to a function or | ||
method. For example:: | ||
>>> def func(a=1, b=2): | ||
... return a + b | ||
... | ||
>>> d = {u'a': 10, u'b': 20} | ||
>>> func(**d) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
TypeError: func() keywords must be strings | ||
>>> func(**unicode_keys_to_strings(d)) | ||
30 | ||
""" | ||
return dict((str(k), v) for k, v in dictionary.iteritems()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters