# Path: internetarchive/iarequest.py
# class S3Request(requests.models.Request):
# class S3PreparedRequest(requests.models.PreparedRequest):
# class MetadataRequest(requests.models.Request):
# class MetadataPreparedRequest(requests.models.PreparedRequest):
#     def __init__(self,
#                  metadata=None,
#                  file_metadata=None,
#                  queue_derive=True,
#                  access_key=None,
#                  secret_key=None,
#                  **kwargs):
#     def prepare(self):
#     def prepare(self, method=None, url=None, headers=None, files=None, data=None,
#                 params=None, auth=None, cookies=None, hooks=None, queue_derive=None,
#                 metadata=None, file_metadata=None):
#     def prepare_headers(self, headers, metadata, file_metadata=None, queue_derive=True):
#         def _prepare_metadata_headers(prepared_metadata, meta_type='meta'):
#     def __init__(self,
#                  metadata=None,
#                  source_metadata=None,
#                  target=None,
#                  priority=None,
#                  access_key=None,
#                  secret_key=None,
#                  append=None,
#                  append_list=None,
#                  **kwargs):
#     def prepare(self):
#     def prepare(self, method=None, url=None, headers=None, files=None, data=None,
#                 params=None, auth=None, cookies=None, hooks=None, metadata={},
#                 source_metadata=None, target=None, priority=None, append=None,
#                 append_list=None):
#     def prepare_body(self, metadata, source_metadata, target, priority, append,
#                      append_list):
# def prepare_patch(metadata, source_metadata, append, append_list=None):
# def prepare_target_patch(metadata, source_metadata, append, target, append_list, key):
#     def dictify(lst, key=None, value=None):
# def prepare_files_patch(metadata, source_metadata, append, target, append_list):
# def prepare_metadata(metadata, source_metadata=None, append=False, append_list=False):
#     def get_index(key):
#     def rm_index(key):
# 
# Path: internetarchive/utils.py
# def deep_update(d, u):
# def validate_s3_identifier(string):
# def needs_quote(s):
# def norm_filepath(fp):
# def get_md5(file_object):
# def chunk_generator(fp, chunk_size):
# def suppress_keyboard_interrupt_message():
#     def new_hook(type, value, traceback):
#     def __init__(self, iterable, size):
#     def read(self, size=-1):  # TBD: add buffer for `len(data) > size` case
#     def __len__(self):
#     def __init__(self, id_list_or_single_id, session):
#     def __len__(self):
#     def __getitem__(self, idx):
#     def __getattr__(self, name):
#     def __repr__(self):
# def get_s3_xml_text(xml_str):
#     def _get_tag_text(tag_name, xml_obj):
# def get_file_size(file_obj):
# def iter_directory(directory):
# def recursive_file_count(files, item=None, checksum=False):
# def is_dir(obj):
# def reraise_modify(caught_exc, append_msg, prepend=False):
# def remove_none(obj):
# def delete_items_from_dict(d, to_delete):
# def is_valid_metadata_key(name):
# def merge_dictionaries(dict0, dict1, keys_to_drop=None):
# def parse_dict_cookies(value):
# class InvalidIdentifierException(Exception):
# class IterableToFileAdapter:
# class IdentifierListAsItems:
# 
# Path: internetarchive/auth.py
# class S3Auth(AuthBase):
# class S3PostAuth(AuthBase):
#     def __init__(self, access_key=None, secret_key=None):
#     def __call__(self, r):
#     def __init__(self, access_key=None, secret_key=None):
#     def __call__(self, r):


import os
import sys
import logging
import socket
from urllib.parse import quote
from requests.exceptions import HTTPError, RetryError, ConnectTimeout, \
    ConnectionError, ReadTimeout
from tqdm import tqdm
from contextlib import nullcontext
from internetarchive import iarequest, utils, auth

        >>> file.delete(access_key='Y6oUrAcCEs4sK8ey',
        ...             secret_key='youRSECRETKEYzZzZ')

    You can retrieve S3 keys here: `https://archive.org/account/s3.php
    <https://archive.org/account/s3.php>`__

    """
    def __init__(self, item, name, file_metadata=None):
        """
        :type item: Item
        :param item: The item that the file is part of.

        :type name: str
        :param name: The filename of the file.

        :type file_metadata: dict
        :param file_metadata: (optional) a dict of metadata for the
                              given file.
        """
        super().__init__(item.item_metadata, name, file_metadata)
        self.item = item
        url_parts = {
            'protocol': item.session.protocol,
            'id': self.identifier,
            'name': quote(name.encode('utf-8')),
            'host': item.session.host,
        }
        self.url = '{protocol}//{host}/download/{id}/{name}'.format(**url_parts)
        if self.item.session.access_key and self.item.session.secret_key:

# Path: internetarchive/iarequest.py
# class S3Request(requests.models.Request):
# class S3PreparedRequest(requests.models.PreparedRequest):
# class MetadataRequest(requests.models.Request):
# class MetadataPreparedRequest(requests.models.PreparedRequest):
#     def __init__(self,
#                  metadata=None,
#                  file_metadata=None,
#                  queue_derive=True,
#                  access_key=None,
#                  secret_key=None,
#                  **kwargs):
#     def prepare(self):
#     def prepare(self, method=None, url=None, headers=None, files=None, data=None,
#                 params=None, auth=None, cookies=None, hooks=None, queue_derive=None,
#                 metadata=None, file_metadata=None):
#     def prepare_headers(self, headers, metadata, file_metadata=None, queue_derive=True):
#         def _prepare_metadata_headers(prepared_metadata, meta_type='meta'):
#     def __init__(self,
#                  metadata=None,
#                  source_metadata=None,
#                  target=None,
#                  priority=None,
#                  access_key=None,
#                  secret_key=None,
#                  append=None,
#                  append_list=None,
#                  **kwargs):
#     def prepare(self):
#     def prepare(self, method=None, url=None, headers=None, files=None, data=None,
#                 params=None, auth=None, cookies=None, hooks=None, metadata={},
#                 source_metadata=None, target=None, priority=None, append=None,
#                 append_list=None):
#     def prepare_body(self, metadata, source_metadata, target, priority, append,
#                      append_list):
# def prepare_patch(metadata, source_metadata, append, append_list=None):
# def prepare_target_patch(metadata, source_metadata, append, target, append_list, key):
#     def dictify(lst, key=None, value=None):
# def prepare_files_patch(metadata, source_metadata, append, target, append_list):
# def prepare_metadata(metadata, source_metadata=None, append=False, append_list=False):
#     def get_index(key):
#     def rm_index(key):
# 
# Path: internetarchive/utils.py
# def deep_update(d, u):
# def validate_s3_identifier(string):
# def needs_quote(s):
# def norm_filepath(fp):
# def get_md5(file_object):
# def chunk_generator(fp, chunk_size):
# def suppress_keyboard_interrupt_message():
#     def new_hook(type, value, traceback):
#     def __init__(self, iterable, size):
#     def read(self, size=-1):  # TBD: add buffer for `len(data) > size` case
#     def __len__(self):
#     def __init__(self, id_list_or_single_id, session):
#     def __len__(self):
#     def __getitem__(self, idx):
#     def __getattr__(self, name):
#     def __repr__(self):
# def get_s3_xml_text(xml_str):
#     def _get_tag_text(tag_name, xml_obj):
# def get_file_size(file_obj):
# def iter_directory(directory):
# def recursive_file_count(files, item=None, checksum=False):
# def is_dir(obj):
# def reraise_modify(caught_exc, append_msg, prepend=False):
# def remove_none(obj):
# def delete_items_from_dict(d, to_delete):
# def is_valid_metadata_key(name):
# def merge_dictionaries(dict0, dict1, keys_to_drop=None):
# def parse_dict_cookies(value):
# class InvalidIdentifierException(Exception):
# class IterableToFileAdapter:
# class IdentifierListAsItems:
# 
# Path: internetarchive/auth.py
# class S3Auth(AuthBase):
# class S3PostAuth(AuthBase):
#     def __init__(self, access_key=None, secret_key=None):
#     def __call__(self, r):
#     def __init__(self, access_key=None, secret_key=None):
#     def __call__(self, r):


# Path: internetarchive/files.py
import os
import sys
import logging
import socket
from urllib.parse import quote
from requests.exceptions import HTTPError, RetryError, ConnectTimeout, \
    ConnectionError, ReadTimeout
from tqdm import tqdm
from contextlib import nullcontext
from internetarchive import iarequest, utils, auth


        >>> file.delete(access_key='Y6oUrAcCEs4sK8ey',
        ...             secret_key='youRSECRETKEYzZzZ')

    You can retrieve S3 keys here: `https://archive.org/account/s3.php
    <https://archive.org/account/s3.php>`__

    """
    def __init__(self, item, name, file_metadata=None):
        """
        :type item: Item
        :param item: The item that the file is part of.

        :type name: str
        :param name: The filename of the file.

        :type file_metadata: dict
        :param file_metadata: (optional) a dict of metadata for the
                              given file.
        """
        super().__init__(item.item_metadata, name, file_metadata)
        self.item = item
        url_parts = {
            'protocol': item.session.protocol,
            'id': self.identifier,
            'name': quote(name.encode('utf-8')),
            'host': item.session.host,
        }
        self.url = '{protocol}//{host}/download/{id}/{name}'.format(**url_parts)
        if self.item.session.access_key and self.item.session.secret_key:

            self.auth = auth.S3Auth(self.item.session.access_key,