Skip to content

Commit

Permalink
Minor cleanup (#7)
Browse files Browse the repository at this point in the history
1. Allow close()'ing the context
2. Change container output to an object rather than a dict
  • Loading branch information
pavius authored Feb 23, 2020
1 parent a15e3fa commit 99fcc93
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion v3io/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.3'
__version__ = '0.2.4'
3 changes: 3 additions & 0 deletions v3io/dataplane/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def __init__(self, logger=None, endpoints=None, max_connections=4, timeout=None)
self._transport = v3io.dataplane.transport.Transport(self._logger, endpoints, max_connections, timeout)
self._access_key = os.environ['V3IO_ACCESS_KEY']

def close(self):
self._transport.close()

def new_session(self, access_key=None):
return v3io.dataplane.session.Session(self,
self._transport,
Expand Down
18 changes: 13 additions & 5 deletions v3io/dataplane/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ def _decode_typed_attributes(self, typed_attributes):
# Containers
#

class Container(object):

def __init__(self, name, creation_date, identifier):
self.name = name
self.creation_date = creation_date
self.identifier = identifier


class GetContainersOutput(Output):

def __init__(self, root):
self.containers = []

for bucket in root.find('Buckets'):
self.containers.append({
'name': bucket.find('Name').text,
'creation_date': bucket.find('CreationDate').text,
'id': int(bucket.find('Id').text),
})
self.containers.append(Container(
name=bucket.find('Name').text,
creation_date=bucket.find('CreationDate').text,
identifier=int(bucket.find('Id').text)
))


class ContainerContent(object):
Expand Down
3 changes: 3 additions & 0 deletions v3io/dataplane/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def setUp(self):
self._session = self._context.new_session()
self._container = self._session.new_container('bigdata')

def tearDown(self):
self._context.close()


class TestContainer(Test):

Expand Down
10 changes: 7 additions & 3 deletions v3io/dataplane/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def __init__(self, logger, endpoints=None, max_connections=4, timeout=None):
# create a tuple of connection pools
self._connection_pools = self._create_connection_pools(self._endpoints, max_connections)

def close(self):
for (endpoint, session) in self._connection_pools:
session.close()

def encode_and_send(self,
container_name,
access_key,
Expand All @@ -36,9 +40,9 @@ def encode_and_send(self,

# create a response
response = v3io.dataplane.response.Response(output,
http_response.status_code,
headers,
http_response.text)
http_response.status_code,
headers,
http_response.text)

# if user didn't specify never to raise, raise for the given statuses
if raise_for_status != RaiseForStatus.never:
Expand Down

0 comments on commit 99fcc93

Please sign in to comment.