;ò ›¡Cc@s5dkZdkZdkZdkZdklZlZdklZdklZl Z dk l Z dk l Z l Z lZlZlZdk lZlZlZdklZdklZd klZd klZd klZd klZd kl Z dk!l"Z"dk!l#Z#dk$l%Z%dk&i'i(Z(ye)ei*ei+ƒƒƒZ,Wne)eƒdƒZ,nXd„Z-dZ.ei/i0e.ƒo%e1Z2d„Z3e3ƒZ4d„Z5n e6Z2e-Z5d„Z7gZ8d„Z9d„Z:d„Z;e<e<d„Z=d„Z>d„Z?d„Z@d„ZAdfd „ƒYZBeeBƒd!eBfd"„ƒYZCd#eBfd$„ƒYZDeeDƒd%efd&„ƒYZEeeEƒd'„ZFd(„ZGd)„ZHe6d*„ZId+ZJd,ZKd-„ZLd.d/„ZMd0„ZNd1„ZOd2„ZPd3„ZQe1d4„ZRd5„ZSe<e<d6„ZTd7e<d8„ZUdS(9N(srandomsrandint(stime(sgetargssgetmro(smd5(s TupleTypesListTypes ClassTypesIntTypesNoneType(s UnicodeTypes StringTypes MethodType(sUserDict(sClassSecurityInfo(s ACCESS_PUBLIC(saq_base(sExtensionClass(sInitializeClass(s getToolByName(slog(s deprecated(sDEBUG_SECURITYl;á cGsdttƒdƒ}ttƒdƒ}|d|dtdt|ƒ}t|ƒi ƒ}|SdS(Nlèl;á s ( sstrstimestsrandomsrs _v_networksargssdatasmd5s hexdigestsuid(sargssuidsrstsdata((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys make_uuids $s/proc/sys/kernel/random/uuidccsCttdƒ}x-no%|iƒd }|idƒ|VqWdS(Nsriiÿÿÿÿi(sopens KERNEL_UUIDsfpsreadsuidsseek(sfpsuid((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pysuuid_gen)s  cGstiƒSdS(N(suid_gensnext(sargs((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pyskernel_make_uuid1scCsUdkl}tt|ƒdƒ o)|iiƒ}|i||ƒ|`n|SdS(s`Fix persisted schema from AT < 1.3 (UserDict-based) to work with the new fixed order schema.(sSchematas_fieldsN( sProducts.Archetypes.SchemasSchematashasattrsaq_basesschemasdatasvaluessfieldss__init__(sschemasfieldssSchemata((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys fixSchema8s  c Os |}t|dƒo |i}n|i}t|ƒ}t|ƒ} |dt j o|dt j o|||ŽSn|dt jo9t | ƒt |dƒjo| t |dƒ } qÁnh} t | ƒt |dƒjoWxT|dt | ƒD]:}|i|tƒ}|tj o|| |<||=qùqùWnt | ƒt | iƒƒ}|t |dƒjoTxQ|d|D]=}|i|tƒ}|tj o| i|ƒ||=q}q}Wn|dt j o|| |ŽSn|do|| | ŽSn|ƒSdS(sN Inspect function and apply positional and keyword arguments as possible. XXX Add more examples. >>> def f(a, b, c=2, d=3): ... print a, b, c, d >>> mapply(f, *(1, 2), **{'d':4}) 1 2 2 4 >>> mapply(f, *(1, 2), **{'c':3}) 1 2 3 3 >>> mapply(f, *(1, 2), **{'j':3}) 1 2 2 3 >>> def f(a, b): ... print a, b >>> mapply(f, *(1, 2), **{'j':3}) 1 2 >>> def f(a, b=2): ... print a, b >>> mapply(f, *(1,), **{'j':3}) 1 2 >>> mapply(f, *(1,), **{'j':3}) 1 2 XXX Should raise an exception 'Multiple values for argument' here. >>> mapply(f, *(1,), **{'a':3}) 1 2 >>> mapply(f, *(1,), **{'b':3}) 1 3 >>> def f(a=1, b=2): ... print a, b >>> mapply(f, *(), **{'b':3}) 1 3 >>> mapply(f, *(), **{'a':3}) 3 2 sim_funciiiN(smethodsmshasattrsim_funcs func_codescodesgetargssfn_argsslistsargss call_argssNoneskwslensnkwsargsgets_markersvalueskeysslargssappend( smethodsargsskwsvaluescodeslargssfn_argssargsms call_argssnkw((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pysmapplyDsB0    "     cCs>t|ƒttgjo |i}nd|i|ifSdS(Ns%s.%s(stypesklasss ClassTypesExtensionClasss __class__s __module__s__name__(sklass((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys className”s cCs$tit}tii|iƒSdS(N(ssyssmoduless__name__smodulesosspathsdirnames__file__(smodule((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys productDir™s cCsQtƒ}|otii||ƒ}n|otii||ƒ}n|SdS(N(s productDirsbasespathsossjoinsfile(spathsfilesbase((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pyspathFors  cCs5|diƒo|diƒ|d}n|SdS(Nii(sstringsislowersupper(sstring((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys capitalize¦scCsFx;|D]3}|i|ƒo|||jo|Sq:qqWtSdS(N(s listofDictssdshas_keyskeysvaluesNone(s listofDictsskeysvaluesd((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pysfindDict«s cCs+|t|idƒ|idƒƒdSdS(Ns\s/i(spathsmaxsrfind(spath((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pysbasename´scCsYt|ƒ}|djogSnh}yx|D]}d||>> dl = DisplayList() Add some keys >>> dl.add('foo', 'bar') >>> dl.add('egg', 'spam') Assert some values >>> dl.index 2 >>> dl.keys() ['foo', 'egg'] >>> dl.values() ['bar', 'spam'] >>> dl.items() (('foo', 'bar'), ('egg', 'spam')) You can't use e.g. objects as keys or values >>> dl.add(object(), 'error') Traceback (most recent call last): TypeError: DisplayList keys must be strings or ints, got >>> dl.add('error', object()) Traceback (most recent call last): TypeError: DisplayList values must be strings or ints, got GOTCHA Adding a value a second time does overwrite the key, too! >>> dl.add('fobar' ,'spam') >>> dl.keys() ['foo', 'fobar'] >>> dl.items() (('foo', 'bar'), ('fobar', 'spam')) Install warning hook for the next tests since they will raise a warning and I don't want to spoil the logs. >>> from Testing.ZopeTestCase import WarningsHook >>> w = WarningsHook(); w.install() Using ints as DisplayList keys works but will raise an deprecation warning You should use IntDisplayList for int keys >>> idl = DisplayList() >>> idl.add(1, 'number one') >>> idl.add(2, 'just the second') >>> idl.items() ((1, 'number one'), (2, 'just the second')) >>> idl.getMsgId(1) 'number one' Remove warning hook >>> w.uninstall(); del w sallowcCsIh|_h|_h|_g|_d|_|o|i|ƒndS(Ni(sselfs_keyss _i18n_msgidss_valuess_itorsindexsdatasfromList(sselfsdata((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys__init__Bs     cCsd|t|ƒfSdS(Ns(sselfsid(sself((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys__repr__KscCst|ƒSdS(N(sstrsself(sself((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys__str__NscCs|SdS(N(sself(sself((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys__call__QscCsBx;|D]3}t|tƒot|ƒ}n|i|ŒqWdS(N(slstsitems isinstancesListTypestuplesselfsadd(sselfslstsitem((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pysfromListTs cCs |iSdS(N(sselfsindex(sself((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys__len__ZscCsŠt|iƒƒ}t|dƒo|iƒ}ntt||ƒƒ}|i}|i t |dhƒƒt ||ƒ}||_|SdS(Nsitemss _i18n_msgids(stuplesselfsitemssashasattrsothersbszips _i18n_msgidssmsgidssupdatesgetattrs DisplayListsv(sselfsothersasbsmsgidssv((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys__add__]s  cCs|d|dSdS(Ni(sasb(sselfsasb((s?/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/utils.pys index_sortkscCs3t|ƒtjotdƒnt|ƒtttfjotdt|ƒƒ‚nt|ƒtttfjotdt|ƒƒ‚nt|ƒtt fjotdt|ƒƒ‚n|i d7_ |i |f}|i |f}||i|<||i|<|ii|ƒ|o||i|                   sIntDisplayListcBsEtZdZeƒZeidƒed„Zed„Zd„Z RS(s‰Static display lists for integer keys, can look up on either side of the dict, and get them in sorted order The IntDisplayList can be used with integer values only. You should use it in favor of a DisplayList if you want to use ints as keys. The support for ints as keys for the ordinary DisplayList will be dropped in the next release. NOTE: Both keys and values *must* contain unique entries! You can have two times the same value. This is a "feature" not a bug. DisplayLists are meant to be used as a list inside html form entry like a drop down. >>> idl = IntDisplayList() Add some keys >>> idl.add(1, 'number one') >>> idl.add(2, 'just the second') Assert some values >>> idl.index 2 >>> idl.keys() [1, 2] >>> idl.values() ['number one', 'just the second'] >>> idl.items() ((1, 'number one'), (2, 'just the second')) You can use only ints as keys >>> idl.add(object(), 'error') Traceback (most recent call last): TypeError: DisplayList keys must be ints, got >>> idl.add(42, object()) Traceback (most recent call last): TypeError: DisplayList values must be strings or ints, got >>> idl.add('stringkey', 'error') Traceback (most recent call last): TypeError: DisplayList keys must be ints, got >>> idl.add(u'unicodekey', 'error') Traceback (most recent call last): TypeError: DisplayList keys must be ints, got GOTCHA Adding a value a second time does overwrite the key, too! >>> idl.add(3 , 'just the second') >>> idl.keys() [1, 3] >>> idl.items() ((1, 'number one'), (3, 'just the second')) It is possible to get the value also by a stringified int >>> idl.getValue("1") 'number one' >>> idl.getValue(u"1") 'number one' >>> idl.getMsgId(1) 'number one' sallowcCs t|ƒtj otdt|ƒƒ‚nt|ƒtttfjotdt|ƒƒ‚nt|ƒttfjotdt|ƒƒ‚n|i d7_ |i |f}|i |f}||i |<||i|<|ii|ƒ|o||i|