Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/vdo/statistics/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/vdo/statistics/__pycache__/Field.cpython-36.opt-1.pyc

3

x?ag��@s�dZddlmZddlmZddlmZddlmZddlTddlmZdd	lZGd
d�de	�Z
Gdd
�d
e
�ZGdd�de�ZGdd�de�Z
Gdd�de�ZGdd�de�ZGdd�de
�ZGdd�de�ZGdd�de
�ZGdd�de�Zd	S)z�
  Field - base class for a field of a collection of statistics

  $Id: //eng/vdo-releases/aluminum/src/python/vdo/statistics/Field.py#2 $
�)�absolute_import)�division)�print_function)�unicode_literals)�*�)�LabeledValueNc@sZeZdZdZejd�Zejd�Zejd�Ze	dd��Z
dd�Zd	d
�Zdd�Z
d
d�ZdS)�FieldzD
  Field is the base class for a field of a statistics structure.
  z([A-Z][a-z])z([a-z])([A-Z])z\$([a-zA-Z0-9_]+)cCs$|jjdd�|�}|jjdd�|�S)a
    Convert a camel-cased string to a set of space separated, lower case words.

    Preserves uppercase acronyms, so 'launchVDOErrorCount' becomes
    'launch VDO error count'.

    :param string: The string to convert

    :return: The converted string
    cSsd|j�j�S)N� )�group�lower)�match�r�/usr/lib/python3.6/Field.py�<lambda>5sz Field._decamel.<locals>.<lambda>cSsdj|j��S)Nr
)�join�groups)r
rrrr7s)�
decamelRE1�sub�
decamelRE2)�cls�stringZloweredrrr�_decamel)szField._decamelcs|jjd|���fdd�S)z�
    Convert a string describing how to derive a field's value into a lambda.

    :param string    The string to convert

    :return: An equivalent lambda
    z"parent.getSampleValue(stats, "\1")cst��S)N)�eval)�stats�parent)�
derivationrrrCsz'Field._generateLambda.<locals>.<lambda>)�
fieldNamesr)�selfrr)rr�_generateLambda9szField._generateLambdacKs�||_|jdd�|_|jdkr(||jn||_|jdd�|_|jrV|jd|j|j��nd|_|j|jdd��|_|jd	d�}|dk|_	d
j
|jd�}|j|r�|n|�|_|r�tdj
|j
����dS)
a�
    Create a new field.

    :param name:     The name of the field
    :param cType:    The class representing the C representation for this field
                     when sampled via an ioctl
    :param **kwargs: Keyword arguments which may be:
                       available: Specifies python code to apply to other
                                  fields of the parent structure to decide
                                  whether this value is available. Defaults
                                  to True.
                       derived:   Specifies python code to apply to other
                                  fields of the parent structure to derive the
                                  value of this field. Defaults to None.
                       display:   If not True, this field will not be included
                                  in labeled output. Defaults to True.
                       label:     The label for this field. If unspecified, the
                                  label will be derived from the field name.
                       length:    if > 1, indicates this field is an array of
                                  the specified cType, otherwise is is a
                                  scalar. Defaults to 1.
    �lengthr�displayT�labelN�	available�True�derivedzgetattr(stats, '{name}'))�namezunknown arguments to Field: {0})r&�popr �cTyper!rr"rr#ZinStruct�format�getValue�	Exception�keys)rr&r(�kwargsr%ZdefaultValuerrr�__init__Es 
zField.__init__cCs|j||�st�S|j||�S)z�
    Extract the value for this field from a sample.

    :param stats: The raw stats returned from an ioctl
    :param parent: The parent of this field

    :return: The value of this field in the current sample
    )r#�NotAvailabler*)rrrrrr�
extractSampleps	zField.extractSamplecCstj||j|�S)z�
    Label a sampled value for this field.

    :param sample: The sampled field value
    :param prefix: The prefix for the label

    :return: A LabeledValue for a value of this field
    )rZmaker")r�sample�prefixrrr�labeled~s	z
Field.labeledN)�__name__�
__module__�__qualname__�__doc__�re�compilerrr�classmethodrrr.r0r3rrrrr	!s


+r	cs eZdZdZ�fdd�Z�ZS)�IntegerFieldz4
  Base class for fields which are integer types.
  cs(tt|�j||�}t|t�r |St|�S)z
    :inherit:
    )�superr;r0�
isinstance�int)rrrr1)�	__class__rrr0�szIntegerField.extractSample)r4r5r6r7r0�
__classcell__rr)r?rr;�sr;cs(eZdZ�fdd�Z�fdd�Z�ZS)�	BoolFieldcstt|�j|tf|�dS)N)r<rAr.�c_byte)rr&r-)r?rrr.�szBoolField.__init__cstt|�j||�dkS)Nr)r<rAr0)rrr)r?rrr0�szBoolField.extractSample)r4r5r6r.r0r@rr)r?rrA�srAcseZdZ�fdd�Z�ZS)�
Uint8Fieldcstt|�j|tf|�dS)N)r<rCr.rB)rr&r-)r?rrr.�szUint8Field.__init__)r4r5r6r.r@rr)r?rrC�srCcseZdZ�fdd�Z�ZS)�Uint32Fieldcstt|�j|tf|�dS)N)r<rDr.Zc_uint)rr&r-)r?rrr.�szUint32Field.__init__)r4r5r6r.r@rr)r?rrD�srDcseZdZ�fdd�Z�ZS)�Uint64Fieldcstt|�j|tf|�dS)N)r<rEr.Zc_ulonglong)rr&r-)r?rrr.�szUint64Field.__init__)r4r5r6r.r@rr)r?rrE�srEcs eZdZdZ�fdd�Z�ZS)�FloatingPointFieldz;
  Base class for fields which are floating point types.
  csttt|�j||��S)z
    :inherit:
    )�floatr<rFr0)rrr)r?rrr0�sz FloatingPointField.extractSample)r4r5r6r7r0r@rr)r?rrF�srFcseZdZ�fdd�Z�ZS)�
FloatFieldcstt|�j|tf|�dS)N)r<rHr.Zc_float)rr&r-)r?rrr.�szFloatField.__init__)r4r5r6r.r@rr)r?rrH�srHcseZdZ�fdd�Z�ZS)�StringFieldcstt|�j|tf|�dS)N)r<rIr.Zc_char)rr&r-)r?rrr.�szStringField.__init__)r4r5r6r.r@rr)r?rrI�srIc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)r/zZ
  A value for numeric statistics which are currently not available; prints
  as 'N/A'.
  cCsdS)NzN/Ar)rrrr�__str__�szNotAvailable.__str__cCsdS)Nr/r)rrrr�__repr__�szNotAvailable.__repr__cCs|S)Nr)r�otherrrr�__add__�szNotAvailable.__add__cCs|S)Nr)rrLrrr�__radd__�szNotAvailable.__radd__cCs|S)Nr)rrLrrr�__sub__�szNotAvailable.__sub__cCs|S)Nr)rrLrrr�__rsub__�szNotAvailable.__rsub__cCs|S)Nr)rrLrrr�__mul__�szNotAvailable.__mul__cCs|S)Nr)rrLrrr�__rmul__�szNotAvailable.__rmul__cCs|S)Nr)rrLrrr�__div__�szNotAvailable.__div__cCs|S)Nr)rrLrrr�__rdiv__�szNotAvailable.__rdiv__cCs|S)Nr)rrrr�__int__�szNotAvailable.__int__cCsd|djt|��S)Nz{0:�})r)�str)r�specrrr�
__format__�szNotAvailable.__format__N)r4r5r6r7rJrKrMrNrOrPrQrRrSrTrUrYrrrrr/�sr/)r7Z
__future__rrrrZctypesrr8�objectr	r;rArCrDrErFrHrIr>r/rrrr�<module>s"i

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists