This is a nice refactoring and improvement. I only have minor comments below.
merge-conditional
-Edwin
>=== modified file 'src/lazr/restful/declarations.py'
>--- src/lazr/restful/declarations.py 2010-01-26 20:05:25 +0000
>+++ src/lazr/restful/declarations.py 2010-01-27 22:49:27 +0000
>@@ -202,7 +202,7 @@
> collection, or if used more than once in the same interface.
> """
>
>- def __init__(self, **params):
>+ def __init__(self, version=None, **params):
> """Create the decorator marking the default collection method.
>
> :param params: Optional parameter values to use when calling the
The docstring should explain how the version parameter should be used.
>+ "%sCollectionAdapter" % interface.__name__[1:],
>+ version)
> factory = type(classname, (BaseCollectionAdapter,), class_dict)
>
> protect_schema(factory, ICollection)
>@@ -1016,8 +1029,9 @@
> if return_type is None:
> return_type = None
>
>- name = '%s_%s_%s_%s' % (prefix, method.interface.__name__, tag['as'],
>- version)
>+ name = _versioned_class_name(
>+ '%s_%s_%s' % (prefix, method.interface.__name__, tag['as']),
>+ version)
> class_dict = {'params' : tuple(tag['params'].values()),
> 'return_type' : return_type,
> '_export_info': tag,
>@@ -1026,8 +1040,20 @@
>
> if tag['type'] == 'write_operation':
> class_dict['send_modification_event'] = True
>- factory = type(make_identifier_safe(name), bases, class_dict)
>+ factory = type(name, bases, class_dict)
> classImplements(factory, provides)
> protect_schema(factory, provides)
>
> return factory
>+
>+
>+def _versioned_class_name(base_name, version):
>+ """Create a class name incorporating the given version string."""
>+ if version is None:
>+ # We need to incorporate the version into a Python class name,
>+ # but we won't find out the name of the earliest version until
>+ # runtime. Use a generic string that won't conflict with a
>+ # real version string.
>+ version = "__Earliest"
>+ name = "%s_%s" % (base_name, version)
>+ return make_identifier_safe(name)
>
>=== modified file 'src/lazr/restful/docs/webservice-declarations.txt'
>--- src/lazr/restful/docs/webservice-declarations.txt 2010-01-25 19:26:30 +0000
>+++ src/lazr/restful/docs/webservice-declarations.txt 2010-01-27 22:49:27 +0000
>@@ -170,15 +170,14 @@
> tagged value.
>
> >>> print_export_tag(IBookSet)
>- collection_default_content: 'getAllBooks'
>- collection_default_content_params: {}
>+ collection_default_content: {None: ('getAllBooks', {})}
> collection_entry_schema: <InterfaceClass __builtin__.IBook>
> type: 'collection'
>
> >>> print_export_tag(ICheckedOutBookSet)
>- collection_default_content: 'getByTitle'
>- collection_default_content_params: {'title': '',
>- 'user': <object...>}
>+ collection_default_content: {None: ('getByTitle',
>+ {'title': '',
>+ 'user': <object object ...>})}
> collection_entry_schema: <InterfaceClass __builtin__.IBook>
> type: 'collection'
>
>@@ -223,8 +222,8 @@
> ... """Another getAll()."""
> Traceback (most recent call last):
> ...
>- TypeError: only one method should be marked with
>- @collection_default_content.
>+ TypeError: Only one method can be marked with
>+ @collection_default_content for version (earliest).
I think this could actually confuse someone, since the parens don't
imply that it is actually the name of the version. It could also be
confusing if @collection_default_content(version="method") yielded the
error message ending with "for version method". I think double-quotes
around the version name would make it clear that the word doesn't have
another meaning in the sentence.
> export_as_webservice_collection() can only be used on Interface.
>
>@@ -1452,7 +1451,6 @@
> It is possible to cache a server response in the browser cache using
> the @cache_for decorator:
>
>- >>> from lazr.restful.testing.webservice import FakeRequest
> >>> from lazr.restful.declarations import cache_for
> >>>
> >>> class ICachedBookSet(IBookSet):
Hi Leonard,
This is a nice refactoring and improvement. I only have minor comments below.
merge-conditional
-Edwin
>=== modified file 'src/lazr/ restful/ declarations. py' restful/ declarations. py 2010-01-26 20:05:25 +0000 restful/ declarations. py 2010-01-27 22:49:27 +0000
>--- src/lazr/
>+++ src/lazr/
>@@ -202,7 +202,7 @@
> collection, or if used more than once in the same interface.
> """
>
>- def __init__(self, **params):
>+ def __init__(self, version=None, **params):
> """Create the decorator marking the default collection method.
>
> :param params: Optional parameter values to use when calling the
The docstring should explain how the version parameter should be used.
>@@ -891,20 +898,26 @@ collection_ adapter( interface) : collection_ adapter( interface, version=None): tagged_ interface( interface, 'collection') getTaggedValue( LAZR_WEBSERVICE _EXPORTED) _default_ content' ] content_ by_version = tag['collection _default_ content' ] content_ by_version) , ( __name_ _, version)) content_ by_version[ version] _entry_ schema' ] Schema( entry_schema) , _default_ content' ], _default_ content_ params' ], apter" % interface. __name_ _[1:] class_name(
> return method(**params)
>
>
>-def generate_
>+def generate_
> """Create a class adapting from interface to ICollection."""
> _check_
>
> tag = interface.
>- method_name = tag['collection
>+ default_
>+ assert (version in default_
>+ "'%s' isn't tagged for export to web service "
>+ "version '%s'." % (interface.
>+ method_name, params = default_
> entry_schema = tag['collection
> class_dict = {
> 'entry_schema' : CollectionEntry
>- 'method_name': tag['collection
>- 'params': tag['collection
>+ 'method_name': method_name,
>+ 'params': params,
> '__doc__': interface.__doc__,
> }
>- classname = "%sCollectionAd
>+ classname =_versioned_
s/=_/= _/
>+ "%sCollectionAd apter" % interface. __name_ _[1:], Adapter, ), class_dict) schema( factory, ICollection) interface. __name_ _, tag['as'], class_name( interface. __name_ _, tag['as']), 'params' ].values( )), 'send_modificat ion_event' ] = True identifier_ safe(name) , bases, class_dict) (factory, provides) schema( factory, provides) class_name( base_name, version): _safe(name) restful/ docs/webservice -declarations. txt' restful/ docs/webservice -declarations. txt 2010-01-25 19:26:30 +0000 restful/ docs/webservice -declarations. txt 2010-01-27 22:49:27 +0000 tag(IBookSet) default_ content: 'getAllBooks' default_ content_ params: {} default_ content: {None: ('getAllBooks', {})} entry_schema: <InterfaceClass __builtin__.IBook> tag(ICheckedOut BookSet) default_ content: 'getByTitle' default_ content_ params: {'title': '', default_ content: {None: ('getByTitle', entry_schema: <InterfaceClass __builtin__.IBook> default_ content. default_ content for version (earliest).
>+ version)
> factory = type(classname, (BaseCollection
>
> protect_
>@@ -1016,8 +1029,9 @@
> if return_type is None:
> return_type = None
>
>- name = '%s_%s_%s_%s' % (prefix, method.
>- version)
>+ name = _versioned_
>+ '%s_%s_%s' % (prefix, method.
>+ version)
> class_dict = {'params' : tuple(tag[
> 'return_type' : return_type,
> '_export_info': tag,
>@@ -1026,8 +1040,20 @@
>
> if tag['type'] == 'write_operation':
> class_dict[
>- factory = type(make_
>+ factory = type(name, bases, class_dict)
> classImplements
> protect_
>
> return factory
>+
>+
>+def _versioned_
>+ """Create a class name incorporating the given version string."""
>+ if version is None:
>+ # We need to incorporate the version into a Python class name,
>+ # but we won't find out the name of the earliest version until
>+ # runtime. Use a generic string that won't conflict with a
>+ # real version string.
>+ version = "__Earliest"
>+ name = "%s_%s" % (base_name, version)
>+ return make_identifier
>
>=== modified file 'src/lazr/
>--- src/lazr/
>+++ src/lazr/
>@@ -170,15 +170,14 @@
> tagged value.
>
> >>> print_export_
>- collection_
>- collection_
>+ collection_
> collection_
> type: 'collection'
>
> >>> print_export_
>- collection_
>- collection_
>- 'user': <object...>}
>+ collection_
>+ {'title': '',
>+ 'user': <object object ...>})}
> collection_
> type: 'collection'
>
>@@ -223,8 +222,8 @@
> ... """Another getAll()."""
> Traceback (most recent call last):
> ...
>- TypeError: only one method should be marked with
>- @collection_
>+ TypeError: Only one method can be marked with
>+ @collection_
I think this could actually confuse someone, since the parens don't default_ content( version= "method" ) yielded the
imply that it is actually the name of the version. It could also be
confusing if @collection_
error message ending with "for version method". I think double-quotes
around the version name would make it clear that the word doesn't have
another meaning in the sentence.
> export_ as_webservice_ collection( ) can only be used on Interface. testing. webservice import FakeRequest declarations import cache_for IBookSet) :
>
>@@ -1452,7 +1451,6 @@
> It is possible to cache a server response in the browser cache using
> the @cache_for decorator:
>
>- >>> from lazr.restful.
> >>> from lazr.restful.
> >>>
> >>> class ICachedBookSet(