def opt_unsigned(self): """ Generate an unsigned rather than a signed RPM. (DEPRECATED; unsigned is the default) """ msg = deprecate.getDeprecationWarningString(self.opt_unsigned, versions.Version("Twisted", 12, 1, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
class PrepareIDNNameTests(unittest.TestCase): """ Tests for L{wokkel.generic.prepareIDNName}. """ suppress = [ SUPPRESS(category=DeprecationWarning, message=re.escape( deprecate.getDeprecationWarningString( generic.prepareIDNName, Version("wokkel", 18, 0, 0), replacement="unicode.encode('idna')"))) ] def test_deprecated(self): """ prepareIDNName is deprecated. """ self.callDeprecated( (Version("wokkel", 18, 0, 0), "unicode.encode('idna')"), generic.prepareIDNName, ("example.com")) test_deprecated.suppress = [] def test_unicode(self): """ A unicode all-ASCII name is converted to an ASCII byte string. """ name = u"example.com" result = generic.prepareIDNName(name) self.assertEqual(b"example.com", result) def test_unicodeNonASCII(self): """ A unicode with non-ASCII is converted to its ACE equivalent. """ name = u"\u00e9chec.example.com" result = generic.prepareIDNName(name) self.assertEqual(b"xn--chec-9oa.example.com", result) def test_unicodeHalfwidthIdeographicFullStop(self): """ Exotic dots in unicode names are converted to Full Stop. """ name = u"\u00e9chec.example\uff61com" result = generic.prepareIDNName(name) self.assertEqual(b"xn--chec-9oa.example.com", result) def test_unicodeTrailingDot(self): """ Unicode names with trailing dots retain the trailing dot. L{encodings.idna.ToASCII} doesn't allow the empty string as the input, hence the implementation needs to strip a trailing dot, and re-add it after encoding the labels. """ name = u"example.com." result = generic.prepareIDNName(name) self.assertEqual(b"example.com.", result)
def opt_unsigned(self): """ Generate an unsigned rather than a signed RPM. (DEPRECATED; unsigned is the default) """ msg = deprecate.getDeprecationWarningString( self.opt_unsigned, versions.Version("Twisted", 12, 1, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
def assertDeprecationWarning(self, deprecatedCallable, warnings): """ Check for a deprecation warning """ self.assertEquals(len(warnings), 1) self.assertEquals(warnings[0]['category'], DeprecationWarning) self.assertEquals(warnings[0]['message'], deprecate.getDeprecationWarningString( deprecatedCallable, versions.Version('Twisted', 11, 0, 0)))
def opt_https(self, port): """ (DEPRECATED: use --listen) Port to listen on for Secure HTTP. """ msg = deprecate.getDeprecationWarningString( self.opt_https, incremental.Version("Twisted", 18, 4, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2) self["https"] = port
def opt_port(self, port): """ (DEPRECATED: use --listen) Strports description of port to start the server on """ msg = deprecate.getDeprecationWarningString( self.opt_port, incremental.Version("Twisted", 18, 4, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2) self["port"] = port
def opt_https(self, port): """ (DEPRECATED: use --http) Port to listen on for Secure HTTP. """ msg = deprecate.getDeprecationWarningString( self.opt_https, incremental.Version('Twisted', 18, 4, 0, release_candidate=1)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2) self['https'] = port
def test_getDeprecationWarningString(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted. """ version = Version('Twisted', 8, 0, 0) self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version), "%s was deprecated in Twisted 8.0.0" % ( qual(self.test_getDeprecationWarningString)))
def opt_passwordfile(self, filename): """ Specify a file containing username:password login info for authenticated ESMTP connections. (DEPRECATED; see --help-auth instead) """ ch = checkers.OnDiskUsernamePasswordDatabase(filename) self.service.smtpPortal.registerChecker(ch) msg = deprecate.getDeprecationWarningString( self.opt_passwordfile, versions.Version('twisted.mail', 11, 0, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
def opt_password_file(self, filename): """ Specify a file containing username:password login info for authenticated connections. (DEPRECATED; see --help-auth instead) """ self['password-file'] = filename msg = deprecate.getDeprecationWarningString( self.opt_password_file, versions.Version('Twisted', 11, 1, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2) self.addChecker(checkers.FilePasswordDB(filename, cache=True))
def opt_passwordfile(self, filename): """ Specify a file containing username:password login info for authenticated ESMTP connections. (DEPRECATED; see --help-auth instead) """ ch = checkers.OnDiskUsernamePasswordDatabase(filename) self.service.smtpPortal.registerChecker(ch) msg = deprecate.getDeprecationWarningString( self.opt_passwordfile, versions.Version('twisted.mail', 11, 0, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
def opt_port(self, port): """ (DEPRECATED: use --http) Strports description of port to start the server on """ msg = deprecate.getDeprecationWarningString( self.opt_port, incremental.Version('Twisted', 18, 4, 0, release_candidate=1)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2) self['port'] = port
def opt_password_file(self, filename): """ Specify a file containing username:password login info for authenticated connections. (DEPRECATED; see --help-auth instead) """ self["password-file"] = filename msg = deprecate.getDeprecationWarningString( self.opt_password_file, versions.Version("Twisted", 11, 1, 0)) warnings.warn(msg, category=DeprecationWarning, stacklevel=2) self.addChecker(checkers.FilePasswordDB(filename, cache=True))
def test_getDeprecationWarningString(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted. """ version = Version("Twisted", 8, 0, 0) self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version), "%s.DeprecationWarningsTests.test_getDeprecationWarningString " "was deprecated in Twisted 8.0.0" % (__name__,), )
def testPasswordfileDeprecation(self): """ Test that the --passwordfile option will emit a correct warning. """ options = Options() options.opt_passwordfile('/dev/null') warnings = self.flushWarnings([self.testPasswordfileDeprecation]) self.assertEquals(warnings[0]['category'], DeprecationWarning) self.assertEquals(len(warnings), 1) msg = deprecate.getDeprecationWarningString(options.opt_passwordfile, versions.Version('twisted.mail', 11, 0, 0)) self.assertEquals(warnings[0]['message'], msg)
def opt_extra(self, arg): """ Add an extra argument. (This is a hack necessary for interfacing with emacs's `gud'.) NOTE: This option is deprecated as of Twisted 11.0 """ warnings.warn(deprecate.getDeprecationWarningString(Options.opt_extra, versions.Version('Twisted', 11, 0, 0)), category=DeprecationWarning, stacklevel=2) if self.extra is None: self.extra = [] self.extra.append(arg)
class Connection(_TLSConnectionMixin, abstract.FileDescriptor, _SocketCloser, _AbortingMixin): """ Superclass of all socket-based FileDescriptors. This is an abstract superclass of all objects which represent a TCP/IP connection based socket. @ivar logstr: prefix used when logging events related to this connection. @type logstr: C{str} """ implements(interfaces.ITCPTransport, interfaces.ISystemHandle) def __init__(self, skt, protocol, reactor=None): abstract.FileDescriptor.__init__(self, reactor=reactor) self.socket = skt self.socket.setblocking(0) self.fileno = skt.fileno self.protocol = protocol def getHandle(self): """Return the socket for this connection.""" return self.socket def doRead(self): """Calls self.protocol.dataReceived with all available data. This reads up to self.bufferSize bytes of data from its socket, then calls self.dataReceived(data) to process it. If the connection is not lost through an error in the physical recv(), this function will return the result of the dataReceived call. """ try: data = self.socket.recv(self.bufferSize) except socket.error, se: if se.args[0] == EWOULDBLOCK: return else: return main.CONNECTION_LOST if not data: return main.CONNECTION_DONE rval = self.protocol.dataReceived(data) if rval is not None: offender = self.protocol.dataReceived warningFormat = ( 'Returning a value other than None from %(fqpn)s is ' 'deprecated since %(version)s.') warningString = deprecate.getDeprecationWarningString( offender, versions.Version('Twisted', 11, 0, 0), format=warningFormat) deprecate.warnAboutFunction(offender, warningString) return rval
def _dataReceived(self, data): if not data: return main.CONNECTION_DONE rval = self.protocol.dataReceived(data) if rval is not None: offender = self.protocol.dataReceived warningFormat = "Returning a value other than None from %(fqpn)s is " "deprecated since %(version)s." warningString = deprecate.getDeprecationWarningString( offender, versions.Version("Twisted", 11, 0, 0), format=warningFormat ) deprecate.warnAboutFunction(offender, warningString) return rval
def test_getDeprecationWarningString(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted. """ version = Version('Twisted', 8, 0, 0) self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version), "twisted.python.test.test_deprecate.TestDeprecationWarnings." "test_getDeprecationWarningString was deprecated in " "Twisted 8.0.0")
def test_getDeprecationWarningString(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted. """ version = Version('Twisted', 8, 0, 0) self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version), "twisted.python.test.test_deprecate.TestDeprecationWarnings." "test_getDeprecationWarningString was deprecated in " "Twisted 8.0.0")
def opt_extra(self, arg): """ Add an extra argument. (This is a hack necessary for interfacing with emacs's `gud'.) NOTE: This option is deprecated as of Twisted 11.0 """ warnings.warn(deprecate.getDeprecationWarningString( Options.opt_extra, versions.Version('Twisted', 11, 0, 0)), category=DeprecationWarning, stacklevel=2) if self.extra is None: self.extra = [] self.extra.append(arg)
def test_deprecateEmitsWarning(self): """ Decorating a callable with L{deprecated} emits a warning. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) def addStackLevel(): dummy() self.assertWarns( DeprecationWarning, getDeprecationWarningString(dummyCallable, version), __file__, addStackLevel)
def test_getDeprecationWarningStringWithFormat(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted, with a message containing additional information about the deprecation. """ version = Version('Twisted', 8, 0, 0) format = DEPRECATION_WARNING_FORMAT + ': This is a message' self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version, format), '%s.DeprecationWarningsTests.test_getDeprecationWarningString was ' 'deprecated in Twisted 8.0.0: This is a message' % (__name__,))
def test_getDeprecationWarningStringWithFormat(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted, with a message containing additional information about the deprecation. """ version = Version('Twisted', 8, 0, 0) format = DEPRECATION_WARNING_FORMAT + ': This is a message' self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version, format), '%s.TestDeprecationWarnings.test_getDeprecationWarningString was ' 'deprecated in Twisted 8.0.0: This is a message' % (__name__, ))
def test_deprecateEmitsWarning(self): """ Decorating a callable with L{deprecated} emits a warning. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) def addStackLevel(): dummy() self.assertWarns( DeprecationWarning, getDeprecationWarningString(dummyCallable, version), __file__, addStackLevel)
def callDeprecated(self, version, f, *args, **kwargs): """ Call a function that should have been deprecated at a specific version and in favor of a specific alternative, and assert that it was thusly deprecated. @param version: A 2-sequence of (since, replacement), where C{since} is a the first L{version<twisted.python.versions.Version>} that C{f} should have been deprecated since, and C{replacement} is a suggested replacement for the deprecated functionality, as described by L{twisted.python.deprecate.deprecated}. If there is no suggested replacement, this parameter may also be simply a L{version<twisted.python.versions.Version>} by itself. @param f: The deprecated function to call. @param args: The arguments to pass to C{f}. @param kwargs: The keyword arguments to pass to C{f}. @return: Whatever C{f} returns. @raise: Whatever C{f} raises. If any exception is raised by C{f}, though, no assertions will be made about emitted deprecations. @raise FailTest: if no warnings were emitted by C{f}, or if the L{DeprecationWarning} emitted did not produce the canonical please-use-something-else message that is standard for Twisted deprecations according to the given version and replacement. """ result = f(*args, **kwargs) warningsShown = self.flushWarnings([self.callDeprecated]) try: info = list(version) except TypeError: since = version replacement = None else: [since, replacement] = info if len(warningsShown) == 0: self.fail('%r is not deprecated.' % (f, )) observedWarning = warningsShown[0]['message'] expectedWarning = getDeprecationWarningString(f, since, replacement=replacement) self.assertEqual(expectedWarning, observedWarning) return result
def test_unsignedFlagDeprecationWarning(self): """ The 'unsigned' flag in tap2rpm should be deprecated, and its use should raise a warning as such. """ config = tap2rpm.MyOptions() config.parseOptions(['--unsigned']) warnings = self.flushWarnings() self.assertEqual(DeprecationWarning, warnings[0]['category']) self.assertEqual( deprecate.getDeprecationWarningString( config.opt_unsigned, versions.Version("Twisted", 12, 1, 0)), warnings[0]['message']) self.assertEqual(1, len(warnings))
def testPasswordfileDeprecation(self): """ Test that the --passwordfile option will emit a correct warning. """ passwd = FilePath(self.mktemp()) passwd.setContent("") options = Options() options.opt_passwordfile(passwd.path) warnings = self.flushWarnings([self.testPasswordfileDeprecation]) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual(len(warnings), 1) msg = deprecate.getDeprecationWarningString(options.opt_passwordfile, versions.Version('twisted.mail', 11, 0, 0)) self.assertEqual(warnings[0]['message'], msg)
def callDeprecated(self, version, f, *args, **kwargs): """ Call a function that should have been deprecated at a specific version and in favor of a specific alternative, and assert that it was thusly deprecated. @param version: A 2-sequence of (since, replacement), where C{since} is a the first L{version<twisted.python.versions.Version>} that C{f} should have been deprecated since, and C{replacement} is a suggested replacement for the deprecated functionality, as described by L{twisted.python.deprecate.deprecated}. If there is no suggested replacement, this parameter may also be simply a L{version<twisted.python.versions.Version>} by itself. @param f: The deprecated function to call. @param args: The arguments to pass to C{f}. @param kwargs: The keyword arguments to pass to C{f}. @return: Whatever C{f} returns. @raise: Whatever C{f} raises. If any exception is raised by C{f}, though, no assertions will be made about emitted deprecations. @raise FailTest: if no warnings were emitted by C{f}, or if the L{DeprecationWarning} emitted did not produce the canonical please-use-something-else message that is standard for Twisted deprecations according to the given version and replacement. """ result = f(*args, **kwargs) warningsShown = self.flushWarnings([self.callDeprecated]) try: info = list(version) except TypeError: since = version replacement = None else: [since, replacement] = info if len(warningsShown) == 0: self.fail('%r is not deprecated.' % (f,)) observedWarning = warningsShown[0]['message'] expectedWarning = getDeprecationWarningString( f, since, replacement=replacement) self.assertEqual(expectedWarning, observedWarning) return result
def _dataReceived(self, data): if not data: return main.CONNECTION_DONE rval = self.protocol.dataReceived(data) if rval is not None: offender = self.protocol.dataReceived warningFormat = ( 'Returning a value other than None from %(fqpn)s is ' 'deprecated since %(version)s.') warningString = deprecate.getDeprecationWarningString( offender, versions.Version('Twisted', 11, 0, 0), format=warningFormat) deprecate.warnAboutFunction(offender, warningString) return rval
def testPasswordfileDeprecation(self): """ Test that the --passwordfile option will emit a correct warning. """ passwd = FilePath(self.mktemp()) passwd.setContent("") options = Options() options.opt_passwordfile(passwd.path) warnings = self.flushWarnings([self.testPasswordfileDeprecation]) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual(len(warnings), 1) msg = deprecate.getDeprecationWarningString(options.opt_passwordfile, versions.Version('twisted.mail', 11, 0, 0)) self.assertEqual(warnings[0]['message'], msg)
def test_getDeprecationWarningStringWithFormat(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted, with a message containing additional information about the deprecation. """ version = Version('Twisted', 8, 0, 0) format = deprecate.DEPRECATION_WARNING_FORMAT + ': This is a message' self.assertEquals( getDeprecationWarningString(self.test_getDeprecationWarningString, version, format), 'twisted.python.test.test_deprecate.TestDeprecationWarnings.' 'test_getDeprecationWarningString was deprecated in ' 'Twisted 8.0.0: This is a message')
def test_deprecateEmitsWarning(self): """ Decorating a callable with L{deprecated} emits a warning. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) def addStackLevel(): dummy() with catch_warnings(record=True) as caught: simplefilter("always") addStackLevel() self.assertEqual(caught[0].category, DeprecationWarning) self.assertEqual(str(caught[0].message), getDeprecationWarningString(dummyCallable, version)) # rstrip in case .pyc/.pyo self.assertEqual(caught[0].filename.rstrip('co'), __file__.rstrip('co'))
def test_deprecateEmitsWarning(self): """ Decorating a callable with L{deprecated} emits a warning. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) def addStackLevel(): dummy() with catch_warnings(record=True) as caught: simplefilter("always") addStackLevel() self.assertEqual(caught[0].category, DeprecationWarning) self.assertEqual(str(caught[0].message), getDeprecationWarningString(dummyCallable, version)) # rstrip in case .pyc/.pyo self.assertEqual(caught[0].filename.rstrip('co'), __file__.rstrip('co'))
def test_getDeprecationWarningStringReplacement(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a string, it will be interpolated directly into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement="something.foobar") self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use something.foobar " "instead" % ( fullyQualifiedName(self.test_getDeprecationWarningString),))
def test_getDeprecationWarningStringReplacement(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a string, it will be interpolated directly into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement="something.foobar") self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use something.foobar " "instead" % ( fullyQualifiedName(self.test_getDeprecationWarningString),))
def test_getDeprecationWarningStringReplacementWithCallable(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a callable, its fully qualified name will be interpolated into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement=dummyReplacementMethod) self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use " "%s.dummyReplacementMethod instead" % (fullyQualifiedName( self.test_getDeprecationWarningString), __name__))
def test_getDeprecationWarningStringReplacementWithCallable(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a callable, its fully qualified name will be interpolated into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement=dummyReplacementMethod) self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use " "%s.dummyReplacementMethod instead" % ( fullyQualifiedName(self.test_getDeprecationWarningString), __name__))
def __init__(self, keyObject): """ Initialize with a private or public C{cryptography.hazmat.primitives.asymmetric} key. @param keyObject: Low level key. @type keyObject: C{cryptography.hazmat.primitives.asymmetric} key. """ # Avoid importing PyCrypto if at all possible if keyObject.__class__.__module__.startswith('Crypto.PublicKey'): warningString = getDeprecationWarningString( Key, Version("Twisted", 16, 0, 0), replacement='passing a cryptography key object') warnings.warn(warningString, DeprecationWarning, stacklevel=2) self.keyObject = keyObject else: self._keyObject = keyObject
def __init__(self, keyObject): """ Initialize with a private or public C{cryptography.hazmat.primitives.asymmetric} key. @param keyObject: Low level key. @type keyObject: C{cryptography.hazmat.primitives.asymmetric} key. """ # Avoid importing PyCrypto if at all possible if keyObject.__class__.__module__.startswith('Crypto.PublicKey'): warningString = getDeprecationWarningString( Key, Version("Twisted", 16, 0, 0), replacement='passing a cryptography key object') warnings.warn(warningString, DeprecationWarning, stacklevel=2) self.keyObject = keyObject else: self._keyObject = keyObject
def test_deprecated(self): """ Make sure that twisted.persisted.journal is deprecated, and check the text of its deprecation warning. """ from twisted.persisted import journal warnings = self.flushWarnings([self.test_deprecated]) # because for some reason deprecate.deprecatedModuleAttribute causes a warning to be # emitted twice in this case. Bug will be filed self.uniquify(warnings) self.assertEqual(len(warnings), 1) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual( warnings[0]['message'], deprecate.getDeprecationWarningString(journal, versions.Version('twisted', 11, 0, 0)) + ": Use a different persistence library. This one is no longer maintained.")
def callDeprecated(self, version, f, *args, **kwargs): """ Call a function that was deprecated at a specific version. @param version: The version that the function was deprecated in. @param f: The deprecated function to call. @return: Whatever the function returns. """ warnings, result = self._captureDeprecationWarnings( f, *args, **kwargs) if len(warnings) == 0: self.fail('%r is not deprecated.' % (f,)) observedWarning = warnings[0] expectedWarning = getDeprecationWarningString(f, version) self.assertEqual(expectedWarning, observedWarning) return result
def test_deprecated(self): """ Make sure that twisted.persisted.journal is deprecated, and check the text of its deprecation warning. """ from twisted.persisted import journal warnings = self.flushWarnings([self.test_deprecated]) # because for some reason deprecate.deprecatedModuleAttribute causes a warning to be # emitted twice in this case. Bug will be filed self.uniquify(warnings) self.assertEqual(len(warnings), 1) self.assertEqual(warnings[0]['category'], DeprecationWarning) self.assertEqual( warnings[0]['message'], deprecate.getDeprecationWarningString( journal, versions.Version('twisted', 11, 0, 0)) + ": Use a different persistence library. This one is no longer maintained." )
class Connection(abstract.FileDescriptor, _SocketCloser): """ Superclass of all socket-based FileDescriptors. This is an abstract superclass of all objects which represent a TCP/IP connection based socket. @ivar logstr: prefix used when logging events related to this connection. @type logstr: C{str} """ implements(interfaces.ITCPTransport, interfaces.ISystemHandle) TLS = 0 def __init__(self, skt, protocol, reactor=None): abstract.FileDescriptor.__init__(self, reactor=reactor) self.socket = skt self.socket.setblocking(0) self.fileno = skt.fileno self.protocol = protocol if SSL: _tlsWaiting = None def startTLS(self, ctx, extra): assert not self.TLS if self.dataBuffer or self._tempDataBuffer: # pre-TLS bytes are still being written. Starting TLS now # will do the wrong thing. Instead, mark that we're trying # to go into the TLS state. self._tlsWaiting = _TLSDelayed([], ctx, extra) return False self.stopReading() self.stopWriting() self._startTLS() self.socket = SSL.Connection(ctx.getContext(), self.socket) self.fileno = self.socket.fileno self.startReading() return True def _startTLS(self): self.TLS = 1 self.__class__ = _getTLSClass(self.__class__) def write(self, bytes): if self._tlsWaiting is not None: self._tlsWaiting.bufferedData.append(bytes) else: abstract.FileDescriptor.write(self, bytes) def writeSequence(self, iovec): if self._tlsWaiting is not None: self._tlsWaiting.bufferedData.extend(iovec) else: abstract.FileDescriptor.writeSequence(self, iovec) def doWrite(self): result = abstract.FileDescriptor.doWrite(self) if self._tlsWaiting is not None: if not self.dataBuffer and not self._tempDataBuffer: waiting = self._tlsWaiting self._tlsWaiting = None self.startTLS(waiting.context, waiting.extra) self.writeSequence(waiting.bufferedData) return result def getHandle(self): """Return the socket for this connection.""" return self.socket def doRead(self): """Calls self.protocol.dataReceived with all available data. This reads up to self.bufferSize bytes of data from its socket, then calls self.dataReceived(data) to process it. If the connection is not lost through an error in the physical recv(), this function will return the result of the dataReceived call. """ try: data = self.socket.recv(self.bufferSize) except socket.error, se: if se.args[0] == EWOULDBLOCK: return else: return main.CONNECTION_LOST if not data: return main.CONNECTION_DONE rval = self.protocol.dataReceived(data) if rval is not None: offender = self.protocol.dataReceived warningFormat = ( 'Returning a value other than None from %(fqpn)s is ' 'deprecated since %(version)s.') warningString = deprecate.getDeprecationWarningString( offender, versions.Version('Twisted', 11, 0, 0), format=warningFormat) deprecate.warnAboutFunction(offender, warningString) return rval