Skip to content

Commit

Permalink
Merge webhtml-4948-4: Deprecate twisted.web.html.
Browse files Browse the repository at this point in the history
Author: adiroiban
Reviewers: hawkowl
Fixes: twisted#4948

git-svn-id: svn://svn.twistedmatrix.com/svn/Twisted/trunk@45255 bbbe8e31-12d6-0310-92fd-ac37d47ddeeb
  • Loading branch information
adiroiban committed Jul 14, 2015
1 parent e7feae3 commit 526a7b0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
15 changes: 14 additions & 1 deletion twisted/web/html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# -*- test-case-name: twisted.web.test.test_html -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

Expand All @@ -10,12 +10,19 @@

from twisted.python import log
from twisted.python.compat import NativeStringIO as StringIO
from twisted.python.deprecate import deprecated
from twisted.python.versions import Version



@deprecated(Version('Twisted', 15, 3, 0), replacement='twisted.web.template')
def PRE(text):
"Wrap <pre> tags around some text and HTML-escape it."
return "<pre>"+escape(text)+"</pre>"



@deprecated(Version('Twisted', 15, 3, 0), replacement='twisted.web.template')
def UL(lst):
io = StringIO()
io.write("<ul>\n")
Expand All @@ -24,6 +31,9 @@ def UL(lst):
io.write("</ul>")
return io.getvalue()



@deprecated(Version('Twisted', 15, 3, 0), replacement='twisted.web.template')
def linkList(lst):
io = StringIO()
io.write("<ul>\n")
Expand All @@ -32,6 +42,9 @@ def linkList(lst):
io.write("</ul>")
return io.getvalue()



@deprecated(Version('Twisted', 15, 3, 0), replacement='twisted.web.template')
def output(func, *args, **kw):
"""output(func, *args, **kw) -> html string
Either return the result of a function (which presumably returns an
Expand Down
43 changes: 43 additions & 0 deletions twisted/web/test/test_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

from twisted.trial import unittest
from twisted.web import html



class WebHtmlTests(unittest.TestCase):
"""
Unit tests for L{twisted.web.html}.
"""

def test_deprecation(self):
"""
Calls to L{twisted.web.html} members emit a deprecation warning.
"""
def assertDeprecationWarningOf(method):
"""
Check that a deprecation warning is present.
"""
warningsShown = self.flushWarnings([self.test_deprecation])
self.assertEqual(len(warningsShown), 1)
self.assertIdentical(
warningsShown[0]['category'], DeprecationWarning)
self.assertEqual(
warningsShown[0]['message'],
'twisted.web.html.%s was deprecated in Twisted 15.3.0; '
'please use twisted.web.template instead' % (
method,),
)

html.PRE('')
assertDeprecationWarningOf('PRE')

html.UL([])
assertDeprecationWarningOf('UL')

html.linkList([])
assertDeprecationWarningOf('linkList')

html.output(lambda: None)
assertDeprecationWarningOf('output')
1 change: 1 addition & 0 deletions twisted/web/topfiles/4948.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
twisted.web.html is now deprecated in favor of twisted.web.template.

0 comments on commit 526a7b0

Please sign in to comment.