
    fʟ                        d Z dZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddlm#Z# ddlm$Z$ ddlm%Z% ddlm&Z& ddlm'Z' ddlm(Z( ddlm)Z) dd lm*Z* dd!lm+Z+  G d" d#e,      Z- e-       Z- G d$ d%e,      Z. G d& d'e.      Z/d( Z0 G d) d*e,      Z1 G d+ d,e      Z2 G d- d.e2      Z3 G d/ d0e3      Z4 G d1 d2e,      Z5 G d3 d4e,      Z6 ee       G d5 d6e6e2             Z7 G d7 d8e7      Z8 G d9 d:e8      Z9 eee       G d; d<e2             Z: G d= d>e;e*      Z< eee       G d? d@e5e2             Z= G dA dBe=      Z> G dC dDe>      Z? G dE dFe?      Z@ G dG dHe;e*      ZA G dI dJe@      ZB G dK dLeB      ZC G dM dNe;e*      ZD G dO dPe=      ZE G dQ dRej                        ZG eG       fdSZHdYdTZI G dU dVe2      ZJ ee       G dW dXe,             ZKy)ZzBootstrapping fields
restructuredtext    N)isinf)notify)	Attribute)	Interface)Invalid)implementer)
providedBy)InterfaceClass)
IInterface)IMethod)ConstraintNotSatisfied)IBeforeObjectAssignedEvent)IContextAwareDefaultFactory)
IFromBytes)IFromUnicode)IValidatable)NotAContainer)NotAnInterface)NotAnIterator)RequiredMissing)SchemaNotCorrectlyImplemented)SchemaNotFullyImplemented)SchemaNotProvided)StopValidation)TooBig)TooLong)TooShort)TooSmall)ValidationError)	WrongTypec                       e Zd Zd Zy)	_NotGivenc                      y)Nz<Not Given> )selfs    t/var/dept/share/cheung/public_html/OutSchool/python/env/lib/python3.12/site-packages/zope/schema/_bootstrapfields.py__repr__z_NotGiven.__repr__<   s        N)__name__
__module____qualname__r(   r%   r)   r'   r#   r#   :   s    r)   r#   c                        e Zd ZddZd Zd Zy)ValidatedPropertyNc                 .    || _         || _        || _        y N)_name_check_allow_none)r&   namecheck
allow_nones       r'   __init__zValidatedProperty.__init__E   s    
%r)   c                     |d u xr | j                   xs ||j                  k(  }|s0| j                  | j                  ||       n|j                  |       ||j                  | j
                  <   y r0   )r3   missing_valuer2   validate__dict__r1   )r&   instvaluebypass_validations       r'   __set__zValidatedProperty.__set__J   sg    d]/t// +*** 	 !{{&D%(e$$)djj!r)   c                 <    || S |j                   | j                     S r0   )r;   r1   )r&   r<   owners      r'   __get__zValidatedProperty.__get__V   s    <K}}TZZ((r)   NF)r*   r+   r,   r7   r?   rB   r%   r)   r'   r.   r.   C   s    &

*)r)   r.   c                       e Zd Zd Zy)DefaultPropertyc                 X   || S |j                   j                  d      }||j                   | j                     S t        j                  |      r ||j
                        }n |       }| j                  | j                  ||       |S ||j                  k7  r|j                  |       |S )NdefaultFactory)	r;   getr1   r   r
   contextr2   r9   r:   )r&   r<   rA   rG   r=   s        r'   rB   zDefaultProperty.__get__^   s    <K**+;<!==,, '11.A"4<<0E"$E;;"KKe$  d(((MM% r)   N)r*   r+   r,   rB   r%   r)   r'   rE   rE   \   s    r)   rE   c                 X    i }| D ]"  }| |   }t        j                  |      s|||<   $ |S )z?Return a dictionary containing all the Fields in a schema.
    )r   r
   )schemafieldsr4   attrs       r'   	getFieldsrN   s   s?     F  d|""4(F4L  Mr)   c                   L    e Zd Zed        Zed        Zed        Zed        Zy)_DocStringHelpersc                    | j                         j                         }t        j                  }|dd  D ]8  }t	        |j                               }|st	        |      |z
  }t        ||      }: t	        |      dk\  r|d   j                         |d<   |t        j                  k  r%t        dt	        |            D ]  }||   |d  ||<    |r|d   s|j                  d       |r|d   s|j                  d       |S )N   r    )

expandtabs
splitlinessysmaxsizelenlstripminrangepopappend)	docstringlinesmarginlinecontentindentis          r'   docstring_to_linesz$_DocStringHelpers.docstring_to_lines   s     $$&113 !"I 	-D$++-(GTW,VV,		- u:?Qx(E!HCKK1c%j) - 8FG,a- E!HIIaL E!H 	Rr)   c                 |    | j                   }| j                   dv rd}|dv rd}||rdndz  }d|| j                  dS )N)__builtin__builtinsrS   )zzope.schema._bootstrapfieldszzope.schema._fieldzzope.schema.z:class:``)r+   r*   )kindmods     r'   make_class_directivez&_DocStringHelpers.make_class_directive   sH    oo??99CHHCcsr!"%t}}55r)   c                     d|d|S )N:z: r%   )clsr4   r=   s      r'   
make_fieldz_DocStringHelpers.make_field   s     %((r)   c                 2   t        |t        t        f      r!| j                  || j	                  |            S t        |t
              st        d|      | j                  |dj                  |D cg c]  }| j	                  |       c}            S c c}w )Nz%make_class_field() can't handle kind z, )
isinstancetyper   rq   rm   tuple	TypeErrorjoin)rp   r4   rk   ts       r'   make_class_fieldz"_DocStringHelpers.make_class_field   s    dT>23>>$(@(@(FGG$&=ACE E~~IIDAqs//2ABD 	DAs   1BN)	r*   r+   r,   staticmethodre   rm   classmethodrq   ry   r%   r)   r'   rP   rP   ~   sT      8 6 6 ) ) D Dr)   rP   c            	            e Zd ZdZdZdZeZdZ e	d      Z
dZ dZdZddddddddef	 fd	Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd ZddZd Zd Z fdZ xZS )FieldNr   defaultrS   TFc
                    d}
dj                  t        j                  |xs d      dd       }|r|r|d|}
n|}
n|r|}
t        t        |   ||
       || _        || _        || _        || _	        ||| _
        || _        || _        t        xj                  dz  c_        t        j                  | _        |	| j                  ur|	| _        yy)a  Pass in field values as keyword parameters.


        Generally, you want to pass either a title and description, or
        a doc string.  If you pass no doc string, it will be computed
        from the title and description.  If you pass a doc string that
        follows the Python coding style (title line separated from the
        body by a blank line), the title and description will be
        computed from the doc string.  Unfortunately, the doc string
        must be passed as a positional argument.

        Here are some examples:

        >>> from zope.schema._bootstrapfields import Field
        >>> f = Field()
        >>> f.__doc__, str(f.title), str(f.description)
        ('', '', '')

        >>> f = Field(title=u'sample')
        >>> str(f.__doc__), str(f.title), str(f.description)
        ('sample', 'sample', '')

        >>> f = Field(title=u'sample', description=u'blah blah\nblah')
        >>> str(f.__doc__), str(f.title), str(f.description)
        ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
        rS   
Nz

rR   )rw   rP   re   superr}   r7   titledescriptionrequiredreadonly
constraintr~   rG   order_Field__missing_value_markerr9   )r&   r   r   r*   r   r   r   r~   rG   r9   __doc__doc_description	__class__s               r'   r7   zField.__init__   s    :  ))001CDSbI
 (-?%GeT#Hg6
&  !(DO, 	q[[
 ; ;;!.D <r)   c                      y)NTr%   r&   r=   s     r'   r   zField.constraint  s    r)   c                     | j                   j                  | j                         }|j                  j                  | j                         ||_        |S r0   )r   __new__r;   updaterI   )r&   rI   clones      r'   bindz
Field.bind  s<    &&t~~6dmm,r)   c                     || j                   k(  r2| j                  r%t        | j                        j	                  | |      y 	 | j                  |       y # t        $ r Y y w xY wr0   )r9   r   r   r*   with_field_and_value	_validater   r   s     r'   r:   zField.validate  s`    D&&&}}%MM&&tU34 
u%! s   A 	A! A!c                     i }t        |       D ]  }|j                  t        |              |j                  dd        |S )Nr   )r
   r   rN   r\   )r&   names	interfaces      r'   __get_property_names_to_comparez%Field.__get_property_names_to_compare+  sC     #D) 	/ILL9-.	/ 			'4 r)   c                 z    t        |       | j                  ft        | j                               z   }t	        |      S r0   )rt   r   ru   %_Field__get_property_names_to_comparehashr   s     r'   __hash__zField.__hash__6  s;     $Z($6689: 	 E{r)   c                     | |u ryt        |       t        |      k7  s| j                  |j                  k7  ry| j                         }|D ]  }t        | |      t        ||      k7  s y y)NTF)rt   r   r   getattr)r&   otherr   r4   s       r'   __eq__zField.__eq__?  so     5=:e$%//(I 446
  	DtT"geT&::	 r)   c                 &    | j                  |       S r0   )r   )r&   r   s     r'   __ne__zField.__ne__S  s    ;;u%%%r)   c                    | j                   Gt        || j                         s1t        || j                   | j                        j	                  | |      	 | j                  |      }|s&t        || j                        j	                  | |      y # t        $ r,}|j                  | |_        |j                  ||_         d }~ww xY wr0   )
_typers   r!   r*   r   r   r    fieldr=   r   )r&   r=   r   es       r'   r   zField._validateV  s    ::!*UDJJ*Gtzz4==""4/0	/J (t}}""4/0   	wwww	s   B 	C'B??Cc                 .    t        || j                        S r0   r   r*   )r&   objects     r'   rH   z	Field.geti  s    vt}}--r)   c                 0    t        || j                  |      S r0   r   )r&   r   r~   s      r'   queryzField.queryl  s    vt}}g66r)   c           	          | j                   rGt        d| j                  d|j                  j                  d|j                  j                  d      t        || j                  |       y )Nz+Can't set values on read-only fields (name=z, class=ri   ))r   rv   r*   r   r+   setattrr&   r   r=   s      r'   setz	Field.seto  sR    ==#}}%//::%//88	: ; ;
 	u-r)   c                    g }|j                  t        j                  dt        |                    |j                  t        j	                  d| j
                               |j                  t        j	                  d| j                               | j                  r9|j                  t        j	                  dt        | j                                     n8|j                  t        j	                  dt        | j                                     | j                  r/|j                  t        j                  d| j                               dD ]t  \  }}t        | |d      }t        |d	      s |j                  d
       |j                  d|z          |j                  d
       |j                  |j                                v |S )a  
        Return a list of ReST formatted lines that will be added
        to the docstring returned by :meth:`getDoc`.

        By default, this will include information about the various
        properties of this object, such as required and readonly status,
        required type, and so on.

        This implementation uses a field list for this.

        Subclasses may override or extend.

        .. versionadded:: 4.6.0
        Implementationz	Read OnlyRequiredzDefault FactoryzDefault ValuezAllowed Type))key_typezKey Type)
value_typez
Value TypeNgetDocrS   z.. rubric:: )r]   rP   ry   rt   rq   r   r   rG   reprr~   r   r   hasattrr   )r&   r_   r4   rubricr   s        r'   getExtraDocLineszField.getExtraDocLinesx  s`     &77d4j* 	+&11+t}}MN&11*dmmLMLL*55!4(;(;#<> ? LL*55dll!35 6 ::LL*;;

, -; 	-LD&D$-Euh'R ^f45R U\\^,	- r)   c                     t         t        |          }t        j	                  |      }|| j                         z  }|j                  d       dj                  |      S )NrS   r   )r   r}   r   rP   re   r   r]   rw   )r&   docr_   r   s      r'   r   zField.getDoc  sP    E4')!44S9&&((Ryyr)   r0   )r*   r+   r,   r   rI   r9   r#   r   r   rE   r~   r   _Element__tagged_valuesr7   r   r   r:   r   r   r   r   r   rH   r   r   r   r   __classcell__r   s   @r'   r}   r}      s     EG M ' Ei(G HI" cB4 $4J</|
	(&0&.7.,\   r)   r}   c                        e Zd Z fdZ xZS )	Containerc                     t         t        |   |       t        |d      s	 t	        |       y y # t
        $ r t        |      j                  | |      w xY w)N__contains__)r   r   r   r   iterrv   r   r   r&   r=   r   s     r'   r   zContainer._validate  sY    i(/un-MU .  M#E*??eLLMs	   / %Ar*   r+   r,   r   r   r   s   @r'   r   r     s    M Mr)   r   c                        e Zd Z fdZ xZS )Iterablec                     t         t        |   |       	 t        |       y # t        $ r t        |      j                  | |      w xY wr0   )r   r   r   r   rv   r   r   r   s     r'   r   zIterable._validate  sH    h'.	IK 	I&;;D%HH	Is	   " %Ar   r   s   @r'   r   r     s    I Ir)   r   c                   V     e Zd ZdZ edd      Z edd      Zd fd	Z fdZ xZ	S )		OrderablezValues of ordered fields can be sorted.

    They can be restricted to a range of values.

    Orderable is a mixin used in combination with Field.
    rZ   T)r6   maxc                 r    d | _         d | _        t        t        |   di | || _         || _        || _        y Nr%   )rZ   r   r   r   r7   r~   )r&   rZ   r   r~   kwr   s        r'   r7   zOrderable.__init__  s>     i'-"-  r)   c                 2   t         t        |   |       | j                  5|| j                  k  r&t	        || j                        j                  | |      | j                  6|| j                  kD  r&t        || j                        j                  | |      y y r0   )r   r   r   rZ   r   r   r   r   r   s     r'   r   zOrderable._validate  s    i(/88EDHH$45$((+@@uMM88EDHH$4)>>tUKK %5r)   )NNN)
r*   r+   r,   r   r.   rZ   r   r7   r   r   r   s   @r'   r   r     s3     Ed
3C
Ed
3C"L Lr)   r   c                   6     e Zd ZdZdZdZd fd	Z fdZ xZS )	MinMaxLenznExpresses constraints on the length of a field.

    MinMaxLen is a mixin used in combination with Field.
    r   Nc                 H    || _         || _        t        t        |   di | y r   )
min_length
max_lengthr   r   r7   )r&   r   r   r   r   s       r'   r7   zMinMaxLen.__init__  s#    $$i'-"-r)   c                 V   t         t        |   |       | j                  >t	        |      | j                  k  r&t        || j                        j                  | |      | j                  ?t	        |      | j                  kD  r&t        || j                        j                  | |      y y r0   )	r   r   r   r   rX   r   r   r   r   r   s     r'   r   zMinMaxLen._validate  s    i(/??&3u:+G5$//2GGe  ??&3u:+G%1FFe  ,H&r)   )r   N)	r*   r+   r,   r   r   r   r7   r   r   r   s   @r'   r   r     s#     JJ.
	 	r)   r   c                   0     e Zd ZdZeZdZ fdZd Z xZ	S )Textz1A field containing text used for human discourse.NFCc                 n    |j                  d| j                        | _        t        t        |   |i | y )Nunicode_normalization)r\   r   r   r   r7   )r&   argsr   r   s      r'   r7   zText.__init__  s4    %'VV#T%?%?&A"dD"D/B/r)   c                     t        |t              r,| j                  r t        j                  | j                  |      }| j                  |       |S )a  
        >>> from zope.schema import Text
        >>> t = Text(constraint=lambda v: 'x' in v)
        >>> t.fromUnicode(b"foo x spam") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        zope.schema._bootstrapinterfaces.WrongType:
            ('foo x spam', <type 'unicode'>, '')
        >>> result = t.fromUnicode(u"foo x spam")
        >>> isinstance(result, bytes)
        False
        >>> str(result)
        'foo x spam'
        >>> t.fromUnicode(u"foo spam") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        zope.schema._bootstrapinterfaces.ConstraintNotSatisfied:
            (u'foo spam', '')
        )rs   strr   unicodedata	normalizer:   r   s     r'   fromUnicodezText.fromUnicode  sC    ( eS!))#--..7er)   )
r*   r+   r,   r   r   r   r   r7   r   r   r   s   @r'   r   r   	  s    ;E!0
r)   r   c                       e Zd ZdZd Zy)TextLinezA text field with no newlines.c                     d|vxr d|vS )Nr   r%   r   s     r'   r   zTextLine.constraint3  s    5 6T%66r)   N)r*   r+   r,   r   r   r%   r)   r'   r   r   0  s
    (7r)   r   c                   :     e Zd ZdZ e       Z fdZ fdZ xZS )Passwordz2A text field containing a text used as a password.c                 L    || j                   u ryt        t        |   ||       y)a   Update the password.

        We use a special marker value that a widget can use
        to tell us that the password didn't change. This is
        needed to support edit forms that don't display the
        existing password and want to work together with
        encryption.

        N)UNCHANGED_PASSWORDr   r   r   )r&   rI   r=   r   s      r'   r   zPassword.set<  s'     D+++h!'51r)   c                     	 t        | j                  | j                              }|| j                  u r|ry t
        t        |   |      S # t        $ r d}Y 1w xY wrC   )boolrH   rI   AttributeErrorr   r   r   r:   )r&   r=   existingr   s      r'   r:   zPassword.validateJ  s\    	DHHT\\23H D+++Xt-e44  	H	s   $A AA)	r*   r+   r,   r   r   r   r   r:   r   r   s   @r'   r   r   7  s    <25 5r)   r   c                   ,    e Zd ZdZeZd Zd Zd Zd Z	y)Boolz
    A field representing a Bool.

    .. versionchanged:: 4.8.0
        Implement :class:`zope.schema.interfaces.IFromBytes`
    c                     t        |t              rt        |t              st        |      }t        j	                  | |       y r0   )rs   intr   r}   r   r   s     r'   r   zBool._validate`  s.     eS!*UD*AKEe$r)   c                     t        |t              rt        |t              st        |      }t        j	                  | ||       y r0   )rs   r   r   r}   r   r   s      r'   r   zBool.setg  s.    eS!*UD*AKE		$&r)   c                 @    |dk(  xs |dk(  }| j                  |       |S )u  
        >>> from zope.schema._bootstrapfields import Bool
        >>> from zope.schema.interfaces import IFromUnicode
        >>> b = Bool()
        >>> IFromUnicode.providedBy(b)
        True
        >>> b.fromUnicode('True')
        True
        >>> b.fromUnicode('')
        False
        >>> b.fromUnicode('true')
        True
        >>> b.fromUnicode('false') or b.fromUnicode('False')
        False
        >>> b.fromUnicode(u'☃')
        False
        Truetrue)r:   )r&   r=   vs      r'   r   zBool.fromUnicodel  s'    * VO.uar)   c                 B    | j                  |j                  d            S )u  
        >>> from zope.schema._bootstrapfields import Bool
        >>> from zope.schema.interfaces import IFromBytes
        >>> b = Bool()
        >>> IFromBytes.providedBy(b)
        True
        >>> b.fromBytes(b'True')
        True
        >>> b.fromBytes(b'')
        False
        >>> b.fromBytes(b'true')
        True
        >>> b.fromBytes(b'false') or b.fromBytes(b'False')
        False
        >>> b.fromBytes(u'☃'.encode('utf-8'))
        False
        utf-8r   decoder   s     r'   	fromByteszBool.fromBytes  s    $ W 566r)   N)
r*   r+   r,   r   r   r   r   r   r   r   r%   r)   r'   r   r   U  s"     E%'
27r)   r   c                       e Zd ZdZy)InvalidNumberLiteralzInvalid number literal.Nr*   r+   r,   r   r%   r)   r'   r   r     s    !r)   r   c                   n    e Zd ZdZej
                  Zeee	j                  eej                  fZeZd Zd Zy)Numbera  
    A field representing a :class:`numbers.Number` and implementing
    :class:`zope.schema.interfaces.INumber`.

    The :meth:`fromUnicode` method will attempt to use the smallest or
    strictest possible type to represent incoming strings::

        >>> from zope.schema._bootstrapfields import Number
        >>> f = Number()
        >>> f.fromUnicode(u"1")
        1
        >>> f.fromUnicode(u"125.6")
        125.6
        >>> f.fromUnicode(u"1+0j")
        (1+0j)
        >>> f.fromUnicode(u"1/2")
        Fraction(1, 2)
        >>> f.fromUnicode(str(2**11234) + '.' + str(2**256))
        ... # doctest: +ELLIPSIS
        Decimal('590...936')
        >>> f.fromUnicode(u"not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'

    Similarly, :meth:`fromBytes` will do the same for incoming byte strings::

        >>> from zope.schema._bootstrapfields import Number
        >>> f = Number()
        >>> f.fromBytes(b"1")
        1
        >>> f.fromBytes(b"125.6")
        125.6
        >>> f.fromBytes(b"1+0j")
        (1+0j)
        >>> f.fromBytes(b"1/2")
        Fraction(1, 2)
        >>> f.fromBytes((str(2**11234) + '.' + str(2**256)).encode('ascii'))
        ... # doctest: +ELLIPSIS
        Decimal('590...936')
        >>> f.fromBytes(b"not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'

    .. versionadded:: 4.6.0
    .. versionchanged:: 4.8.0
        Implement :class:`zope.schema.interfaces.IFromBytes`

    c                    d }| j                   D ]c  }	  ||      }|t        u r<t        |      r1t        j                  | j                   v rt        j                  |      }| j                  |       |c S  	  | j                  |j                   j                  | |      # t        t        j                  f$ r}|}Y d }~d }~ww xY w# d }w xY wr0   )_unicode_convertersfloatr   decimalDecimalr:   
ValueErrorInvalidOperation_validation_errorr   r   )r&   r=   last_exc	convertervalr   s         r'   r   zNumber.fromUnicode  s    11 	I&&!#J#OOt/G/GG!//%0C c"
		($(((--8MMe   8 89  Hs$   AB6)C C8B??CCc                 B    | j                  |j                  d            S )Nr   r   r   s     r'   r   zNumber.fromBytes  s    W 566r)   N)r*   r+   r,   r   numbersr  r   r   r  	fractionsFractioncomplexr  r  r  r   r
  r   r   r%   r)   r'   r  r    sD    1d NNE 	UI&&
 -*7r)   r  c                   H    e Zd ZdZej
                  Zeee	e
j                  fZy)Complexa  
    A field representing a :class:`numbers.Complex` and implementing
    :class:`zope.schema.interfaces.IComplex`.

    The :meth:`fromUnicode` method is like that for :class:`Number`,
    but doesn't allow Decimals::

        >>> from zope.schema._bootstrapfields import Complex
        >>> f = Complex()
        >>> f.fromUnicode(u"1")
        1
        >>> f.fromUnicode(u"125.6")
        125.6
        >>> f.fromUnicode(u"1+0j")
        (1+0j)
        >>> f.fromUnicode(u"1/2")
        Fraction(1, 2)
        >>> f.fromUnicode(str(2**11234) + '.' + str(2**256))
        ... # doctest: +ELLIPSIS
        inf
        >>> f.fromUnicode(u"not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'

    Similarly for :meth:`fromBytes`:

        >>> from zope.schema._bootstrapfields import Complex
        >>> f = Complex()
        >>> f.fromBytes(b"1")
        1
        >>> f.fromBytes(b"125.6")
        125.6
        >>> f.fromBytes(b"1+0j")
        (1+0j)
        >>> f.fromBytes(b"1/2")
        Fraction(1, 2)
        >>> f.fromBytes((str(2**11234) + '.' + str(2**256)).encode('ascii'))
        ... # doctest: +ELLIPSIS
        inf
        >>> f.fromBytes(b"not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'

    .. versionadded:: 4.6.0
    N)r*   r+   r,   r   r  r  r   r   r  r  r  r  r  r%   r)   r'   r  r    s(    .^ OOEw	0B0BCr)   r  c                   F    e Zd ZdZej
                  Zeee	j                  fZy)Reala  
    A field representing a :class:`numbers.Real` and implementing
    :class:`zope.schema.interfaces.IReal`.

    The :meth:`fromUnicode` method is like that for :class:`Complex`,
    but doesn't allow Decimals or complex numbers::

        >>> from zope.schema._bootstrapfields import Real
        >>> f = Real()
        >>> f.fromUnicode("1")
        1
        >>> f.fromUnicode("125.6")
        125.6
        >>> f.fromUnicode("1+0j") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Fraction: '1+0j'
        >>> f.fromUnicode("1/2")
        Fraction(1, 2)
        >>> f.fromUnicode(str(2**11234) + '.' + str(2**256))
        ... # doctest: +ELLIPSIS
        inf
        >>> f.fromUnicode("not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'

    .. versionadded:: 4.6.0
    N)r*   r+   r,   r   r  r  r   r   r  r  r  r  r%   r)   r'   r  r  /  s%    : LLEy'9'9:r)   r  c                   D    e Zd ZdZej
                  Zeej                  fZ
y)Rationala  
    A field representing a :class:`numbers.Rational` and implementing
    :class:`zope.schema.interfaces.IRational`.

    The :meth:`fromUnicode` method is like that for :class:`Real`,
    but does not allow arbitrary floating point numbers::

        >>> from zope.schema._bootstrapfields import Rational
        >>> f = Rational()
        >>> f.fromUnicode("1")
        1
        >>> f.fromUnicode("1/2")
        Fraction(1, 2)
        >>> f.fromUnicode("125.6")
        Fraction(628, 5)
        >>> f.fromUnicode("1+0j") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Fraction: '1+0j'
        >>> f.fromUnicode(str(2**11234) + '.' + str(2**256))
        ... # doctest: +ELLIPSIS
        Fraction(195..., 330...)
        >>> f.fromUnicode("not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'

    .. versionadded:: 4.6.0
    N)r*   r+   r,   r   r  r  r   r   r  r  r  r%   r)   r'   r  r  Q  s%    : E	 2 23r)   r  c                       e Zd ZdZy)InvalidIntLiteralzInvalid int literal.Nr   r%   r)   r'   r  r  s      r)   r  c                   2    e Zd ZdZej
                  ZefZe	Z
y)Integrala}  
    A field representing a :class:`numbers.Integral` and implementing
    :class:`zope.schema.interfaces.IIntegral`.

    The :meth:`fromUnicode` method only allows integral values::

        >>> from zope.schema._bootstrapfields import Integral
        >>> f = Integral()
        >>> f.fromUnicode("125")
        125
        >>> f.fromUnicode("125.6") #doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidIntLiteral: invalid literal for int(): 125.6

    Similarly for :meth:`fromBytes`:

        >>> from zope.schema._bootstrapfields import Integral
        >>> f = Integral()
        >>> f.fromBytes(b"125")
        125
        >>> f.fromBytes(b"125.6") #doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidIntLiteral: invalid literal for int(): 125.6

    .. versionadded:: 4.6.0
    N)r*   r+   r,   r   r  r  r   r   r  r  r
  r%   r)   r'   r  r  w  s"    8 E&)r)   r  c                       e Zd ZdZeZefZy)IntzkA field representing a native integer type. and implementing
    :class:`zope.schema.interfaces.IInt`.
    N)r*   r+   r,   r   r   r   r  r%   r)   r'   r  r    s     E&r)   r  c                       e Zd ZdZy)InvalidDecimalLiteralzRaised by decimal fieldsNr   r%   r)   r'   r!  r!    r  r)   r!  c                   F    e Zd ZdZej
                  Zej
                  fZeZ	y)r  a:  
    A field representing a native :class:`decimal.Decimal` and implementing
    :class:`zope.schema.interfaces.IDecimal`.

    The :meth:`fromUnicode` method only accepts values that can be parsed
    by the ``Decimal`` constructor::

        >>> from zope.schema._field import Decimal
        >>> f = Decimal()
        >>> f.fromUnicode("1")
        Decimal('1')
        >>> f.fromUnicode("125.6")
        Decimal('125.6')
        >>> f.fromUnicode("1+0j") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidDecimalLiteral: Invalid literal for Decimal(): 1+0j
        >>> f.fromUnicode("1/2") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidDecimalLiteral: Invalid literal for Decimal(): 1/2
        >>> f.fromUnicode(str(2**11234) + '.' + str(2**256))
        ... # doctest: +ELLIPSIS
        Decimal('5901...936')
        >>> f.fromUnicode("not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidDecimalLiteral: could not convert string to float: not a number

    Likewise for :meth:`fromBytes`::

        >>> from zope.schema._field import Decimal
        >>> f = Decimal()
        >>> f.fromBytes(b"1")
        Decimal('1')
        >>> f.fromBytes(b"125.6")
        Decimal('125.6')
        >>> f.fromBytes(b"1+0j") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidDecimalLiteral: Invalid literal for Decimal(): 1+0j
        >>> f.fromBytes(b"1/2") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidDecimalLiteral: Invalid literal for Decimal(): 1/2
        >>> f.fromBytes((str(2**11234) + '.' + str(2**256)).encode("ascii"))
        ... # doctest: +ELLIPSIS
        Decimal('5901...936')
        >>> f.fromBytes(b"not a number") # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        ...
        InvalidDecimalLiteral: could not convert string to float: not a number


    N)
r*   r+   r,   r   r  r  r   r  r!  r
  r%   r)   r'   r  r    s&    6n OOE"??,-r)   r  c                        e Zd Z fdZ xZS )_ObjectsBeingValidatedc                 H    t         t        |           t               | _        y r0   )r   r$  r7   r   ids_being_validated)r&   r   s    r'   r7   z_ObjectsBeingValidated.__init__  s    $d46#&5 r)   )r*   r+   r,   r7   r   r   s   @r'   r$  r$    s    ) )r)   r$  c                 L   i }| t         u r|S t        |      }|j                  }||v r|S |j                  |       	 | j	                  d      D ]a  }| |   }t        j                  |      r	 t        j                  |      r.t        ||      }|j                  |      }|j                  |       c 	 |j                  |       |S # t        $ r}	|	||<   Y d}	~	d}	~	wt        $ r(}	t        |	      j                  |d      ||<   Y d}	~	d}	~	ww xY w# |j                  |       w xY w)a  
    Validate that *value* conforms to the schema interface *schema*.

    All :class:`zope.schema.interfaces.IField` members of the *schema*
    are validated after being bound to *value*. (Note that we do not check for
    arbitrary :class:`zope.interface.Attribute` members being present.)

    :return: A `dict` mapping field names to `ValidationError` subclasses.
       A non-empty return value means that validation failed.
    T)allN)r   idr&  addr   r   r
   r   r   r   r:   r    r   r   r   remove)
rK   r=   _validating_objectserrorsid_valuer&  r4   	attributefield_valueerrors
             r'   get_schema_validation_errorsr2    s+    F
 
 %yH-AA&&H%-LLTL* 	8DtI!!),8**95")%"6K )u 5I&&{3	8& 	""8,M # %$t! 88 &&y$7 t8 	""8,sH   0D -AC0D 	DCD D%DD DD D#c                     t        | |      }g }|r|s	 | j                  ||       ||fS ||fS # t        $ r Y ||fS w xY w)a  
    Validate that *value* conforms to the schema interface *schema*.

    This includes checking for any schema validation errors (using
    `get_schema_validation_errors`). If that succeeds, and
    *validate_invariants* is true, then we proceed to check for any
    declared invariants.

    Note that this does not include a check to see if the *value*
    actually provides the given *schema*.

    :return: If there were any validation errors, either schema or
             invariant, return a two tuple (schema_error_dict,
             invariant_error_list). If there were no errors, returns a
             two-tuple where both members are empty.
    )r2  validateInvariantsr   )rK   r=   validate_invariantsschema_error_dictinvariant_errorss        r'   get_validation_errorsr8  "  sq    " 5VUC
 #4	%%e-=> /00/00  	
 /00	s   . 	==c                   H     e Zd ZdZdZef fd	Z fdZ fdZ fdZ	 xZ
S )ObjectzD
    Implementation of :class:`zope.schema.interfaces.IObject`.
    Nc                     |t         u r| j                  }t        j                  |      st	        || j
                        || _        |j                  dd      | _        t        t        | *  di | y)a>  
        Object(schema=<Not Given>, *, validate_invariants=True, **kwargs)

        Create an `~.IObject` field. The keyword arguments are as for
        `~.Field`.

        .. versionchanged:: 4.6.0
           Add the keyword argument *validate_invariants*. When true (the
           default), the schema's ``validateInvariants`` method will be
           invoked to check the ``@invariant`` properties of the schema.
        .. versionchanged:: 4.6.0
           The *schema* argument can be ommitted in a subclass
           that specifies a ``schema`` attribute.
        r5  TNr%   )r#   rK   r   r
   r   r*   r\   r5  r   r:  r7   )r&   rK   r   r   s      r'   r7   zObject.__init__L  sd     Y[[F$$V, !77#%66*?#F fd$*r*r)   c                     t         t        |          }|j                  t        j                  d| j                               |S )NzMust Provide)r   r:  r   r]   rP   ry   rK   )r&   r_   r   s     r'   r   zObject.getExtraDocLinesh  s:    fd46&77DKK) 	*r)   c                    t         t        |   |       | j                  j	                  |      s&t        | j                  |      j                  | |      t        | j                  || j                        \  }}|s|rGt        |j                               |z   }t        || j                  ||      j                  | |      }	 |y # ~~~~w xY wr0   )r   r:  r   rK   r
   r   r   r8  r5  listvaluesr   r*   )r&   r=   r6  r7  r-  	exceptionr   s         r'   r   zObject._validaten  s    fd%e, {{%%e,#DKK7LLe  /DKK$$/
++  0+22458HHF5! 	
 #"4/  !1 $%s   C Cc                     t        || j                  |      }t        |       |j                  }t        t
        |   ||       y r0   )BeforeObjectAssignedEventr*   r   r   r   r:  r   )r&   r   r=   eventr   s       r'   r   z
Object.set  s:     *%Gu fd.r)   )r*   r+   r,   r   rK   r#   r7   r   r   r   r   r   s   @r'   r:  r:  F  s,     F' +8B	/ 	/r)   r:  c                       e Zd ZdZd Zy)rB  zDAn object is going to be assigned to an attribute on another object.c                 .    || _         || _        || _        y r0   )r   r4   rI   )r&   r   r4   rI   s       r'   r7   z"BeforeObjectAssignedEvent.__init__  s    	r)   N)r*   r+   r,   r   r7   r%   r)   r'   rB  rB    s
    Nr)   rB  )T)Lr   __docformat__r  r  r  rV   	threadingr   mathr   
zope.eventr   zope.interfacer   r   r   r	   r
   zope.interface.interfacer   zope.interface.interfacesr   r    zope.schema._bootstrapinterfacesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   r#   r.   rE   rN   rP   r}   r   r   r   r   r   r   r   r   r  r   r  r  r  r  r  r  r  r!  r  localr$  r2  r8  r:  rB  r%   r)   r'   <module>rO     sZ  "    
     $ $ " & % 3 0 - C G H 7 9 9 : ; : < J F > ; 3 4 5 5 < 6  K	) )2' .8D 8Dvs I s l	M 	M	Iy 	I#L #LL 2 \#9e # #L7t 75x 5< \:&A75 A7 'A7H": " \:&Y7Y Y7 'Y7x1Df 1Dh;7 ;D4t 4D
O *x *D!( !J :.f :.z)Y__ ) 6L5M6r!1HR/U R/j '(  )r)   