files.new_contents: # Licensed to the Apache Software Foundation (ASF) under one or more
  # contributor license agreements.  See the NOTICE file distributed with
  # this work for additional information regarding copyright ownership.
  # The ASF licenses this file to You under the Apache License, Version 2.0
  # (the "License"); you may not use this file except in compliance with
  # the License.  You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  """
  Provides base classes for working with storage
  """
  
  # Backward compatibility for Python 2.5
  from __future__ import with_statement
  
  from typing import Dict
  from typing import Iterator
  from typing import List
  from typing import Optional
  from typing import Type
  
  import os.path                          # pylint: disable-msg=W0404
  import hashlib
  import warnings
  import errno
  from os.path import join as pjoin
  
  from libcloud.utils.py3 import httplib
  from libcloud.utils.py3 import b
  
  import libcloud.utils.files
  from libcloud.common.types import LibcloudError
  from libcloud.common.base import Connection
  from libcloud.common.base import ConnectionUserAndKey, BaseDriver
  from libcloud.storage.types import ObjectDoesNotExistError
  
  __all__ = [
      'Object',
      'Container',
      'StorageDriver',
  
      'CHUNK_SIZE',
      'DEFAULT_CONTENT_TYPE'
  ]
  
  CHUNK_SIZE = 8096
  
  # Default Content-Type which is sent when uploading an object if one is not
  # supplied and can't be detected when using non-strict mode.
  DEFAULT_CONTENT_TYPE = 'application/octet-stream'
  
  
  class Object(object):
      """
      Represents an object (BLOB).
      """
  
      def __init__(self,
                   name,  # type: str
                   size,  # type: int
                   hash,  # type: str
                   extra,  # type: dict
                   meta_data,  # type: dict
                   container,  # type: Container
                   driver,  # type: StorageDriver
                   ):
          """
          :param name: Object name (must be unique per container).
          :type  name: ``str``
  
          :param size: Object size in bytes.
          :type  size: ``int``
  
          :param hash: Object hash.
          :type  hash: ``str``
  
          :param container: Object container.
          :type  container: :class:`libcloud.storage.base.Container`
  
          :param extra: Extra attributes.
          :type  extra: ``dict``
  
          :param meta_data: Optional object meta data.
          :type  meta_data: ``dict``
  
          :param driver: StorageDriver instance.
          :type  driver: :class:`libcloud.storage.base.
  
  [... the rest is omitted ...]
files.new_path: libcloud/storage/base.py
files.old_contents: # Licensed to the Apache Software Foundation (ASF) under one or more
  # contributor license agreements.  See the NOTICE file distributed with
  # this work for additional information regarding copyright ownership.
  # The ASF licenses this file to You under the Apache License, Version 2.0
  # (the "License"); you may not use this file except in compliance with
  # the License.  You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  """
  Provides base classes for working with storage
  """
  
  # Backward compatibility for Python 2.5
  from __future__ import with_statement
  
  from typing import Dict
  from typing import Iterator
  from typing import List
  from typing import Optional
  from typing import Type
  
  import os.path                          # pylint: disable-msg=W0404
  import hashlib
  import warnings
  import errno
  from os.path import join as pjoin
  
  from libcloud.utils.py3 import httplib
  from libcloud.utils.py3 import b
  
  import libcloud.utils.files
  from libcloud.common.types import LibcloudError
  from libcloud.common.base import Connection
  from libcloud.common.base import ConnectionUserAndKey, BaseDriver
  from libcloud.storage.types import ObjectDoesNotExistError
  
  __all__ = [
      'Object',
      'Container',
      'StorageDriver',
  
      'CHUNK_SIZE',
      'DEFAULT_CONTENT_TYPE'
  ]
  
  CHUNK_SIZE = 8096
  
  # Default Content-Type which is sent when uploading an object if one is not
  # supplied and can't be detected when using non-strict mode.
  DEFAULT_CONTENT_TYPE = 'application/octet-stream'
  
  
  class Object(object):
      """
      Represents an object (BLOB).
      """
  
      def __init__(self,
                   name,  # type: str
                   size,  # type: int
                   hash,  # type: str
                   extra,  # type: dict
                   meta_data,  # type: dict
                   container,  # type: Container
                   driver,  # type: StorageDriver
                   ):
          """
          :param name: Object name (must be unique per container).
          :type  name: ``str``
  
          :param size: Object size in bytes.
          :type  size: ``int``
  
          :param hash: Object hash.
          :type  hash: ``str``
  
          :param container: Object container.
          :type  container: :class:`libcloud.storage.base.Container`
  
          :param extra: Extra attributes.
          :type  extra: ``dict``
  
          :param meta_data: Optional object meta data.
          :type  meta_data: ``dict``
  
          :param driver: StorageDriver instance.
          :type  driver: :class:`libcloud.storage.base.
  
  [... the rest is omitted ...]
files.old_path: libcloud/storage/base.py
files.new_contents: # Licensed to the Apache Software Foundation (ASF) under one or more
  # contributor license agreements.  See the NOTICE file distributed with
  # this work for additional information regarding copyright ownership.
  # The ASF licenses this file to You under the Apache License, Version 2.0
  # (the "License"); you may not use this file except in compliance with
  # the License.  You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  """
  Provides storage driver for working with local filesystem
  """
  
  from __future__ import with_statement
  
  import errno
  import os
  import shutil
  
  try:
      import lockfile
      from lockfile import LockTimeout, mkdirlockfile
  except ImportError:
      raise ImportError('Missing lockfile dependency, you can install it '
                        'using pip: pip install lockfile')
  
  from libcloud.utils.files import read_in_chunks
  from libcloud.utils.files import exhaust_iterator
  from libcloud.utils.py3 import relpath
  from libcloud.utils.py3 import u
  from libcloud.common.base import Connection
  from libcloud.storage.base import Object, Container, StorageDriver
  from libcloud.common.types import LibcloudError
  from libcloud.storage.types import ContainerAlreadyExistsError
  from libcloud.storage.types import ContainerDoesNotExistError
  from libcloud.storage.types import ContainerIsNotEmptyError
  from libcloud.storage.types import ObjectError
  from libcloud.storage.types import ObjectDoesNotExistError
  from libcloud.storage.types import InvalidContainerNameError
  
  IGNORE_FOLDERS = ['.lock', '.hash']
  
  
  class LockLocalStorage(object):
      """
      A class to help in locking a local path before being updated
      """
      def __init__(self, path):
          self.path = path
          self.lock = mkdirlockfile.MkdirLockFile(self.path, threaded=True)
  
      def __enter__(self):
          try:
              self.lock.acquire(timeout=0.1)
          except LockTimeout:
              raise LibcloudError('Lock timeout')
  
      def __exit__(self, type, value, traceback):
          if self.lock.is_locked():
              self.lock.release()
  
          if value is not None:
              raise value
  
  
  class LocalStorageDriver(StorageDriver):
      """
      Implementation of local file-system based storage. This is helpful
      where the user would want to use the same code (using libcloud) and
      switch between cloud storage and local storage
      """
  
      connectionCls = Connection
      name = 'Local Storage'
      website = 'http://example.com'
      hash_type = 'md5'
  
      def __init__(self, key, secret=None, secure=True, host=None, port=None,
                   **kwargs):
  
          #
  
  [... the rest is omitted ...]
files.new_path: libcloud/storage/drivers/local.py
files.old_contents: # Licensed to the Apache Software Foundation (ASF) under one or more
  # contributor license agreements.  See the NOTICE file distributed with
  # this work for additional information regarding copyright ownership.
  # The ASF licenses this file to You under the Apache License, Version 2.0
  # (the "License"); you may not use this file except in compliance with
  # the License.  You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  """
  Provides storage driver for working with local filesystem
  """
  
  from __future__ import with_statement
  
  import errno
  import os
  import shutil
  
  try:
      import lockfile
      from lockfile import LockTimeout, mkdirlockfile
  except ImportError:
      raise ImportError('Missing lockfile dependency, you can install it '
                        'using pip: pip install lockfile')
  
  from libcloud.utils.files import read_in_chunks
  from libcloud.utils.py3 import relpath
  from libcloud.utils.py3 import u
  from libcloud.common.base import Connection
  from libcloud.storage.base import Object, Container, StorageDriver
  from libcloud.common.types import LibcloudError
  from libcloud.storage.types import ContainerAlreadyExistsError
  from libcloud.storage.types import ContainerDoesNotExistError
  from libcloud.storage.types import ContainerIsNotEmptyError
  from libcloud.storage.types import ObjectError
  from libcloud.storage.types import ObjectDoesNotExistError
  from libcloud.storage.types import InvalidContainerNameError
  
  IGNORE_FOLDERS = ['.lock', '.hash']
  
  
  class LockLocalStorage(object):
      """
      A class to help in locking a local path before being updated
      """
      def __init__(self, path):
          self.path = path
          self.lock = mkdirlockfile.MkdirLockFile(self.path, threaded=True)
  
      def __enter__(self):
          try:
              self.lock.acquire(timeout=0.1)
          except LockTimeout:
              raise LibcloudError('Lock timeout')
  
      def __exit__(self, type, value, traceback):
          if self.lock.is_locked():
              self.lock.release()
  
          if value is not None:
              raise value
  
  
  class LocalStorageDriver(StorageDriver):
      """
      Implementation of local file-system based storage. This is helpful
      where the user would want to use the same code (using libcloud) and
      switch between cloud storage and local storage
      """
  
      connectionCls = Connection
      name = 'Local Storage'
      website = 'http://example.com'
      hash_type = 'md5'
  
      def __init__(self, key, secret=None, secure=True, host=None, port=None,
                   **kwargs):
  
          # Use the key as the path to the storage
  
  
  [... the rest is omitted ...]
files.old_path: libcloud/storage/drivers/local.py
files.new_contents: # Licensed to the Apache Software Foundation (ASF) under one or more
  # contributor license agreements.  See the NOTICE file distributed with
  # this work for additional information regarding copyright ownership.
  # The ASF licenses this file to You under the Apache License, Version 2.0
  # (the "License"); you may not use this file except in compliance with
  # the License.  You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  import base64
  import hmac
  import time
  from hashlib import sha1
  
  import libcloud.utils.py3
  
  try:
      if libcloud.utils.py3.DEFAULT_LXML:
          from lxml.etree import Element, SubElement
      else:
          from xml.etree.ElementTree import Element, SubElement
  except ImportError:
      from xml.etree.ElementTree import Element, SubElement
  
  from libcloud.utils.py3 import httplib
  from libcloud.utils.py3 import urlquote
  from libcloud.utils.py3 import b
  from libcloud.utils.py3 import tostring
  
  from libcloud.utils.xml import fixxpath, findtext
  from libcloud.utils.files import read_in_chunks
  from libcloud.common.types import InvalidCredsError, LibcloudError
  from libcloud.common.base import ConnectionUserAndKey, RawResponse
  from libcloud.common.aws import AWSBaseResponse, AWSDriver, \
      AWSTokenConnection, SignedAWSConnection
  
  from libcloud.storage.base import Object, Container, StorageDriver
  from libcloud.storage.types import ContainerError
  from libcloud.storage.types import ContainerIsNotEmptyError
  from libcloud.storage.types import InvalidContainerNameError
  from libcloud.storage.types import ContainerDoesNotExistError
  from libcloud.storage.types import ObjectDoesNotExistError
  from libcloud.storage.types import ObjectHashMismatchError
  
  # How long before the token expires
  EXPIRATION_SECONDS = 15 * 60
  
  S3_US_STANDARD_HOST = 's3.amazonaws.com'
  S3_US_EAST2_HOST = 's3-us-east-2.amazonaws.com'
  S3_US_WEST_HOST = 's3-us-west-1.amazonaws.com'
  S3_US_WEST_OREGON_HOST = 's3-us-west-2.amazonaws.com'
  S3_US_GOV_WEST_HOST = 's3-us-gov-west-1.amazonaws.com'
  S3_CN_NORTH_HOST = 's3.cn-north-1.amazonaws.com.cn'
  S3_CN_NORTHWEST_HOST = 's3.cn-northwest-1.amazonaws.com.cn'
  S3_EU_WEST_HOST = 's3-eu-west-1.amazonaws.com'
  S3_EU_WEST2_HOST = '
  
  [... the rest is omitted ...]
files.new_path: libcloud/storage/drivers/s3.py
files.old_contents: # Licensed to the Apache Software Foundation (ASF) under one or more
  # contributor license agreements.  See the NOTICE file distributed with
  # this work for additional information regarding copyright ownership.
  # The ASF licenses this file to You under the Apache License, Version 2.0
  # (the "License"); you may not use this file except in compliance with
  # the License.  You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  import base64
  import hmac
  import time
  from hashlib import sha1
  
  import libcloud.utils.py3
  
  try:
      if libcloud.utils.py3.DEFAULT_LXML:
          from lxml.etree import Element, SubElement
      else:
          from xml.etree.ElementTree import Element, SubElement
  except ImportError:
      from xml.etree.ElementTree import Element, SubElement
  
  from libcloud.utils.py3 import httplib
  from libcloud.utils.py3 import urlquote
  from libcloud.utils.py3 import b
  from libcloud.utils.py3 import tostring
  
  from libcloud.utils.xml import fixxpath, findtext
  from libcloud.utils.files import read_in_chunks
  from libcloud.common.types import InvalidCredsError, LibcloudError
  from libcloud.common.base import ConnectionUserAndKey, RawResponse
  from libcloud.common.aws import AWSBaseResponse, AWSDriver, \
      AWSTokenConnection, SignedAWSConnection
  
  from libcloud.storage.base import Object, Container, StorageDriver
  from libcloud.storage.types import ContainerError
  from libcloud.storage.types import ContainerIsNotEmptyError
  from libcloud.storage.types import InvalidContainerNameError
  from libcloud.storage.types import ContainerDoesNotExistError
  from libcloud.storage.types import ObjectDoesNotExistError
  from libcloud.storage.types import ObjectHashMismatchError
  
  # How long before the token expires
  EXPIRATION_SECONDS = 15 * 60
  
  S3_US_STANDARD_HOST = 's3.amazonaws.com'
  S3_US_EAST2_HOST = 's3-us-east-2.amazonaws.com'
  S3_US_WEST_HOST = 's3-us-west-1.amazonaws.com'
  S3_US_WEST_OREGON_HOST = 's3-us-west-2.amazonaws.com'
  S3_US_GOV_WEST_HOST = 's3-us-gov-west-1.amazonaws.com'
  S3_CN_NORTH_HOST = 's3.cn-north-1.amazonaws.com.cn'
  S3_CN_NORTHWEST_HOST = 's3.cn-northwest-1.amazonaws.com.cn'
  S3_EU_WEST_HOST = 's3-eu-west-1.amazonaws.com'
  S3_EU_WEST2_HOST = '
  
  [... the rest is omitted ...]
files.old_path: libcloud/storage/drivers/s3.py