Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib64/python3.9/site-packages/mercurial/__pycache__/ |
Upload File : |
a �+�bZi � @ s d Z ddlmZmZ ddlZddlZddlZddlmZ ddl m Z mZ ddlm Z ddlmZmZmZmZmZmZmZ dd lmZmZmZ ejZd d� ZG dd � d e�ZG dd� de�Zdd� ZG dd� de�Z dd� Z!G dd� de�Z"G dd� de�Z#G dd� de�Z$G dd� de�Z%G dd� de�Z&G d d!� d!e�Z'G d"d#� d#e�Z(G d$d%� d%e�Z)e j*d&d'�G d(d)� d)e��Z+d*d+� Z,dGd,d-�Z-d.d/� Z.dHd0d1�Z/d2d3� Z0d4d5� Z1dId6d7�Z2dJd8d9�Z3e� Z4G d:d;� d;ej5�Z6dKd=d>�Z7d?d@� Z8ej9dAdB� �Z:ej9dCdD� �Z;dEdF� Z<dS )La~ Generic output formatting for Mercurial The formatter provides API to show data in various ways. The following functions should be used in place of ui.write(): - fm.write() for unconditional output - fm.condwrite() to show some extra data conditionally in plain output - fm.context() to provide changectx to template output - fm.data() to provide extra data to JSON or template output - fm.plain() to show raw text that isn't provided to JSON or template output To show structured data (e.g. date tuples, dicts, lists), apply fm.format*() beforehand so the data is converted to the appropriate data type. Use fm.isplain() if you need to convert or format data conditionally which isn't supported by the formatter API. To build nested structure (i.e. a list of dicts), use fm.nested(). See also https://www.mercurial-scm.org/wiki/GenericTemplatingPlan fm.condwrite() vs 'if cond:': In most cases, use fm.condwrite() so users can selectively show the data in template output. If it's costly to build data, use plain 'if cond:' with fm.write(). fm.nested() vs fm.formatdict() (or fm.formatlist()): fm.nested() should be used to form a tree structure (a list of dicts of lists of dicts...) which can be accessed through template keywords, e.g. "{foo % "{bar % {...}} {baz % {...}}"}". On the other hand, fm.formatdict() exports a dict-type object to template, which can be accessed by e.g. "{get(foo, key)}" function. Doctest helper: >>> def show(fn, verbose=False, **opts): ... import sys ... from . import ui as uimod ... ui = uimod.ui() ... ui.verbose = verbose ... ui.pushbuffer() ... try: ... return fn(ui, ui.formatter(pycompat.sysbytes(fn.__name__), ... pycompat.byteskwargs(opts))) ... finally: ... print(pycompat.sysstr(ui.popbuffer()), end='') Basic example: >>> def files(ui, fm): ... files = [(b'foo', 123, (0, 0)), (b'bar', 456, (1, 0))] ... for f in files: ... fm.startitem() ... fm.write(b'path', b'%s', f[0]) ... fm.condwrite(ui.verbose, b'date', b' %s', ... fm.formatdate(f[2], b'%Y-%m-%d %H:%M:%S')) ... fm.data(size=f[1]) ... fm.plain(b'\n') ... fm.end() >>> show(files) foo bar >>> show(files, verbose=True) foo 1970-01-01 00:00:00 bar 1970-01-01 00:00:01 >>> show(files, template=b'json') [ { "date": [0, 0], "path": "foo", "size": 123 }, { "date": [1, 0], "path": "bar", "size": 456 } ] >>> show(files, template=b'path: {path}\ndate: {date|rfc3339date}\n') path: foo date: 1970-01-01T00:00:00+00:00 path: bar date: 1970-01-01T00:00:01+00:00 Nested example: >>> def subrepos(ui, fm): ... fm.startitem() ... fm.write(b'reponame', b'[%s]\n', b'baz') ... files(ui, fm.nested(b'files', tmpl=b'{reponame}')) ... fm.end() >>> show(subrepos) [baz] foo bar >>> show(subrepos, template=b'{reponame}: {join(files % "{path}", ", ")}\n') baz: foo, bar � )�absolute_import�print_functionN� )�_)�hex�short)�attr)�error�pycompat�templatefilters� templatekw� templater�templateutil�util)�cborutil�dateutil� stringutilc C s t | td�tttjttf�S )z�Check if the given object can be directly passed in to formatter's write() and data() functions Returns False if the object is unsupported or must be pre-processed by formatdate(), formatdict(), or formatlist(). N)� isinstance�type�bool�intr Zlong�float�bytes)�obj� r �9/usr/lib64/python3.9/site-packages/mercurial/formatter.py�isprintable� s r c @ sD e Zd ZdZdZedd� �Zedd� �Zedd� �Zed d � �Z dS )�_nullconverterz=convert non-primitive data types to be processed by formatterFc C s | S )z$wrap nested data by appropriate typer ��data�tmpl�sepr r r � wrapnested� s z_nullconverter.wrapnestedc C s | \}}t |�|fS �z(convert date tuple to appropriate format)r )�date�fmt�tsZtzr r r � formatdate� s z_nullconverter.formatdatec C s t | �S �z:convert dict or key-value pairs to appropriate dict format)�dict�r �key�valuer% r! r r r � formatdict� s z_nullconverter.formatdictc C s t | �S �z+convert iterable to appropriate list format)�list�r �namer% r! r r r � formatlist� s z_nullconverter.formatlistN� �__name__� __module__�__qualname__�__doc__�storecontext�staticmethodr"