Ticket #3036: 3036.diff

File 3036.diff, 5.3 KB (added by Peter van Kampen, 17 years ago)

Patch for #3036

  • django/core/serializers/__init__.py

     
    33
    44Usage::
    55
    6     >>> from django.core import serializers
    7     >>> json = serializers.serialize("json", some_query_set)
    8     >>> objects = list(serializers.deserialize("json", json))
     6    from django.core import serializers
     7    json = serializers.serialize("json", some_query_set)
     8    objects = list(serializers.deserialize("json", json))
    99
    1010To add your own serializers, use the SERIALIZATION_MODULES setting::
    1111
  • django/core/validators.py

     
    410410    >>> v(8, None)
    411411    >>> v(16, None)
    412412    >>> v(17, None)
    413     django.core.validators.ValidationError: ['This value must be a power of 2.']
     413    Traceback (most recent call last):
     414      File "doctest.py", line 1212, in __run
     415        compileflags, 1) in test.globs
     416      File "<doctest django.core.validators.IsAPowerOf[4]>", line 1, in <module>
     417        v(17, None)
     418      File "django/core/validators.py", line 424, in __call__
     419    ValidationError: [u'This value must be a power of 2.']
    414420    """
    415421    def __init__(self, power_of):
    416422        self.power_of = power_of
  • django/utils/feedgenerator.py

     
    33
    44Sample usage:
    55
     6>>> from django.utils import feedgenerator
    67>>> feed = feedgenerator.Rss201rev2Feed(
    78...     title=u"Poynter E-Media Tidbits",
    89...     link=u"http://www.poynter.org/column.asp?id=31",
  • django/utils/datastructures.py

     
    238238    may contain dots to specify inner dictionaries. It's confusing, but this
    239239    example should make sense.
    240240
    241     >>> d = DotExpandedDict({'person.1.firstname': ['Simon'],
    242             'person.1.lastname': ['Willison'],
    243             'person.2.firstname': ['Adrian'],
    244             'person.2.lastname': ['Holovaty']})
    245     >>> d
    246     {'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']},
    247     '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}
    248     >>> d['person']
    249     {'1': {'firstname': ['Simon'], 'lastname': ['Willison'],
    250     '2': {'firstname': ['Adrian'], 'lastname': ['Holovaty']}
    251     >>> d['person']['1']
    252     {'firstname': ['Simon'], 'lastname': ['Willison']}
     241    >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], \
     242                    'person.1.lastname': ['Willison'], \
     243                    'person.2.firstname': ['Adrian'], \
     244                    'person.2.lastname': ['Holovaty']})
     245    >>> d['person']['1']['lastname']
     246    ['Willison']
     247    >>> d['person']['1']['firstname']
     248    ['Simon']
     249    >>> d['person']['2']['lastname']
     250    ['Holovaty']
     251    >>> d['person']['2']['firstname']
     252    ['Adrian']
    253253
    254254    # Gotcha: Results are unpredictable if the dots are "uneven":
    255255    >>> DotExpandedDict({'c.1': 2, 'c.2': 3, 'c': 1})
    256     >>> {'c': 1}
     256    {'c': 1}
    257257    """
    258258    def __init__(self, key_to_list_mapping):
    259259        for k, v in key_to_list_mapping.items():
  • django/template/__init__.py

     
    3434
    3535Sample code:
    3636
    37 >>> import template
    38 >>> s = '''
     37
     38
     39>>> from django import template
     40>>> s = u'''
    3941... <html>
    4042... {% if test %}
    4143...     <h1>{{ varvalue }}</h1>
     
    4951
    5052>>> c = template.Context({'test':True, 'varvalue': 'Hello'})
    5153>>> t.render(c)
    52 '\n<html>\n\n    <h1>Hello</h1>\n\n</html>\n'
     54u'\\n<html>\\n\\n    <h1>Hello</h1>\\n\\n</html>\\n'
    5355>>> c = template.Context({'test':False, 'varvalue': 'Hello'})
    5456>>> t.render(c)
    55 '\n<html>\n\n</html>\n'
     57u'\\n<html>\\n\\n</html>\\n'
    5658"""
    5759import re
    5860from inspect import getargspec
     
    528530    and return a list of tuples of the filter name and arguments.
    529531    Sample:
    530532        >>> token = 'variable|default:"Default value"|date:"Y-m-d"'
    531         >>> p = FilterParser(token)
    532         >>> p.filters
    533         [('default', 'Default value'), ('date', 'Y-m-d')]
    534         >>> p.var
     533        >>> p = Parser('')
     534        >>> fe = FilterExpression(token, p)
     535        >>> len(fe.filters)
     536        2
     537        >>> fe.var
    535538        'variable'
    536 
    537     This class should never be instantiated outside of the
    538     get_filters_from_token helper function.
    539539    """
    540540    def __init__(self, token, parser):
    541541        self.token = token
     
    646646
    647647    >>> c = {'article': {'section':'News'}}
    648648    >>> resolve_variable('article.section', c)
    649     'News'
     649    u'News'
    650650    >>> resolve_variable('article', c)
    651651    {'section': 'News'}
    652652    >>> class AClass: pass
     
    654654    >>> c.article = AClass()
    655655    >>> c.article.section = 'News'
    656656    >>> resolve_variable('article.section', c)
    657     'News'
     657    u'News'
    658658
    659659    (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.')
    660660    """
Back to Top