[wwwsearch-commits] r41292 - wwwsearch/ClientForm/trunk
jjlee at codespeak.net
jjlee at codespeak.net
Sun Mar 25 17:55:54 CEST 2007
Author: jjlee
Date: Sun Mar 25 17:55:52 2007
New Revision: 41292
Modified:
wwwsearch/ClientForm/trunk/ClientForm.py
wwwsearch/ClientForm/trunk/test.py
Log:
Fix some deprecation bugs: Fix stacklevel (warnings should cite calling code, not library code). Fix cases where we were accidentally messing with global warning state where we just wanted a utility function to temporarily hide warnings. Also, fix one case to use backwards_compat=False.
Modified: wwwsearch/ClientForm/trunk/ClientForm.py
==============================================================================
--- wwwsearch/ClientForm/trunk/ClientForm.py (original)
+++ wwwsearch/ClientForm/trunk/ClientForm.py Sun Mar 25 17:55:52 2007
@@ -117,11 +117,11 @@
try:
import warnings
except ImportError:
- def deprecation(message):
+ def deprecation(message, stack_offset=0):
pass
else:
- def deprecation(message):
- warnings.warn(message, DeprecationWarning, stacklevel=2)
+ def deprecation(message, stack_offset=0):
+ warnings.warn(message, DeprecationWarning, stacklevel=3+stack_offset)
VERSION = "0.2.7"
@@ -1081,7 +1081,7 @@
_urlunparse=urlparse.urlunparse,
):
if backwards_compat:
- deprecation("operating in backwards-compatibility mode")
+ deprecation("operating in backwards-compatibility mode", 1)
fp = form_parser_class(entitydefs, encoding)
while 1:
data = file.read(CHUNK)
Modified: wwwsearch/ClientForm/trunk/test.py
==============================================================================
--- wwwsearch/ClientForm/trunk/test.py (original)
+++ wwwsearch/ClientForm/trunk/test.py Sun Mar 25 17:55:52 2007
@@ -50,6 +50,7 @@
warnings.filterwarnings('ignore', category=DeprecationWarning)
def reset_deprecations():
warnings.filterwarnings('default', category=DeprecationWarning)
+ #warnings.resetwarnings() # XXX probably safer
def raise_deprecations():
try:
registry = ClientForm.__warningregistry__
@@ -324,7 +325,9 @@
url,
)
+ hide_deprecations()
forms = ClientForm.ParseResponse(r)
+ reset_deprecations()
self.assertEqual(len(forms), 1)
form = forms[0]
self.assertEqual(form.action, url+"abc")
@@ -750,6 +753,7 @@
forms = ClientForm.ParseFile(
StringIO("<form><textarea>\n\nblah\n</textarea></form>"),
"http://example.com/",
+ backwards_compat=False,
)
ctl = forms[0].find_control(type="textarea")
self.assertEqual(ctl.value, "\r\nblah\r\n")
@@ -810,11 +814,10 @@
def get_control(name, file=file, compat=compat):
file.seek(0)
- hide_deprecations()
forms = ClientForm.ParseFile(file, "http://localhost/",
- backwards_compat=compat)
- reset_deprecations()
+ backwards_compat=False)
form = forms[0]
+ form.backwards_compat = compat
return form.find_control(name)
# can't call item_disabled with no args
@@ -2164,10 +2167,8 @@
def test_deselect_disabled(self):
def get_new_form(f, compat):
f.seek(0)
- hide_deprecations()
form = ClientForm.ParseFile(f, "http://example.com/",
backwards_compat=False)[0]
- reset_deprecations()
form.backwards_compat = compat
return form
@@ -3075,8 +3076,10 @@
</select>
</form>
""")
+ if compat: hide_deprecations()
form = ClientForm.ParseFile(f, "http://example.com/",
backwards_compat=compat)[0]
+ if compat: reset_deprecations()
ctl = form.find_control("form.grocery")
# ordinary case
self.assertEqual(ctl.get("p", nr=1).id, "3")
More information about the wwwsearch-commits
mailing list