コード例 #1
0
 def __init__(self, scard, pcard):
     super(ProbTable, self).__init__()
     if not issequence(scard):
         scard = [scard]
     if not issequence(pcard):
         pcard = [pcard]
     self._nvars = len(scard)
     self._npars = len(pcard)
     self._cvars = tuple(scard)
     self._cpars = tuple(pcard)
     self._table = self._initTable(scard, pcard)
コード例 #2
0
 def __init__(self, scard, pcard):
     super(ProbTable, self).__init__()
     if not issequence(scard):
         scard = [scard]
     if not issequence(pcard):
         pcard = [pcard]
     self._nvars = len(scard)
     self._npars = len(pcard)
     self._cvars = tuple(scard)
     self._cpars = tuple(pcard)
     self._table = self._initTable(scard, pcard)
コード例 #3
0
    def extract(self, state):
        source = self._source
        if source is None:
            source = os.environ
        env_vars = self._manager.optionsWithSpecifier(EnvVar)
        multiple_vars  = self._manager.optionsWithSpecifier(Multiple) 
        multiple_vars |= self._manager.optionsWithSpecifier(JoinSources) # Union of sets
        prefix = self.getEnvPrefix()
        if not issequence(prefix):
            prefix = [prefix]
        if not prefix:
            prefix = [None]
        prefix = [p or '' for p in prefix]
        split_char = self.getSplitChar()

        for p in prefix:
            for var in env_vars:
                whole_var = (p+var).upper()
                if whole_var in source:
                    value = source[whole_var]
                    if var in multiple_vars:
                        for item in value.split(split_char):
                            state.append( (var, item, 'env:%s'%p, whole_var) )
                    else:
                        state.append( (var, value, 'env:%s'%p, whole_var) )
コード例 #4
0
    def extract(self, state):
        source = self._source
        if source is None:
            source = os.environ
        env_vars = self._manager.optionsWithSpecifier(EnvVar)
        multiple_vars = self._manager.optionsWithSpecifier(Multiple)
        multiple_vars |= self._manager.optionsWithSpecifier(
            JoinSources)  # Union of sets
        prefix = self.getEnvPrefix()
        if not issequence(prefix):
            prefix = [prefix]
        if not prefix:
            prefix = [None]
        prefix = [p or '' for p in prefix]
        split_char = self.getSplitChar()

        for p in prefix:
            for var in env_vars:
                whole_var = (p + var).upper()
                if whole_var in source:
                    value = source[whole_var]
                    if var in multiple_vars:
                        for item in value.split(split_char):
                            state.append((var, item, 'env:%s' % p, whole_var))
                    else:
                        state.append((var, value, 'env:%s' % p, whole_var))
コード例 #5
0
ファイル: externals.py プロジェクト: andymwood/Gmail-Backup
 def unifyExternalMethods(cls, em):
     ret = {}
     for meth_name, specifiers in em.iteritems():
         if issequence(specifiers):
             ret[meth_name] = set(specifiers)
         else:
             ret[meth_name] = set([specifiers])
     return ret
コード例 #6
0
 def unifyExternalMethods(cls, em):
     ret = {}
     for meth_name, specifiers in em.iteritems():
         if issequence(specifiers):
             ret[meth_name] = set(specifiers)
         else:
             ret[meth_name] = set([specifiers])
     return ret
コード例 #7
0
 def __getitem__(self, item):
     if not issequence(item):
         item = [item]
     if len(item) == 1:
         return self._objects[item[0]]
     elif len(item) == 2:
         return self._objects[item[0]][item[1]]
     else:
         raise IndexError('Invalid index: %r' % item)
コード例 #8
0
 def __getitem__(self, item):
     if not issequence(item):
         item = [item]
     if len(item) == 1:
         return self._objects[item[0]]
     elif len(item) == 2:
         return self._objects[item[0]][item[1]]
     else:
         raise IndexError('Invalid index: %r' % item)
コード例 #9
0
 def createConceptGroups(self, grp):
     if not issequence(grp):
         grp = [grp]
     ret = []
     for item in grp:
         for i in item.split(','):
             if i.startswith('@'):
                 ret.extend(CONCEPT_GROUPS.get(i[1:], []))
             else:
                 ret.append(i)
     return set(ret)
コード例 #10
0
 def createConceptGroups(self, grp):
     if not issequence(grp):
         grp = [grp]
     ret = []
     for item in grp:
         for i in item.split(','):
             if i.startswith('@'):
                 ret.extend(CONCEPT_GROUPS.get(i[1:], []))
             else:
                 ret.append(i)
     return set(ret)
コード例 #11
0
 def createFilterChain(self, filters):
     if not filters:
         raise ValueError('You must specify some filters')
     if not issequence(filters):
         filters = [filters]
     chain = []
     for f in filters:
         if chain:
             chain[-1].setContentHandler(f)
         chain.append(f)
     return chain[0], chain[-1]
コード例 #12
0
    def _prepareSource(self, source):
        """Předpřipraví zdroj `source`

        Je-li `source` None, vrátí [], není-li `source` posloupnost, vrátí
        ``[source]``. Ve výsledku expanduje znak tilda ``~`` na domovský
        adresář aktuálního uživatele. Z výsledku odstraní již zpracované
        soubory podle `processedFiles`.

        :See:
            processedFiles
        """
        if source is None:
            source = []
        elif not issequence(source):
            source = [source]
        source = [f for f in (expanduser(f) for f in source) if isfile(f)]
        source = [f for f in source if f not in self.processedFiles]
        return source
コード例 #13
0
    def _prepareSource(self, source):
        """Předpřipraví zdroj `source`

        Je-li `source` None, vrátí [], není-li `source` posloupnost, vrátí
        ``[source]``. Ve výsledku expanduje znak tilda ``~`` na domovský
        adresář aktuálního uživatele. Z výsledku odstraní již zpracované
        soubory podle `processedFiles`.

        :See:
            processedFiles
        """
        if source is None:
            source = []
        elif not issequence(source):
            source = [source]
        source = [f for f in (expanduser(f) for f in source) if isfile(f)]
        source = [f for f in source if f not in self.processedFiles]
        return source
コード例 #14
0
    def getHelpDict(self, screenWidth=None):
        if screenWidth is None:
            screenWidth = self._screenWidth

        option_help = {}

        for ehelp in self._ex_help:
            if ehelp is None:
                continue
            for opt_name, opt_desc in ehelp.iteritems():
                if opt_name not in option_help:
                    option_help[opt_name] = []
                if not issequence(opt_desc):
                    opt_desc = [opt_desc]
                option_help[opt_name].extend(opt_desc)

        max_desc_width = 0

        manager_help = self._manager.helpForOptions

        for opt_name in option_help:
            opt_doc = manager_help.get(opt_name, '')
            opt_desc = option_help[opt_name]
            opt_desc = ', '.join(opt_desc)
            max_desc_width = max(max_desc_width, len(opt_desc))
            option_help[opt_name] = (opt_desc, opt_doc)

        padding = 2

        template = '%%-%ds' % max_desc_width + ' ' * padding

        wrap_width = max(screenWidth - max_desc_width - padding, 30)

        str_help = {}
        for opt_name, (opt_desc, opt_doc) in option_help.iteritems():
            par = []
            lines = self._wrapParagraphs(opt_doc,
                                         wrap_width).splitlines() or ['']
            for line in lines:
                par.append(template % opt_desc + line)
                opt_desc = ''
            str_help[opt_name] = '\n'.join(par).rstrip()
        return str_help
コード例 #15
0
    def getHelpDict(self, screenWidth=None):
        if screenWidth is None:
            screenWidth = self._screenWidth

        option_help = {}

        for ehelp in self._ex_help:
            if ehelp is None:
                continue
            for opt_name, opt_desc in ehelp.iteritems():
                if opt_name not in option_help:
                    option_help[opt_name] = []
                if not issequence(opt_desc):
                    opt_desc = [opt_desc]
                option_help[opt_name].extend(opt_desc)

        max_desc_width = 0

        manager_help = self._manager.helpForOptions

        for opt_name in option_help:
            opt_doc = manager_help.get(opt_name, '')
            opt_desc = option_help[opt_name]
            opt_desc = ', '.join(opt_desc)
            max_desc_width = max(max_desc_width, len(opt_desc))
            option_help[opt_name] = (opt_desc, opt_doc)

        padding = 2

        template = '%%-%ds' % max_desc_width + ' '*padding

        wrap_width = max(screenWidth - max_desc_width - padding, 30)

        str_help = {} 
        for opt_name, (opt_desc, opt_doc) in option_help.iteritems():
            par = []
            lines = self._wrapParagraphs(opt_doc, wrap_width).splitlines() or ['']
            for line in lines:
                par.append(template % opt_desc + line)
                opt_desc = ''
            str_help[opt_name] = '\n'.join(par).rstrip()
        return str_help
コード例 #16
0
 def _convertSlices(self, item):
     var = []
     cond = []
     cur = var
     if not issequence(item):
         item = [item]
     for i in item:
         if isinstance(i, slice):
             if cur is cond:
                 raise ValueError("Malformed probability index")
             if i.step is not None:
                 raise ValueError("Malformed probability index")
             if i.start is not None:
                 var.append(i.start)
             if i.stop is None:
                 raise ValueError("Malformed probability index")
             else:
                 cond.append(i.stop)
             cur = cond
         else:
             cur.append(i)
     return tuple(var), tuple(cond)
コード例 #17
0
 def _convertSlices(self, item):
     var = []
     cond = []
     cur = var
     if not issequence(item):
         item = [item]
     for i in item:
         if isinstance(i, slice):
             if cur is cond:
                 raise ValueError("Malformed probability index")
             if i.step is not None:
                 raise ValueError("Malformed probability index")
             if i.start is not None:
                 var.append(i.start)
             if i.stop is None:
                 raise ValueError("Malformed probability index")
             else:
                 cond.append(i.stop)
             cur = cond
         else:
             cur.append(i)
     return tuple(var), tuple(cond)