Merge lp:~leonardr/lazr.restful/its-really-read-only into lp:lazr.restful
Proposed by
Leonard Richardson
Status: | Merged |
---|---|
Approved by: | Guilherme Salgado |
Approved revision: | 142 |
Merged at revision: | 141 |
Proposed branch: | lp:~leonardr/lazr.restful/its-really-read-only |
Merge into: | lp:lazr.restful |
Diff against target: | 0 lines |
To merge this branch: | bzr merge lp:~leonardr/lazr.restful/its-really-read-only |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guilherme Salgado (community) | Approve | ||
Review via email: mp+33820@code.launchpad.net |
Description of the change
This simple branch makes it possible to take a read-write field and publish it as read-only in the web service. I tested this with a simple doctest, and by changing the integration test example web service so that ICookbook.
The opposite of this branch is taking a read-only field and publishing it as read-write. This was already supported by the use of mutators. That's a much more complicated situation and there's no need to do anything nearly as complicated here.
To post a comment you must log in.
Hi Leonard,
This branch looks fine; I have just one minor suggestion.
review approve
status approved
On Thu, 2010-08-26 at 18:48 +0000, Leonard Richardson wrote: restful/ declarations. py' restful/ declarations. py 2010-08-18 18:02:44 +0000 restful/ declarations. py 2010-08-26 18:48:44 +0000 stack[' type'] = FIELD_TYPE key_for_ argument_ key = {'exported_as' : 'as', key_for_ argument_ key[key] key_for_ argument_ key.items( ): stack[annotatio n_key] = kwparams.pop(key) by_annotations = tags.get( annotations' , (None, {})) 'readonly' , None) == False): 'readonly' , False):
[...]
> === modified file 'src/lazr/
> --- src/lazr/
> +++ src/lazr/
> @@ -213,14 +213,13 @@
> annotation_
>
> annotation_
> - 'exported' : 'exported'}
> + 'exported' : 'exported',
> + 'readonly' : 'readonly'}
>
> - # The only valid keyword parameters are 'exported' and
> - # 'exported_as', which manage the behavior in the first
> - # version. If these keywords are present, incorporate them into
> - # the VersionedDict.
> - for key in ('exported_as', 'exported'):
> - annotation_key = annotation_
> + # If keyword parameters are present, they define the field's
> + # behavior for the first version. Incorporate them into the
> + # VersionedDict.
> + for (key, annotation_key) in annotation_
> if key in kwparams:
> annotation_
> # If any keywords are left over, raise an exception.
> @@ -918,6 +917,19 @@
> mutated_by, mutated_
> 'mutator_
> readonly = (field.readonly and mutated_by is None)
> + # Clear up some possible confusion.
> + if (readonly and tags.get(
> + raise TypeError(
> + ("%s.%s is defined as a read-only field and you "
> + "haven't defined a mutator for it. You can't just "
> + "declare it to be read-write in the web service: "
> + "you need to define a mutator.") % (
> + interface.__name__, field.__name__))
> + if not readonly and tags.get(
> + # The field is read-write internally, but the
> + # developer wants it to be read-only through the web
> + # service.
> + readonly = True
There's something about using tags.get() twice with different arguments
that makes this code (IMHO) not as easy to follow as it should be. Maybe
it's just me, but I thought of the following, which certainly makes it
look clearer:
if 'readonly' in tags:
publish_ as_readonly = tags.get( 'readonly' ) as_readonly:
raise TypeError(...) as_readonly:
readonly = True
if readonly and not publish_
if not readonly and publish_
What do you think?
> attrs[tags['as']] = copy_field( _=tags[ 'as'], readonly=readonly) class_name(
> field, __name_
> class_name = _versioned_