Merge lp:~thumper/lazr.enum/case-insensitive-getTokenByTerm into lp:lazr.enum

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: 32
Merged at revision: 31
Proposed branch: lp:~thumper/lazr.enum/case-insensitive-getTokenByTerm
Merge into: lp:lazr.enum
Diff against target: 47 lines (+16/-2)
3 files modified
HACKING.txt (+10/-0)
src/lazr/enum/README.txt (+3/-0)
src/lazr/enum/_enum.py (+3/-2)
To merge this branch: bzr merge lp:~thumper/lazr.enum/case-insensitive-getTokenByTerm
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+51843@code.launchpad.net

Description of the change

Given that the token value of the enumerated item is guaranteed to be unique considering case insensitivity, I've changed the getTermByToken method to be case insensitive in its looking for the term.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Cheers for updating HACKING.txt; I've also stumbled on this before.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING.txt'
2--- HACKING.txt 2009-03-24 14:12:06 +0000
3+++ HACKING.txt 2011-03-02 01:43:52 +0000
4@@ -39,3 +39,13 @@
5 or send a message to:
6
7 lazr-developers@lists.launchpad.net
8+
9+
10+Getting started
11+---------------
12+
13+lazr.enum uses buildout to get the dependencies.
14+
15+ python bootstrap.py
16+ bin/buildout
17+ bin/test -c
18
19=== modified file 'src/lazr/enum/README.txt'
20--- src/lazr/enum/README.txt 2009-06-08 21:29:30 +0000
21+++ src/lazr/enum/README.txt 2011-03-02 01:43:52 +0000
22@@ -69,6 +69,9 @@
23 >>> item.title
24 'Apple'
25
26+ >>> Fruit.getTermByToken('apple').value
27+ <Item Fruit.APPLE, Apple>
28+
29 The length of an EnumeratedType returns the number of items it has.
30
31 >>> print len(Fruit)
32
33=== modified file 'src/lazr/enum/_enum.py'
34--- src/lazr/enum/_enum.py 2009-06-08 21:29:30 +0000
35+++ src/lazr/enum/_enum.py 2011-03-02 01:43:52 +0000
36@@ -421,8 +421,9 @@
37 def getTermByToken(self, token):
38 """See `IVocabularyTokenized`."""
39 # The sort_order of the enumerated type lists all the items.
40- if token in self.sort_order:
41- return TokenizedItem(getattr(self, token))
42+ upper_token = token.upper()
43+ if upper_token in self.sort_order:
44+ return TokenizedItem(getattr(self, upper_token))
45 else:
46 # If the token is not specified in the sort order then check
47 # the titles of the items. This is to support the transition

Subscribers

People subscribed via source and target branches

to all changes: