← Back
Editing: copyright.cpython-38.pyc
U &]�^B` � @ s� d Z ddlmZ ddlZddlZddlZddlZddlZz4ddlm Z m Z mZmZm Z mZmZmZmZmZ W n ek r� Y nX ddlmZ dZeeg�ZG dd� de�ZG d d � d e�ZG dd� dee�Zd d� ZG dd� de�Z dd� Z!G dd� de�Z"G dd� de�Z#dd� Z$dd� Z%dd� Z&dd� Z'G dd � d e�(d d!��Z)d"d#� Z*G d$d%� d%ej+�Z,G d&d'� d'ej+�Z-G d(d)� d)ej+�Z.zee,e-f Z/ee.e,e-f Z0W n e1k �r� Y nX dS )*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 ----------------- � )�unicode_literalsN) �Any�IO�Iterable�Iterator�List�Optional�Pattern�Text�Tuple�Union)�deb822zBhttps://www.debian.org/doc/packaging-manuals/copyright-format/1.0/c @ s 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 A s r c @ s e Zd ZdZdS )�NotMachineReadableErrorzFRaised when the input is not a machine-readable debian/copyright file.Nr r r r r r E s r c @ s e Zd ZdZdS )�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 I s r c C s |rt | ��t�| � d S �N)r �warnings�warn)�msg�strictr r r � _complainQ 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 retrive 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 | _|dk r�ttjj||d��}|s<td��t |d �| _ tdt|��D ]V}|| }d|kr�t ||�}| j�|� qXd|kr�t||�}| j�|� qXtd|� qXnt � | _ 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 �Deb822Ziter_paragraphsr �Header�_Copyright__header�range�len�FilesParagraph�append�LicenseParagraphr ) �selfr r! r Z paragraphs�i�pZpfZpl�� __class__r r r&