コード例 #1
0
ファイル: utils.py プロジェクト: AnneGilles/node.ext.python
 def set(self, fromimport=None, names=None):
     if fromimport is None and names is None:
         raise ValueError(u"No definitions given.")
     imports = self.context.imports()
     if len(imports) == 0:
         import_ = Import(fromimport, names)
         import_.__name__ = str(import_.uuid)
         self._add(import_)
         return
     existent = False
     for imp in imports:
         if imp.fromimport == fromimport:
             existent = True
     if not existent:
         import_ = Import(fromimport, names)
         import_.__name__ = str(import_.uuid)
         self._add(import_)
         return
     for imp in imports:
         if imp.fromimport == fromimport:
             for name in names:
                 update = False
                 for iname, asname in imp.names:
                     if iname == name[0]:
                         update = True
             if update:
                 for i in range(len(imp.names)):
                     if imp.names[i][0] == name[0]:
                         imp.names[i] = name
             else:
                 imp.names.append(name)
コード例 #2
0
 def set(self, fromimport=None, names=None):
     if fromimport is None and names is None:
         raise ValueError(u"No definitions given.")
     imports = self.context.imports()
     if len(imports) == 0:
         import_ = Import(fromimport, names)
         import_.__name__ = str(import_.uuid)
         self._add(import_)
         return
     existent = False
     for imp in imports:
         if imp.fromimport == fromimport:
             existent = True
     if not existent:
         import_ = Import(fromimport, names)
         import_.__name__ = str(import_.uuid)
         self._add(import_)
         return
     for imp in imports:
         if imp.fromimport == fromimport:
             for name in names:
                 update = False
                 for iname, asname in imp.names:
                     if iname == name[0]:
                         update = True
             if update:
                 for i in range(len(imp.names)):
                     if imp.names[i][0] == name[0]:
                         imp.names[i] = name
             else:
                 imp.names.append(name)
コード例 #3
0
ファイル: utils.py プロジェクト: bluedynamics/node.ext.python
    def set(self, fromimport=None, names=None):

        if fromimport is None and names is None:
            raise ValueError(u"No definitions given.")
        
        if type(names) == str:
            #accept names to be a string and convert if necessary
            names = [[names, None]]
        else:
            # convert entries to [name,None] if the entry is a string
            [type(n) == str and [n, None] or n for n in names]
        
        imports = self.context.imports()
        if len(imports) == 0:
            import_ = Import(fromimport, names)
            import_.__name__ = str(import_.uuid)
            self._add(import_)
            return
        existent = False
        for imp in imports:
            if imp.fromimport == fromimport:
                existent = True
        if not existent:
            import_ = Import(fromimport, names)
            import_.__name__ = str(import_.uuid)
            self._add(import_)
            return
        for imp in imports:
            if imp.fromimport == fromimport:
                for name in names:
                    update = False
                    for iname, asname in imp.names:
                        if iname == name[0]:
                            update = True
                if update:
                    for i in range(len(imp.names)):
                        if imp.names[i][0] == name[0]:
                            imp.names[i] = name
                else:
                    imp.names.append(name)