Current File : //proc/self/root/usr/lib/python3/dist-packages/debian/substvars.py
""" Facilities for reading and writing Debian substvars files

The aim of this module is to provide programmatic access to Debian substvars
files to query and manipulate them. The format for the changelog is defined in
`deb-substvars(5)
<https://manpages.debian.org/stretch/dpkg-dev/deb-substvars.5.html>`_

Overview
========

The most common use-case for substvars is for package helpers to add or update
a substvars (e.g., to add a dependency).  This would look something like:

    >>> from debian.substvars import Substvars
    >>> from tempfile import TemporaryDirectory
    >>> import os
    >>> # Using a tmp dir for the sake of doctests
    >>> with TemporaryDirectory() as debian_dir:
    ...    filename = os.path.join(debian_dir, "foo.substvars")
    ...    with Substvars.load_from_path(filename, missing_ok=True) as svars:
    ...        svars.add_dependency("misc:Depends", "bar (>= 1.0)")

By default, the module creates new substvars as "mandatory" substvars (that
triggers a warning by dpkg-gecontrol if not used.  However, it does also
support the "optional" substvars introduced in dpkg 1.21.8.  See
`Substvars.as_substvars` for an example of how to use the "optional"
substvars.


The :class:`Substvars` class is the key class within this module.

Substvars Classes
-----------------
"""


import contextlib
import errno
import re
import sys
import typing
from abc import ABC
from collections import OrderedDict
from collections.abc import MutableMapping
from types import TracebackType
from typing import Dict, Set, Optional, Union, Iterator, IO, Iterable, TYPE_CHECKING, Type

try:
    from os import PathLike
    AnyPath = Union[PathLike, str, bytes]
except ImportError:
    pass

T = typing.TypeVar('T')

_SUBSTVAR_PATTERN = re.compile(
    r"^(?P<name>\w[-:\dA-Za-z]*)(?P<assignment_type>[?]?=)(?P<value>.*)$"
)


class Substvar:

    __slots__ = ['_assignment_operator', '_value']

    def __init__(self, initial_value="",  # type: str
                 assignment_operator='=',  # type: str
                 ):
        # type: (...) -> None

        # We have 2 values for _value:
        # 1) string: The variable is set to a fixed string.  This variant is
        #    round-trip safe.
        # 2) set: The variable is dependency-like field.  This variant is *NOT*
        #    round-trip safe.
        #
        # When reading substvars from files, we always use variant 1) and then
        # lazily convert to 2) when necessary.  This choice makes the substvars
        # round-trip safe by default until someone messes with a substvar.
        self._value = initial_value   # type: Union[str, Set[str]]
        self.assignment_operator = assignment_operator  # type: str

    @property
    def assignment_operator(self):
        # type: () -> str
        return self._assignment_operator

    @assignment_operator.setter
    def assignment_operator(self, new_operator):
        # type: (str) -> None
        if new_operator not in {'=', '?='}:
            raise ValueError('Operator must be one of: "=", or "?=" - got: ' + new_operator)
        self._assignment_operator = new_operator

    def add_dependency(self, dependency_clause):
        # type: (str) -> None
        if self._value == "":
            self._value = {dependency_clause}
            return
        if isinstance(self._value, str):
            # Convert to dependency format
            self._value = {v.strip() for v in self._value.split(',')}
        self._value.add(dependency_clause)

    def resolve(self):
        # type: () -> str
        if isinstance(self._value, set):
            return ", ".join(sorted(self._value))
        return self._value

    def __eq__(self, other):
        # type: (object) -> bool
        if other is None or not isinstance(other, Substvar):
            return False
        if self.assignment_operator != other.assignment_operator:
            return False
        return self.resolve() == other.resolve()


if sys.version_info >= (3, 9) or TYPE_CHECKING:
    class _Substvars_Base(contextlib.AbstractContextManager[T], MutableMapping[str, str], ABC):
        pass
else:
    # Python 3.5 - 3.8 compat - we are not allowed to subscript the abc.MutableMapping
    # - use this little hack to work around it
    # Note that Python 3.5 is so old that it does not have AbstractContextManager,
    # so we re-implement it here as well.
    class _Substvars_Base(typing.Generic[T], MutableMapping, ABC):

        def __enter__(self):
            return self

        def __exit__(self, exc_type, exc_val, exc_tb):
            return None


class Substvars(_Substvars_Base['Substvars']):
    """Substvars is a dict-like object containing known substvars for a given package.

    >>> substvars = Substvars()
    >>> substvars['foo'] = 'bar, golf'
    >>> substvars['foo']
    'bar, golf'
    >>> substvars.add_dependency('foo', 'dpkg (>= 1.20.0)')
    >>> substvars['foo']
    'bar, dpkg (>= 1.20.0), golf'
    >>> 'foo' in substvars
    True
    >>> sorted(substvars)
    ['foo']
    >>> del substvars['foo']
    >>> substvars['foo']
    Traceback (most recent call last):
        ...
    KeyError: 'foo'
    >>> substvars.get('foo')
    >>> # None
    >>> substvars['foo'] = ""
    >>> substvars['foo']
    ''

    The Substvars object also provide methods for serializing and deserializing
    the substvars into and from the format used by dpkg-gencontrol.

    The Substvars object can be used as a context manager, which causes the substvars
    to be saved when the context manager exits successfully (i.e., no exceptions are raised).
    """

    __slots__ = ['_vars_dict', '_substvars_path']

    def __init__(self):
        # type: () -> None
        self._vars_dict = OrderedDict()  # type: Dict[str, Substvar]
        self._substvars_path = None  # type: Optional[AnyPath]

    @classmethod
    def load_from_path(cls, substvars_path, missing_ok=False):
        # type: (AnyPath, bool) -> Substvars
        """Shorthand for initializing a Substvars from a file

        The return substvars will have `substvars_path` set to the provided path enabling
        `save()` to work out of the box. This also makes it easy to combine this with the
        context manager interface to automatically save the file again.

        >>> import os
        >>> from tempfile import TemporaryDirectory
        >>> with TemporaryDirectory() as tmpdir:
        ...    filename = os.path.join(tmpdir, "foo.substvars")
        ...    # Obviously, this does not exist
        ...    print("Exists before: " + str(os.path.exists(filename)))
        ...    with Substvars.load_from_path(filename, missing_ok=True) as svars:
        ...        svars.add_dependency("misc:Depends", "bar (>= 1.0)")
        ...    print("Exists after: " + str(os.path.exists(filename)))
        Exists before: False
        Exists after: True

        :param substvars_path: The path to load from
        :param missing_ok: If True, then the path does not have to exist (i.e.
          FileNotFoundError causes an empty Substvars object to be returned).  Combined
          with the context manager, this is useful for packaging helpers that want to
          append / update to the existing if it exists or create it if it does not exist.
        """
        substvars = cls()
        try:
            with open(substvars_path, 'r', encoding='utf-8') as fd:
                substvars.read_substvars(fd)
        except OSError as e:
            if e.errno != errno.ENOENT or not missing_ok:
                raise
        substvars.substvars_path = substvars_path
        return substvars

    @property
    def _vars(self):
        # type: () -> Dict[str, Substvar]
        # Indirection to support subclasses that want to provide lazy loading or other "fun stuff"
        return self._vars_dict

    @_vars.setter
    def _vars(self, vars_dict):
        # type: (Dict[str, Substvar]) -> None
        # Indirection to support subclasses that want to provide lazy loading or other "fun stuff"
        self._vars_dict = vars_dict

    @property
    def substvars_path(self):
        # type: () -> Optional[AnyPath]
        return self._substvars_path

    @substvars_path.setter
    def substvars_path(self, new_path):
        # type: (Optional[AnyPath]) -> None
        self._substvars_path = new_path

    def add_dependency(self, substvar, dependency_clause):
        # type: (str, str) -> None
        """Add a dependency clause to a given substvar

        >>> substvars = Substvars()
        >>> # add_dependency automatically creates variables
        >>> 'misc:Recommends' not in substvars
        True
        >>> substvars.add_dependency('misc:Recommends', "foo (>= 1.0)")
        >>> substvars['misc:Recommends']
        'foo (>= 1.0)'
        >>> # It can be appended to other variables
        >>> substvars['foo'] = 'bar, golf'
        >>> substvars.add_dependency('foo', 'dpkg (>= 1.20.0)')
        >>> substvars['foo']
        'bar, dpkg (>= 1.20.0), golf'
        >>> # Exact duplicates are ignored
        >>> substvars.add_dependency('foo', 'dpkg (>= 1.20.0)')
        >>> substvars['foo']
        'bar, dpkg (>= 1.20.0), golf'

        """
        try:
            variable = self._vars[substvar]
        except KeyError:
            variable = Substvar()
            self._vars[substvar] = variable
        variable.add_dependency(dependency_clause)

    def __exit__(self,
                 exc_type,  # type: Optional[Type[BaseException]]
                 exc_val,  # type: Optional[BaseException]
                 exc_tb,  # type: Optional[TracebackType]
                 ):
        # type: (...) -> Optional[bool]
        if exc_type is None:
            self.save()
        return super().__exit__(exc_type, exc_val, exc_tb)

    def __iter__(self):
        # type: () -> Iterator[str]
        return iter(self._vars)

    def __len__(self) -> int:
        return len(self._vars_dict)

    def __contains__(self, item):
        # type: (object) -> bool
        return item in self._vars

    def __getitem__(self, key):
        # type: (str) -> str
        return self._vars[key].resolve()

    def __delitem__(self, key):
        # type: (str) -> None
        del self._vars[key]

    def __setitem__(self, key, value):
        # type: (str, str) -> None
        self._vars[key] = Substvar(value)

    @property
    def as_substvar(self):
        # type: () -> MutableMapping[str, Substvar]
        """Provides a mapping to the Substvars object for more advanced operations

        Treating a substvars file mostly as a "str -> str" mapping is sufficient for many cases.
        But when full control over the substvars (like fiddling with the assignment operator) is
        needed this attribute is useful.

        >>> content = '''
        ... # Some comment (which is allowed but no one uses them - also, they are not preserved)
        ... shlib:Depends=foo (>= 1.0), libbar2 (>= 2.1-3~)
        ... random:substvar?=With the new assignment operator from dpkg 1.21.8
        ... '''
        >>> substvars = Substvars()
        >>> substvars.read_substvars(content.splitlines())
        >>> substvars.as_substvar["shlib:Depends"].assignment_operator
        '='
        >>> substvars.as_substvar["random:substvar"].assignment_operator
        '?='
        >>> # Mutation is also possible
        >>> substvars.as_substvar["shlib:Depends"].assignment_operator = '?='
        >>> print(substvars.dump(), end="")
        shlib:Depends?=foo (>= 1.0), libbar2 (>= 2.1-3~)
        random:substvar?=With the new assignment operator from dpkg 1.21.8
        """
        # This is an indirection of `_vars` to avoid exposing the `_vars` setter
        return self._vars

    def __eq__(self, other):
        # type: (object) -> bool
        if other is None or not isinstance(other, Substvars):
            return False
        return self._vars == other._vars

    def dump(self):
        # type: () -> str
        """Debug aid that generates a string representation of the content

        For persisting the contents, please consider `save()` or `write_substvars`.
        """
        return "".join("{}{}{}\n".format(k, v.assignment_operator, v.resolve())
                       for k, v in self._vars.items()
                       )

    def save(self):
        # type: () -> None
        """Save the substvars file

        Replace the path denoted by the `substvars_path` attribute with the
        in-memory version of the substvars.  Note that the `substvars_path`
        property must be not None for this method to work.
        """
        if self._substvars_path is None:
            raise TypeError("The substvar does not have a substvars_path: Please"
                            " set substvars_path first or use write_substvars")

        with open(self._substvars_path, 'w', encoding='utf-8') as fd:
            return self.write_substvars(fd)

    def write_substvars(self, fileobj):
        # type: (IO[str]) -> None
        """Write a copy of the substvars to an open text file

        :param fileobj: The open file (should open in text mode using the UTF-8 encoding)
        """
        fileobj.writelines("{}{}{}\n".format(k, v.assignment_operator, v.resolve())
                           for k, v in self._vars.items()
                           )

    def read_substvars(self, fileobj):
        # type: (Iterable[str]) -> None
        """Read substvars from an open text file in the format supported by dpkg-gencontrol

        On success, all existing variables will be discarded and only variables
        from the file will be present after this method completes.  In case of
        any IO related errors, the object retains its state prior to the call
        of this method.

        >>> content = '''
        ... # Some comment (which is allowed but no one uses them - also, they are not preserved)
        ... shlib:Depends=foo (>= 1.0), libbar2 (>= 2.1-3~)
        ... random:substvar?=With the new assignment operator from dpkg 1.21.8
        ... '''
        >>> substvars = Substvars()
        >>> substvars.read_substvars(content.splitlines())
        >>> substvars["shlib:Depends"]
        'foo (>= 1.0), libbar2 (>= 2.1-3~)'
        >>> substvars["random:substvar"]
        'With the new assignment operator from dpkg 1.21.8'

        :param fileobj: An open file (in text mode using the UTF-8 encoding) or an
          iterable of str that provides line by line content.
        """
        vars_dict = OrderedDict()
        for line in fileobj:
            if line.strip() == '' or line[0] == '#':
                continue
            m = _SUBSTVAR_PATTERN.match(line.rstrip("\r\n"))
            if not m:
                continue
            varname, assignment_operator, value = m.groups()
            vars_dict[varname] = Substvar(value, assignment_operator=assignment_operator)
        self._vars = vars_dict
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!