コード例 #1
0
    def __setitem__(self, n, v):
        if isinstance(n, int):  # d[1]
            self._dir[n] = v
        elif isinstance(n, slice):
            # d['foo':] adds a new foo
            n = n.start
            if self._dNS and not islst(n):
                n = (self._dNS, n)

            nv = Element(n)
            self._dir.append(nv)

        else:  # d["foo"] replaces first <foo> and dels rest
            if self._dNS and not islst(n):
                n = (self._dNS, n)

            nv = Element(n)
            nv._dir.append(v)
            replaced = False

            todel = []
            for i in xrange(len(self)):
                if self[i]._name == n:
                    if replaced:
                        todel.append(i)
                    else:
                        self[i] = nv
                        replaced = True
            if not replaced:
                self._dir.append(nv)
            for i in sorted(todel, reverse=True):
                del self[i]
コード例 #2
0
ファイル: xmltramp.py プロジェクト: hynekcer/Beatbox
    def __setitem__(self, n, v):
        if isinstance(n, int):  # d[1]
            self._dir[n] = v
        elif isinstance(n, slice):
            # d['foo':] adds a new foo
            n = n.start
            if self._dNS and not islst(n):
                n = (self._dNS, n)

            nv = Element(n)
            self._dir.append(nv)

        else:  # d["foo"] replaces first <foo> and dels rest
            if self._dNS and not islst(n):
                n = (self._dNS, n)

            nv = Element(n)
            nv._dir.append(v)
            replaced = False

            todel = []
            for i in xrange(len(self)):
                if self[i]._name == n:
                    if replaced:
                        todel.append(i)
                    else:
                        self[i] = nv
                        replaced = True
            if not replaced:
                self._dir.append(nv)
            for i in sorted(todel, reverse=True):
                del self[i]
コード例 #3
0
ファイル: _beatbox.py プロジェクト: wordpressramu/Beatbox
 def chunkRequests(self, collection, chunkLength=None):
     if not islst(collection):
         yield [collection]
     else:
         if chunkLength is None:
             chunkLength = self.batchSize
         for i in xrange(0, len(collection), chunkLength):
             yield collection[i:i + chunkLength]
コード例 #4
0
ファイル: _beatbox.py プロジェクト: hynekcer/Beatbox
 def chunkRequests(self, collection, chunkLength=None):
     if not islst(collection):
         yield [collection]
     else:
         if chunkLength is None:
             chunkLength = self.batchSize
         for i in xrange(0, len(collection), chunkLength):
             yield collection[i:i + chunkLength]