File: //usr/lib/python3/dist-packages/debian/__pycache__/copyright.cpython-310.pyc
o
���a�` � @ s� d Z ddlZddlZddlZddlZddlZz&ddlmZmZm Z m
Z
mZmZm
Z
mZmZmZmZmZ ed Zed ZW n eyG dZY nw ddlmZ dZeeg�Ze�e�ZG d d
� d
e�ZG dd� de�Z G d
d� dee!�Z"dd� Z#G dd� de$�Z%dd� Z&G dd� de$�Z'G dd� de$�Z(dd� Z)dd� Z*dd� Z+dd � Z,G d!d"� d"e�-d"d#��Z.d$d%� Z/G d&d'� d'ej0�Z1G d(d)� d)ej0�Z2G d*d+� d+ej0�Z3dS ),a9 Utilities for parsing and creating machine-readable debian/copyright files.
The specification for the format (also known as DEP5) is available here:
https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Start from the Copyright docstring for usage information.
Copyright Classes
-----------------
� N)�Any�Callable�IO�Iterable�Iterator�List�Optional�Pattern�Text�Tuple�Union�
TYPE_CHECKING)�FilesParagraph�LicenseParagraph)�Headerr r F)�deb822zBhttps://www.debian.org/doc/packaging-manuals/copyright-format/1.0/c @ � e Zd ZdZdS )�Errorz)Base class for exceptions in this module.N��__name__�
__module__�__qualname__�__doc__� r r �2/usr/lib/python3/dist-packages/debian/copyright.pyr G � r c @ r )�NotMachineReadableErrorzFRaised when the input is not a machine-readable debian/copyright file.Nr r r r r r K r r c @ r )�MachineReadableFormatErrorz�Raised when the input is not valid.
This is both a `copyright.Error` and a `ValueError` to ease handling of
errors coming from this module.
Nr r r r r r O r r c C s |rt | ��t�| � d S �N)r �logger�warning)�msg�strictr r r � _complainW s r# c s~ e Zd ZdZd� fdd� Zedd� �Zejd d� �Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� Z
dd� Zddd�Z� ZS )� Copyrighta� Represents a debian/copyright file.
A Copyright object contains a Header paragraph and a list of additional
Files or License paragraphs. It provides methods to iterate over those
paragraphs, in addition to adding new ones. It also provides a mechanism
for finding the Files paragraph (if any) that matches a particular
filename.
Typical usage::
with io.open('debian/copyright', 'rt', encoding='utf-8') as f:
c = copyright.Copyright(f)
header = c.header
# Header exposes standard fields, e.g.
print('Upstream name: ', header.upstream_name)
lic = header.license
if lic:
print('Overall license: ', lic.synopsis)
# You can also retrieve and set custom fields.
header['My-Special-Field'] = 'Very special'
# Find the license for a given file.
paragraph = c.find_files_paragraph('debian/rules')
if paragraph:
print('License for debian/rules: ', paragraph.license)
# Dump the result, including changes, to another file.
with io.open('debian/copyright.new', 'wt', encoding='utf-8') as f:
c.dump(f=f)
It is possible to build up a Copyright from scratch, by modifying the
header and using add_files_paragraph and add_license_paragraph. See the
associated method docstrings.
N�utf-8Tc s� t t| ��� g | _|durZttjj||d��}|std��t |d �| _
tdt|��D ]+}|| }d|v rBt
||�}| j�|� q,d|v rRt||�}| j�|� q,td|� q,dS t � | _
dS ) a� Create a new copyright file in the current format.
:param sequence: Sequence of lines, e.g. a list of strings or a
file-like object. If not specified, a blank Copyright object is
initialized.
:param encoding: Encoding to use, in case input is raw byte strings.
It is recommended to use unicode objects everywhere instead, e.g.
by opening files in text mode.
:param strict: Raise if format errors are detected in the data.
Raises:
:class:`NotMachineReadableError` if 'sequence' does not contain a
machine-readable debian/copyright file.
MachineReadableFormatError if 'sequence' is not a valid file.
N)�sequence�encodingzno paragraphs in inputr � �Files�Licensez=Non-header paragraph has neither "Files" nor "License" fields)�superr$ �__init__�_Copyright__paragraphs�listr �Deb822�iter_paragraphsr r �_Copyright__header�range�lenr �appendr r# ) �selfr&