Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2ed9df

Browse files
committed
Fixed bugs regarding lines starting with '.' (both receiving and sending).
Added a minimal test function.
1 parent e20aef5 commit e2ed9df

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

Lib/nntplib.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def getlongresp(self):
137137
line = self.getline()
138138
if line == '.':
139139
break
140+
if line[:2] == '..':
141+
line = line[1:]
140142
list.append(line)
141143
return resp, list
142144

@@ -407,8 +409,8 @@ def post(self, f):
407409
break
408410
if line[-1] == '\n':
409411
line = line[:-1]
410-
if line == '.':
411-
line = '..'
412+
if line[:1] == '.':
413+
line = '.' + line
412414
self.putline(line)
413415
self.putline('.')
414416
return self.getresp()
@@ -431,8 +433,8 @@ def ihave(self, id, f):
431433
break
432434
if line[-1] == '\n':
433435
line = line[:-1]
434-
if line == '.':
435-
line = '..'
436+
if line[:1] == '.':
437+
line = '.' + line
436438
self.putline(line)
437439
self.putline('.')
438440
return self.getresp()
@@ -446,3 +448,22 @@ def quit(self):
446448
self.sock.close()
447449
del self.file, self.sock
448450
return resp
451+
452+
453+
# Minimal test function
454+
def _test():
455+
s = NNTP('news')
456+
resp, count, first, last, name = s.group('comp.lang.python')
457+
print resp
458+
print 'Group', name, 'has', count, 'articles, range', first, 'to', last
459+
resp, subs = s.xhdr('subject', first + '-' + last)
460+
print resp
461+
for item in subs:
462+
print "%7s %s" % item
463+
resp = s.quit()
464+
print resp
465+
466+
467+
# Run the test when run as a script
468+
if __name__ == '__main__':
469+
_test()

0 commit comments

Comments
 (0)