Current File : //usr/share/gdb/python/gdb/printing.pyc
�
�� Rc@s�dZddlZddlZddlZddlZejddkrXeZeZ	nde
fd��YZde
fd��YZe
d	�Zd
efd��YZddd
��YZdefd��YZdS(s+Utilities for working with pretty-printers.i����Niit
PrettyPrintercBs#eZdZdd�Zd�ZRS(sA basic pretty-printer.

    Attributes:
        name: A unique string among all printers for the context in which
            it is defined (objfile, progspace, or global(gdb)), and should
            meaningfully describe what can be pretty-printed.
            E.g., "StringPiece" or "protobufs".
        subprinters: An iterable object with each element having a `name'
            attribute, and, potentially, "enabled" attribute.
            Or this is None if there are no subprinters.
        enabled: A boolean indicating if the printer is enabled.

    Subprinters are for situations where "one" pretty-printer is actually a
    collection of several printers.  E.g., The libstdc++ pretty-printer has
    a pretty-printer for each of several different types, based on regexps.
    cCs||_||_t|_dS(N(tnametsubprinterstTruetenabled(tselfRR((s%/usr/share/gdb/python/gdb/printing.pyt__init__3s		cCstd��dS(NsPrettyPrinter __call__(tNotImplementedError(Rtval((s%/usr/share/gdb/python/gdb/printing.pyt__call__8sN(t__name__t
__module__t__doc__tNoneRR	(((s%/usr/share/gdb/python/gdb/printing.pyRstSubPrettyPrintercBseZdZd�ZRS(s�Baseclass for sub-pretty-printers.

    Sub-pretty-printers needn't use this, but it formalizes what's needed.

    Attributes:
        name: The name of the subprinter.
        enabled: A boolean indicating if the subprinter is enabled.
    cCs||_t|_dS(N(RRR(RR((s%/usr/share/gdb/python/gdb/printing.pyRGs	(R
RRR(((s%/usr/share/gdb/python/gdb/printing.pyR=scCs�t|d�r/t|d�r/td��nt|d�r]t|d�r]td��nt|d�s{td��n|dkr�tjd�r�tjd	t�nt}n/tjd�r�tjd
|j|jf�nt|d�r�t|jt	�std��n|jj
d�d
kr9td��nd
}xi|jD][}t|d�r�|j|jkr�|r�|j|=Pq�t
d|j��n|d}qIWn|jjd
|�dS(s�Register pretty-printer PRINTER with OBJ.

    The printer is added to the front of the search list, thus one can override
    an existing printer if one needs to.  Use a different name when overriding
    an existing printer, otherwise an exception will be raised; multiple
    printers with the same name are disallowed.

    Arguments:
        obj: Either an objfile, progspace, or None (in which case the printer
            is registered globally).
        printer: Either a function of one argument (old way) or any object
            which has attributes: name, enabled, __call__.
        replace: If True replace any existing copy of the printer.
            Otherwise if the printer already exists raise an exception.

    Returns:
        Nothing.

    Raises:
        TypeError: A problem with the type of the printer.
        ValueError: The printer's name contains a semicolon ";".
        RuntimeError: A printer with the same name is already registered.

    If the caller wants the printer to be listable and disableable, it must
    follow the PrettyPrinter API.  This applies to the old way (functions) too.
    If printer is an object, __call__ is a method of two arguments:
    self, and the value to be pretty-printed.  See PrettyPrinter.
    R
Rsprinter missing attribute: nameRs"printer missing attribute: enabledR	s#printer missing attribute: __call__tverboses)Registering global %s pretty-printer ...
s)Registering %s pretty-printer for %s ...
sprinter name is not a stringt;issemicolon ';' in printer names%pretty-printer already registered: %siN(thasattrt	TypeErrorR
tgdbt	parametertwriteRtfilenamet
isinstancet
basestringtfindt
ValueErrortpretty_printerstRuntimeErrortinsert(tobjtprintertreplacetitp((s%/usr/share/gdb/python/gdb/printing.pytregister_pretty_printerLs8" 		!
tRegexpCollectionPrettyPrintercBs?eZdZdefd��YZd�Zd�Zd�ZRS(syClass for implementing a collection of regular-expression based pretty-printers.

    Intended usage:

    pretty_printer = RegexpCollectionPrettyPrinter("my_library")
    pretty_printer.add_printer("myclass1", "^myclass1$", MyClass1Printer)
    ...
    pretty_printer.add_printer("myclassN", "^myclassN$", MyClassNPrinter)
    register_pretty_printer(obj, pretty_printer)
    tRegexpSubprintercBseZd�ZRS(cCsAttj|�j|�||_||_tj|�|_dS(N(	tsuperR$R%Rtregexptgen_printertretcompiletcompiled_re(RRR'R(((s%/usr/share/gdb/python/gdb/printing.pyR�s		(R
RR(((s%/usr/share/gdb/python/gdb/printing.pyR%�scCstt|�j|g�dS(N(R&R$R(RR((s%/usr/share/gdb/python/gdb/printing.pyR�scCs#|jj|j|||��dS(soAdd a printer to the list.

        The printer is added to the end of the list.

        Arguments:
            name: The name of the subprinter.
            regexp: The regular expression, as a string.
            gen_printer: A function/method that given a value returns an
                object to pretty-print it.

        Returns:
            Nothing.
        N(RtappendR%(RRR'R(((s%/usr/share/gdb/python/gdb/printing.pytadd_printer�scCsbtjj|j�j}|s"dSx9|jD].}|jr,|jj	|�r,|j
|�Sq,WdS(s1Lookup the pretty-printer for the provided value.N(Rttypestget_basic_typettypettagR
RRR+tsearchR((RRttypenameR((s%/usr/share/gdb/python/gdb/printing.pyR	�s(R
RRRR%RR-R	(((s%/usr/share/gdb/python/gdb/printing.pyR$�s

		t
_EnumInstancecBseZd�Zd�ZRS(cCs||_||_dS(N(tenumeratorsR(RR5R((s%/usr/share/gdb/python/gdb/printing.pyR�s	cCs�g}t|j�}t}xH|jD]=\}}||@dkr%|j|�||@}t}q%q%W|sy|dkr�|jd|�nd|jdj|�fS(Nis<unknown: 0x%x>s	0x%x [%s]s | (tlongRtFalseR5R,Rtjoin(Rt	flag_listtvt	any_foundte_namete_value((s%/usr/share/gdb/python/gdb/printing.pyt	to_string�s

(R
RRR>(((s%/usr/share/gdb/python/gdb/printing.pyR4�s	tFlagEnumerationPrintercBs eZdZd�Zd�ZRS(s�A pretty-printer which can be used to print a flag-style enumeration.
    A flag-style enumeration is one where the enumerators are or'd
    together to create values.  The new printer will print these
    symbolically using '|' notation.  The printer must be registered
    manually.  This printer is most useful when an enum is flag-like,
    but has some overlap.  GDB's built-in printing will not handle
    this case, but this printer will attempt to.cCs#tt|�j|�t|_dS(N(R&R?RR7tinitialized(Rt	enum_type((s%/usr/share/gdb/python/gdb/printing.pyR�scCs�|jsyt|_tj|j�}g|_x0|j�D]"}|jj|j|jf�q:W|jj	dd��n|j
r�t|j|�SdSdS(NtkeycSs|jS(N(tenumval(tx((s%/usr/share/gdb/python/gdb/printing.pyt<lambda>s(
R@RRtlookup_typeRR5tfieldsR,RCtsortRR4R
(RRtflagstfield((s%/usr/share/gdb/python/gdb/printing.pyR	�s			 	(R
RRRR	(((s%/usr/share/gdb/python/gdb/printing.pyR?�s	((RRt	gdb.typesR)tsystversion_infotstrRtintR6tobjectRRR7R#R$R4R?(((s%/usr/share/gdb/python/gdb/printing.pyt<module>s	 LA