<EOL>setup_py_path = PyFunceble.CURRENT_DIRECTORY + "<STR_LIT>"<EOL>if self.is_dev_version():<EOL><INDENT>regexes = {<EOL>'<STR_LIT>': r'<STR_LIT>',<EOL>'<STR_LIT>': r'<STR_LIT>',<EOL>}<EOL><DEDENT>elif self.is_master_version():<EOL><INDENT>regexes = {<EOL>'<STR_LIT>': r'<STR_LIT>',<EOL>'<STR_LIT>': r'<STR_LIT>',<EOL>}<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>to_update = File(setup_py_path).read()<EOL>for replacement, regex in regexes.items():<EOL><INDENT>to_update = Regex(to_update, regex, replace_with=replacement).replace()<EOL><DEDENT>File(setup_py_path).write(to_update, overwrite=True)<EOL>

Update :code:`setup.py` so that it always have the right name.


<EOL>travis_yml_path = PyFunceble.CURRENT_DIRECTORY + "<STR_LIT>"<EOL>if self.is_dev_version():<EOL><INDENT>regexes = {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>}<EOL><DEDENT>elif self.is_master_version():<EOL><INDENT>regexes = {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>}<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>to_update = File(travis_yml_path).read()<EOL>for replacement, regex in regexes.items():<EOL><INDENT>to_update = Regex(to_update, regex, replace_with=replacement).replace()<EOL><DEDENT>File(travis_yml_path).write(to_update, overwrite=True)<EOL>

Update :code:`.travis.yml` according to current branch.


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>historical_formating_error = (<EOL>PyFunceble.CURRENT_DIRECTORY + "<STR_LIT>"<EOL>)<EOL>if PyFunceble.path.isfile(historical_formating_error):<EOL><INDENT>data = Dict().from_json(File(historical_formating_error).read())<EOL>data_to_parse = {}<EOL>top_keys = data.keys()<EOL>for top_key in top_keys:<EOL><INDENT>low_keys = data[top_key].keys()<EOL>data_to_parse[top_key] = {}<EOL>for low_key in low_keys:<EOL><INDENT>if low_key.isdigit():<EOL><INDENT>data_to_parse[top_key][<EOL>int(low_key) - (self.one_day_in_seconds * <NUM_LIT:30>)<EOL>] = data[top_key][low_key]<EOL><DEDENT>else:<EOL><INDENT>data_to_parse[top_key][<EOL>int(PyFunceble.time()) - (self.one_day_in_seconds * <NUM_LIT:30>)<EOL>] = data[top_key][low_key]<EOL><DEDENT><DEDENT><DEDENT>if "<STR_LIT>" in PyFunceble.INTERN:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"].update(data_to_parse)<EOL><DEDENT>else:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"] = data_to_parse<EOL><DEDENT>File(historical_formating_error).delete()<EOL><DEDENT><DEDENT>

Format the old format so it can be merged into the newer format.


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>database_content = Dict().from_json(File(self.inactive_db_path).read())<EOL>database_top_keys = database_content.keys()<EOL>for database_top_key in database_top_keys:<EOL><INDENT>if database_top_key not in PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][<EOL>database_top_key<EOL>] = database_content[database_top_key]<EOL><DEDENT>else:<EOL><INDENT>database_low_keys = database_content[database_top_key].keys()<EOL>for database_low_key in database_low_keys:<EOL><INDENT>if (<EOL>database_low_key<EOL>not in PyFunceble.INTERN["<STR_LIT>"][database_top_key]<EOL>):  <EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][database_top_key][<EOL>database_low_key<EOL>] = database_content[database_top_key][database_low_key]<EOL><DEDENT>else:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][database_top_key][<EOL>database_low_key<EOL>].extend(<EOL>database_content[database_top_key][database_low_key]<EOL>)<EOL>PyFunceble.INTERN["<STR_LIT>"][database_top_key][<EOL>database_low_key<EOL>] = List(<EOL>PyFunceble.INTERN["<STR_LIT>"][database_top_key][<EOL>database_low_key<EOL>]<EOL>).format()<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

Merge the real database with the older one which
has already been set into :code:`PyFunceble.INTERN["inactive_db"]`


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>self._reformat_historical_formating_error()<EOL>if PyFunceble.path.isfile(self.inactive_db_path):<EOL><INDENT>self._merge()<EOL><DEDENT><DEDENT>

Return the current content of the inactive-db.json file.


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>Dict(PyFunceble.INTERN["<STR_LIT>"]).to_json(self.inactive_db_path)<EOL><DEDENT>

Save the current database into the inactive-db.json file.


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>if (<EOL>"<STR_LIT>" in PyFunceble.INTERN<EOL>and PyFunceble.INTERN["<STR_LIT>"]<EOL>in PyFunceble.INTERN["<STR_LIT>"]<EOL>and PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]]<EOL>):<EOL><INDENT>database_keys = [<EOL>x<EOL>for x in PyFunceble.INTERN["<STR_LIT>"][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>].keys()<EOL>if x.isdigit()<EOL>]<EOL>if database_keys:<EOL><INDENT>recent_date = max(database_keys)<EOL><DEDENT>else:  <EOL><INDENT>return int(PyFunceble.time())<EOL><DEDENT>if int(PyFunceble.time()) > int(recent_date) + self.one_day_in_seconds:<EOL><INDENT>return int(PyFunceble.time())<EOL><DEDENT>if int(PyFunceble.time()) < int(recent_date) + self.days_in_seconds:<EOL><INDENT>return int(recent_date)<EOL><DEDENT><DEDENT><DEDENT>return int(PyFunceble.time())<EOL>

Get the timestamp where we are going to save our current list.

:return: The timestamp to append with the currently tested element.
:rtype: int|str


Save the current :code.`PyFunceble.CONFIGURATION['to_test']`
into the current timestamp.


Remove all occurence of :code:`PyFunceble.CONFIGURATION['to_test']`
from the database.


<EOL>result = []<EOL>if (<EOL>PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>and PyFunceble.INTERN["<STR_LIT>"]<EOL>):<EOL><INDENT>for key in PyFunceble.INTERN["<STR_LIT>"][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>]:<EOL><INDENT>if key == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>result.extend(<EOL>PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>key<EOL>]<EOL>)<EOL><DEDENT><DEDENT>return result<EOL>

Get the content of the database.

:return: The content of the database.
:rtype: list


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>if PyFunceble.INTERN["<STR_LIT>"] in PyFunceble.INTERN[<EOL>"<STR_LIT>"<EOL>] or (<EOL>PyFunceble.INTERN["<STR_LIT>"] in PyFunceble.INTERN["<STR_LIT>"]<EOL>and PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]]<EOL>and "<STR_LIT>"<EOL>in PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]]<EOL>and PyFunceble.INTERN["<STR_LIT>"]<EOL>in PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>"<STR_LIT>"<EOL>]<EOL>):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

Check if the currently tested element is into the database.


if (<EOL>not PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>and PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Check if we are authorized to work with our database.


if self._authorization() and "<STR_LIT>" not in PyFunceble.INTERN:<EOL><INDENT>if PyFunceble.path.isfile(self.whois_db_path):<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"] = Dict().from_json(<EOL>File(self.whois_db_path).read()<EOL>)<EOL><DEDENT>else:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"] = {}<EOL><DEDENT><DEDENT>


if self._authorization():<EOL><INDENT>Dict(PyFunceble.INTERN["<STR_LIT>"]).to_json(self.whois_db_path)<EOL><DEDENT>


if (<EOL>self._authorization()<EOL>and PyFunceble.INTERN["<STR_LIT>"] in PyFunceble.INTERN["<STR_LIT>"]<EOL>and PyFunceble.INTERN["<STR_LIT>"]<EOL>in PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]]<EOL>):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Check if the element is into the database.


if (<EOL>self._authorization()<EOL>and self.is_in_database()<EOL>and int(<EOL>PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>]["<STR_LIT>"]<EOL>)<EOL>< int(PyFunceble.time())<EOL>):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Check if the current time is older than the one in the database.


if self._authorization() and self.is_in_database() and not self.is_time_older():<EOL><INDENT>result = PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>]["<STR_LIT>"]<EOL>if result:<EOL><INDENT>return result<EOL><DEDENT><DEDENT>return None<EOL>

Get the expiration date from the database.

:return: The expiration date from the database.
:rtype: str|None


if self._authorization():<EOL><INDENT>if self.epoch < int(PyFunceble.time()):<EOL><INDENT>state = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>state = "<STR_LIT>"<EOL><DEDENT>if self.is_in_database():<EOL><INDENT>if (<EOL>str(self.epoch)<EOL>!= PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>]["<STR_LIT>"]<EOL>):<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>].update(<EOL>{<EOL>"<STR_LIT>": str(self.epoch),<EOL>"<STR_LIT:state>": state,<EOL>"<STR_LIT>": self.expiration_date,<EOL>}<EOL>)<EOL><DEDENT>elif self.is_time_older():<EOL><INDENT>if (<EOL>PyFunceble.INTERN["<STR_LIT>"][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>][PyFunceble.INTERN["<STR_LIT>"]]["<STR_LIT:state>"]<EOL>!= "<STR_LIT>"<EOL>):  <EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>][PyFunceble.INTERN["<STR_LIT>"]].update({"<STR_LIT:state>": "<STR_LIT>"})<EOL><DEDENT><DEDENT>elif (<EOL>PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>]["<STR_LIT:state>"]<EOL>!= "<STR_LIT>"<EOL>):<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>].update({"<STR_LIT:state>": "<STR_LIT>"})<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if (<EOL>not PyFunceble.INTERN["<STR_LIT>"]<EOL>in PyFunceble.INTERN["<STR_LIT>"]<EOL>):<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][<EOL>PyFunceble.INTERN["<STR_LIT>"]<EOL>] = {}<EOL><DEDENT>PyFunceble.INTERN["<STR_LIT>"][PyFunceble.INTERN["<STR_LIT>"]].update(<EOL>{<EOL>PyFunceble.INTERN["<STR_LIT>"]: {<EOL>"<STR_LIT>": str(self.epoch),<EOL>"<STR_LIT:state>": state,<EOL>"<STR_LIT>": self.expiration_date,<EOL>}<EOL>}<EOL>)<EOL><DEDENT>self._backup()<EOL><DEDENT>

Add the currently tested element into the database.


<EOL>public_suffix_url = (<EOL>"<STR_LIT>"<EOL>% "<STR_LIT>"<EOL>)<EOL>return Download(public_suffix_url, return_data=True).text()<EOL>

Get the database from the public suffix repository.


<EOL>line = line.strip()<EOL>if not line.startswith("<STR_LIT>") and "<STR_LIT:.>" in line:<EOL><INDENT>line = line.encode("<STR_LIT>").decode("<STR_LIT:utf-8>")<EOL>if line.startswith("<STR_LIT>"):<EOL><INDENT>line = line[<NUM_LIT:2>:]<EOL><DEDENT>extension = line.split("<STR_LIT:.>")[-<NUM_LIT:1>]<EOL>if extension in self.public_suffix_db:<EOL><INDENT>self.public_suffix_db[extension] = List(<EOL>self.public_suffix_db[extension] + [line]<EOL>).format()<EOL><DEDENT>else:<EOL><INDENT>self.public_suffix_db.update({extension: [line]})<EOL><DEDENT><DEDENT>

Extract the extension from the given line.

:param line: The line from the official public suffix repository.
:type line: str


if not PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>print(<EOL>"<STR_LIT>" % PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"],<EOL>end="<STR_LIT:U+0020>",<EOL>)<EOL><DEDENT>list(map(self._extensions, self._data().split("<STR_LIT:\n>")))<EOL>Dict(self.public_suffix_db).to_json(self.destination)<EOL>if not PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>print(PyFunceble.INTERN["<STR_LIT>"])<EOL><DEDENT>

Update of the content of the :code:`public-suffix.json`.


if not PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"] = Dict().from_json(<EOL>File(self.destination).read()<EOL>)<EOL><DEDENT>

Load the public suffix database into the system.


<EOL>domain_validation = self.checker.is_domain_valid()<EOL>ip_validation = self.checker.is_ip_valid()<EOL>if "<STR_LIT>" in PyFunceble.INTERN:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"].update(<EOL>{<EOL>"<STR_LIT>": domain_validation,<EOL>"<STR_LIT>": ip_validation,<EOL>}<EOL>)<EOL><DEDENT>if (<EOL>domain_validation<EOL>and not ip_validation<EOL>or domain_validation<EOL>or PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>):<EOL><INDENT>PyFunceble.INTERN.update(<EOL>{"<STR_LIT>": HTTPCode().get(), "<STR_LIT>": Referer().get()}<EOL>)<EOL>if not PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>return PyFunceble.INTERN["<STR_LIT>"]<EOL><DEDENT>if PyFunceble.INTERN["<STR_LIT>"] and not self.checker.is_subdomain():<EOL><INDENT>return self._extract()<EOL><DEDENT>Logs().whois(self.whois_record)<EOL>return None<EOL><DEDENT>if (<EOL>ip_validation<EOL>and not domain_validation<EOL>or ip_validation<EOL>or PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>):<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"] = HTTPCode().get()<EOL>Logs().whois(self.whois_record)<EOL>return None<EOL><DEDENT>Logs().whois(self.whois_record)<EOL>return False<EOL>

Execute the logic behind the meaning of ExpirationDate + return the matched status.

:return:
    The status of the tested domain.
    Can be one of the official status.
:rtype: str


return str(number).zfill(<NUM_LIT:2>)<EOL>

Convert 1 digit number to two digits.

:param number: A number or a digit string.
:type number: str|int

:return: A 2 or more digit string.
:rtype: str


<EOL>short_month = {<EOL>"<STR_LIT>": [str(<NUM_LIT:1>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:2>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:3>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:4>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:5>), "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:6>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:7>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:8>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:9>), "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:10>), "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:11>), "<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": [str(<NUM_LIT:12>), "<STR_LIT>", "<STR_LIT>"],<EOL>}<EOL>for month in short_month:<EOL><INDENT>if data in short_month[month]:<EOL><INDENT>return month<EOL><DEDENT><DEDENT>return data<EOL>

Convert a given month into our unified format.

:param data: The month to convert or shorten.
:type data: str

:return: The unified month name.
:rtype: str


def _cases_management(self, regex_number, matched_result):

<EOL>cases = {<EOL>"<STR_LIT>": [[<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:10>, <NUM_LIT:11>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT:32>, <NUM_LIT>, <NUM_LIT>], [<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>]],<EOL>"<STR_LIT>": [[<NUM_LIT>, <NUM_LIT:15>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>], [<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:2>]],<EOL>"<STR_LIT>": [<EOL>[<NUM_LIT:4>, <NUM_LIT:5>, <NUM_LIT:6>, <NUM_LIT:7>, <NUM_LIT:8>, <NUM_LIT:9>, <NUM_LIT:12>, <NUM_LIT>, <NUM_LIT:16>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT:20>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT:30>, <NUM_LIT>],<EOL>[<NUM_LIT:2>, <NUM_LIT:1>, <NUM_LIT:0>],<EOL>],<EOL>}<EOL>for case in cases:<EOL><INDENT>case_data = cases[case]<EOL>if int(regex_number) in case_data[<NUM_LIT:0>]:<EOL><INDENT>return [<EOL>self._convert_1_to_2_digits(matched_result[case_data[<NUM_LIT:1>][<NUM_LIT:0>]]),<EOL>self._convert_or_shorten_month(matched_result[case_data[<NUM_LIT:1>][<NUM_LIT:1>]]),<EOL>str(matched_result[case_data[<NUM_LIT:1>][<NUM_LIT:2>]]),<EOL>]<EOL><DEDENT><DEDENT>return matched_result<EOL>

A little internal helper of self.format. (Avoiding of nested loops)

.. note::
    Please note that the second value of the case represent the groups
    in order :code:`[day,month,year]`.

    This means that a :code:`[2,1,0]` will be for example for a date
    in format :code:`2017-01-02` where
    :code:`01` is the month.

:param regex_number: The identifiant of the regex.
:type regex_number: int

:param matched_result: The matched result to format.
:type matched_result: list

:return:
    A list representing the expiration date.
    The list can be "decoded" like :code:`[day, month, year]`
:rtype: list|None


if not date_to_convert:  <EOL><INDENT>date_to_convert = self.expiration_date<EOL><DEDENT>regex_dates = {<EOL>"<STR_LIT:1>": r"<STR_LIT>",<EOL>"<STR_LIT:2>": r"<STR_LIT>",<EOL>"<STR_LIT:3>": r"<STR_LIT>",<EOL>"<STR_LIT:4>": r"<STR_LIT>",<EOL>"<STR_LIT:5>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",  <EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",  <EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",  <EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",  <EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",  <EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>}<EOL>for regx in regex_dates:<EOL><INDENT>matched_result = Regex(<EOL>date_to_convert, regex_dates[regx], return_data=True, rematch=True<EOL>).match()<EOL>if matched_result:<EOL><INDENT>date = self._cases_management(regx, matched_result)<EOL>if date:<EOL><INDENT>return "<STR_LIT:->".join(date)<EOL><DEDENT><DEDENT><DEDENT>return "<STR_LIT>"<EOL>

Format the expiration date into an unified format (01-jan-1970).

:param date_to_convert:
    The date to convert. In other words, the extracted date.
:type date_to_convert: str

:return: The formatted expiration date.
:rtype: str


<EOL>expiration_date_from_database = Whois().get_expiration_date()<EOL>if expiration_date_from_database:<EOL><INDENT>Generate(<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>",<EOL>expiration_date_from_database,<EOL>).status_file()<EOL>return PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]<EOL><DEDENT>self.whois_record = Lookup().whois(PyFunceble.INTERN["<STR_LIT>"])<EOL>to_match = [<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>r"<STR_LIT>",<EOL>]<EOL>if self.whois_record:<EOL><INDENT>if "<STR_LIT>" in PyFunceble.INTERN:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>] = self.whois_record<EOL><DEDENT>for string in to_match:<EOL><INDENT>expiration_date = Regex(<EOL>self.whois_record, string, return_data=True, rematch=True, group=<NUM_LIT:0><EOL>).match()<EOL>if expiration_date:<EOL><INDENT>self.expiration_date = expiration_date[<NUM_LIT:0>].strip()<EOL>regex_rumbers = r"<STR_LIT>"<EOL>if Regex(<EOL>self.expiration_date, regex_rumbers, return_data=False<EOL>).match():<EOL><INDENT>self.expiration_date = self._format()<EOL>if (<EOL>self.expiration_date<EOL>and not Regex(<EOL>self.expiration_date,<EOL>r"<STR_LIT>",<EOL>return_data=False,<EOL>).match()<EOL>):<EOL><INDENT>Logs().expiration_date(self.expiration_date)<EOL>Logs().whois(self.whois_record)<EOL><DEDENT>if "<STR_LIT>" in PyFunceble.INTERN:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>] = self.expiration_date<EOL><DEDENT>Generate(<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>",<EOL>self.expiration_date,<EOL>).status_file()<EOL>Logs().whois(self.whois_record)<EOL>Whois(expiration_date=self.expiration_date).add()<EOL>return PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]<EOL><DEDENT>Logs().whois(self.whois_record)<EOL>return None<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>

Extract the expiration date from the whois record.

:return: The status of the domain.
:rtype: str


@classmethod<EOL><INDENT>def get(cls):  <DEDENT>

if Check().is_url_valid() or PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>if "<STR_LIT>" in PyFunceble.INTERN:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"]["<STR_LIT>"] = True<EOL><DEDENT>PyFunceble.INTERN.update({"<STR_LIT>": HTTPCode().get()})<EOL>active_list = []<EOL>active_list.extend(PyFunceble.HTTP_CODE["<STR_LIT:list>"]["<STR_LIT>"])<EOL>active_list.extend(PyFunceble.HTTP_CODE["<STR_LIT:list>"]["<STR_LIT>"])<EOL>inactive_list = []<EOL>inactive_list.extend(PyFunceble.HTTP_CODE["<STR_LIT:list>"]["<STR_LIT>"])<EOL>inactive_list.append("<STR_LIT:*>" * <NUM_LIT:3>)<EOL>if PyFunceble.INTERN["<STR_LIT>"] in active_list:<EOL><INDENT>return URLStatus(PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]).handle()<EOL><DEDENT>if PyFunceble.INTERN["<STR_LIT>"] in inactive_list:<EOL><INDENT>return URLStatus(PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]).handle()<EOL><DEDENT><DEDENT>if "<STR_LIT>" in PyFunceble.INTERN:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"]["<STR_LIT>"] = False<EOL><DEDENT>return URLStatus(PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]).handle()<EOL>

Execute the logic behind the URL handling.

:return: The status of the URL.
:rtype: str


if "<STR_LIT>" in PyFunceble.INTERN and PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>expiration_date = ExpirationDate().get()<EOL>if expiration_date is False:<EOL><INDENT>return cls.handle(status="<STR_LIT>")<EOL><DEDENT>if expiration_date == PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>return expiration_date, "<STR_LIT>"<EOL><DEDENT>return cls.handle(status="<STR_LIT>")<EOL><DEDENT>raise NotImplementedError("<STR_LIT>")<EOL>

Get the status while testing for an IP or domain.

.. note::
    We consider that the domain or IP we are currently testing
    is into :code:`PyFunceble.INTERN["to_test"]`.


@classmethod<EOL><INDENT>def handle(cls, status, invalid_source="<STR_LIT>"):<DEDENT>

if status.lower() not in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>source = "<STR_LIT>"<EOL>if Lookup().nslookup():<EOL><INDENT>status, source = cls.extra_rules.handle(<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"], source<EOL>)<EOL>Generate(status, source).status_file()<EOL>return status, source<EOL><DEDENT>status, source = cls.extra_rules.handle(<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"], source<EOL>)<EOL>Generate(status, source).status_file()<EOL>return status, source<EOL><DEDENT>status, source = cls.extra_rules.handle(<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"], invalid_source<EOL>)<EOL>Generate(status, source).status_file()<EOL>return status, source<EOL>

Handle the lack of WHOIS and expiration date. :smile_cat:

:param matched_status: The status that we have to handle.
:type status: str

:param invalid_source:
    The source to set when we handle INVALID element.
:type invalid_source: str

:return:
    The strus of the domain after generating the files desired
    by the user.
:rtype: str


<EOL>source = "<STR_LIT>"<EOL>if self.catched.lower() not in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>Generate(self.catched, source).status_file()<EOL><DEDENT>else:<EOL><INDENT>Generate(self.catched, "<STR_LIT>").status_file()<EOL><DEDENT>return self.catched<EOL>


<EOL>Generate(self.catched, "<STR_LIT>").status_file()<EOL>return self.catched<EOL>


<EOL>return (<EOL>Regex(element, cls.regex_replace, replace_with="<STR_LIT>")<EOL>.replace()<EOL>.replace("<STR_LIT>", "<STR_LIT>")<EOL>)<EOL>

Implement the standard and alphabetical sorting.

:param element: The element we are currently reading.
:type element: str

:return: The formatted element.
:rtype: str


<EOL>to_sort = "<STR_LIT>"<EOL>full_extension = "<STR_LIT>"<EOL>element = element.lower()<EOL>url_base = Check().is_url_valid(element, return_base=True)<EOL>if not isinstance(url_base, str):<EOL><INDENT>if "<STR_LIT:.>" in element:<EOL><INDENT>extension_index = element.rindex("<STR_LIT:.>") + <NUM_LIT:1><EOL>extension = element[extension_index:]<EOL>if extension in PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>for suffix in PyFunceble.INTERN["<STR_LIT>"][extension]:<EOL><INDENT>formatted_suffix = "<STR_LIT:.>" + suffix<EOL>if element.endswith(formatted_suffix):<EOL><INDENT>suffix_index = element.rindex(formatted_suffix)<EOL>to_sort = element[:suffix_index]<EOL>full_extension = suffix<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if not full_extension:<EOL><INDENT>full_extension = element[extension_index:]<EOL>to_sort = element[: extension_index - <NUM_LIT:1>]<EOL><DEDENT>full_extension += "<STR_LIT:.>"<EOL>tros_ot = to_sort[::-<NUM_LIT:1>]<EOL>if "<STR_LIT:.>" in tros_ot:<EOL><INDENT>full_extension = (<EOL>tros_ot[: tros_ot.index("<STR_LIT:.>")][::-<NUM_LIT:1>] + "<STR_LIT:.>" + full_extension<EOL>)<EOL>tros_ot = tros_ot[tros_ot.index("<STR_LIT:.>") + <NUM_LIT:1> :]<EOL>reversion = full_extension + "<STR_LIT:.>".join(<EOL>[x[::-<NUM_LIT:1>] for x in tros_ot.split("<STR_LIT:.>")]<EOL>)<EOL>return (<EOL>Regex(reversion, cls.regex_replace, replace_with="<STR_LIT>")<EOL>.replace()<EOL>.replace("<STR_LIT>", "<STR_LIT>")<EOL>)<EOL><DEDENT>return (<EOL>Regex(<EOL>to_sort + full_extension,<EOL>cls.regex_replace,<EOL>replace_with="<STR_LIT>",<EOL>)<EOL>.replace()<EOL>.replace("<STR_LIT>", "<STR_LIT>")<EOL>)<EOL><DEDENT>return element<EOL><DEDENT>protocol_position = element.rindex(url_base)<EOL>protocol = element[:protocol_position]<EOL>return protocol + cls.hierarchical(url_base)<EOL>

The idea behind this method is to sort a list of domain hierarchicaly.

:param element: The element we are currently reading.
:type element: str

:return: The formatted element.
:rtype: str

.. note::
    For a domain like :code:`aaa.bbb.ccc.tdl`.

    A normal sorting is done in the following order:
        1. :code:`aaa`
        2. :code:`bbb`
        3. :code:`ccc`
        4. :code:`tdl`

    This method allow the sorting to be done in the following order:
        1. :code:`tdl`
        2. :code:`ccc`
        3. :code:`bbb`
        4. :code:`aaa`


with open("<STR_LIT>") as file:<EOL><INDENT>requirements = file.read().splitlines()<EOL><DEDENT>return requirements<EOL>

This function extract all requirements from requirements.txt.


to_match = comp(r'<STR_LIT>')<EOL>extracted = to_match.findall(<EOL>open("<STR_LIT>", encoding="<STR_LIT:utf-8>").read()<EOL>)[<NUM_LIT:0>]<EOL>return "<STR_LIT:.>".join([x for x in extracted.split("<STR_LIT:.>") if x.isdigit()])<EOL>

This function will extract the version from PyFunceble/__init__.py


return open("<STR_LIT>", encoding="<STR_LIT:utf-8>").read()<EOL>

This function return the long description.


to_match = comp(r'<STR_LIT>')<EOL>extracted = to_match.findall(<EOL>open("<STR_LIT>", encoding="<STR_LIT:utf-8>").read()<EOL>)[<NUM_LIT:0>]<EOL>if not full:<EOL><INDENT>return "<STR_LIT:.>".join([x for x in extracted.split("<STR_LIT:.>") if x.isdigit()])<EOL><DEDENT>return extracted<EOL>

This function will extract the version from PyFunceble/__init__.py

Argument:
    - full: bool
        True: Return the full version name
        False: Return the short version


if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if self.buf:<EOL><INDENT>rv = self.buf<EOL>self.buf = None<EOL>return rv<EOL><DEDENT>else:<EOL><INDENT>return next(self.iterator)<EOL><DEDENT>

x.__next__() -> the next value, or raise StopIteration


self.left = self.limit<EOL>


if self.left is not None:<EOL><INDENT>size = min(size, self.left)<EOL><DEDENT>if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if size < <NUM_LIT:0>:<EOL><INDENT>return '<STR_LIT>'.join(self)<EOL><DEDENT>elif not size:<EOL><INDENT>chunk = '<STR_LIT>'<EOL><DEDENT>elif self.buf:<EOL><INDENT>chunk = self.buf<EOL>self.buf = None<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>chunk = next(self.iterator)<EOL><DEDENT>except StopIteration:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>if len(chunk) > size:<EOL><INDENT>self.buf = chunk[size:]<EOL>chunk = chunk[:size]<EOL><DEDENT>if self.left is not None:<EOL><INDENT>self.left -= len(chunk)<EOL><DEDENT>return chunk<EOL>

read([size]) -> read at most size bytes, returned as a string.

If the size argument is negative or omitted, read until EOF is reached.
Notice that when in non-blocking mode, less data than what was
requested may be returned, even if no size parameter was given.


if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>data = '<STR_LIT>'<EOL>while '<STR_LIT:\n>' not in data and (size < <NUM_LIT:0> or len(data) < size):<EOL><INDENT>if size < <NUM_LIT:0>:<EOL><INDENT>chunk = self.read(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>chunk = self.read(size - len(data))<EOL><DEDENT>if not chunk:<EOL><INDENT>break<EOL><DEDENT>data += chunk<EOL><DEDENT>if '<STR_LIT:\n>' in data:<EOL><INDENT>data, sep, rest = data.partition('<STR_LIT:\n>')<EOL>data += sep<EOL>if self.buf:<EOL><INDENT>self.buf = rest + self.buf<EOL><DEDENT>else:<EOL><INDENT>self.buf = rest<EOL><DEDENT><DEDENT>return data<EOL>

readline([size]) -> next line from the file, as a string.

Retain newline.  A non-negative size argument limits the maximum
number of bytes to return (an incomplete line may be returned then).
Return an empty string at EOF.


if self.closed:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>lines = []<EOL>while True:<EOL><INDENT>line = self.readline(sizehint)<EOL>if not line:<EOL><INDENT>break<EOL><DEDENT>lines.append(line)<EOL>if sizehint >= <NUM_LIT:0>:<EOL><INDENT>sizehint -= len(line)<EOL>if sizehint <= <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>return lines<EOL>

readlines([size]) -> list of strings, each a line from the file.

Call readline() repeatedly and return a list of the lines so read.
The optional size argument, if given, is an approximate bound on the
total number of bytes in the lines returned.


something = self.read(<NUM_LIT:1>)<EOL>if something:<EOL><INDENT>if self.buf:<EOL><INDENT>self.buf = something + self.buf<EOL><DEDENT>else:<EOL><INDENT>self.buf = something<EOL><DEDENT>return False<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>

Check whether the "file" is empty reading the single byte.


self.iterator = None<EOL>self.closed = True<EOL>

close() -> None or (perhaps) an integer.  Close the file.

Sets data attribute .closed to True.  A closed file cannot be used for
further I/O operations.  close() may be called more than once without
error.  Some kinds of file objects (for example, opened by popen())
may return an exit status upon closing.


def request(self, method, path, contents, headers, decode_json=False,<EOL>stream=False, query=None, cdn=False):

if query:<EOL><INDENT>path += '<STR_LIT:?>' + '<STR_LIT:&>'.join(<EOL>('<STR_LIT>' % (quote(k), quote(v)) if v else quote(k))<EOL>for k, v in sorted(six.iteritems(query)))<EOL><DEDENT>reset_func = self._default_reset_func<EOL>if isinstance(contents, six.string_types):<EOL><INDENT>contents = StringIO(contents)<EOL><DEDENT>tell = getattr(contents, '<STR_LIT>', None)<EOL>seek = getattr(contents, '<STR_LIT>', None)<EOL>if tell and seek:<EOL><INDENT>try:<EOL><INDENT>orig_pos = tell()<EOL>reset_func = lambda: seek(orig_pos)<EOL><DEDENT>except Exception:<EOL><INDENT>tell = seek = None<EOL><DEDENT><DEDENT>elif not contents:<EOL><INDENT>reset_func = lambda: None<EOL><DEDENT>status = <NUM_LIT:0><EOL>reason = '<STR_LIT>'<EOL>attempt = <NUM_LIT:0><EOL>while attempt < self.attempts:<EOL><INDENT>attempt += <NUM_LIT:1><EOL>if cdn:<EOL><INDENT>conn_path = self.cdn_path<EOL><DEDENT>else:<EOL><INDENT>conn_path = self.storage_path<EOL><DEDENT>titled_headers = dict((k.title(), v) for k, v in six.iteritems({<EOL>'<STR_LIT>': self.user_agent}))<EOL>if headers:<EOL><INDENT>titled_headers.update(<EOL>(k.title(), v) for k, v in six.iteritems(headers))<EOL><DEDENT>resp = None<EOL>if not hasattr(contents, '<STR_LIT>'):<EOL><INDENT>if method not in self.no_content_methods and contents and'<STR_LIT>' not in titled_headers and'<STR_LIT>' not in titled_headers:<EOL><INDENT>titled_headers['<STR_LIT>'] = str(<EOL>len(contents or '<STR_LIT>'))<EOL><DEDENT>req = self.Request.blank(<EOL>conn_path + path,<EOL>environ={'<STR_LIT>': method, '<STR_LIT>': True},<EOL>headers=titled_headers, body=contents)<EOL>verbose_headers = '<STR_LIT:U+0020>'.join(<EOL>'<STR_LIT>' % (k, v) for k, v in six.iteritems(titled_headers))<EOL>self.verbose(<EOL>'<STR_LIT>', method, conn_path + path, verbose_headers)<EOL>resp = req.get_response(self.swift_proxy)<EOL><DEDENT>else:<EOL><INDENT>req = self.Request.blank(<EOL>conn_path + path,<EOL>environ={'<STR_LIT>': method, '<STR_LIT>': True},<EOL>headers=titled_headers)<EOL>content_length = None<EOL>for h, v in six.iteritems(titled_headers):<EOL><INDENT>if h.lower() == '<STR_LIT>':<EOL><INDENT>content_length = int(v)<EOL><DEDENT>req.headers[h] = v<EOL><DEDENT>if method not in self.no_content_methods andcontent_length is None:<EOL><INDENT>titled_headers['<STR_LIT>'] = '<STR_LIT>'<EOL>req.headers['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>req.content_length = content_length<EOL><DEDENT>req.body_file = contents<EOL>verbose_headers = '<STR_LIT:U+0020>'.join(<EOL>'<STR_LIT>' % (k, v) for k, v in six.iteritems(titled_headers))<EOL>self.verbose(<EOL>'<STR_LIT>', method, conn_path + path, verbose_headers)<EOL>resp = req.get_response(self.swift_proxy)<EOL><DEDENT>status = resp.status_int<EOL>reason = resp.status.split('<STR_LIT:U+0020>', <NUM_LIT:1>)[<NUM_LIT:1>]<EOL>hdrs = headers_to_dict(resp.headers.items())<EOL>if stream:<EOL><INDENT>def iter_reader(size=-<NUM_LIT:1>):<EOL><INDENT>if size == -<NUM_LIT:1>:<EOL><INDENT>return '<STR_LIT>'.join(resp.app_iter)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>return next(resp.app_iter)<EOL><DEDENT>except StopIteration:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT><DEDENT>iter_reader.read = iter_reader<EOL>value = iter_reader<EOL><DEDENT>else:<EOL><INDENT>value = resp.body<EOL><DEDENT>self.verbose('<STR_LIT>', status, reason)<EOL>if status and status // <NUM_LIT:100> != <NUM_LIT:5>:<EOL><INDENT>if not stream and decode_json and status // <NUM_LIT:100> == <NUM_LIT:2>:<EOL><INDENT>if value:<EOL><INDENT>value = json.loads(value)<EOL><DEDENT>else:<EOL><INDENT>value = None<EOL><DEDENT><DEDENT>return (status, reason, hdrs, value)<EOL><DEDENT>if reset_func:<EOL><INDENT>reset_func()<EOL><DEDENT>self.sleep(<NUM_LIT:2> ** attempt)<EOL><DEDENT>raise Exception('<STR_LIT>' % (method, path, status, reason))<EOL>


return self.storage_path.rsplit('<STR_LIT:/>', <NUM_LIT:1>)[<NUM_LIT:1>]<EOL>


client = None<EOL>try:<EOL><INDENT>client = self.clients.get(block=False)<EOL><DEDENT>except queue.Empty:<EOL><INDENT>pass<EOL><DEDENT>if not client:<EOL><INDENT>self.client_id += <NUM_LIT:1><EOL>kwargs = dict(self.kwargs)<EOL>kwargs['<STR_LIT>'] = kwargs.get(<EOL>'<STR_LIT>', '<STR_LIT>') + str(self.client_id)<EOL>client = self.client_class(*self.args, **kwargs)<EOL><DEDENT>return client<EOL>

Obtains a client for use, whether an existing unused client
or a brand new one if none are available.


self.clients.put(client)<EOL>

Returns a client back into the pool for availability to
future calls to get_client. This should only be called if
get_client was used to obtain the client; with_client is a
context manager that does this for you.


client = self.get_client()<EOL>yield client<EOL>self.put_client(client)<EOL>

A context manager that obtains a client for use, whether an
existing unused client or a brand new one if none are
available.


pass<EOL>

Resets the client, closing any connections and discarding any
state. This can be useful if some exceptional condition
occurred and the request/response state can no longer be
certain.


pass<EOL>

Just performs any authentication steps without making an
actual request to the Swift system.


raise Exception('<STR_LIT>')<EOL>

Performs a direct HTTP request to the Swift service.

:param method: The request method ('GET', 'HEAD', etc.)
:param path: The request path.
:param contents: The body of the request. May be a string or
    a file-like object.
:param headers: A dict of request headers and values.
:param decode_json: If set True, the response body will be
    treated as JSON and decoded result returned instead of
    the raw contents.
:param stream: If set True, the response body will return as
    a file-like object; otherwise, the response body will be
    read in its entirety and returned as a string. Overrides
    decode_json.
:param query: A dict of query parameters and values to append
    to the path.
:param cdn: If set True, the request will be sent to the CDN
    management endpoint instead of the default storage
    endpoint.
:returns: A tuple of (status, reason, headers, contents).

    :status: An int for the HTTP status code.
    :reason: The str for the HTTP status (ex: "Ok").
    :headers: A dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be
        a list.
    :contents: Depending on the decode_json and stream
        settings, this will either be the raw response
        string, the JSON decoded object, or a file-like
        object.


raise Exception('<STR_LIT>')<EOL>

Returns the account identifier for the Swift account being
accessed.


def head_account(self, headers=None, query=None, cdn=False):

return self.request(<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

HEADs the account and returns the results. Useful headers
returned are:

=========================== =================================
x-account-bytes-used        Object storage used for the
                            account, in bytes.
x-account-container-count   The number of containers in the
                            account.
x-account-object-count      The number of objects in the
                            account.
=========================== =================================

Also, any user headers beginning with x-account-meta- are
returned.

These values can be delayed depending the Swift cluster.

:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def get_account(self, headers=None, prefix=None, delimiter=None,<EOL>marker=None, end_marker=None, limit=None, query=None,<EOL>cdn=False, decode_json=True):

query = dict(query or {})<EOL>query['<STR_LIT>'] = '<STR_LIT>'<EOL>if prefix:<EOL><INDENT>query['<STR_LIT>'] = prefix<EOL><DEDENT>if delimiter:<EOL><INDENT>query['<STR_LIT>'] = delimiter<EOL><DEDENT>if marker:<EOL><INDENT>query['<STR_LIT>'] = marker<EOL><DEDENT>if end_marker:<EOL><INDENT>query['<STR_LIT>'] = end_marker<EOL><DEDENT>if limit:<EOL><INDENT>query['<STR_LIT>'] = limit<EOL><DEDENT>return self.request(<EOL>'<STR_LIT:GET>', '<STR_LIT>', '<STR_LIT>', headers, decode_json=decode_json, query=query,<EOL>cdn=cdn)<EOL>

GETs the account and returns the results. This is done to list
the containers for the account. Some useful headers are also
returned:

=========================== =================================
x-account-bytes-used        Object storage used for the
                            account, in bytes.
x-account-container-count   The number of containers in the
                            account.
x-account-object-count      The number of objects in the
                            account.
=========================== =================================

Also, any user headers beginning with x-account-meta- are
returned.

These values can be delayed depending the Swift cluster.

:param headers: Additional headers to send with the request.
:param prefix: The prefix container names must match to be
    listed.
:param delimiter: The delimiter for the listing. Delimiters
    indicate how far to progress through container names
    before "rolling them up". For instance, a delimiter='.'
    query on an account with the containers::

        one.one
        one.two
        two
        three.one

    would return the JSON value of::

        [{'subdir': 'one.'},
         {'count': 0, 'bytes': 0, 'name': 'two'},
         {'subdir': 'three.'}]

    Using this with prefix can allow you to traverse a psuedo
    hierarchy.
:param marker: Only container names after this marker will be
    returned. Swift returns a limited number of containers
    per request (often 10,000). To get the next batch of
    names, you issue another query with the marker set to the
    last name you received. You can continue to issue
    requests until you receive no more names.
:param end_marker: Only container names before this marker will be
    returned.
:param limit: Limits the size of the list returned per
    request. The default and maximum depends on the Swift
    cluster (usually 10,000).
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param decode_json: If set False, the usual decoding of the
    JSON response will be skipped and the raw contents will
    be returned instead.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the decoded JSON response or the raw str
        for the HTTP body.


def put_account(self, headers=None, query=None, cdn=False, body=None):

return self.request(<EOL>'<STR_LIT>', '<STR_LIT>', body or '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

PUTs the account and returns the results. This is usually
done with the extract-archive bulk upload request and has no
other use I know of (but the call is left open in case there
ever is).

:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: Some account PUT requests, like the
    extract-archive bulk upload request, take a body.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def post_account(self, headers=None, query=None, cdn=False, body=None):

return self.request(<EOL>'<STR_LIT:POST>', '<STR_LIT>', body or '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

POSTs the account and returns the results. This is usually
done to set X-Account-Meta-xxx headers. Note that any existing
X-Account-Meta-xxx headers will remain untouched. To remove an
X-Account-Meta-xxx header, send the header with an empty
string as its value.

:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: No known Swift POSTs take a body; but the option
    is there for the future.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def delete_account(self, headers=None,<EOL>yes_i_mean_delete_the_account=False, query=None,<EOL>cdn=False, body=None):

if not yes_i_mean_delete_the_account and (<EOL>not body or not query or '<STR_LIT>' not in query):<EOL><INDENT>return (<NUM_LIT:0>, '<STR_LIT>', {},<EOL>'<STR_LIT>')<EOL><DEDENT>return self.request(<EOL>'<STR_LIT>', '<STR_LIT>', body or '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

Sends a DELETE request to the account and returns the results.

With ``query['bulk-delete'] = ''`` this might mean a bulk
delete request where the body of the request is new-line
separated, url-encoded list of names to delete. Be careful
with this! One wrong move and you might mark your account for
deletion of you have the access to do so!

For a plain DELETE to the account, on clusters that support
it and, assuming you have permissions to do so, the account
will be marked as deleted and immediately begin removing the
objects from the cluster in the backgound.

THERE IS NO GOING BACK!

:param headers: Additional headers to send with the request.
:param yes_i_mean_delete_the_account: Set to True to verify
    you really mean to delete the entire account. This is
    required unless ``body and 'bulk-delete' in query``.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: Some account DELETE requests, like the bulk
    delete request, take a body.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be
        a list.
    :contents: is the str for the HTTP body.


def head_container(self, container, headers=None, query=None, cdn=False):

path = self._container_path(container)<EOL>return self.request(<EOL>'<STR_LIT>', path, '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

HEADs the container and returns the results. Useful headers
returned are:

=========================== =================================
x-container-bytes-used      Object storage used for the
                            container, in bytes.
x-container-object-count    The number of objects in the
                            container.
=========================== =================================

Also, any user headers beginning with x-container-meta- are
returned.

These values can be delayed depending the Swift cluster.

:param container: The name of the container.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def get_container(self, container, headers=None, prefix=None,<EOL>delimiter=None, marker=None, end_marker=None,<EOL>limit=None, query=None, cdn=False, decode_json=True):

query = dict(query or {})<EOL>query['<STR_LIT>'] = '<STR_LIT>'<EOL>if prefix:<EOL><INDENT>query['<STR_LIT>'] = prefix<EOL><DEDENT>if delimiter:<EOL><INDENT>query['<STR_LIT>'] = delimiter<EOL><DEDENT>if marker:<EOL><INDENT>query['<STR_LIT>'] = marker<EOL><DEDENT>if end_marker:<EOL><INDENT>query['<STR_LIT>'] = end_marker<EOL><DEDENT>if limit:<EOL><INDENT>query['<STR_LIT>'] = limit<EOL><DEDENT>return self.request(<EOL>'<STR_LIT:GET>', self._container_path(container), '<STR_LIT>', headers,<EOL>decode_json=decode_json, query=query, cdn=cdn)<EOL>

GETs the container and returns the results. This is done to
list the objects for the container. Some useful headers are
also returned:

=========================== =================================
x-container-bytes-used      Object storage used for the
                            container, in bytes.
x-container-object-count    The number of objects in the
                            container.
=========================== =================================

Also, any user headers beginning with x-container-meta- are
returned.

These values can be delayed depending the Swift cluster.

:param container: The name of the container.
:param headers: Additional headers to send with the request.
:param prefix: The prefix object names must match to be
    listed.
:param delimiter: The delimiter for the listing. Delimiters
    indicate how far to progress through object names before
    "rolling them up". For instance, a delimiter='/' query on
    an container with the objects::

        one/one
        one/two
        two
        three/one

    would return the JSON value of::

        [{'subdir': 'one/'},
         {'count': 0, 'bytes': 0, 'name': 'two'},
         {'subdir': 'three/'}]

    Using this with prefix can allow you to traverse a psuedo
    hierarchy.
:param marker: Only object names after this marker will be
    returned. Swift returns a limited number of objects per
    request (often 10,000). To get the next batch of names,
    you issue another query with the marker set to the last
    name you received. You can continue to issue requests
    until you receive no more names.
:param end_marker: Only object names before this marker will be
    returned.
:param limit: Limits the size of the list returned per
    request. The default and maximum depends on the Swift
    cluster (usually 10,000).
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param decode_json: If set False, the usual decoding of the
    JSON response will be skipped and the raw contents will
    be returned instead.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the decoded JSON response or the raw str
        for the HTTP body.


def put_container(self, container, headers=None, query=None, cdn=False,<EOL>body=None):

path = self._container_path(container)<EOL>return self.request(<EOL>'<STR_LIT>', path, body or '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

PUTs the container and returns the results. This is usually
done to create new containers and can also be used to set
X-Container-Meta-xxx headers. Note that if the container
already exists, any existing X-Container-Meta-xxx headers will
remain untouched. To remove an X-Container-Meta-xxx header,
send the header with an empty string as its value.

:param container: The name of the container.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: Some container PUT requests, like the
    extract-archive bulk upload request, take a body.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def post_container(self, container, headers=None, query=None, cdn=False,<EOL>body=None):

path = self._container_path(container)<EOL>return self.request(<EOL>'<STR_LIT:POST>', path, body or '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

POSTs the container and returns the results. This is usually
done to set X-Container-Meta-xxx headers. Note that any
existing X-Container-Meta-xxx headers will remain untouched.
To remove an X-Container-Meta-xxx header, send the header with
an empty string as its value.

:param container: The name of the container.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: No known Swift POSTs take a body; but the option
    is there for the future.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def delete_container(self, container, headers=None, query=None, cdn=False,<EOL>body=None):

DELETEs the container and returns the results.

:param container: The name of the container.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: Some container DELETE requests might take a body
    in the future.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def head_object(self, container, obj, headers=None, query=None, cdn=False):

path = self._object_path(container, obj)<EOL>return self.request(<EOL>'<STR_LIT>', path, '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

HEADs the object and returns the results.

:param container: The name of the container.
:param obj: The name of the object.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def get_object(self, container, obj, headers=None, stream=True, query=None,<EOL>cdn=False):

path = self._object_path(container, obj)<EOL>return self.request(<EOL>'<STR_LIT:GET>', path, '<STR_LIT>', headers, query=query, stream=stream, cdn=cdn)<EOL>

GETs the object and returns the results.

:param container: The name of the container.
:param obj: The name of the object.
:param headers: Additional headers to send with the request.
:param stream: Indicates whether to stream the contents or
    preread them fully and return them as a str. Default:
    True to stream the contents. When streaming, contents
    will have the standard file-like-object read function,
    which accepts an optional size parameter to limit how
    much data is read per call. When streaming is on, be
    certain to fully read the contents before issuing another
    request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: if *stream* was True, *contents* is a
        file-like-object of the contents of the HTTP body. If
        *stream* was False, *contents* is just a simple str of
        the HTTP body.


def put_object(self, container, obj, contents, headers=None, query=None,<EOL>cdn=False):

path = self._object_path(container, obj)<EOL>return self.request(<EOL>'<STR_LIT>', path, contents, headers, query=query, cdn=cdn)<EOL>

PUTs the object and returns the results. This is used to
create or overwrite objects. X-Object-Meta-xxx can optionally
be sent to be stored with the object. Content-Type,
Content-Encoding and other standard HTTP headers can often
also be set, depending on the Swift cluster.

Note that you can set the ETag header to the MD5 sum of the
contents for extra verification the object was stored
correctly.

:param container: The name of the container.
:param obj: The name of the object.
:param contents: The contents of the object to store. This can
    be a simple str, or a file-like-object with at least a
    read function. If the file-like-object also has tell and
    seek functions, the PUT can be reattempted on any server
    error.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def post_object(self, container, obj, headers=None, query=None, cdn=False,<EOL>body=None):

path = self._object_path(container, obj)<EOL>return self.request(<EOL>'<STR_LIT:POST>', path, body or '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

POSTs the object and returns the results. This is used to
update the object's header values. Note that all headers must
be sent with the POST, unlike the account and container POSTs.
With account and container POSTs, existing headers are
untouched. But with object POSTs, any existing headers are
removed. The full list of supported headers depends on the
Swift cluster, but usually include Content-Type,
Content-Encoding, and any X-Object-Meta-xxx headers.

:param container: The name of the container.
:param obj: The name of the object.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: No known Swift POSTs take a body; but the option
    is there for the future.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


def delete_object(self, container, obj, headers=None, query=None,<EOL>cdn=False, body=None):

path = self._object_path(container, obj)<EOL>return self.request(<EOL>'<STR_LIT>', path, body or '<STR_LIT>', headers, query=query, cdn=cdn)<EOL>

DELETEs the object and returns the results.

:param container: The name of the container.
:param obj: The name of the object.
:param headers: Additional headers to send with the request.
:param query: Set to a dict of query values to send on the
    query string of the request.
:param cdn: If set True, the CDN management interface will be
    used.
:param body: Some object DELETE requests might take a body in
    the future.
:returns: A tuple of (status, reason, headers, contents).

    :status: is an int for the HTTP status code.
    :reason: is the str for the HTTP status (ex: "Ok").
    :headers: is a dict with all lowercase keys of the HTTP
        headers; if a header has multiple values, it will be a
        list.
    :contents: is the str for the HTTP body.


if cdn:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if isinstance(contents, six.string_types):<EOL><INDENT>contents = StringIO(contents)<EOL><DEDENT>if not headers:<EOL><INDENT>headers = {}<EOL><DEDENT>if not query:<EOL><INDENT>query = {}<EOL><DEDENT>rpath = path.lstrip('<STR_LIT:/>')<EOL>if '<STR_LIT:/>' in rpath:<EOL><INDENT>container_name, object_name = rpath.split('<STR_LIT:/>', <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>container_name = rpath<EOL>object_name = '<STR_LIT>'<EOL><DEDENT>if not container_name:<EOL><INDENT>status, reason, hdrs, body = self._account(<EOL>method, contents, headers, stream, query, cdn)<EOL><DEDENT>elif not object_name:<EOL><INDENT>status, reason, hdrs, body = self._container(<EOL>method, container_name, contents, headers, stream, query, cdn)<EOL><DEDENT>else:<EOL><INDENT>status, reason, hdrs, body = self._object(<EOL>method, container_name, object_name, contents, headers, stream,<EOL>query, cdn)<EOL><DEDENT>if status and status // <NUM_LIT:100> != <NUM_LIT:5>:<EOL><INDENT>if not stream and decode_json and status // <NUM_LIT:100> == <NUM_LIT:2>:<EOL><INDENT>if body:<EOL><INDENT>body = loads(body)<EOL><DEDENT>else:<EOL><INDENT>body = None<EOL><DEDENT><DEDENT>return (status, reason, hdrs, body)<EOL><DEDENT>raise Exception('<STR_LIT>' % (method, path, status, reason))<EOL>


return quote(self.local_path, safe='<STR_LIT>')<EOL>


def generate_temp_url(method, url, seconds, key):

method = method.upper()<EOL>base_url, object_path = url.split('<STR_LIT>')<EOL>object_path = '<STR_LIT>' + object_path<EOL>expires = int(time.time() + seconds)<EOL>hmac_body = '<STR_LIT>' % (method, expires, object_path)<EOL>sig = hmac.new(key, hmac_body, hashlib.sha1).hexdigest()<EOL>return '<STR_LIT>' % (<EOL>base_url, object_path, sig, expires)<EOL>

Returns a TempURL good for the given request method, url, and
number of seconds from now, signed by the given key.


if len(trans_id) >= <NUM_LIT> and trans_id[:<NUM_LIT:2>] == '<STR_LIT>' and trans_id[<NUM_LIT>] == '<STR_LIT:->':<EOL><INDENT>try:<EOL><INDENT>return int(trans_id[<NUM_LIT>:<NUM_LIT>], <NUM_LIT:16>)<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return None<EOL>

Returns the time.time() embedded in the trans_id or None if no
time information is embedded.

Copied from the Swift codebase.
Copyright (c) 2010-2012 OpenStack Foundation


if isinstance(value, six.text_type):<EOL><INDENT>value = value.encode('<STR_LIT:utf8>')<EOL><DEDENT>elif not isinstance(value, six.string_types):<EOL><INDENT>value = str(value)<EOL><DEDENT>return parse.quote(value, safe)<EOL>

Much like parse.quote in that it returns a URL encoded string
for the given value, protecting the safe characters; but this
version also ensures the value is UTF-8 encoded.


hdrs = {}<EOL>for h, v in headers:<EOL><INDENT>h = h.lower()<EOL>if h in hdrs:<EOL><INDENT>if isinstance(hdrs[h], list):<EOL><INDENT>hdrs[h].append(v)<EOL><DEDENT>else:<EOL><INDENT>hdrs[h] = [hdrs[h], v]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>hdrs[h] = v<EOL><DEDENT><DEDENT>return hdrs<EOL>

Converts a sequence of (name, value) tuples into a dict where if
a given name occurs more than once its value in the dict will be
a list of values.


self.reset()<EOL>if not self.auth_url:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>funcs = []<EOL>if self.auth_methods:<EOL><INDENT>for method in self.auth_methods.split('<STR_LIT:U+002C>'):<EOL><INDENT>funcs.append(getattr(self, '<STR_LIT:_>' + method))<EOL><DEDENT><DEDENT>if not funcs:<EOL><INDENT>if '<STR_LIT:1.0>' in self.auth_url:<EOL><INDENT>funcs = [self._auth1, self._auth2key, self._auth2password]<EOL>if not self.auth_tenant:<EOL><INDENT>funcs.append(self._auth2password_force_tenant)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>funcs = [self._auth2key, self._auth2password]<EOL>if not self.auth_tenant:<EOL><INDENT>funcs.append(self._auth2password_force_tenant)<EOL><DEDENT>funcs.append(self._auth1)<EOL><DEDENT><DEDENT>info = []<EOL>for func in funcs:<EOL><INDENT>status, reason = func()<EOL>info.append('<STR_LIT>' % (status, reason))<EOL>if status // <NUM_LIT:100> == <NUM_LIT:2>:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise self.HTTPException('<STR_LIT>' % info)<EOL><DEDENT>


def request(self, method, path, contents, headers, decode_json=False,<EOL>stream=False, query=None, cdn=False):

if query:<EOL><INDENT>path += '<STR_LIT:?>' + '<STR_LIT:&>'.join(<EOL>('<STR_LIT>' % (quote(k), quote(v)) if v else quote(k))<EOL>for k, v in sorted(six.iteritems(query)))<EOL><DEDENT>reset_func = self._default_reset_func<EOL>if isinstance(contents, six.string_types):<EOL><INDENT>contents = StringIO(contents)<EOL><DEDENT>tell = getattr(contents, '<STR_LIT>', None)<EOL>seek = getattr(contents, '<STR_LIT>', None)<EOL>if tell and seek:<EOL><INDENT>try:<EOL><INDENT>orig_pos = tell()<EOL>reset_func = lambda: seek(orig_pos)<EOL><DEDENT>except Exception:<EOL><INDENT>tell = seek = None<EOL><DEDENT><DEDENT>elif not contents:<EOL><INDENT>reset_func = lambda: None<EOL><DEDENT>status = <NUM_LIT:0><EOL>reason = '<STR_LIT>'<EOL>attempt = <NUM_LIT:0><EOL>while attempt < self.attempts:<EOL><INDENT>attempt += <NUM_LIT:1><EOL>if time() >= self.conn_discard:<EOL><INDENT>self.storage_conn = None<EOL>self.cdn_conn = None<EOL><DEDENT>if cdn:<EOL><INDENT>conn = self.cdn_conn<EOL>conn_path = self.cdn_path<EOL><DEDENT>else:<EOL><INDENT>conn = self.storage_conn<EOL>conn_path = self.storage_path<EOL><DEDENT>if not conn:<EOL><INDENT>parsed, conn = self._connect(cdn=cdn)<EOL>if conn:<EOL><INDENT>if cdn:<EOL><INDENT>self.cdn_conn = conn<EOL>self.cdn_path = conn_path = parsed.path<EOL><DEDENT>else:<EOL><INDENT>self.storage_conn = conn<EOL>self.storage_path = conn_path = parsed.path<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise self.HTTPException(<EOL>'<STR_LIT>' % (method, path))<EOL><DEDENT><DEDENT>self.conn_discard = time() + <NUM_LIT:4><EOL>titled_headers = dict((k.title(), v) for k, v in six.iteritems({<EOL>'<STR_LIT>': self.user_agent,<EOL>'<STR_LIT>': self.auth_token}))<EOL>if headers:<EOL><INDENT>titled_headers.update(<EOL>(k.title(), v) for k, v in six.iteritems(headers))<EOL><DEDENT>try:<EOL><INDENT>if not hasattr(contents, '<STR_LIT>'):<EOL><INDENT>if method not in self.no_content_methods and contents and'<STR_LIT>' not in titled_headers and'<STR_LIT>' not in titled_headers:<EOL><INDENT>titled_headers['<STR_LIT>'] = str(<EOL>len(contents or '<STR_LIT>'))<EOL><DEDENT>verbose_headers = '<STR_LIT:U+0020>'.join(<EOL>'<STR_LIT>' % (k, v)<EOL>for k, v in sorted(six.iteritems(titled_headers)))<EOL>self.verbose(<EOL>'<STR_LIT>', method, conn_path + path,<EOL>verbose_headers)<EOL>conn.request(<EOL>method, conn_path + path, contents, titled_headers)<EOL><DEDENT>else:<EOL><INDENT>conn.putrequest(method, conn_path + path)<EOL>content_length = None<EOL>for h, v in sorted(six.iteritems(titled_headers)):<EOL><INDENT>if h == '<STR_LIT>':<EOL><INDENT>content_length = int(v)<EOL><DEDENT>conn.putheader(h, v)<EOL><DEDENT>if method not in self.no_content_methods andcontent_length is None:<EOL><INDENT>titled_headers['<STR_LIT>'] = '<STR_LIT>'<EOL>conn.putheader('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>conn.endheaders()<EOL>verbose_headers = '<STR_LIT:U+0020>'.join(<EOL>'<STR_LIT>' % (k, v)<EOL>for k, v in sorted(six.iteritems(titled_headers)))<EOL>self.verbose(<EOL>'<STR_LIT>', method, conn_path + path,<EOL>verbose_headers)<EOL>if method not in self.no_content_methods andcontent_length is None:<EOL><INDENT>chunk = contents.read(self.chunk_size)<EOL>while chunk:<EOL><INDENT>conn.send('<STR_LIT>' % (len(chunk), chunk))<EOL>chunk = contents.read(self.chunk_size)<EOL><DEDENT>conn.send('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>left = content_length or <NUM_LIT:0><EOL>while left > <NUM_LIT:0>:<EOL><INDENT>size = self.chunk_size<EOL>if size > left:<EOL><INDENT>size = left<EOL><DEDENT>chunk = contents.read(size)<EOL>if not chunk:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>conn.send(chunk)<EOL>left -= len(chunk)<EOL><DEDENT><DEDENT><DEDENT>resp = conn.getresponse()<EOL>status = resp.status<EOL>reason = resp.reason<EOL>hdrs = headers_to_dict(resp.getheaders())<EOL>if stream:<EOL><INDENT>value = resp<EOL><DEDENT>else:<EOL><INDENT>value = resp.read()<EOL>resp.close()<EOL><DEDENT><DEDENT>except Exception as err:<EOL><INDENT>status = <NUM_LIT:0><EOL>reason = '<STR_LIT>' % (type(err), str(err))<EOL>hdrs = {}<EOL>value = None<EOL><DEDENT>self.verbose('<STR_LIT>', status or '<STR_LIT:->', reason)<EOL>self.verbose('<STR_LIT>', hdrs)<EOL>if status == <NUM_LIT>:<EOL><INDENT>if stream:<EOL><INDENT>value.close()<EOL><DEDENT>conn.close()<EOL>self.auth()<EOL>attempt -= <NUM_LIT:1><EOL><DEDENT>elif status and status // <NUM_LIT:100> != <NUM_LIT:5>:<EOL><INDENT>if not stream and decode_json and status // <NUM_LIT:100> == <NUM_LIT:2>:<EOL><INDENT>if value:<EOL><INDENT>value = json.loads(value.decode('<STR_LIT:utf-8>'))<EOL><DEDENT>else:<EOL><INDENT>value = None<EOL><DEDENT><DEDENT>self.conn_discard = time() + <NUM_LIT:4><EOL>return (status, reason, hdrs, value)<EOL><DEDENT>else:<EOL><INDENT>if stream and value:<EOL><INDENT>value.close()<EOL><DEDENT>conn.close()<EOL><DEDENT>if reset_func:<EOL><INDENT>reset_func()<EOL><DEDENT>self.sleep(<NUM_LIT:2> ** attempt)<EOL><DEDENT>raise self.HTTPException(<EOL>'<STR_LIT>' % (method, path, status, reason))<EOL>


for conn in (self.storage_conn, self.cdn_conn):<EOL><INDENT>if conn:<EOL><INDENT>try:<EOL><INDENT>conn.close()<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>self.storage_conn = None<EOL>self.cdn_conn = None<EOL>


if not(self.storage_url or self.storage_path):<EOL><INDENT>self.auth()<EOL><DEDENT>return (self.storage_url or self.storage_path).rsplit('<STR_LIT:/>', <NUM_LIT:1>)[<NUM_LIT:1>]<EOL>


def aes_encrypt(key, stdin, preamble=None, chunk_size=<NUM_LIT>,<EOL>content_length=None):

if not AES256CBC_Support:<EOL><INDENT>raise Exception(<EOL>'<STR_LIT>')<EOL><DEDENT>if preamble:<EOL><INDENT>yield preamble<EOL><DEDENT>key = hashlib.sha256(key).digest()<EOL>chunk_size = max(<NUM_LIT:16>, chunk_size >> <NUM_LIT:4> << <NUM_LIT:4>)<EOL>iv = Crypto.Random.new().read(<NUM_LIT:16>)<EOL>yield iv<EOL>encryptor = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, iv)<EOL>reading = True<EOL>left = None<EOL>if content_length is not None and content_length >= <NUM_LIT:0>:<EOL><INDENT>left = content_length<EOL><DEDENT>while reading:<EOL><INDENT>size = chunk_size<EOL>if left is not None and size > left:<EOL><INDENT>size = left<EOL><DEDENT>chunk = stdin.read(size)<EOL>if not chunk:<EOL><INDENT>if left is not None and left > <NUM_LIT:0>:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>yield encryptor.encrypt('<STR_LIT:\x00>' * <NUM_LIT:16>)<EOL>break<EOL><DEDENT>if left is not None:<EOL><INDENT>left -= len(chunk)<EOL>if left <= <NUM_LIT:0>:<EOL><INDENT>reading = False<EOL><DEDENT><DEDENT>block = chunk<EOL>trailing = len(block) % <NUM_LIT:16><EOL>while trailing:<EOL><INDENT>size = <NUM_LIT:16> - trailing<EOL>if left is not None and size > left:<EOL><INDENT>size = left<EOL><DEDENT>chunk = stdin.read(size)<EOL>if not chunk:<EOL><INDENT>if left is not None and left > <NUM_LIT:0>:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>reading = False<EOL>chunk = chr(trailing) * (<NUM_LIT:16> - trailing)<EOL><DEDENT>elif left is not None:<EOL><INDENT>left -= len(chunk)<EOL>if left <= <NUM_LIT:0>:<EOL><INDENT>reading = False<EOL><DEDENT><DEDENT>block += chunk<EOL>trailing = len(block) % <NUM_LIT:16><EOL><DEDENT>yield encryptor.encrypt(block)<EOL><DEDENT>

Generator that encrypts a content stream using AES 256 in CBC
mode.

:param key: Any string to use as the encryption key.
:param stdin: Where to read the contents from.
:param preamble: str to yield initially useful for providing a
    hint for future readers as to the algorithm in use.
:param chunk_size: Largest amount to read at once.
:param content_length: The number of bytes to read from stdin.
    None or < 0 indicates reading until EOF.


def aes_decrypt(key, stdin, chunk_size=<NUM_LIT>):

if not AES256CBC_Support:<EOL><INDENT>raise Exception(<EOL>'<STR_LIT>')<EOL><DEDENT>key = hashlib.sha256(key).digest()<EOL>chunk_size = max(<NUM_LIT:16>, chunk_size >> <NUM_LIT:4> << <NUM_LIT:4>)<EOL>iv = stdin.read(<NUM_LIT:16>)<EOL>while len(iv) < <NUM_LIT:16>:<EOL><INDENT>chunk = stdin.read(<NUM_LIT:16> - len(iv))<EOL>if not chunk:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT><DEDENT>decryptor = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, iv)<EOL>data = '<STR_LIT>'<EOL>while True:<EOL><INDENT>chunk = stdin.read(chunk_size)<EOL>if not chunk:<EOL><INDENT>if len(data) != <NUM_LIT:16>:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>data = decryptor.decrypt(data)<EOL>trailing = ord(data[-<NUM_LIT:1>])<EOL>if trailing > <NUM_LIT:15>:<EOL><INDENT>raise IOError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT:%s>' % trailing)<EOL><DEDENT>yield data[:trailing]<EOL>break<EOL><DEDENT>data += chunk<EOL>if len(data) > <NUM_LIT:16>:<EOL><INDENT>trailing = (len(data) % <NUM_LIT:16>) or <NUM_LIT:16><EOL>yield decryptor.decrypt(data[:-trailing])<EOL>data = data[-trailing:]<EOL><DEDENT><DEDENT>

Generator that decrypts a content stream using AES 256 in CBC
mode.

:param key: Any string to use as the decryption key.
:param stdin: Where to read the encrypted data from.
:param chunk_size: Largest amount to read at once.


with context.io_manager.with_stdout() as fp:<EOL><INDENT>trans_time = get_trans_id_time(x_trans_id)<EOL>trans_info = x_trans_id[<NUM_LIT>:]<EOL>msg = '<STR_LIT>' + x_trans_id + '<STR_LIT:\n>'<EOL>if not trans_time:<EOL><INDENT>msg += '<STR_LIT>''<STR_LIT>''<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>msg += '<STR_LIT>' % (<EOL>trans_time,<EOL>time.strftime(<EOL>'<STR_LIT>', time.gmtime(trans_time)))<EOL><DEDENT>msg += '<STR_LIT>' + trans_info + '<STR_LIT:\n>'<EOL>fp.write(msg)<EOL>fp.flush()<EOL><DEDENT>

Translates any information that can be determined from the
x_trans_id and sends that to the context.io_manager's stdout.

See :py:mod:`swiftly.cli.trans` for context usage information.

See :py:class:`CLITrans` for more information.


path = path.lstrip('<STR_LIT:/>') if path else None<EOL>if path and '<STR_LIT:/>' in path:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' % path)<EOL><DEDENT>limit = context.query.get('<STR_LIT>')<EOL>delimiter = context.query.get('<STR_LIT>')<EOL>prefix = context.query.get('<STR_LIT>')<EOL>marker = context.query.get('<STR_LIT>')<EOL>end_marker = context.query.get('<STR_LIT>')<EOL>conc = Concurrency(context.concurrency)<EOL>while True:<EOL><INDENT>with context.client_manager.with_client() as client:<EOL><INDENT>if not path:<EOL><INDENT>status, reason, headers, contents = client.get_account(<EOL>headers=context.headers, prefix=prefix,<EOL>delimiter=delimiter, marker=marker, end_marker=end_marker,<EOL>limit=limit, query=context.query, cdn=context.cdn)<EOL><DEDENT>else:<EOL><INDENT>status, reason, headers, contents = client.get_container(<EOL>path, headers=context.headers, prefix=prefix,<EOL>delimiter=delimiter, marker=marker, end_marker=end_marker,<EOL>limit=limit, query=context.query, cdn=context.cdn)<EOL><DEDENT>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents.read()<EOL><DEDENT>if not path:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (status, reason))<EOL><DEDENT>else:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (path, status, reason))<EOL><DEDENT><DEDENT><DEDENT>if not contents:<EOL><INDENT>break<EOL><DEDENT>for item in contents:<EOL><INDENT>name = (path + '<STR_LIT:/>' if path else '<STR_LIT>') + item.get(<EOL>'<STR_LIT:name>', item.get('<STR_LIT>'))<EOL>args = list(context.remaining_args)<EOL>try:<EOL><INDENT>index = args.index('<STR_LIT>')<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>')<EOL><DEDENT>args[index] = name<EOL>for (exc_type, exc_value, exc_tb, result) insix.itervalues(conc.get_results()):<EOL><INDENT>if exc_value:<EOL><INDENT>conc.join()<EOL>raise exc_value<EOL><DEDENT><DEDENT>conc.spawn(name, _cli_call, context, name, args)<EOL><DEDENT>marker = contents[-<NUM_LIT:1>]['<STR_LIT:name>']<EOL>if limit:<EOL><INDENT>break<EOL><DEDENT><DEDENT>conc.join()<EOL>for (exc_type, exc_value, exc_tb, result) insix.itervalues(conc.get_results()):<EOL><INDENT>if exc_value:<EOL><INDENT>conc.join()<EOL>raise exc_value<EOL><DEDENT><DEDENT>

Issues commands for each item in an account or container listing.

See :py:mod:`swiftly.cli.fordo` for context usage information.

See :py:class:`CLIForDo` for more information.


def cli_tempurl(context, method, path, seconds=None, use_container=False):

with contextlib.nested(<EOL>context.io_manager.with_stdout(),<EOL>context.client_manager.with_client()) as (fp, client):<EOL><INDENT>method = method.upper()<EOL>path = path.lstrip('<STR_LIT:/>')<EOL>seconds = seconds if seconds is not None else <NUM_LIT><EOL>if '<STR_LIT:/>' not in path:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' % path)<EOL><DEDENT>if use_container:<EOL><INDENT>key_type = '<STR_LIT>'<EOL>container = path.split('<STR_LIT:/>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>status, reason, headers, contents =client.head_container(container)<EOL><DEDENT>else:<EOL><INDENT>key_type = '<STR_LIT>'<EOL>status, reason, headers, contents =client.head_account()<EOL><DEDENT>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' %<EOL>(key_type.title(), status, reason))<EOL><DEDENT>key = headers.get('<STR_LIT>' % key_type)<EOL>if not key:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' %<EOL>(key_type.title(), key_type))<EOL><DEDENT>url = client.storage_url + '<STR_LIT:/>' + path<EOL>fp.write(generate_temp_url(method, url, seconds, key))<EOL>fp.write('<STR_LIT:\n>')<EOL>fp.flush()<EOL><DEDENT>

Generates a TempURL and sends that to the context.io_manager's
stdout.

See :py:mod:`swiftly.cli.tempurl` for context usage information.

See :py:class:`CLITempURL` for more information.

:param context: The :py:class:`swiftly.cli.context.CLIContext` to
    use.
:param method: The method for the TempURL (GET, PUT, etc.)
:param path: The path the TempURL should direct to.
:param seconds: The number of seconds the TempURL should be good
    for. Default: 3600
:param use_container: If True, will create a container level TempURL
    useing X-Container-Meta-Temp-Url-Key instead of
    X-Account-Meta-Temp-Url-Key.


context = CLIContext()<EOL>for item in dir(self):<EOL><INDENT>if item[<NUM_LIT:0>] != '<STR_LIT:_>' and item not in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>setattr(context, item, getattr(self, item))<EOL><DEDENT><DEDENT>return context<EOL>

Returns a new CLIContext instance that is a shallow copy of
the original, much like dict's copy method.


def write_headers(self, fp, headers, mute=None):

if headers:<EOL><INDENT>if not mute:<EOL><INDENT>mute = []<EOL><DEDENT>fmt = '<STR_LIT>' % (max(len(k) for k in headers) + <NUM_LIT:1>)<EOL>for key in sorted(headers):<EOL><INDENT>if key in mute:<EOL><INDENT>continue<EOL><DEDENT>fp.write(fmt % (key.title() + '<STR_LIT::>', headers[key]))<EOL><DEDENT>fp.flush()<EOL><DEDENT>

Convenience function to output headers in a formatted fashion
to a file-like fp, optionally muting any headers in the mute
list.


with context.io_manager.with_stdout() as stdout:<EOL><INDENT>with context.io_manager.with_stdin() as stdin:<EOL><INDENT>crypt_type = stdin.read(<NUM_LIT:1>)<EOL>if crypt_type == AES256CBC:<EOL><INDENT>for chunk in aes_decrypt(key, stdin):<EOL><INDENT>stdout.write(chunk)<EOL><DEDENT>stdout.flush()<EOL><DEDENT>else:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' % crypt_type)<EOL><DEDENT><DEDENT><DEDENT>

Decrypts context.io_manager's stdin and sends that to
context.io_manager's stdout.

See :py:mod:`swiftly.cli.decrypt` for context usage information.

See :py:class:`CLIDecrypt` for more information.


def _resolve_option(self, options, option_name, section_name):

if getattr(options, option_name, None) is not None:<EOL><INDENT>return<EOL><DEDENT>if option_name.startswith(section_name + '<STR_LIT:_>'):<EOL><INDENT>environ_name = option_name.upper()<EOL>conf_name = option_name[len(section_name) + <NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>environ_name = (section_name + '<STR_LIT:_>' + option_name).upper()<EOL>conf_name = option_name<EOL><DEDENT>setattr(<EOL>options, option_name,<EOL>os.environ.get(<EOL>environ_name,<EOL>(self.context.conf.get(section_name, {})).get(conf_name)))<EOL>

Resolves an option value into options.

        Sets options.<option_name> to a resolved value. Any value
        already in options overrides a value in os.environ which
        overrides self.context.conf.

        :param options: The options instance as returned by optparse.
        :param option_name: The name of the option, such as
            ``auth_url``.
        :param section_name: The name of the section, such as
            ``swiftly``.


limit = context.query.get('<STR_LIT>')<EOL>delimiter = context.query.get('<STR_LIT>')<EOL>prefix = context.query.get('<STR_LIT>')<EOL>marker = context.query.get('<STR_LIT>')<EOL>end_marker = context.query.get('<STR_LIT>')<EOL>if context.raw:<EOL><INDENT>with context.client_manager.with_client() as client:<EOL><INDENT>status, reason, headers, contents = client.get_account(<EOL>decode_json=False, headers=context.headers, limit=limit,<EOL>marker=marker, end_marker=end_marker, query=context.query,<EOL>cdn=context.cdn)<EOL>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents = contents.read()<EOL><DEDENT><DEDENT>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>raise ReturnCode('<STR_LIT>' % (status, reason))<EOL><DEDENT>with context.io_manager.with_stdout() as fp:<EOL><INDENT>if context.output_headers:<EOL><INDENT>context.write_headers(<EOL>fp, headers, context.muted_account_headers)<EOL><DEDENT>fp.write(contents)<EOL>fp.flush()<EOL><DEDENT>return<EOL><DEDENT>with context.client_manager.with_client() as client:<EOL><INDENT>status, reason, headers, contents = client.get_account(<EOL>headers=context.headers, limit=limit, marker=marker,<EOL>end_marker=end_marker, query=context.query, cdn=context.cdn)<EOL>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents.read()<EOL><DEDENT>raise ReturnCode('<STR_LIT>' % (status, reason))<EOL><DEDENT><DEDENT>if context.output_headers and not context.all_objects:<EOL><INDENT>with context.io_manager.with_stdout() as fp:<EOL><INDENT>context.write_headers(<EOL>fp, headers, context.muted_account_headers)<EOL><DEDENT><DEDENT>while contents:<EOL><INDENT>if context.all_objects:<EOL><INDENT>new_context = context.copy()<EOL>new_context.query = dict(new_context.query)<EOL>for remove in (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if remove in new_context.query:<EOL><INDENT>del new_context.query[remove]<EOL><DEDENT><DEDENT>for item in contents:<EOL><INDENT>if '<STR_LIT:name>' in item:<EOL><INDENT>new_path = item['<STR_LIT:name>'].encode('<STR_LIT:utf8>')<EOL>cli_get_container_listing(new_context, new_path)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>with context.io_manager.with_stdout() as fp:<EOL><INDENT>for item in contents:<EOL><INDENT>if context.full:<EOL><INDENT>fp.write('<STR_LIT>' % (<EOL>item.get('<STR_LIT>', '<STR_LIT:->'),<EOL>item.get('<STR_LIT:count>', '<STR_LIT:->')))<EOL><DEDENT>fp.write(item.get(<EOL>'<STR_LIT:name>', item.get('<STR_LIT>')))<EOL>fp.write('<STR_LIT:\n>')<EOL><DEDENT>fp.flush()<EOL><DEDENT><DEDENT>if limit:<EOL><INDENT>break<EOL><DEDENT>marker = contents[-<NUM_LIT:1>].get('<STR_LIT:name>', contents[-<NUM_LIT:1>].get('<STR_LIT>', '<STR_LIT>'))<EOL>with context.client_manager.with_client() as client:<EOL><INDENT>status, reason, headers, contents = client.get_account(<EOL>headers=context.headers, limit=limit, delimiter=delimiter,<EOL>prefix=prefix, end_marker=end_marker, marker=marker,<EOL>query=context.query, cdn=context.cdn)<EOL>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents.read()<EOL><DEDENT>raise ReturnCode('<STR_LIT>' % (status, reason))<EOL><DEDENT><DEDENT><DEDENT>

Performs a GET on the account as a listing request.

See :py:mod:`swiftly.cli.get` for context usage information.

See :py:class:`CLIGet` for more information.


path = path.strip('<STR_LIT:/>') if path else None<EOL>if not path or '<STR_LIT:/>' in path:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' %<EOL>path)<EOL><DEDENT>context.suppress_container_name = True<EOL>limit = context.query.get('<STR_LIT>')<EOL>delimiter = context.query.get('<STR_LIT>')<EOL>prefix = context.query.get('<STR_LIT>')<EOL>marker = context.query.get('<STR_LIT>')<EOL>end_marker = context.query.get('<STR_LIT>')<EOL>if context.raw:<EOL><INDENT>with context.client_manager.with_client() as client:<EOL><INDENT>status, reason, headers, contents = client.get_container(<EOL>path, decode_json=False, headers=context.headers, limit=limit,<EOL>marker=marker, end_marker=end_marker, query=context.query,<EOL>cdn=context.cdn)<EOL>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents = contents.read()<EOL><DEDENT><DEDENT>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (path, status, reason))<EOL><DEDENT>with context.io_manager.with_stdout() as fp:<EOL><INDENT>if context.output_headers:<EOL><INDENT>context.write_headers(<EOL>fp, headers, context.muted_container_headers)<EOL><DEDENT>fp.write(contents)<EOL>fp.flush()<EOL><DEDENT>return<EOL><DEDENT>with context.client_manager.with_client() as client:<EOL><INDENT>status, reason, headers, contents = client.get_container(<EOL>path, headers=context.headers, limit=limit, delimiter=delimiter,<EOL>prefix=prefix, marker=marker, end_marker=end_marker,<EOL>query=context.query, cdn=context.cdn)<EOL>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents.read()<EOL><DEDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (path, status, reason))<EOL><DEDENT><DEDENT>if context.output_headers and not context.all_objects:<EOL><INDENT>with context.io_manager.with_stdout() as fp:<EOL><INDENT>context.write_headers(<EOL>fp, headers, context.muted_container_headers)<EOL><DEDENT><DEDENT>conc = Concurrency(context.concurrency)<EOL>while contents:<EOL><INDENT>if context.all_objects:<EOL><INDENT>new_context = context.copy()<EOL>new_context.query = dict(new_context.query)<EOL>for remove in (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if remove in new_context.query:<EOL><INDENT>del new_context.query[remove]<EOL><DEDENT><DEDENT>for item in contents:<EOL><INDENT>if '<STR_LIT:name>' in item:<EOL><INDENT>for (exc_type, exc_value, exc_tb, result) insix.itervalues(conc.get_results()):<EOL><INDENT>if exc_value:<EOL><INDENT>conc.join()<EOL>raise exc_value<EOL><DEDENT><DEDENT>new_path = path + '<STR_LIT:/>' + item['<STR_LIT:name>'].encode('<STR_LIT:utf8>')<EOL>conc.spawn(new_path, cli_get, new_context, new_path)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>with context.io_manager.with_stdout() as fp:<EOL><INDENT>for item in contents:<EOL><INDENT>if context.full:<EOL><INDENT>fp.write('<STR_LIT>' % (<EOL>item.get('<STR_LIT>', '<STR_LIT:->'),<EOL>item.get('<STR_LIT>', '<STR_LIT:->')[:<NUM_LIT>].replace(<EOL>'<STR_LIT:T>', '<STR_LIT:U+0020>'),<EOL>item.get('<STR_LIT>', '<STR_LIT:->'),<EOL>item.get('<STR_LIT>', '<STR_LIT:->')))<EOL><DEDENT>fp.write(item.get(<EOL>'<STR_LIT:name>', item.get('<STR_LIT>')))<EOL>fp.write('<STR_LIT:\n>')<EOL><DEDENT>fp.flush()<EOL><DEDENT><DEDENT>if limit:<EOL><INDENT>break<EOL><DEDENT>marker = contents[-<NUM_LIT:1>].get('<STR_LIT:name>', contents[-<NUM_LIT:1>].get('<STR_LIT>', '<STR_LIT>'))<EOL>with context.client_manager.with_client() as client:<EOL><INDENT>status, reason, headers, contents = client.get_container(<EOL>path, headers=context.headers, limit=limit,<EOL>delimiter=delimiter, prefix=prefix, end_marker=end_marker,<EOL>marker=marker, query=context.query, cdn=context.cdn)<EOL>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents.read()<EOL><DEDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (path, status, reason))<EOL><DEDENT><DEDENT><DEDENT>conc.join()<EOL>for (exc_type, exc_value, exc_tb, result) insix.itervalues(conc.get_results()):<EOL><INDENT>if exc_value:<EOL><INDENT>raise exc_value<EOL><DEDENT><DEDENT>

Performs a GET on the container as a listing request.

See :py:mod:`swiftly.cli.get` for context usage information.

See :py:class:`CLIGet` for more information.


path = path.lstrip('<STR_LIT:/>') if path else None<EOL>if not path:<EOL><INDENT>return cli_get_account_listing(context)<EOL><DEDENT>elif '<STR_LIT:/>' not in path.rstrip('<STR_LIT:/>'):<EOL><INDENT>return cli_get_container_listing(context, path)<EOL><DEDENT>status, reason, headers, contents = <NUM_LIT:0>, '<STR_LIT>', {}, '<STR_LIT>'<EOL>with context.client_manager.with_client() as client:<EOL><INDENT>status, reason, headers, contents = client.get_object(<EOL>*path.split('<STR_LIT:/>', <NUM_LIT:1>), headers=context.headers, query=context.query,<EOL>cdn=context.cdn)<EOL>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents.read()<EOL><DEDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (path, status, reason))<EOL><DEDENT>if context.decrypt:<EOL><INDENT>crypt_type = contents.read(<NUM_LIT:1>)<EOL>if crypt_type == AES256CBC:<EOL><INDENT>contents = FileLikeIter(aes_decrypt(<EOL>context.decrypt, contents,<EOL>chunk_size=getattr(client, '<STR_LIT>', <NUM_LIT>)))<EOL><DEDENT>else:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (path, crypt_type))<EOL><DEDENT><DEDENT>def disk_closed_callback(disk_path):<EOL><INDENT>if context.remove_empty_files and not os.path.getsize(disk_path):<EOL><INDENT>os.unlink(disk_path)<EOL>if context.io_manager.stdout_root:<EOL><INDENT>dirname = os.path.dirname(disk_path)<EOL>while dirname and dirname.startswith(<EOL>context.io_manager.stdout_root):<EOL><INDENT>try:<EOL><INDENT>os.rmdir(dirname)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT>dirname = os.path.dirname(dirname)<EOL><DEDENT><DEDENT>return<EOL><DEDENT>if (headers.get('<STR_LIT>') in<EOL>['<STR_LIT>', '<STR_LIT>'] and<EOL>headers.get('<STR_LIT>') == '<STR_LIT:0>'):<EOL><INDENT>os.unlink(disk_path)<EOL>os.makedirs(disk_path)<EOL><DEDENT>mtime = <NUM_LIT:0><EOL>if '<STR_LIT>' in headers:<EOL><INDENT>mtime = float(headers['<STR_LIT>'])<EOL><DEDENT>elif '<STR_LIT>' in headers:<EOL><INDENT>mtime = time.mktime(time.strptime(<EOL>headers['<STR_LIT>'], '<STR_LIT>'))<EOL><DEDENT>if mtime:<EOL><INDENT>os.utime(disk_path, (mtime, mtime))<EOL><DEDENT><DEDENT>out_path = path<EOL>if context.suppress_container_name:<EOL><INDENT>out_path = out_path.split('<STR_LIT:/>', <NUM_LIT:1>)[<NUM_LIT:1>]<EOL><DEDENT>out_path = context.io_manager.client_path_to_os_path(out_path)<EOL>with context.io_manager.with_stdout(<EOL>out_path, disk_closed_callback=disk_closed_callback) as fp:<EOL><INDENT>if context.output_headers:<EOL><INDENT>context.write_headers(<EOL>fp, headers, context.muted_object_headers)<EOL>fp.write('<STR_LIT:\n>')<EOL><DEDENT>chunk = contents.read(<NUM_LIT>)<EOL>while chunk:<EOL><INDENT>fp.write(chunk)<EOL>chunk = contents.read(<NUM_LIT>)<EOL><DEDENT>fp.flush()<EOL><DEDENT><DEDENT>

Performs a GET on the item (account, container, or object).

See :py:mod:`swiftly.cli.get` for context usage information.

See :py:class:`CLIGet` for more information.


with context.io_manager.with_stdout() as stdout:<EOL><INDENT>with context.io_manager.with_stdin() as stdin:<EOL><INDENT>for chunk in aes_encrypt(key, stdin, preamble=AES256CBC):<EOL><INDENT>stdout.write(chunk)<EOL><DEDENT>stdout.flush()<EOL><DEDENT><DEDENT>

Encrypts context.io_manager's stdin and sends that to
context.io_manager's stdout.

This can be useful to encrypt to disk before attempting to
upload, allowing uploads retries and segmented encrypted objects.

See :py:mod:`swiftly.cli.encrypt` for context usage information.

See :py:class:`CLIEncrypt` for more information.


with context.io_manager.with_stdout() as fp:<EOL><INDENT>with context.client_manager.with_client() as client:<EOL><INDENT>info = []<EOL>client.auth()<EOL>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.auth_cache_path))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.auth_url))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.auth_user))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.auth_key))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.auth_tenant))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.auth_methods))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.storage_path))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.cdn_path))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.local_path))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', '<STR_LIT:U+0020>'.join(client.regions)))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.default_region))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.region))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.snet))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.storage_url))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.cdn_url))<EOL><DEDENT>if getattr(client, '<STR_LIT>', None):<EOL><INDENT>info.append(('<STR_LIT>', client.auth_token))<EOL><DEDENT>if not info:<EOL><INDENT>info.append((<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'))<EOL><DEDENT>fmt = '<STR_LIT>' % (max(len(t) for t, v in info) + <NUM_LIT:1>)<EOL>for t, v in info:<EOL><INDENT>fp.write(fmt % (t + '<STR_LIT::>', v))<EOL><DEDENT>fp.flush()<EOL><DEDENT><DEDENT>

Authenticates and then outputs the resulting information.

See :py:mod:`swiftly.cli.auth` for context usage information.

See :py:class:`CLIAuth` for more information.


def cli_help(context, command_name, general_parser, command_parsers):

if command_name == '<STR_LIT>':<EOL><INDENT>command_name = '<STR_LIT>'<EOL><DEDENT>with context.io_manager.with_stdout() as stdout:<EOL><INDENT>if not command_name:<EOL><INDENT>general_parser.print_help(stdout)<EOL><DEDENT>elif command_name in command_parsers:<EOL><INDENT>command_parsers[command_name].option_parser.print_help(stdout)<EOL><DEDENT>else:<EOL><INDENT>raise ReturnCode('<STR_LIT>' % command_name)<EOL><DEDENT><DEDENT>

Outputs help information.

See :py:mod:`swiftly.cli.help` for context usage information.

See :py:class:`CLIHelp` for more information.

:param context: The :py:class:`swiftly.cli.context.CLIContext` to
    use.
:param command_name: The command_name to output help information
    for, or set to None or an empty string to output the general
    help information.
:param general_parser: The
    :py:class:`swiftly.cli.optionparser.OptionParser` for general
    usage.
:param command_parsers: A dict of (name, :py:class:`CLICommand`)
    for specific command usage.


path = path.lstrip('<STR_LIT:/>') if path else None<EOL>with context.client_manager.with_client() as client:<EOL><INDENT>if not path:<EOL><INDENT>status, reason, headers, contents = client.head_account(<EOL>headers=context.headers, query=context.query, cdn=context.cdn)<EOL>mute = context.muted_account_headers<EOL><DEDENT>elif '<STR_LIT:/>' not in path.rstrip('<STR_LIT:/>'):<EOL><INDENT>path = path.rstrip('<STR_LIT:/>')<EOL>status, reason, headers, contents = client.head_container(<EOL>path, headers=context.headers, query=context.query,<EOL>cdn=context.cdn)<EOL>mute = context.muted_container_headers<EOL><DEDENT>else:<EOL><INDENT>status, reason, headers, contents = client.head_object(<EOL>*path.split('<STR_LIT:/>', <NUM_LIT:1>), headers=context.headers,<EOL>query=context.query, cdn=context.cdn)<EOL>mute = context.muted_object_headers<EOL><DEDENT>if hasattr(contents, '<STR_LIT>'):<EOL><INDENT>contents = contents.read()<EOL><DEDENT><DEDENT>if status // <NUM_LIT:100> != <NUM_LIT:2>:<EOL><INDENT>if status == <NUM_LIT> and context.ignore_404:<EOL><INDENT>return<EOL><DEDENT>if not path:<EOL><INDENT>raise ReturnCode('<STR_LIT>' % (status, reason))<EOL><DEDENT>elif '<STR_LIT:/>' not in path:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (path, status, reason))<EOL><DEDENT>else:<EOL><INDENT>raise ReturnCode(<EOL>'<STR_LIT>' % (path, status, reason))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with context.io_manager.with_stdout() as fp:<EOL><INDENT>context.write_headers(fp, headers, mute)<EOL><DEDENT><DEDENT>

Performs a HEAD on the item (account, container, or object).

See :py:mod:`swiftly.cli.head` for context usage information.

See :py:class:`CLIHead` for more information.