�
'f�� � � � d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlmZ ddlmZ ej* d� Zdad� ZdBd �ZdCd
�ZdBd�ZdDd�Zd
� Zd� Zd� Zd� Z d� Z!d� Z"d� Z#d� Z$de
jJ ddfd�Z&d� Z'd� Z(d� Z)de
jJ dfd�Z*d� Z+d� Z,dEdd�d�Z-dEd�Z.dZ/d Z0d!Z1d"Z2d#Z3d$Z4d%Z5d&Z6d'Z7d(Z8d)Z9d*Z:d+� Z;d,� Z<dEd-�Z=d.� Z>d/� Z?d0� Z@dFd1ed2eAd3dfd4�ZBd5� ZCd6� ZDd7� ZEdEd8�ZFd9� ZGd:� ZHd;� ZIdGd<�ZJd=� ZKd>� ZLd?� ZMdEd@�ZNdA� ZOej� j� ZQej� j� ZRy)Hz/Convenience functions for use in package hooks.� N)�impl)�
ProblemReportz[^0-9a-zA-Z_.-]c � � t | t � r| j d� } t j d| j dd� � S )z{Generate a valid report key name from a file path.
This will replace invalid punctuation symbols with valid ones.
�UTF-8�.� �_)�
isinstance�bytes�decode�_invalid_key_chars_re�sub�replace)�paths �2/usr/lib/python3/dist-packages/apport/hookutils.py�path_to_keyr ) s: � �
�$����{�{�7�#�� �$�$�S�$�,�,�s�C�*@�A�A� TFc � � d|v ry|st |� }t j j |� rt | ||||� yy)a� Attach file contents if file exists.
If key is not specified, the key name will be derived from the file
name with path_to_key().
If overwrite is True, an existing key will be updated. If it is False, a
new key with '_' appended will be added instead.
If the contents is valid UTF-8, or force_unicode is True, then the value
will be a string, otherwise it will be bytes.
�../N)r �osr �exists�attach_file��reportr �key� overwrite�
force_unicodes r �attach_file_if_existsr 3 s@ � �
��}����$��� �w�w�~�~�d���F�D�#�y�-�@� r c �F � d| v ryt j | t j t j z t j z � }t j
|� }t j j | � }|j t j |� j k7 s| |k7 rt j |� yt j |j � r>t j |d� 5 }|j � j � }ddd� nt j |� y|rj! dd� � S j! d� S # 1 sw Y �0xY w# t" |