mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 00:22:28 +02:00
For reference, a buggy attempt to implement slicing
but slice assignment seems to mangle the .spaced list in some cases
This commit is contained in:
@@ -76,7 +76,6 @@ class RawNginxDumper(object):
|
||||
yield b0
|
||||
continue
|
||||
b = copy.deepcopy(b0)
|
||||
indentation = ""
|
||||
if spacey(b[0]):
|
||||
yield b.pop(0) # indentation
|
||||
if not b:
|
||||
@@ -197,7 +196,7 @@ class UnspacedList(list):
|
||||
|
||||
def insert(self, i, x):
|
||||
item, spaced_item = self._coerce(x)
|
||||
self.spaced.insert(i + self._spaces_before(i), spaced_item)
|
||||
self.spaced.insert(self._spaced_position(i), spaced_item)
|
||||
list.insert(self, i, item)
|
||||
|
||||
def append(self, x):
|
||||
@@ -215,13 +214,28 @@ class UnspacedList(list):
|
||||
l.extend(other)
|
||||
return l
|
||||
|
||||
def __setslice__(self, i, j, newslice):
|
||||
for idx in reversed(range(self._spaced_position(i), self._spaced_position(j))):
|
||||
print "delspace", idx
|
||||
del self.spaced[idx]
|
||||
for idx in reversed(range(i,j)):
|
||||
print "del", idx
|
||||
list.__delitem__(self, idx)
|
||||
for idx, item in enumerate(newslice):
|
||||
self.insert(i + idx, item)
|
||||
|
||||
def __setitem__(self, i, value):
|
||||
if isinstance(i, slice):
|
||||
#raise NotImplementedError("Slice operations on UnspacedLists not yet implemented")
|
||||
for pos in xrange(i.start or 0, i.stop or len(self), i.step or 1):
|
||||
self.__setitem__(pos, value)
|
||||
return
|
||||
item, spaced_item = self._coerce(value)
|
||||
self.spaced.__setitem__(i + self._spaces_before(i), spaced_item)
|
||||
self.spaced.__setitem__(self._spaced_position(i), spaced_item)
|
||||
list.__setitem__(self, i, item)
|
||||
|
||||
def __delitem__(self, i):
|
||||
self.spaced.__delitem__(i + self._spaces_before(i))
|
||||
self.spaced.__delitem__(self._spaced_position(i))
|
||||
list.__delitem__(self, i)
|
||||
|
||||
def __deepcopy__(self, unused_memo):
|
||||
@@ -230,14 +244,17 @@ class UnspacedList(list):
|
||||
return l
|
||||
|
||||
|
||||
def _spaces_before(self, idx):
|
||||
"Count the number of spaces in the spaced list before pos idx in the spaceless one"
|
||||
def _spaced_position(self, idx):
|
||||
"Convert from indexes in the unspaced list to positions in the spaced one"
|
||||
print "lookup", idx
|
||||
spaces = 0
|
||||
pos = 0
|
||||
if idx < 0:
|
||||
idx = len(self) + idx
|
||||
while idx != -1:
|
||||
if spacey(self.spaced[pos]):
|
||||
spaces += 1
|
||||
else:
|
||||
idx -= 1
|
||||
pos += 1
|
||||
return spaces
|
||||
return idx + spaces
|
||||
|
||||
Reference in New Issue
Block a user