Skip to content

Commit

Permalink
Merge branch 'trunk' into 10002-mypy-internet
Browse files Browse the repository at this point in the history
  • Loading branch information
wsanchez authored Oct 12, 2020
2 parents 2f90db9 + 95ebd69 commit 7e3bb33
Show file tree
Hide file tree
Showing 29 changed files with 331 additions and 485 deletions.
12 changes: 6 additions & 6 deletions docs/core/development/policy/coding-standard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ This makes the script more portable but note that it is not a foolproof method.
Always make sure that ``/usr/bin/env`` exists or use a softlink/symbolic link to point it to the correct path.
Python's distutils will rewrite the shebang line upon installation so this policy only covers the source files in version control.

#. For core scripts, add an entry to ``_CONSOLE_SCRIPTS`` in ``src/twisted/python/_setup.py``:
#. For core scripts, add an entry point to ``"console_scripts"`` in ``setup.cfg``:

.. code-block:: python
.. code-block:: cfg
_CONSOLE_SCRIPTS = [
[options.entry_points]
console_scripts =
...
"twistd = twisted.scripts.twistd:run",
"yourmodule" = "twisted.scripts.yourmodule:run",
]
twistd = twisted.scripts.twistd:run
yourmodule = twisted.scripts.yourmodule:run
#. And end with:

Expand Down
6 changes: 1 addition & 5 deletions docs/core/howto/python3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ Porting to Python 3
Introduction
------------

Twisted is currently being ported to work with Python 3.5+.
Twisted currently supports only Python 3.5+.
This document covers Twisted-specific issues in porting your code to Python 3.

Most, but not all, of Twisted has been ported, and therefore only a subset of modules are installed under Python 3.
You can see the remaining modules that need to be ported at :api:`twisted.python._setup.notPortedModules <twisted.python._setup.notPortedModules>`, if it is not listed there, then most of all of that module will be ported.


API Differences
---------------

Expand Down
33 changes: 0 additions & 33 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ allow_untyped_defs = True
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.conch.insults.insults]
warn_return_any = False

[mypy-twisted.conch.ssh.channel]
warn_return_any = False

[mypy-twisted.conch.ssh.keys]
warn_return_any = False

Expand Down Expand Up @@ -510,15 +504,6 @@ check_untyped_defs = False
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.mail._except]
warn_return_any = False

[mypy-twisted.mail.imap4]
warn_return_any = False

[mypy-twisted.mail.smtp]
warn_return_any = False

[mypy-twisted.mail.relaymanager]
allow_incomplete_defs = True

Expand All @@ -532,9 +517,6 @@ warn_return_any = False
[mypy-twisted.names.dns]
warn_return_any = False

[mypy-twisted.names.test.test_dns]
warn_return_any = False

[mypy-twisted.pair.*]
allow_untyped_defs = True
check_untyped_defs = False
Expand All @@ -559,12 +541,6 @@ check_untyped_defs = False
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.protocols.amp]
warn_return_any = False

[mypy-twisted.protocols.sip]
warn_return_any = False

[mypy-twisted.protocols.test.test_basic]
allow_incomplete_defs = True

Expand Down Expand Up @@ -808,9 +784,6 @@ check_untyped_defs = False
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.web.error]
warn_return_any = False

[mypy-twisted.web.util]
allow_incomplete_defs = True

Expand All @@ -820,12 +793,6 @@ check_untyped_defs = False

[mypy-twisted.words.im.basesupport]
allow_incomplete_defs = True

[mypy-twisted.words.im.locals]
warn_return_any = False

[mypy-twisted.words.protocols.jabber.jid]
warn_return_any = False

[mypy-twisted.words.xish.domish]
warn_return_any = False
62 changes: 62 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[metadata]
name = Twisted
version = attr: src.twisted.__version__
description = An asynchronous networking framework written in Python
author = Twisted Matrix Laboratories
author_email = twisted-python@twistedmatrix.com
maintainer = Glyph Lefkowitz
maintainer_email = glyph@twistedmatrix.com
url = https://twistedmatrix.com/
project_urls =
Documentation=https://twistedmatrix.com/documents/current/
Source=https://github.com/twisted/twisted
Issues=https://twistedmatrix.com/trac/report
license = MIT
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
long_description_content_type = text/x-rst

[options]
python_requires = >=3.5.2
install_requires =
zope.interface >= 4.4.2
constantly >= 15.1
incremental >= 16.10.1
Automat >= 0.8.0
hyperlink >= 17.1.1
PyHamcrest >= 1.9.0
attrs >= 19.2.0
setup_requires = incremental >= 16.10.1
include_package_data = True
zip_safe = False
package_dir = =src
packages = find:

[options.packages.find]
where = src

[options.entry_points]
console_scripts =
ckeygen = twisted.conch.scripts.ckeygen:run
cftp = twisted.conch.scripts.cftp:run
conch = twisted.conch.scripts.conch:run
mailmail = twisted.mail.scripts.mailmail:run
pyhtmlizer = twisted.scripts.htmlizer:run
tkconch = twisted.conch.scripts.tkconch:run
trial = twisted.scripts.trial:run
twist = twisted.application.twist._twist:Twist.main
twistd = twisted.scripts.twistd:run

[options.exclude_package_data]
* =
*.c
*.h
*.pxi
*.pyx
build.bat
4 changes: 2 additions & 2 deletions src/twisted/conch/insults/insults.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,13 @@ class _const:
@ivar name: A string naming this constant
"""

def __init__(self, name):
def __init__(self, name: str) -> None:
self.name = name

def __repr__(self) -> str:
return "[" + self.name + "]"

def __bytes__(self):
def __bytes__(self) -> bytes:
return ("[" + self.name + "]").encode("ascii")


Expand Down
14 changes: 7 additions & 7 deletions src/twisted/conch/ssh/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from zope.interface import implementer

from twisted.python import log
from twisted.python.compat import nativeString
from twisted.internet import interfaces
from twisted.logger import Logger

Expand Down Expand Up @@ -83,9 +82,9 @@ def __init__(
self.id = None # gets set later by SSHConnection

def __str__(self) -> str:
return nativeString(self.__bytes__())
return self.__bytes__().decode("ascii")

def __bytes__(self):
def __bytes__(self) -> bytes:
"""
Return a byte string representation of the channel
"""
Expand All @@ -101,9 +100,10 @@ def __bytes__(self):

def logPrefix(self):
id = (self.id is not None and str(self.id)) or "unknown"
name = self.name
if name:
name = nativeString(name)
if self.name:
name = self.name.decode("ascii")
else:
name = "None"
return "SSHChannel %s (%s) on %s" % (name, id, self.conn.logPrefix())

def channelOpen(self, specificData):
Expand Down Expand Up @@ -156,7 +156,7 @@ def requestReceived(self, requestType, data):
@type data: L{bytes}
@rtype: L{bool}
"""
foo = nativeString(requestType.replace(b"-", b"_"))
foo = requestType.replace(b"-", b"_").decode("ascii")
f = getattr(self, "request_" + foo, None)
if f:
return f(data)
Expand Down
28 changes: 17 additions & 11 deletions src/twisted/mail/_except.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Exceptions in L{twisted.mail}.
"""

from typing import Optional


class IMAP4Exception(Exception):
pass
Expand Down Expand Up @@ -94,25 +96,32 @@ class SMTPClientError(SMTPError):
"""

def __init__(
self, code, resp, log=None, addresses=None, isFatal=False, retry=False
self,
code: int,
resp: bytes,
log: Optional[bytes] = None,
addresses: Optional[object] = None,
isFatal: bool = False,
retry: bool = False,
):
"""
@param code: The SMTP response code associated with this error.
@param resp: The string response associated with this error.
@param log: A string log of the exchange leading up to and including
the error.
@type log: L{bytes}
@param isFatal: A boolean indicating whether this connection can
proceed or not. If True, the connection will be dropped.
@param retry: A boolean indicating whether the delivery should be
retried. If True and the factory indicates further retries are
desirable, they will be attempted, otherwise the delivery will be
failed.
"""
if isinstance(resp, str): # type: ignore[unreachable]
resp = resp.encode("utf-8") # type: ignore[unreachable]

if isinstance(log, str): # type: ignore[unreachable]
log = log.encode("utf-8") # type: ignore[unreachable]

self.code = code
self.resp = resp
self.log = log
Expand All @@ -123,17 +132,14 @@ def __init__(
def __str__(self) -> str:
return self.__bytes__().decode("utf-8")

def __bytes__(self):
def __bytes__(self) -> bytes:
if self.code > 0:
res = ["{:03d} {}".format(self.code, self.resp)]
res = ["{:03d} ".format(self.code).encode("utf-8") + self.resp]
else:
res = [self.resp]
if self.log:
res.append(self.log)
res.append(b"")
for (i, r) in enumerate(res):
if isinstance(r, str):
res[i] = r.encode("utf-8")
return b"\n".join(res)


Expand Down
Loading

0 comments on commit 7e3bb33

Please sign in to comment.