0001-Fix-syntax-for-python3.7.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. From ef2bd5d0c0ca66aae16bf1344dfb18d52a6f5c74 Mon Sep 17 00:00:00 2001
  2. From: Asaf Kahlon <asafka7@gmail.com>
  3. Date: Wed, 26 Sep 2018 17:47:02 +0300
  4. Subject: [PATCH 1/1] Fix syntax for python3.7
  5. Based on upstream patch (dcaf946217b4ea1684e98a9ebc4f9925d76f3108)
  6. to solve python3.7 syntax error with "async" keyword.
  7. Signed-off-by: Asaf Kahlon <asafka7@gmail.com>
  8. ---
  9. src/twisted/conch/manhole.py | 15 ++++++++-------
  10. src/twisted/mail/imap4.py | 19 +++++++++++--------
  11. src/twisted/python/compat.py | 24 ++++++++++++++++++++++++
  12. 3 files changed, 43 insertions(+), 15 deletions(-)
  13. diff --git a/src/twisted/conch/manhole.py b/src/twisted/conch/manhole.py
  14. index 3326f90aa..17ca05c58 100644
  15. --- a/src/twisted/conch/manhole.py
  16. +++ b/src/twisted/conch/manhole.py
  17. @@ -19,7 +19,7 @@ from io import BytesIO
  18. from twisted.conch import recvline
  19. from twisted.internet import defer
  20. -from twisted.python.compat import _tokenize
  21. +from twisted.python.compat import _tokenize, get_async_param
  22. from twisted.python.htmlizer import TokenPrinter
  23. class FileWrapper:
  24. @@ -151,9 +151,9 @@ class ManholeInterpreter(code.InteractiveInterpreter):
  25. return failure
  26. - def write(self, data, async=False):
  27. - self.handler.addOutput(data, async)
  28. -
  29. + def write(self, data, async_=None, **kwargs):
  30. + async_ = get_async_param(async_, **kwargs)
  31. + self.handler.addOutput(data, async_)
  32. CTRL_C = b'\x03'
  33. @@ -237,14 +237,15 @@ class Manhole(recvline.HistoricRecvLine):
  34. return not w.endswith(b'\n') and not w.endswith(b'\x1bE')
  35. - def addOutput(self, data, async=False):
  36. - if async:
  37. + def addOutput(self, data, async_=None, **kwargs):
  38. + async_ = get_async_param(async_, **kwargs)
  39. + if async_:
  40. self.terminal.eraseLine()
  41. self.terminal.cursorBackward(len(self.lineBuffer) + len(self.ps[self.pn]))
  42. self.terminal.write(data)
  43. - if async:
  44. + if async_:
  45. if self._needsNewline():
  46. self.terminal.nextLine()
  47. diff --git a/src/twisted/mail/imap4.py b/src/twisted/mail/imap4.py
  48. index 0ca1f1c5e..295053a6c 100644
  49. --- a/src/twisted/mail/imap4.py
  50. +++ b/src/twisted/mail/imap4.py
  51. @@ -42,7 +42,7 @@ from twisted.python.compat import (
  52. _bytesChr, unichr as chr, _b64decodebytes as decodebytes,
  53. _b64encodebytes as encodebytes,
  54. intToBytes, iterbytes, long, nativeString, networkString, unicode,
  55. - _matchingString, _PY3
  56. + _matchingString, _PY3, get_async_param,
  57. )
  58. from twisted.internet import interfaces
  59. @@ -1090,8 +1090,9 @@ class IMAP4Server(basic.LineReceiver, policies.TimeoutMixin):
  60. self._respond(b'NO', tag, message)
  61. - def sendUntaggedResponse(self, message, async=False):
  62. - if not async or (self.blocked is None):
  63. + def sendUntaggedResponse(self, message, async_=None, **kwargs):
  64. + async_ = get_async_param(async_, **kwargs)
  65. + if not async_ or (self.blocked is None):
  66. self._respond(message, None, None)
  67. else:
  68. self._queuedAsync.append(message)
  69. @@ -2497,9 +2498,9 @@ class IMAP4Server(basic.LineReceiver, policies.TimeoutMixin):
  70. #
  71. def modeChanged(self, writeable):
  72. if writeable:
  73. - self.sendUntaggedResponse(message=b'[READ-WRITE]', async=True)
  74. + self.sendUntaggedResponse(message=b'[READ-WRITE]', async_=True)
  75. else:
  76. - self.sendUntaggedResponse(message=b'[READ-ONLY]', async=True)
  77. + self.sendUntaggedResponse(message=b'[READ-ONLY]', async_=True)
  78. def flagsChanged(self, newFlags):
  79. @@ -2508,14 +2509,16 @@ class IMAP4Server(basic.LineReceiver, policies.TimeoutMixin):
  80. msg = intToBytes(mId) + (
  81. b' FETCH (FLAGS (' +b' '.join(encodedFlags) + b'))'
  82. )
  83. - self.sendUntaggedResponse(msg, async=True)
  84. + self.sendUntaggedResponse(msg, async_=True)
  85. def newMessages(self, exists, recent):
  86. if exists is not None:
  87. - self.sendUntaggedResponse(intToBytes(exists) + b' EXISTS', async=True)
  88. + self.sendUntaggedResponse(
  89. + intToBytes(exists) + b' EXISTS', async_=True)
  90. if recent is not None:
  91. - self.sendUntaggedResponse(intToBytes(recent) + b' RECENT', async=True)
  92. + self.sendUntaggedResponse(
  93. + intToBytes(recent) + b' RECENT', async_=True)
  94. TIMEOUT_ERROR = error.TimeoutError()
  95. diff --git a/src/twisted/python/compat.py b/src/twisted/python/compat.py
  96. index 855e427aa..ba13bb4dd 100644
  97. --- a/src/twisted/python/compat.py
  98. +++ b/src/twisted/python/compat.py
  99. @@ -833,6 +833,29 @@ except ImportError:
  100. from collections import Sequence
  101. +def get_async_param(async_=None, **kwargs):
  102. + """
  103. + Provide a backwards-compatible way to get async param value that does not
  104. + cause a syntax error under Python 3.7.
  105. +
  106. + @param async_: async_ param value (should default to None)
  107. + @type async_: L{bool}
  108. +
  109. + @param kwargs: keyword arguments of the caller (only async is allowed)
  110. + @type async_: L{dict}
  111. +
  112. + @raise TypeError: Both async_ and async specified.
  113. +
  114. + @return: Final async_ param value
  115. + @rtype: L{bool}
  116. + """
  117. + if async_ is None and 'async' in kwargs:
  118. + async_ = kwargs.pop('async')
  119. + if kwargs:
  120. + raise TypeError
  121. + return bool(async_)
  122. +
  123. +
  124. __all__ = [
  125. "reraise",
  126. "execfile",
  127. @@ -874,4 +897,5 @@ __all__ = [
  128. "raw_input",
  129. "_tokenize",
  130. "Sequence",
  131. + "get_async_param",
  132. ]
  133. --
  134. 2.17.1