Skip to content

Commit

Permalink
Merge "Drop Glance Client"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 21, 2012
2 parents 3580a48 + 76c3620 commit 0cd4a4e
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 4,204 deletions.
1,087 changes: 0 additions & 1,087 deletions bin/glance

This file was deleted.

451 changes: 0 additions & 451 deletions glance/client.py

This file was deleted.

70 changes: 0 additions & 70 deletions glance/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,76 +86,6 @@ def wrapped(self, method, url, body, headers):
return wrapped


class ImageBodyIterator(object):

"""
A class that acts as an iterator over an image file's
chunks of data. This is returned as part of the result
tuple from `glance.client.Client.get_image`
"""

def __init__(self, source):
"""
Constructs the object from a readable image source
(such as an HTTPResponse or file-like object)
"""
self.source = source

def __iter__(self):
"""
Exposes an iterator over the chunks of data in the
image file.
"""
while True:
chunk = self.source.read(CHUNKSIZE)
if chunk:
yield chunk
else:
break


class SendFileIterator:
"""
Emulate iterator pattern over sendfile, in order to allow
send progress be followed by wrapping the iteration.
"""
def __init__(self, connection, body):
self.connection = connection
self.body = body
self.offset = 0
self.sending = True

def __iter__(self):
class OfLength:
def __init__(self, len):
self.len = len

def __len__(self):
return self.len

while self.sending:
try:
sent = sendfile.sendfile(self.connection.sock.fileno(),
self.body.fileno(),
self.offset,
CHUNKSIZE)
except OSError as e:
# suprisingly, sendfile may fail transiently instead of
# blocking, in which case we select on the socket in order
# to wait on its return to a writeable state before resuming
# the send loop
if e.errno in (errno.EAGAIN, errno.EBUSY):
wlist = [self.connection.sock.fileno()]
rfds, wfds, efds = select.select([], wlist, [])
if wfds:
continue
raise

self.sending = (sent != 0)
self.offset += sent
yield OfLength(sent)


class HTTPSClientAuthConnection(httplib.HTTPSConnection):
"""
Class to make a HTTPS connection, with support for
Expand Down
Loading

0 comments on commit 0cd4a4e

Please sign in to comment.