diff options
| author | Tom Christie | 2011-12-29 13:31:12 +0000 |
|---|---|---|
| committer | Tom Christie | 2011-12-29 13:31:12 +0000 |
| commit | 07349597ab936dc9887caa70b5d7d2860c897b12 (patch) | |
| tree | db1fdb8934e4d8dc8d3afe8d1e9fd076e3a4e27d /djangorestframework/utils | |
| parent | 1bdc5eacc6290c486796eb5ab8fa29092137dab6 (diff) | |
| download | django-rest-framework-07349597ab936dc9887caa70b5d7d2860c897b12.tar.bz2 | |
whitespace fixes
Diffstat (limited to 'djangorestframework/utils')
| -rw-r--r-- | djangorestframework/utils/__init__.py | 16 | ||||
| -rw-r--r-- | djangorestframework/utils/breadcrumbs.py | 12 | ||||
| -rw-r--r-- | djangorestframework/utils/description.py | 14 | ||||
| -rw-r--r-- | djangorestframework/utils/mediatypes.py | 4 |
4 files changed, 23 insertions, 23 deletions
diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index 04baea78..305311f4 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -36,7 +36,7 @@ def as_tuple(obj): return obj return (obj,) - + def url_resolves(url): """ Return True if the given URL is mapped to a view in the urlconf, False otherwise. @@ -50,7 +50,7 @@ def url_resolves(url): # From http://www.koders.com/python/fidB6E125C586A6F49EAC38992CF3AFDAAE35651975.aspx?s=mdef:xml #class object_dict(dict): -# """object view of dict, you can +# """object view of dict, you can # >>> a = object_dict() # >>> a.fish = 'fish' # >>> a['fish'] @@ -103,8 +103,8 @@ class XML2Dict(object): old = node_tree[tag] if not isinstance(old, list): node_tree.pop(tag) - node_tree[tag] = [old] # multi times, so change old dict to a list - node_tree[tag].append(tree) # add the new one + node_tree[tag] = [old] # multi times, so change old dict to a list + node_tree[tag].append(tree) # add the new one return node_tree @@ -117,13 +117,13 @@ class XML2Dict(object): """ result = re.compile("\{(.*)\}(.*)").search(tag) if result: - value.namespace, tag = result.groups() + value.namespace, tag = result.groups() return (tag, value) def parse(self, file): """parse a xml file to a dict""" f = open(file, 'r') - return self.fromstring(f.read()) + return self.fromstring(f.read()) def fromstring(self, s): """parse a string""" @@ -159,7 +159,7 @@ class XMLRenderer(): xml.characters(smart_unicode(data)) def dict2xml(self, data): - stream = StringIO.StringIO() + stream = StringIO.StringIO() xml = SimplerXMLGenerator(stream, "utf-8") xml.startDocument() @@ -172,4 +172,4 @@ class XMLRenderer(): return stream.getvalue() def dict2xml(input): - return XMLRenderer().dict2xml(input)
\ No newline at end of file + return XMLRenderer().dict2xml(input) diff --git a/djangorestframework/utils/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py index 0b043c78..6cf978ed 100644 --- a/djangorestframework/utils/breadcrumbs.py +++ b/djangorestframework/utils/breadcrumbs.py @@ -3,12 +3,12 @@ from djangorestframework.utils.description import get_name def get_breadcrumbs(url): """Given a url returns a list of breadcrumbs, which are each a tuple of (name, url).""" - + from djangorestframework.views import View - + def breadcrumbs_recursive(url, breadcrumbs_list): """Add tuples of (name, url) to the breadcrumbs list, progressively chomping off parts of the url.""" - + try: (view, unused_args, unused_kwargs) = resolve(url) except: @@ -17,15 +17,15 @@ def get_breadcrumbs(url): # Check if this is a REST framework view, and if so add it to the breadcrumbs if isinstance(getattr(view, 'cls_instance', None), View): breadcrumbs_list.insert(0, (get_name(view), url)) - + if url == '': # All done return breadcrumbs_list - + elif url.endswith('/'): # Drop trailing slash off the end and continue to try to resolve more breadcrumbs return breadcrumbs_recursive(url.rstrip('/'), breadcrumbs_list) - + # Drop trailing non-slash off the end and continue to try to resolve more breadcrumbs return breadcrumbs_recursive(url[:url.rfind('/') + 1], breadcrumbs_list) diff --git a/djangorestframework/utils/description.py b/djangorestframework/utils/description.py index 25bef80b..ce61e558 100644 --- a/djangorestframework/utils/description.py +++ b/djangorestframework/utils/description.py @@ -10,7 +10,7 @@ from djangorestframework.resources import Resource, FormResource, ModelResource def get_name(view): """ Return a name for the view. - + If view has a name attribute, use that, otherwise use the view's class name, with 'CamelCaseNames' converted to 'Camel Case Names'. """ @@ -22,7 +22,7 @@ def get_name(view): # If this view has a resource that's been overridden, then use that resource for the name if getattr(view, 'resource', None) not in (None, Resource, FormResource, ModelResource): name = view.resource.__name__ - + # Chomp of any non-descriptive trailing part of the resource class name if name.endswith('Resource') and name != 'Resource': name = name[:-len('Resource')] @@ -30,7 +30,7 @@ def get_name(view): # If the view has a descriptive suffix, eg '*** List', '*** Instance' if getattr(view, '_suffix', None): name += view._suffix - + # Otherwise if it's a function view use the function's name elif getattr(view, '__name__', None) is not None: name = view.__name__ @@ -62,12 +62,12 @@ def get_description(view): # grok the class instance that we stored when as_view was called. if getattr(view, 'cls_instance', None): view = view.cls_instance - + # If this view has a resource that's been overridden, then use the resource's doctring if getattr(view, 'resource', None) not in (None, Resource, FormResource, ModelResource): doc = view.resource.__doc__ - + # Otherwise use the view doctring elif getattr(view, '__doc__', None): doc = view.__doc__ @@ -81,11 +81,11 @@ def get_description(view): whitespace_counts = [len(line) - len(line.lstrip(' ')) for line in doc.splitlines()[1:] if line.lstrip()] - # unindent the docstring if needed + # unindent the docstring if needed if whitespace_counts: whitespace_pattern = '^' + (' ' * min(whitespace_counts)) return re.sub(re.compile(whitespace_pattern, re.MULTILINE), '', doc) # otherwise return it as-is return doc - + diff --git a/djangorestframework/utils/mediatypes.py b/djangorestframework/utils/mediatypes.py index ae734e62..3c0eefc4 100644 --- a/djangorestframework/utils/mediatypes.py +++ b/djangorestframework/utils/mediatypes.py @@ -111,7 +111,7 @@ class _MediaType(object): # return Decimal(self.params.get('q', '1.0')) # except: # return Decimal(0) - + #def score(self): # """ # Return an overall score for a given media type given it's quality and precedence. @@ -119,7 +119,7 @@ class _MediaType(object): # # NB. quality values should only have up to 3 decimal points # # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9 # return self.quality * 10000 + self.precedence - + #def as_tuple(self): # return (self.main_type, self.sub_type, self.params) |
