[ 
https://issues.apache.org/jira/browse/AVRO-1788?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15527776#comment-15527776
 ] 

ASF GitHub Bot commented on AVRO-1788:
--------------------------------------

GitHub user ssaamm opened a pull request:

    https://github.com/apache/avro/pull/133

    AVRO-1788: Implement Python 2 API

    The Python 2 API and the Python 3 API differ unnecessarily, making it more 
difficult to write code that supports both major Python versions. Additionally, 
a lot of these function names were non-Pythonic.
    
    This contribution is my original work, and I license the work to the 
project under the project's open source license.
    
    Tests pass:
    
    ```
    
/Users/sam/dev/avro/lang/py3/env/lib/python3.5/site-packages/setuptools/dist.py:294:
 UserWarning: The version specified ('1.9.0-SNAPSHOT') is an invalid version, 
this may not work as expected with newer versions of setuptools, pip, and PyPI. 
Please see PEP 440 for more details.
      "details." % self.metadata.version
    testCsv (avro.tests.test_script.TestCat) ... ok
    testCsvHeader (avro.tests.test_script.TestCat) ... ok
    testFields (avro.tests.test_script.TestCat) ... ok
    testFiles (avro.tests.test_script.TestCat) ... ok
    testFilter (avro.tests.test_script.TestCat) ... ok
    testHelp (avro.tests.test_script.TestCat) ... ok
    testJsonPretty (avro.tests.test_script.TestCat) ... ok
    testPrint (avro.tests.test_script.TestCat) ... ok
    testPrintSchema (avro.tests.test_script.TestCat) ... ok
    testSkip (avro.tests.test_script.TestCat) ... ok
    testVersion (avro.tests.test_script.TestCat) ... ok
    testAppend (avro.tests.test_datafile.TestDataFile) ... ok
    testContextManager (avro.tests.test_datafile.TestDataFile) ... ok
    testMetadata (avro.tests.test_datafile.TestDataFile) ... ok
    testRoundTrip (avro.tests.test_datafile.TestDataFile) ... ok
    testInterop (avro.tests.test_datafile_interop.TestDataFileInterop) ... ok
    testSymbolsInOrder (avro.tests.test_enum.TestEnum) ... ok
    testSymbolsInReverseOrder (avro.tests.test_enum.TestEnum) ... ok
    testBinaryIntEncoding (avro.tests.test_io.TestIO) ... ok
    testBinaryLongEncoding (avro.tests.test_io.TestIO) ... ok
    testDefaultValue (avro.tests.test_io.TestIO) ... ok
    testFieldOrder (avro.tests.test_io.TestIO) ... ok
    testNoDefaultValue (avro.tests.test_io.TestIO) ... ok
    testProjection (avro.tests.test_io.TestIO) ... ok
    testRoundTrip (avro.tests.test_io.TestIO) ... ok
    testSchemaPromotion (avro.tests.test_io.TestIO) ... ok
    testSkipInt (avro.tests.test_io.TestIO) ... ok
    testSkipLong (avro.tests.test_io.TestIO) ... ok
    testTypeException (avro.tests.test_io.TestIO) ... ok
    testUnknownSymbol (avro.tests.test_io.TestIO) ... ok
    testValidate (avro.tests.test_io.TestIO) ... ok
    testEchoService (avro.tests.test_ipc.TestIPC)
    Tests client-side of the Echo service. ... 2016-09-27 18:14:00,348 INFO 
test_ipc.py:118 : Echo RPC Server listening on 127.0.0.1:57632
    2016-09-27 18:14:00,348 INFO test_ipc.py:119 : RPC socket: <socket.socket 
fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, 
laddr=('127.0.0.1', 57632)>
    2016-09-27 18:14:00,349 INFO ipc.py:179 : Sending handshake request: 
{'serverHash': b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2', 
'clientHash': b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2'}
    2016-09-27 18:14:00,350 INFO ipc.py:204 : writing request: {'ping': 
{'text': 'hello ping', 'timestamp': 31415}}
    2016-09-27 18:14:00,350 INFO ipc.py:654 : Serialized request: 
b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2\x00\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2\x00\x00\x08ping\xee\xea\x03\x14hello
 ping'
    2016-09-27 18:14:00,351 INFO ipc.py:412 : Processing handshake request: 
{'serverHash': b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2', 
'clientProtocol': None, 'meta': None, 'clientHash': 
b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2'}
    2016-09-27 18:14:00,351 INFO ipc.py:441 : Handshake response: {'match': 
'BOTH'}
    2016-09-27 18:14:00,351 INFO ipc.py:375 : Processing request: {'ping': 
{'text': 'hello ping', 'timestamp': 31415}}
    2016-09-27 18:14:00,351 INFO test_ipc.py:90 : Message: {"response": 
{"type": "record", "namespace": "org.apache.avro.ipc.echo", "name": "Pong", 
"fields": [{"type": "long", "name": "timestamp", "default": -1}, {"type": 
"org.apache.avro.ipc.echo.Ping", "name": "ping"}]}, "errors": [], "request": 
[{"type": {"type": "record", "namespace": "org.apache.avro.ipc.echo", "name": 
"Ping", "fields": [{"type": "long", "name": "timestamp", "default": -1}, 
{"type": "string", "name": "text", "default": ""}]}, "name": "ping"}]}
    2016-09-27 18:14:00,351 INFO test_ipc.py:91 : Request: {'ping': {'text': 
'hello ping', 'timestamp': 31415}}
    2016-09-27 18:14:00,352 INFO ipc.py:656 : Serialized response: 
b'\x00\x00\x00\x00\x00\x00\xbe\x90\xe9\xde\xedU\xee\xea\x03\x14hello ping'
    127.0.0.1 - - [27/Sep/2016 18:14:00] "POST / HTTP/1.1" 200 -
    2016-09-27 18:14:00,352 INFO ipc.py:665 : Response sent
    2016-09-27 18:14:00,353 INFO ipc.py:219 : Processing handshake response: 
{'serverHash': None, 'match': 'BOTH', 'meta': None, 'serverProtocol': None}
    2016-09-27 18:14:00,353 INFO test_ipc.py:143 : Received echo response: 
{'timestamp': 1475018040351, 'ping': {'text': 'hello ping', 'timestamp': 31415}}
    2016-09-27 18:14:00,353 INFO ipc.py:179 : Sending handshake request: 
{'serverHash': b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2', 
'clientHash': b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2'}
    2016-09-27 18:14:00,353 INFO ipc.py:204 : writing request: {'ping': 
{'text': 'hello again', 'timestamp': 123456}}
    2016-09-27 18:14:00,354 INFO ipc.py:654 : Serialized request: 
b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2\x00\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2\x00\x00\x08ping\x80\x89\x0f\x16hello
 again'
    2016-09-27 18:14:00,354 INFO ipc.py:412 : Processing handshake request: 
{'serverHash': b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2', 
'clientProtocol': None, 'meta': None, 'clientHash': 
b'\xcc9\x86\xfb\xb6\xad\x8a\ni\xf9X\xbb\x06\xc6\x15\xb2'}
    2016-09-27 18:14:00,355 INFO ipc.py:441 : Handshake response: {'match': 
'BOTH'}
    2016-09-27 18:14:00,355 INFO ipc.py:375 : Processing request: {'ping': 
{'text': 'hello again', 'timestamp': 123456}}
    2016-09-27 18:14:00,355 INFO test_ipc.py:90 : Message: {"response": 
{"type": "record", "namespace": "org.apache.avro.ipc.echo", "name": "Pong", 
"fields": [{"type": "long", "name": "timestamp", "default": -1}, {"type": 
"org.apache.avro.ipc.echo.Ping", "name": "ping"}]}, "errors": [], "request": 
[{"type": {"type": "record", "namespace": "org.apache.avro.ipc.echo", "name": 
"Ping", "fields": [{"type": "long", "name": "timestamp", "default": -1}, 
{"type": "string", "name": "text", "default": ""}]}, "name": "ping"}]}
    2016-09-27 18:14:00,355 INFO test_ipc.py:91 : Request: {'ping': {'text': 
'hello again', 'timestamp': 123456}}
    2016-09-27 18:14:00,355 INFO ipc.py:656 : Serialized response: 
b'\x00\x00\x00\x00\x00\x00\xc6\x90\xe9\xde\xedU\x80\x89\x0f\x16hello again'
    127.0.0.1 - - [27/Sep/2016 18:14:00] "POST / HTTP/1.1" 200 -
    2016-09-27 18:14:00,355 INFO ipc.py:665 : Response sent
    2016-09-27 18:14:00,356 INFO ipc.py:219 : Processing handshake response: 
{'serverHash': None, 'match': 'BOTH', 'meta': None, 'serverProtocol': None}
    2016-09-27 18:14:00,356 INFO test_ipc.py:149 : Received echo response: 
{'timestamp': 1475018040355, 'ping': {'text': 'hello again', 'timestamp': 
123456}}
    ok
    testEquivalenceAfterRoundTrip (avro.tests.test_protocol.TestProtocol) ... ok
    testInnerNamespaceNotRendered (avro.tests.test_protocol.TestProtocol) ... ok
    testInnerNamespaceSet (avro.tests.test_protocol.TestProtocol) ... ok
    testParse (avro.tests.test_protocol.TestProtocol) ... ok
    testValidCastToStringAfterParse (avro.tests.test_protocol.TestProtocol) ... 
ok
    testCorrectRecursiveExtraction (avro.tests.test_schema.TestSchema) ... ok
    testDocAttributes (avro.tests.test_schema.TestSchema) ... ok
    testEquivalenceAfterRoundTrip (avro.tests.test_schema.TestSchema) ... ok
    testFullname (avro.tests.test_schema.TestSchema)
    The fullname is determined in one of the following ways: ... ok
    testOtherAttributes (avro.tests.test_schema.TestSchema) ... ok
    testParse (avro.tests.test_schema.TestSchema) ... ok
    testValidCastToStringAfterParse (avro.tests.test_schema.TestSchema) ... ok
    testMultiFile (avro.tests.test_script.TestWrite) ... ok
    testOutfile (avro.tests.test_script.TestWrite) ... ok
    testStdin (avro.tests.test_script.TestWrite) ... ok
    testVersion (avro.tests.test_script.TestWrite) ... ok
    testWriteCsv (avro.tests.test_script.TestWrite) ... ok
    testWriteJson (avro.tests.test_script.TestWrite) ... ok
    
    ----------------------------------------------------------------------
    Ran 50 tests in 2.305s
    
    OK
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ssaamm/avro master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/avro/pull/133.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #133
    
----
commit 846ac19a1c944865f1d96cc767e713ee1f25c4ea
Author: Samuel Taylor <[email protected]>
Date:   2016-09-27T23:08:58Z

    AVRO-1788: Implement Python 2 API

----


> python api differs unnecessarily between python2 and python3
> ------------------------------------------------------------
>
>                 Key: AVRO-1788
>                 URL: https://issues.apache.org/jira/browse/AVRO-1788
>             Project: Avro
>          Issue Type: Wish
>            Reporter: Alexander Hasha
>            Priority: Minor
>
> It is difficult to use the python avro module in projects that maintain 
> simultaneous compatibility between python 2 and python 3, because there are 
> small differences in the API between the two versions in the module that seem 
> unnecessary.
> For example, to parse a schema string in python 2:
> {code}
> from avro.schema import parse
> {code}
> and in python 3:
> {code}
> from avro.schema import Parse
> {code}
> In Python2, DatumReader's constructor has keyword argument "writers_schema", 
> and in Python 3 it becomes "writer_schema" (no s).
> Would it be possible to align method names and arguments across the two 
> modules?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to