-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type configs #97
Merged
Merged
Type configs #97
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
96e6651
get rid of redundant ALLOWED_PROPERTY_TYPES
dannyroberts ad5f153
remove basestring from MAP_TYPES_PROPERTIES
dannyroberts d28c0d2
make the treatment of types completely configurable
dannyroberts 55f2fc5
add and test update_properties Meta variable
dannyroberts e82deb3
remove support for python 2.6
dannyroberts 88535ec
allow unknown options in Meta
dannyroberts 59a46c4
bump version to 0.6.0
dannyroberts efa2924
r-prefix all regexes
dannyroberts f1f4973
document TypeConfig class
dannyroberts 7c49c72
change version to beta
dannyroberts b7c0d60
remove stale comment
dannyroberts 77e0af3
better assert
dannyroberts 64d3a4d
change TypeConfig.update to updated
dannyroberts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
language: python | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
install: "pip install . --use-mirrors" | ||
script: "python setup.py test" |
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 |
---|---|---|
@@ -1,13 +1,49 @@ | ||
from __future__ import absolute_import | ||
from .base import JsonObjectBase, _LimitedDictInterfaceMixin | ||
from .convert import STRING_CONVERSIONS | ||
|
||
import decimal | ||
import datetime | ||
|
||
class JsonObject(JsonObjectBase, _LimitedDictInterfaceMixin): | ||
from . import properties | ||
import re | ||
|
||
|
||
re_date = re.compile('^(\d{4})\D?(0[1-9]|1[0-2])\D?([12]\d|0[1-9]|3[01])$') | ||
re_time = re.compile('^([01]\d|2[0-3])\D?([0-5]\d)\D?([0-5]\d)?\D?(\d{3,6})?$') | ||
re_datetime = re.compile( | ||
r'^(\d{4})\D?(0[1-9]|1[0-2])\D?([12]\d|0[1-9]|3[01])' | ||
'(\D?([01]\d|2[0-3])\D?([0-5]\d)\D?([0-5]\d)?\D?(\d{3,6})?' | ||
'([zZ]|([\+-])([01]\d|2[0-3])\D?([0-5]\d)?)?)?$' | ||
) | ||
re_decimal = re.compile('^(\d+)\.(\d+)$') | ||
|
||
_string_conversions = STRING_CONVERSIONS | ||
|
||
class JsonObject(JsonObjectBase, _LimitedDictInterfaceMixin): | ||
def __getstate__(self): | ||
return self.to_json() | ||
|
||
def __setstate__(self, dct): | ||
self.__init__(dct) | ||
|
||
class Meta(object): | ||
properties = { | ||
decimal.Decimal: properties.DecimalProperty, | ||
datetime.datetime: properties.DateTimeProperty, | ||
datetime.date: properties.DateProperty, | ||
datetime.time: properties.TimeProperty, | ||
str: properties.StringProperty, | ||
unicode: properties.StringProperty, | ||
bool: properties.BooleanProperty, | ||
int: properties.IntegerProperty, | ||
long: properties.IntegerProperty, | ||
float: properties.FloatProperty, | ||
list: properties.ListProperty, | ||
dict: properties.DictProperty, | ||
set: properties.SetProperty, | ||
} | ||
string_conversions = ( | ||
(re_date, datetime.date), | ||
(re_time, datetime.time), | ||
(re_datetime, datetime.datetime), | ||
(re_decimal, decimal.Decimal), | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it matters in this case, but you need to put an
r
in front of each line if you want each line to be that type of string literal:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, great catch. You're right that it doesn't "matter" in this case, because two python "oddities" cancel each other out: (1) string-type prefixes only apply to the first in a multiline concatenation (ok I mean that makes sense) (2) "\d" is silently treated as two characters "\d" for any character that isn't part of an escape sequence, while "\n" is a single character. So the loosey-gooseyness of (2) obscured (1) and hasn't been causing an error.