<s> from decimal import Decimal <EOL> from jsonobject . base_properties import JsonProperty <EOL> from jsonobject . exceptions import BadValueError <EOL> import re <EOL> from . datatypes import GeoPoint <EOL> def _canonical_decimal ( n ) : <EOL> """<STR_LIT>""" <EOL> decimal = Decimal ( n ) <EOL> if unicode ( decimal ) != n : <EOL> raise ValueError ( '<STR_LIT>' <EOL> . format ( n ) ) <EOL> return decimal <EOL> def _canonical_decimal_round_tiny_exp ( n ) : <EOL> """<STR_LIT>""" <EOL> exp_match = re . match ( r'<STR_LIT>' , n ) <EOL> if exp_match : <EOL> e = int ( exp_match . group ( <NUM_LIT:1> ) ) <EOL> if e < <NUM_LIT:4> : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( n ) ) <EOL> else : <EOL> return Decimal ( '<STR_LIT:0>' ) <EOL> else : <EOL> return _canonical_decimal ( n ) <EOL> class GeoPointProperty ( JsonProperty ) : <EOL> """<STR_LIT>""" <EOL> def wrap ( self , obj ) : <EOL> try : <EOL> latitude , longitude , altitude , accuracy = obj . split ( '<STR_LIT:U+0020>' ) <EOL> except ( TypeError , AttributeError , ValueError ) : <EOL> raise BadValueError ( "<STR_LIT>" <EOL> . format ( obj ) ) <EOL> try : <EOL> latitude = _canonical_decimal ( latitude ) <EOL> longitude = _canonical_decimal ( longitude ) <EOL> altitude = _canonical_decimal_round_tiny_exp ( altitude ) <EOL> accuracy = _canonical_decimal ( accuracy ) <EOL> except ValueError : <EOL> raise BadValueError ( "<STR_LIT>" <EOL> . format ( obj ) ) <EOL> return GeoPoint ( latitude , longitude , altitude , accuracy ) <EOL> def unwrap ( self , obj ) : <EOL> return obj , '<STR_LIT>' . format ( * obj ) </s>
