Skip to content

Commit

Permalink
Bump Twisted dependency to 13.1.0 (released June 2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyov committed Dec 1, 2016
1 parent e1ea0c4 commit c8cf1a3
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 98 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
Twisted>=10.0.0
Twisted>=13.1.0
lxml
pyOpenSSL
cssselect>=0.9
Expand Down
36 changes: 16 additions & 20 deletions scrapy/xlib/tx/_newclient.py
Expand Up @@ -38,26 +38,21 @@
from twisted.internet.defer import Deferred, succeed, fail, maybeDeferred
from twisted.internet.defer import CancelledError
from twisted.internet.protocol import Protocol
from twisted.protocols.basic import LineReceiver
from twisted.web.iweb import UNKNOWN_LENGTH
from twisted.web.http_headers import Headers
#from twisted.protocols.basic import LineReceiver
from twisted.web.iweb import UNKNOWN_LENGTH, IResponse
#from twisted.web.http_headers import Headers
from twisted.web.http import NO_CONTENT, NOT_MODIFIED
from twisted.web.http import _DataLoss, PotentialDataLoss
from twisted.web.http import _IdentityTransferDecoder, _ChunkedTransferDecoder

from twisted.web._newclient import (
BadHeaders, ExcessWrite, ParseError, BadResponseVersion, _WrapperException,
RequestGenerationFailed, RequestTransmissionFailed,
WrongBodyLength, ResponseDone, RequestNotSent,
LengthEnforcingConsumer, makeStatefulDispatcher, ChunkedEncoder,
TransportProxyProducer,
RequestGenerationFailed, RequestTransmissionFailed, ConnectionAborted,
WrongBodyLength, ResponseDone, ResponseFailed, RequestNotSent,
ResponseNeverReceived, HTTPParser, HTTPClientParser, Request,
LengthEnforcingConsumer, makeStatefulDispatcher, Response, ChunkedEncoder,
TransportProxyProducer, HTTP11ClientProtocol
)
# newer than 10.0.0
#from twisted.web._newclient import (
# ConnectionAborted, ResponseFailed, ResponseNeverReceived, HTTPParser,
# HTTPClientParser, Request, Response, HTTP11ClientProtocol,
#)
from .iweb import IResponse

# States HTTPParser can be in
STATUS = 'STATUS'
Expand Down Expand Up @@ -130,7 +125,7 @@ class RequestTransmissionFailed(_WrapperException):
@ivar reasons: A C{list} of one or more L{Failure} instances giving the
reasons the request transmission was considered to have failed.
"""
}}} '''
class ConnectionAborted(Exception):
Expand All @@ -139,7 +134,7 @@ class ConnectionAborted(Exception):
"""
''' {{{
class WrongBodyLength(Exception):
"""
An L{IBodyProducer} declared the number of bytes it was going to
Expand All @@ -155,7 +150,7 @@ class ResponseDone(Exception):
protocol passed to L{Response.deliverBody} and indicates that the entire
response has been delivered.
"""
}}} '''
class ResponseFailed(_WrapperException):
Expand All @@ -182,7 +177,7 @@ class ResponseNeverReceived(ResponseFailed):
"""
''' {{{
class RequestNotSent(Exception):
"""
L{RequestNotSent} indicates that an attempt was made to issue a request but
Expand All @@ -191,7 +186,7 @@ class RequestNotSent(Exception):
to send a request using a protocol which is no longer connected to a
server.
"""
}}} '''
def _callAppFunction(function):
Expand Down Expand Up @@ -777,7 +772,7 @@ def stopWriting(self):
_callAppFunction(self.bodyProducer.stopProducing)
''' {{{
class LengthEnforcingConsumer:
"""
An L{IConsumer} proxy which enforces an exact length requirement on the
Expand Down Expand Up @@ -1201,7 +1196,7 @@ def pauseProducing(self):
"""
if self._producer is not None:
self._producer.pauseProducing()
}}} '''
class HTTP11ClientProtocol(Protocol):
Expand Down Expand Up @@ -1527,3 +1522,4 @@ def abort(self):
d = Deferred()
self._abortDeferreds.append(d)
return d
}}} '''
38 changes: 16 additions & 22 deletions scrapy/xlib/tx/client.py
Expand Up @@ -29,23 +29,18 @@ def urlunparse(parts):
from twisted.web import http
from twisted.internet import defer, protocol, task, reactor
from twisted.internet.interfaces import IProtocol
from twisted.internet.endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint
from twisted.python import failure
from twisted.python.components import proxyForInterface
from twisted.web import error
from twisted.web.iweb import UNKNOWN_LENGTH, IBodyProducer
from twisted.web.iweb import UNKNOWN_LENGTH, IBodyProducer, IResponse
from twisted.web.http_headers import Headers

from twisted.web.client import (
PartialDownloadError,
PartialDownloadError, FileBodyProducer,
CookieAgent, GzipDecoder, ContentDecoderAgent, RedirectAgent,
Agent, ProxyAgent, HTTPConnectionPool, readBody,
)
# newer than 10.0.0
#from twisted.web.client import (
# CookieAgent, GzipDecoder, ContentDecoderAgent, RedirectAgent, FileBodyProducer,
# HTTPConnectionPool, Agent, ProxyAgent,
#)

from .endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint
from .iweb import IResponse

''' {{{
class PartialDownloadError(error.Error):
Expand All @@ -54,7 +49,7 @@ class PartialDownloadError(error.Error):
@ivar response: All of the response body which was downloaded.
"""
}}} '''
class _URL(tuple):
"""
Expand Down Expand Up @@ -138,22 +133,21 @@ def _makeGetterFactory(url, factoryFactory, contextFactory=None,
else:
reactor.connectTCP(host, port, factory)
return factory

}}} '''

# The code which follows is based on the new HTTP client implementation. It
# should be significantly better than anything above, though it is not yet
# feature equivalent.

from twisted.web.error import SchemeNotSupported
from ._newclient import Request, Response, HTTP11ClientProtocol
from twisted.web._newclient import ResponseDone
from ._newclient import ResponseFailed
from twisted.web._newclient import RequestNotSent, RequestTransmissionFailed
from twisted.web._newclient import (
PotentialDataLoss, _WrapperException)
from ._newclient import (
ResponseNeverReceived)
#from twisted.web.error import SchemeNotSupported
from twisted.web._newclient import Response
#from twisted.web._newclient import Request, HTTP11ClientProtocol
from twisted.web._newclient import ResponseDone, ResponseFailed
#from twisted.web._newclient import RequestNotSent, RequestTransmissionFailed
#from twisted.web._newclient import (
# ResponseNeverReceived, PotentialDataLoss, _WrapperException)

''' {{{
try:
from twisted.internet.ssl import ClientContextFactory
except ImportError:
Expand Down Expand Up @@ -1170,7 +1164,7 @@ def readBody(response):
d = defer.Deferred()
response.deliverBody(_ReadBodyProtocol(response.code, response.phrase, d))
return d

}}} '''


__all__ = [
Expand Down
38 changes: 17 additions & 21 deletions scrapy/xlib/tx/endpoints.py
Expand Up @@ -21,38 +21,33 @@
import warnings

from twisted.internet import interfaces, defer, error, fdesc
from twisted.internet.protocol import (
ClientFactory, Protocol, Factory)
#from twisted.internet.protocol import (
# ClientFactory, Protocol)
from twisted.internet.protocol import Factory
#from twisted.internet import threads, ProcessProtocol
from twisted.internet.interfaces import IStreamServerEndpointStringParser
from twisted.internet.interfaces import IStreamClientEndpointStringParser
#from twisted.internet.interfaces import IStreamClientEndpointStringParser
from twisted.python.filepath import FilePath
#from twisted.python.failure import Failure
#from twisted.python import log
from twisted.python.components import proxyForInterface
#from twisted.python.components import proxyForInterface

from twisted.plugin import IPlugin, getPlugins
#from twisted.internet import stdio

# newer than 10.0.0
#from twisted.internet.endpoints import (
# TCP4ServerEndpoint, TCP6ServerEndpoint, TCP4ClientEndpoint, SSL4ServerEndpoint, SSL4ClientEndpoint,
# UNIXServerEndpoint, UNIXClientEndpoint, AdoptedStreamServerEndpoint, connectProtocol,
# quoteStringArgument,
# serverFromString, #> using newer _parseSSL, _tokenize in _serverParsers
# clientFromString, #> using newer _clientParsers
# _WrappingProtocol, _WrappingFactory, _TCPServerEndpoint,
# _parseTCP, _parseUNIX, _loadCAsFromDir,
# _parseSSL, _tokenize,
# _parseClientTCP, _parseClientSSL, _parseClientUNIX,
#)

from .interfaces import IFileDescriptorReceiver
from twisted.internet.endpoints import (
clientFromString, serverFromString, quoteStringArgument,
TCP4ServerEndpoint, TCP6ServerEndpoint,
TCP4ClientEndpoint, TCP6ClientEndpoint,
UNIXServerEndpoint, UNIXClientEndpoint,
SSL4ServerEndpoint, SSL4ClientEndpoint,
AdoptedStreamServerEndpoint, connectProtocol,
)


__all__ = ["TCP4ClientEndpoint", "SSL4ServerEndpoint"]


''' {{{
class _WrappingProtocol(Protocol):
"""
Wrap another protocol in order to notify my user when a connection has
Expand All @@ -71,7 +66,7 @@ def __init__(self, connectedDeferred, wrappedProtocol):
self._wrappedProtocol = wrappedProtocol
for iface in [interfaces.IHalfCloseableProtocol,
IFileDescriptorReceiver]:
interfaces.IFileDescriptorReceiver]:
if iface.providedBy(self._wrappedProtocol):
directlyProvides(self, iface)
Expand Down Expand Up @@ -609,6 +604,7 @@ def listen(self, factory):
def _parseTCP(factory, port, interface="", backlog=50):
"""
Internal parser function for L{_parseServer} to convert the string
Expand Down Expand Up @@ -1280,4 +1276,4 @@ class OneShotFactory(Factory):
def buildProtocol(self, addr):
return protocol
return endpoint.connect(OneShotFactory())

}}} '''

0 comments on commit c8cf1a3

Please sign in to comment.