|
Revision 304:239f24fbd17c, 1.4 KB
(checked in by Menno Smits <menno@…>, 2 weeks ago)
|
|
updated copyright date to 2012
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | """ |
|---|
| 6 | Work-around for Python Issue 5943 (http://bugs.python.org/issue5949). |
|---|
| 7 | |
|---|
| 8 | This will patch imaplib's IMAP4_SSL.readline method with the fixed |
|---|
| 9 | verion in Python versions that are known to have the problem. |
|---|
| 10 | |
|---|
| 11 | The problem definitely exists in Python 2.5 and 2.6 up until but not |
|---|
| 12 | including 2.6.5. It was also fixed in Python 2.7 alpha 2 so no attempt |
|---|
| 13 | is made to patch 2.7 versions. |
|---|
| 14 | |
|---|
| 15 | Please let me know if there's more Python versions that should be |
|---|
| 16 | patched. |
|---|
| 17 | |
|---|
| 18 | Efforts are made to only perform the patch once. |
|---|
| 19 | """ |
|---|
| 20 | |
|---|
| 21 | import sys |
|---|
| 22 | import imaplib |
|---|
| 23 | |
|---|
| 24 | def _is_affected_version(sys_version): |
|---|
| 25 | sys_version = sys_version[:3] |
|---|
| 26 | if sys_version < (2, 5, 0): |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | return False |
|---|
| 30 | elif sys_version < (2, 6, 5): |
|---|
| 31 | return True |
|---|
| 32 | return False |
|---|
| 33 | |
|---|
| 34 | def _fixed_readline(self): |
|---|
| 35 | """Read line from remote.""" |
|---|
| 36 | line = [] |
|---|
| 37 | while 1: |
|---|
| 38 | char = self.sslobj.read(1) |
|---|
| 39 | line.append(char) |
|---|
| 40 | if char in ("\n", ""): return ''.join(line) |
|---|
| 41 | |
|---|
| 42 | _fixed_readline.patched = True |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | ssl_class = imaplib.IMAP4_SSL |
|---|
| 46 | |
|---|
| 47 | if _is_affected_version(sys.version_info) and not hasattr(ssl_class.readline, 'patched'): |
|---|
| 48 | ssl_class.readline = _fixed_readline |
|---|