3 �ga� � @ s� d dl Z d dlZd dlmZ d dlmZ ddlmZ ddlm Z ddl mZ dZd Z d Zed�Zed�Zeejjd ��e Zed�dd�Ze� ZG dd� de�ZG dd� de�ZG dd� de�ZdS )� N)�Path)�Union� )�__version__)� is_windows)�UTF8ZXDG_CONFIG_HOMEZHTTPIE_CONFIG_DIR�httpiez.configz.httpiez %APPDATA%)�returnc C sZ t jjt�} | rt| �S tr tS tj� }|t }|j � r<|S t jjt |t �}t|�t S )a� Return the path to the httpie configuration directory. This directory isn't guaranteed to exist, and nor are any of its ancestors (only the legacy ~/.httpie, if returned, is guaranteed to exist). XDG Base Directory Specification support: <https://wiki.archlinux.org/index.php/XDG_Base_Directory> $XDG_CONFIG_HOME is supported; $XDG_CONFIG_DIRS is not ) �os�environ�get�ENV_HTTPIE_CONFIG_DIRr r �DEFAULT_WINDOWS_CONFIG_DIR�home�"DEFAULT_RELATIVE_LEGACY_CONFIG_DIR�exists�ENV_XDG_CONFIG_HOME� DEFAULT_RELATIVE_XDG_CONFIG_HOME�DEFAULT_CONFIG_DIRNAME)Zenv_config_dirZhome_dirZlegacy_config_dirZxdg_config_home_dir� r �/usr/lib/python3.6/config.py�get_default_config_dir s r c @ s e Zd ZdS )�ConfigFileErrorN)�__name__� __module__�__qualname__r r r r r = s r c sT e Zd ZdZdZdZed�� fdd�Zdd� Ze d�dd �Z d d� Zdd � Z� Z S )�BaseConfigDictN)�pathc s t � j� || _d S )N)�super�__init__r )�selfr )� __class__r r r F s zBaseConfigDict.__init__c C s | j jjdddd� d S )Ni� T)�mode�parents�exist_ok)r �parent�mkdir)r r r r �ensure_directoryJ s zBaseConfigDict.ensure_directory)r c C s | j j� S )N)r r )r r r r �is_newM s zBaseConfigDict.is_newc ! C s� t | �jj� }yx| jjtd��`}ytj|�}W n@ tk rn } z$t d|� d|� d| j� d���W Y d d }~X nX | j |� W d Q R X W nH tk r� Y n6 tk r� } zt d|� d|� ���W Y d d }~X nX d S )N)�encodingzinvalid z file: z [�]zcannot read ) �typer �lowerr �openr �json�load� ValueErrorr �update�FileNotFoundError�OSError)r Zconfig_type�f�data�er r r r/ P s .zBaseConfigDict.loadc C sf dt i| d<