source: ralphm-patches/deprecate_prepareIDNName.patch @ 72:727b4d29c48e

Last change on this file since 72:727b4d29c48e was 72:727b4d29c48e, checked in by Ralph Meijer <ralphm@…>, 8 years ago

Major reworking of avatars, session manager and stanza handlers.

File size: 4.3 KB
  • NEWS

    # HG changeset patch
    # Parent 0df30a4798f74087bb2984bdb2e6bfaf8e2bfe17
    Deprecate prepareIDNName.
    
    C{unicode.encode('idna')} does exactly the same as the recently
    introduced L{generic.prepareIDNName}.
    
    diff --git a/NEWS b/NEWS
    a b  
     10.8.0 (xxxx-xx-xx)
     2==================
     3
     4Deprecations
     5--------
     6
     7 - wokkel.generic.prepareIDNName is deprecated in favor of
     8   unicode.encode('idna').
     9
     10
    1110.7.1 (2013-01-12)
    212==================
    313
  • wokkel/client.py

    diff --git a/wokkel/client.py b/wokkel/client.py
    a b  
    8787
    8888    def __init__(self, jid, password, host=None, port=5222):
    8989        self.jid = jid
    90         self.domain = generic.prepareIDNName(jid.host)
     90        self.domain = jid.host.encode('idna')
    9191        self.host = host
    9292        self.port = port
    9393
     
    182182
    183183
    184184def clientCreator(factory):
    185     domain = generic.prepareIDNName(factory.authenticator.jid.host)
     185    domain = factory.authenticator.jid.host.encode('idna')
    186186    c = XMPPClientConnector(reactor, domain, factory)
    187187    c.connect()
    188188    return factory.deferred
  • wokkel/generic.py

    diff --git a/wokkel/generic.py b/wokkel/generic.py
    a b  
    77Generic XMPP protocol helpers.
    88"""
    99
    10 from encodings import idna
    11 
    1210from zope.interface import implements
    1311
    1412from twisted.internet import defer, protocol
    1513from twisted.python import reflect
     14from twisted.python.deprecate import deprecated
     15from twisted.python.versions import Version
    1616from twisted.words.protocols.jabber import error, jid, xmlstream
    1717from twisted.words.protocols.jabber.xmlstream import toResponse
    1818from twisted.words.xish import domish, utility
     
    332332
    333333
    334334
     335@deprecated(Version("Wokkel", 0, 8, 0), "unicode.encode('idna')")
    335336def prepareIDNName(name):
    336337    """
    337338    Encode a unicode IDN Domain Name into its ACE equivalent.
     
    341342    result is an ASCII byte string of the encoded labels, separated by the
    342343    standard full stop.
    343344    """
    344     result = []
    345     labels = idna.dots.split(name)
    346 
    347     if labels and len(labels[-1]) == 0:
    348         trailing_dot = b'.'
    349         del labels[-1]
    350     else:
    351         trailing_dot = b''
    352 
    353     for label in labels:
    354         result.append(idna.ToASCII(label))
    355 
    356     return b'.'.join(result) + trailing_dot
     345    return name.encode('idna')
  • wokkel/server.py

    diff --git a/wokkel/server.py b/wokkel/server.py
    a b  
    2929from twisted.words.protocols.jabber import error, ijabber, jid, xmlstream
    3030from twisted.words.xish import domish
    3131
    32 from wokkel.generic import DeferredXmlStreamFactory, XmlPipe, prepareIDNName
     32from wokkel.generic import DeferredXmlStreamFactory, XmlPipe
    3333
    3434NS_DIALBACK = 'jabber:server:dialback'
    3535
     
    468468
    469469
    470470def initiateS2S(factory):
    471     domain = prepareIDNName(factory.authenticator.otherHost)
     471    domain = factory.authenticator.otherHost.encode('idna')
    472472    c = XMPPServerConnector(reactor, domain, factory)
    473473    c.connect()
    474474    return factory.deferred
  • wokkel/test/test_generic.py

    diff --git a/wokkel/test/test_generic.py b/wokkel/test/test_generic.py
    a b  
    55Tests for L{wokkel.generic}.
    66"""
    77
     8import re
     9
     10from twisted.python import deprecate
     11from twisted.python.versions import Version
    812from twisted.trial import unittest
     13from twisted.trial.util import suppress as SUPPRESS
    914from twisted.words.xish import domish
    1015from twisted.words.protocols.jabber.jid import JID
    1116
     
    276281    Tests for L{wokkel.generic.prepareIDNName}.
    277282    """
    278283
     284    suppress = [SUPPRESS(category=DeprecationWarning,
     285                         message=re.escape(
     286                             deprecate.getDeprecationWarningString(
     287                                 generic.prepareIDNName,
     288                                 Version("Wokkel", 0, 8, 0),
     289                                 replacement="unicode.encode('idna')")))]
     290
     291
     292    def test_deprecated(self):
     293        """
     294        prepareIDNName is deprecated.
     295        """
     296        self.callDeprecated((Version("Wokkel", 0, 8, 0),
     297                             "unicode.encode('idna')"),
     298                            generic.prepareIDNName, (b"example.com"))
     299    test_deprecated.suppress = []
     300
     301
    279302    def test_bytestring(self):
    280303        """
    281304        An ASCII-encoded byte string is left as-is.
Note: See TracBrowser for help on using the repository browser.