Fixed #3036 -- Fixed some doctest strings that were failing. Thanks to pterk for the original patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6268 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2007-09-15 08:29:56 +00:00
parent 671a8359e8
commit 84e824fbbf
5 changed files with 33 additions and 34 deletions

View File

@ -3,9 +3,9 @@ Interfaces for serializing Django objects.
Usage:: Usage::
>>> from django.core import serializers from django.core import serializers
>>> json = serializers.serialize("json", some_query_set) json = serializers.serialize("json", some_query_set)
>>> objects = list(serializers.deserialize("json", json)) objects = list(serializers.deserialize("json", json))
To add your own serializers, use the SERIALIZATION_MODULES setting:: To add your own serializers, use the SERIALIZATION_MODULES setting::

View File

@ -405,12 +405,17 @@ class NumberIsInRange(object):
class IsAPowerOf(object): class IsAPowerOf(object):
""" """
>>> v = IsAPowerOf(2) Usage: If you create an instance of the IsPowerOf validator:
>>> v(4, None) v = IsAPowerOf(2)
>>> v(8, None)
>>> v(16, None) The following calls will succeed:
>>> v(17, None) v(4, None)
django.core.validators.ValidationError: ['This value must be a power of 2.'] v(8, None)
v(16, None)
But this call:
v(17, None)
will raise "django.core.validators.ValidationError: ['This value must be a power of 2.']"
""" """
def __init__(self, power_of): def __init__(self, power_of):
self.power_of = power_of self.power_of = power_of

View File

@ -34,14 +34,8 @@ will be raised if the template doesn't have proper syntax.
Sample code: Sample code:
>>> import template >>> from django import template
>>> s = ''' >>> s = u'<html>{% if test %}<h1>{{ varvalue }}</h1>{% endif %}</html>'
... <html>
... {% if test %}
... <h1>{{ varvalue }}</h1>
... {% endif %}
... </html>
... '''
>>> t = template.Template(s) >>> t = template.Template(s)
(t is now a compiled template, and its render() method can be called multiple (t is now a compiled template, and its render() method can be called multiple
@ -49,10 +43,10 @@ times with multiple contexts)
>>> c = template.Context({'test':True, 'varvalue': 'Hello'}) >>> c = template.Context({'test':True, 'varvalue': 'Hello'})
>>> t.render(c) >>> t.render(c)
'\n<html>\n\n <h1>Hello</h1>\n\n</html>\n' u'<html><h1>Hello</h1></html>'
>>> c = template.Context({'test':False, 'varvalue': 'Hello'}) >>> c = template.Context({'test':False, 'varvalue': 'Hello'})
>>> t.render(c) >>> t.render(c)
'\n<html>\n\n</html>\n' u'<html></html>'
""" """
import re import re
from inspect import getargspec from inspect import getargspec
@ -529,10 +523,11 @@ class FilterExpression(object):
and return a list of tuples of the filter name and arguments. and return a list of tuples of the filter name and arguments.
Sample: Sample:
>>> token = 'variable|default:"Default value"|date:"Y-m-d"' >>> token = 'variable|default:"Default value"|date:"Y-m-d"'
>>> p = FilterParser(token) >>> p = Parser('')
>>> p.filters >>> fe = FilterExpression(token, p)
[('default', 'Default value'), ('date', 'Y-m-d')] >>> len(fe.filters)
>>> p.var 2
>>> fe.var
'variable' 'variable'
This class should never be instantiated outside of the This class should never be instantiated outside of the
@ -647,7 +642,7 @@ def resolve_variable(path, context):
>>> c = {'article': {'section':'News'}} >>> c = {'article': {'section':'News'}}
>>> resolve_variable('article.section', c) >>> resolve_variable('article.section', c)
'News' u'News'
>>> resolve_variable('article', c) >>> resolve_variable('article', c)
{'section': 'News'} {'section': 'News'}
>>> class AClass: pass >>> class AClass: pass
@ -655,7 +650,7 @@ def resolve_variable(path, context):
>>> c.article = AClass() >>> c.article = AClass()
>>> c.article.section = 'News' >>> c.article.section = 'News'
>>> resolve_variable('article.section', c) >>> resolve_variable('article.section', c)
'News' u'News'
(The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.') (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.')
""" """

View File

@ -238,22 +238,20 @@ class DotExpandedDict(dict):
may contain dots to specify inner dictionaries. It's confusing, but this may contain dots to specify inner dictionaries. It's confusing, but this
example should make sense. example should make sense.
>>> d = DotExpandedDict({'person.1.firstname': ['Simon'], >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], \
'person.1.lastname': ['Willison'], 'person.1.lastname': ['Willison'], \
'person.2.firstname': ['Adrian'], 'person.2.firstname': ['Adrian'], \
'person.2.lastname': ['Holovaty']}) 'person.2.lastname': ['Holovaty']})
>>> d >>> d
{'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']}, {'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']}, '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}
'2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}
>>> d['person'] >>> d['person']
{'1': {'firstname': ['Simon'], 'lastname': ['Willison'], {'1': {'lastname': ['Willison'], 'firstname': ['Simon']}, '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}
'2': {'firstname': ['Adrian'], 'lastname': ['Holovaty']}
>>> d['person']['1'] >>> d['person']['1']
{'firstname': ['Simon'], 'lastname': ['Willison']} {'lastname': ['Willison'], 'firstname': ['Simon']}
# Gotcha: Results are unpredictable if the dots are "uneven": # Gotcha: Results are unpredictable if the dots are "uneven":
>>> DotExpandedDict({'c.1': 2, 'c.2': 3, 'c': 1}) >>> DotExpandedDict({'c.1': 2, 'c.2': 3, 'c': 1})
>>> {'c': 1} {'c': 1}
""" """
def __init__(self, key_to_list_mapping): def __init__(self, key_to_list_mapping):
for k, v in key_to_list_mapping.items(): for k, v in key_to_list_mapping.items():

View File

@ -3,6 +3,7 @@ Syndication feed generation library -- used for generating RSS, etc.
Sample usage: Sample usage:
>>> from django.utils import feedgenerator
>>> feed = feedgenerator.Rss201rev2Feed( >>> feed = feedgenerator.Rss201rev2Feed(
... title=u"Poynter E-Media Tidbits", ... title=u"Poynter E-Media Tidbits",
... link=u"http://www.poynter.org/column.asp?id=31", ... link=u"http://www.poynter.org/column.asp?id=31",