# Path: python/boto/glacier/exceptions.py
# class TreeHashDoesNotMatchError(DownloadArchiveError):
#     pass
# 
# class DownloadArchiveError(Exception):
#     pass
# 
# Path: python/boto/glacier/writer.py
# def bytes_to_hex(str):
#     return ''.join(["%02x" % ord(x) for x in str]).strip()
# 
# def chunk_hashes(bytestring, chunk_size=_ONE_MEGABYTE):
#     chunk_count = int(math.ceil(len(bytestring) / float(chunk_size)))
#     hashes = []
#     for i in xrange(chunk_count):
#         start = i * chunk_size
#         end = (i + 1) * chunk_size
#         hashes.append(hashlib.sha256(bytestring[start:end]).digest())
#     return hashes
# 
# def tree_hash(fo):
#     """
#     Given a hash of each 1MB chunk (from chunk_hashes) this will hash
#     together adjacent hashes until it ends up with one big one. So a
#     tree of hashes.
#     """
#     hashes = []
#     hashes.extend(fo)
#     while len(hashes) > 1:
#         new_hashes = []
#         while True:
#             if len(hashes) > 1:
#                 first = hashes.pop(0)
#                 second = hashes.pop(0)
#                 new_hashes.append(hashlib.sha256(first + second).digest())
#             elif len(hashes) == 1:
#                 only = hashes.pop(0)
#                 new_hashes.append(only)
#             else:
#                 break
#         hashes.extend(new_hashes)
#     return hashes[0]


import math
import socket
from .exceptions import TreeHashDoesNotMatchError, DownloadArchiveError
from .writer import bytes_to_hex, chunk_hashes, tree_hash
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#



class Job(object):

    DefaultPartSize = 4 * 1024 * 1024

    ResponseDataElements = (('Action', 'action', None),
                            ('ArchiveId', 'archive_id', None),
                            ('ArchiveSizeInBytes', 'archive_size', 0),
                            ('Completed', 'completed', False),
                            ('CompletionDate', 'completion_date', None),

# Path: python/boto/glacier/exceptions.py
# class TreeHashDoesNotMatchError(DownloadArchiveError):
#     pass
# 
# class DownloadArchiveError(Exception):
#     pass
# 
# Path: python/boto/glacier/writer.py
# def bytes_to_hex(str):
#     return ''.join(["%02x" % ord(x) for x in str]).strip()
# 
# def chunk_hashes(bytestring, chunk_size=_ONE_MEGABYTE):
#     chunk_count = int(math.ceil(len(bytestring) / float(chunk_size)))
#     hashes = []
#     for i in xrange(chunk_count):
#         start = i * chunk_size
#         end = (i + 1) * chunk_size
#         hashes.append(hashlib.sha256(bytestring[start:end]).digest())
#     return hashes
# 
# def tree_hash(fo):
#     """
#     Given a hash of each 1MB chunk (from chunk_hashes) this will hash
#     together adjacent hashes until it ends up with one big one. So a
#     tree of hashes.
#     """
#     hashes = []
#     hashes.extend(fo)
#     while len(hashes) > 1:
#         new_hashes = []
#         while True:
#             if len(hashes) > 1:
#                 first = hashes.pop(0)
#                 second = hashes.pop(0)
#                 new_hashes.append(hashlib.sha256(first + second).digest())
#             elif len(hashes) == 1:
#                 only = hashes.pop(0)
#                 new_hashes.append(only)
#             else:
#                 break
#         hashes.extend(new_hashes)
#     return hashes[0]


# Path: python/boto/glacier/job.py
import math
import socket
from .exceptions import TreeHashDoesNotMatchError, DownloadArchiveError
from .writer import bytes_to_hex, chunk_hashes, tree_hash

# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#



class Job(object):

    DefaultPartSize = 4 * 1024 * 1024

    ResponseDataElements = (('Action', 'action', None),
                            ('ArchiveId', 'archive_id', None),
                            ('ArchiveSizeInBytes', 'archive_size', 0),
                            ('Completed', 'completed', False),
                            ('CompletionDate', 'completion_date', None),

                            ('CreationDate', 'creation_date', None),