Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ pip-delete-this-directory.txt

.venv*
*.ignore.py
*.avro
*.avro

# IntelliJ
/.idea/
10 changes: 5 additions & 5 deletions confluent/schemaregistry/client/CachedSchemaRegistryClient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib2
import urllib
import json
import sys

Expand Down Expand Up @@ -33,7 +33,7 @@ def _send_request(self, url, method='GET', body=None, headers=None):
if body:
body = json.dumps(body)

new_req = urllib2.Request(url, data=body)
new_req = urllib.request.Request(url, data=body)
# must be callable
new_req.get_method = lambda: method
# set the accept header
Expand All @@ -46,16 +46,16 @@ def _send_request(self, url, method='GET', body=None, headers=None):
for header_name in headers:
new_req.add_header(header_name, headers[header_name])
try:
response = urllib2.urlopen(new_req)
response = urllib.request.urlopen(new_req)
# read response
result = json.loads(response.read())
# build meta with headers as a dict
meta = response.info().dict
meta = dict(response.info().items())
# http code
code = response.getcode()
# return result + meta tuple
return (result, meta, code)
except urllib2.HTTPError as e:
except urllib.error.HTTPError as e:
code = e.code
result = json.loads(e.read())
message = "HTTP Error (%d) from schema registry: %s %d" % (code,
Expand Down
4 changes: 2 additions & 2 deletions confluent/schemaregistry/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def __repr__(self):
def __str__(self):
return self.message

from MockSchemaRegistryClient import *
from CachedSchemaRegistryClient import *
from .MockSchemaRegistryClient import *
from .CachedSchemaRegistryClient import *
9 changes: 6 additions & 3 deletions confluent/schemaregistry/serializers/MessageSerializer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from avro import io
import StringIO
from io import BytesIO
import json
import logging
import struct
import sys

from . import SerializerError

MAGIC_BYTE = 0
_LOGGER = logging.getLogger(__name__)

HAS_FAST = False
try:
Expand All @@ -16,7 +18,7 @@
pass


class ContextStringIO(StringIO.StringIO):
class ContextBytesIO(BytesIO):
"""
Wrapper to allow use of StringIO via 'with' constructs.
"""
Expand Down Expand Up @@ -132,6 +134,7 @@ def _get_decoder_func(self, schema_id, payload):
try:
schema = self.registry_client.get_by_id(schema_id)
except:
_LOGGER.info("failed to get schema {} from registry".format(schema_id), exc_info=sys.exc_info())
schema = None

if not schema:
Expand Down Expand Up @@ -174,7 +177,7 @@ def decode_message(self, message):
if len(message) <= 5:
raise SerializerError("message is too small to decode")

with ContextStringIO(message) as payload:
with ContextBytesIO(message) as payload:
magic,schema_id = struct.unpack('>bI',payload.read(5))
if magic != MAGIC_BYTE:
raise SerializerError("message does not start with magic byte")
Expand Down
2 changes: 1 addition & 1 deletion confluent/schemaregistry/serializers/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def parse_schema_from_string(schema_str):
"""Parse a schema given a schema string"""
return schema.parse(schema_str)
return schema.Parse(schema_str)

def parse_schema_from_file(schema_path):
"""Parse a schema from a file path"""
Expand Down
2 changes: 1 addition & 1 deletion confluent/schemaregistry/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def __repr__(self):
def __str__(self):
return self.message

from MessageSerializer import *
from .MessageSerializer import *
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Project uses simplejson, so ensure that it gets installed or upgraded
# on the target machine
install_requires = ['avro'],
install_requires = ['avro-python3'],

# metadata for upload to PyPI
author = 'Verisign',
Expand Down