Merge lp:~gary/lazr.restful/bug691841 into lp:lazr.restful

Proposed by Gary Poster
Status: Merged
Approved by: Robert Collins
Approved revision: 160
Merged at revision: 160
Proposed branch: lp:~gary/lazr.restful/bug691841
Merge into: lp:lazr.restful
Diff against target: 72 lines (+21/-16)
2 files modified
src/lazr/restful/example/base/tests/entry.txt (+2/-2)
src/lazr/restful/metazcml.py (+19/-14)
To merge this branch: bzr merge lp:~gary/lazr.restful/bug691841
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Benji York Pending
Review via email: mp+46312@code.launchpad.net

Description of the change

This branch makes lazr.restful's tests pass in 2.6 and 2.7 (they were breaking in 2.7).

Comments 2 and 3 of bug 691841 describe the rationale for the two changes. Briefly, for one change, 2.7's inspect.is_class now is more discerning and recognizes that interfaces are not actually classes, so we need to accommodate that. For another change, None is no longer allowed as a header value in Python2.7's httplib.HTTPConnection.putheader, so we adjust the tests accordingly.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Looks great to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restful/example/base/tests/entry.txt'
2--- src/lazr/restful/example/base/tests/entry.txt 2010-10-25 16:31:09 +0000
3+++ src/lazr/restful/example/base/tests/entry.txt 2011-01-14 19:17:10 +0000
4@@ -55,7 +55,7 @@
5 >>> negotiated_type('application/vnd.sun.wadl+xml')
6 'application/vnd.sun.wadl+xml'
7
8- >>> negotiated_type(None)
9+ >>> negotiated_type('')
10 'application/json'
11
12 >>> negotiated_type('text/html')
13@@ -85,7 +85,7 @@
14 ... uri = '/cookbooks/Everyday%20Greens?ws.accept=' + query_string
15 ... return negotiated_type(header, uri)
16
17- >>> qs_negotiated_type('application/json', None)
18+ >>> qs_negotiated_type('application/json', '')
19 'application/json'
20
21 >>> qs_negotiated_type('application/json', 'application/xhtml+xml')
22
23=== modified file 'src/lazr/restful/metazcml.py'
24--- src/lazr/restful/metazcml.py 2010-08-03 20:16:24 +0000
25+++ src/lazr/restful/metazcml.py 2011-01-14 19:17:10 +0000
26@@ -146,6 +146,23 @@
27 handler('registerAdapter', factory, (interface, marker),
28 provides, name, info)
29
30+def _is_exported_interface(member):
31+ """Helper for find_exported_interfaces; a predicate to inspect.getmembers.
32+
33+ Returns True if member is a webservice-aware Exception or interface.
34+ """
35+ if (inspect.isclass(member) and
36+ issubclass(member, Exception) and
37+ getattr(member, '__lazr_webservice_error__', None) is not None):
38+ # This is a webservice-aware Exception.
39+ return True
40+ if IInterface.providedBy(member):
41+ tag = member.queryTaggedValue(LAZR_WEBSERVICE_EXPORTED)
42+ if tag is not None and tag['type'] in [ENTRY_TYPE, COLLECTION_TYPE]:
43+ # This is a webservice-aware interface.
44+ return True
45+ return False
46+
47 def find_exported_interfaces(module):
48 """Find all the interfaces in a module marked for export.
49
50@@ -153,20 +170,8 @@
51
52 :return: iterator of interfaces.
53 """
54- for name, interface in inspect.getmembers(module, inspect.isclass):
55- if issubclass(interface, Exception):
56- if getattr(interface, '__lazr_webservice_error__', None) is None:
57- continue
58- yield interface
59-
60- if not IInterface.providedBy(interface):
61- continue
62- tag = interface.queryTaggedValue(LAZR_WEBSERVICE_EXPORTED)
63- if tag is None:
64- continue
65- if tag['type'] in [ENTRY_TYPE, COLLECTION_TYPE]:
66- yield interface
67-
68+ return (interface for name, interface
69+ in inspect.getmembers(module, _is_exported_interface))
70
71 def find_interfaces_and_contributors(module):
72 """Find the interfaces and its contributors marked for export.

Subscribers

People subscribed via source and target branches