[issue33143] encode UTF-16 generates unexpected results

2018-03-26 Thread Anders Rundgren
Anders Rundgren <anders.rundgren@gmail.com> added the comment: Thanx for the superquick response! I really appreciate it. I'm obviously a Python n00b Anders -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python

[issue33143] encode UTF-16 generates unexpected results

2018-03-26 Thread Anders Rundgren
New submission from Anders Rundgren <anders.rundgren@gmail.com>: Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>

[issue26229] Make number serialization ES6/V8 compatible

2016-02-02 Thread Anders Rundgren
Anders Rundgren added the comment: In ES6/V8-compatible implementations which include "node.js", Chrome, Firefox, Safari and (of course) my Java reference implementation you can take a cryptographic hash of a JSON object with a predictable result. That is, this request is in no w

[issue26229] Make number serialization ES6/V8 compatible

2016-02-02 Thread Anders Rundgren
Anders Rundgren added the comment: An easier fix than mucking around in the pretty complex number serializer code would be adding an "ES6Format" option to the "json.dump*" methods which could use the supplied conversion code as is. For JSON parsing in an ES6-compatible way

[issue26229] Make number serialization ES6/V8 compatible

2016-01-30 Thread Anders Rundgren
Anders Rundgren added the comment: As I said, the problem is close to fixed in 3.5. You should not consider the JCS specification as the [sole] target but the ability to creating a normalized JSON object which has many uses including calculating a hash of such objects

[issue26241] repr() and str() are identical for floats in 3.5

2016-01-30 Thread Anders Rundgren
New submission from Anders Rundgren: According to the documentation repr() and str() are different when it comes to number formatting. A test with a 100 million random and selected IEEE 64-bit values returned no differences -- components: Interpreter Core messages: 259244 nosy

[issue26241] repr() and str() are identical for floats in 3.5

2016-01-30 Thread Anders Rundgren
Anders Rundgren added the comment: Apparently the docs have changed since 2.7: https://docs.python.org/3.5/tutorial/floatingpoint.html However, the documentation still "sort of" mentions repr() as the most accurate form which isn't entirely correct since it nowadays is identi

[issue26229] Make number serialization ES6/V8 compatible

2016-01-27 Thread Anders Rundgren
New submission from Anders Rundgren: ECMA has in their latest release defined that JSON elements must be ordered during serialization. This is easy to accomplish using Python's OrderedDict. What is less trivial is that numbers have to be formatted in a certain way as well. I have tested

[issue26191] pip on Windows doesn't honor Case

2016-01-24 Thread Anders Rundgren
New submission from Anders Rundgren: pip install Crypto Terminates correctly and the package is there as well. Unfortunately the directory is named "crypto" rather than "Crypto" so when I perform >>>import Crypto the interpreter fails. >>>import cryp

[issue23123] Only READ support for Decimal in json

2014-12-30 Thread Anders Rundgren
Anders Rundgren added the comment: Antoine Pitrou added the comment: To cope with this potential problem, compliant parsers must preserve the original textual representation of properties internally in order to support JCS normalization requirements That sounds ridiculous. Did someone

[issue23123] Only READ support for Decimal in json

2014-12-30 Thread Anders Rundgren
Anders Rundgren added the comment: Antoine Pitrou added the comment: I won't claim to know/understand the specifics, but message payload in base64 actually sounds reasonable to me, if far from optimal (both from readibility and space overhead POV) :-). It is indeed a working solution

[issue23123] Only READ support for Decimal in json

2014-12-29 Thread Anders Rundgren
Anders Rundgren added the comment: I guess my particular requirement/wish is unusual (keeping the original textual representation of a floating point number intact) while using Decimal should be fairly universal. If these things could be combined in a Decimal support option I would

[issue23123] Only READ support for Decimal in json

2014-12-29 Thread Anders Rundgren
Anders Rundgren added the comment: Bob, Your'e right, I have put up a requirement for JSON serializing that may be over the top. OTOH, there are (AFAICT...) only two possible solutions: 1. Outlaw floating point data from the plot 2. Insist that serializers conform to the spec As a pragmatic I

[issue23123] Only READ support for Decimal in json

2014-12-29 Thread Anders Rundgren
Anders Rundgren added the comment: Well, I could have insisted on canonicalization of floating-point data but that's so awkward that outlawing such data is a cleaner approach. Since the target for JCS is security- and payment-protocols, I don't think the absence of floating-point support

[issue23123] Only READ support for Decimal in json

2014-12-29 Thread Anders Rundgren
Anders Rundgren added the comment: Using simplejson I got it to work!!! I just wonder what you think of the solution: import collections import simplejson as json from decimal import Decimal class EnhancedDecimal(Decimal): def __str__ (self): return self.saved_string def __new__

[issue23123] Only READ support for Decimal in json

2014-12-29 Thread Anders Rundgren
Anders Rundgren added the comment: Bob, I'm not sure I understand why you say that JCS requires *almost* full normalization. Using browsers you can generate fully compliant JCS objects using like 20 lines of javascript/webcrypto (here excluding base64 support). No normalization step

[issue23123] Only READ support for Decimal in json

2014-12-29 Thread Anders Rundgren
Anders Rundgren added the comment: The current JCS validator is only 150 lines and does both RSA and EC signatures: https://code.google.com/p/openkeystore/source/browse/python/trunk/src/org/webpki/json/JCSValidator.py My Java-version is much more advanced but this is quite useful anyway

[issue23123] Only READ support for Decimal in json

2014-12-29 Thread Anders Rundgren
Anders Rundgren added the comment: Ethan Furman added the comment: I am not a regular json user, but my impression is the format is pretty basic, and we would be overloading it to try and keep numbers with three decimal places as Decimal, and anything else as float. Isn't json's main

[issue23123] Only READ support for Decimal in json

2014-12-28 Thread Anders Rundgren
Anders Rundgren added the comment: I was actually hoping to implement the final part of this: https://openkeystore.googlecode.com/svn/resources/trunk/docs/jcs.html#Normalization_and_Signature_Validation It seems that the current Decimal implementation wouldn't save me anyway since it modifies

[issue23123] Only READ support for Decimal in json

2014-12-28 Thread Anders Rundgren
Anders Rundgren added the comment: It would be great if I could use a sub-classed Decimal during parsing but since it doesn't appear to be a way to serialize the result using the json package I'm probably stuck with the current 99% solution. I have solved this in Java and JavaScript

[issue23123] Only READ support for Decimal in json

2014-12-27 Thread Anders Rundgren
New submission from Anders Rundgren: jsonString = '{t:6,h:4.50, g:text,j:1.40e450}' jsonObject = json.loads(jsonString, object_pairs_hook=collections.OrderedDict,parse_float=Decimal) for item in jsonObject: print jsonObject[item] 6 4.50 text 1.40E+450 Works as expected. However, there seems