eaiovnaovbqoebvqoeavibavo 3 C] @s<GdddeZGdddeZGdddeZddZdS) c@sheZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)ConfigNamespaceaAbstract class representing the interface of Config objects. A ConfigNamespace is a collection of names mapped to values, where the values may be nested namespaces. Values can be accessed via container notation - obj[key] - or via dotted notation - obj.key. Both these access methods are equivalent. To minimize name conflicts between namespace keys and class members, the number of class members should be minimized, and the names of all class members should start with an underscore. Subclasses must implement the methods for container-like access, and this class will automatically provide dotted access. cCst|S)N)NotImplementedError)selfkeyr/usr/lib/python3.6/config.py_getitemszConfigNamespace._getitemcCst||dS)N)r)rrvaluerrr __setitem__szConfigNamespace.__setitem__cCs t|dS)N)r)rrrrr __delitem__szConfigNamespace.__delitem__cCstS)N)r)rrrr__iter__szConfigNamespace.__iter__cCs t|dS)N)r)rnamerrr_new_namespace szConfigNamespace._new_namespacec Cs(y|j|Wntk r"dSXdS)NFT)rKeyError)rrrrr __contains__#s zConfigNamespace.__contains__c Cs*y |j|Stk r$t||SXdS)N)rr Undefined)rrrrr __getitem__6s zConfigNamespace.__getitem__c CsBy |j|Stk r<|jdr2|jdr2tt||SXdS)N__)rr startswithendswithAttributeErrorr)rr rrr __getattr__<s  zConfigNamespace.__getattr__c CsDytj||tj|||Wn tk r>|j||YnXdS)N)object__getattribute__ __setattr__rr )rr rrrrrDs  zConfigNamespace.__setattr__c Cs@ytj||tj||Wntk r:|j|YnXdS)N)rr __delattr__rr )rr rrrrKs  zConfigNamespace.__delattr__cCs|jj|dS)N)__dict__update)rstaterrr __setstate__VszConfigNamespace.__setstate__N)__name__ __module__ __qualname____doc__rr r r r rrrrrrrrrrrs rc@s(eZdZdZddZddZddZdS) raHelper class used to hold undefined names until assignment. This class helps create any undefined subsections when an assignment is made to a nested value. For example, if the statement is "cfg.a.b.c = 42", but "cfg.a.b" does not exist yet. cCs tj|d|tj|d|dS)Nr namespace)rr)rr r#rrr__init__aszUndefined.__init__cCs|jj|j}|||<dS)N)r#r r )rr robjrrrreszUndefined.__setattr__cCs|jj|j}|||<dS)N)r#r r )rr rr%rrrr iszUndefined.__setitem__N)rr r!r"r$rr rrrrrYsrc@sVeZdZdZdZddZddZddZd d Zd d Z dddZ ddZ ddZ dS) BasicConfigaRepresents a hierarchical collection of named values. Values are added using dotted notation: >>> n = BasicConfig() >>> n.x = 7 >>> n.name.first = 'paramjit' >>> n.name.last = 'oberoi' ...and accessed the same way, or with [...]: >>> n.x 7 >>> n.name.first 'paramjit' >>> n.name.last 'oberoi' >>> n['x'] 7 >>> n['name']['first'] 'paramjit' Iterating over the namespace object returns the keys: >>> l = list(n) >>> l.sort() >>> l ['name', 'x'] Values can be deleted using 'del' and printed using 'print'. >>> n.aaa = 42 >>> del n.x >>> print(n) aaa = 42 name.first = paramjit name.last = oberoi Nested namepsaces are also namespaces: >>> isinstance(n.name, ConfigNamespace) True >>> print(n.name) first = paramjit last = oberoi >>> sorted(list(n.name)) ['first', 'last'] Finally, values can be read from a file as follows: >>> from six import StringIO >>> sio = StringIO(''' ... # comment ... ui.height = 100 ... ui.width = 150 ... complexity = medium ... have_python ... data.secret.password = goodness=gracious me ... ''') >>> n = BasicConfig() >>> n._readfp(sio) >>> print(n) complexity = medium data.secret.password = goodness=gracious me have_python ui.height = 100 ui.width = 150 NcCs i|_dS)N)_data)rrrrr$szBasicConfig.__init__cCs |j|S)N)r')rrrrrrszBasicConfig._getitemcCs||j|<dS)N)r')rrrrrrr szBasicConfig.__setitem__cCs |j|=dS)N)r')rrrrrr szBasicConfig.__delitem__cCs t|jS)N)iterr')rrrrr szBasicConfig.__iter__cCsg}t|jj}|jxl|D]d}|j|}t|trT|j|jd||fdq |dkrp|jd||fq |jd|||fq Wdj|S)Nz%s%s.)prefixz%s%sz %s%s = %s ) listr'keyssort isinstancerappend__str__join)rr*linesr-r rrrrr1s   zBasicConfig.__str__cCst}||j|<|S)N)r&r')rr r%rrrr s zBasicConfig._new_namespacec Csx|j}|sP|j}|sq|ddkr,q|jdd}t|dkrN|}d}n|dj}|dj}|jd}|}xD|ddD]4}||kr||}t|tstd|q|j|}qW|||d<qWdS) N#=.zvalue-namespace conflictr9)readlinestripsplitlenr/r TypeErrorr ) rfplinedatar rZname_componentsnsnrrr_readfps0        zBasicConfig._readfp)r)) rr r!r"r'r$rr r r r1r rDrrrrr&psD r&cCsjxdt|D]X}||}t|trZ||krD||}t|tsNtdn |j|}t||q |||<q WdS)aImports values from source into target. Recursively walks the ConfigNamespace and inserts values into the ConfigNamespace. For example: >>> n = BasicConfig() >>> n.playlist.expand_playlist = True >>> n.ui.display_clock = True >>> n.ui.display_qlength = True >>> n.ui.width = 150 >>> print(n) playlist.expand_playlist = True ui.display_clock = True ui.display_qlength = True ui.width = 150 >>> from iniparse import ini >>> i = ini.INIConfig() >>> update_config(i, n) >>> print(i) [playlist] expand_playlist = True [ui] display_clock = True display_qlength = True width = 150 zvalue-namespace conflictN)sortedr/rr>r update_config)targetsourcer rZmynsrrrrFs     rFN)rrrr&rFrrrrsX