2005-11-30 04:08:46 +00:00
|
|
|
"""
|
|
|
|
###################
|
|
|
|
# Empty QueryDict #
|
|
|
|
###################
|
|
|
|
|
|
|
|
>>> q = QueryDict('')
|
|
|
|
|
|
|
|
>>> q['foo']
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
2007-09-20 15:51:19 +00:00
|
|
|
MultiValueDictKeyError: "Key 'foo' not found in <QueryDict: {}>"
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q['something'] = 'bar'
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.get('foo', 'default')
|
|
|
|
'default'
|
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> q.setlist('foo', ['bar', 'baz'])
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.appendlist('foo', ['bar'])
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.has_key('foo')
|
|
|
|
False
|
|
|
|
|
2007-04-26 13:30:48 +00:00
|
|
|
>>> 'foo' in q
|
|
|
|
False
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.items()
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> q.lists()
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> q.keys()
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> q.values()
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> len(q)
|
|
|
|
0
|
|
|
|
|
|
|
|
>>> q.update({'foo': 'bar'})
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.pop('foo')
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.popitem()
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.clear()
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.setdefault('foo', 'bar')
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.urlencode()
|
|
|
|
''
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Mutable copy of empty QueryDict #
|
|
|
|
###################################
|
|
|
|
|
|
|
|
>>> q = q.copy()
|
|
|
|
|
|
|
|
>>> q['foo']
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
2007-09-20 15:51:19 +00:00
|
|
|
MultiValueDictKeyError: "Key 'foo' not found in <QueryDict: {}>"
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q['name'] = 'john'
|
|
|
|
|
|
|
|
>>> q['name']
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'john'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
2007-05-11 08:22:06 +00:00
|
|
|
>>> del q['name']
|
|
|
|
>>> 'name' in q
|
|
|
|
False
|
|
|
|
|
|
|
|
>>> q['name'] = 'john'
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.get('foo', 'default')
|
|
|
|
'default'
|
|
|
|
|
|
|
|
>>> q.get('name', 'default')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'john'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.getlist('name')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'john']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> q.setlist('foo', ['bar', 'baz'])
|
|
|
|
|
|
|
|
>>> q.get('foo', 'default')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'baz'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'bar', u'baz']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.appendlist('foo', 'another')
|
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'bar', u'baz', u'another']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q['foo']
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'another'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.has_key('foo')
|
|
|
|
True
|
|
|
|
|
2007-04-26 13:30:48 +00:00
|
|
|
>>> 'foo' in q
|
|
|
|
True
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.items()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[(u'foo', u'another'), (u'name', u'john')]
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.lists()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[(u'foo', [u'bar', u'baz', u'another']), (u'name', [u'john'])]
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.keys()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'foo', u'name']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.values()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'another', u'john']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> len(q)
|
|
|
|
2
|
|
|
|
|
|
|
|
>>> q.update({'foo': 'hello'})
|
|
|
|
|
|
|
|
# Displays last value
|
|
|
|
>>> q['foo']
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'hello'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.get('foo', 'not available')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'hello'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'bar', u'baz', u'another', u'hello']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.pop('foo')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'bar', u'baz', u'another', u'hello']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
2007-05-19 18:34:00 +00:00
|
|
|
>>> q.pop('foo', 'not there')
|
|
|
|
'not there'
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.get('foo', 'not there')
|
|
|
|
'not there'
|
|
|
|
|
|
|
|
>>> q.setdefault('foo', 'bar')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'bar'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q['foo']
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'bar'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'bar']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.urlencode()
|
|
|
|
'foo=bar&name=john'
|
|
|
|
|
|
|
|
>>> q.clear()
|
|
|
|
|
|
|
|
>>> len(q)
|
|
|
|
0
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# QueryDict with one key/value pair #
|
|
|
|
#####################################
|
|
|
|
|
|
|
|
>>> q = QueryDict('foo=bar')
|
|
|
|
|
|
|
|
>>> q['foo']
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'bar'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q['bar']
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
2007-09-20 15:51:19 +00:00
|
|
|
MultiValueDictKeyError: "Key 'bar' not found in <QueryDict: {u'foo': [u'bar']}>"
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q['something'] = 'bar'
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.get('foo', 'default')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'bar'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.get('bar', 'default')
|
|
|
|
'default'
|
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'bar']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.getlist('bar')
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> q.setlist('foo', ['bar', 'baz'])
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.appendlist('foo', ['bar'])
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.has_key('foo')
|
|
|
|
True
|
|
|
|
|
2007-04-26 13:30:48 +00:00
|
|
|
>>> 'foo' in q
|
|
|
|
True
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.has_key('bar')
|
|
|
|
False
|
|
|
|
|
2007-04-26 13:30:48 +00:00
|
|
|
>>> 'bar' in q
|
|
|
|
False
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.items()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[(u'foo', u'bar')]
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.lists()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[(u'foo', [u'bar'])]
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.keys()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'foo']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.values()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'bar']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> len(q)
|
|
|
|
1
|
|
|
|
|
|
|
|
>>> q.update({'foo': 'bar'})
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.pop('foo')
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.popitem()
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.clear()
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.setdefault('foo', 'bar')
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.urlencode()
|
|
|
|
'foo=bar'
|
|
|
|
|
|
|
|
#####################################################
|
|
|
|
# QueryDict with two key/value pairs with same keys #
|
|
|
|
#####################################################
|
|
|
|
|
|
|
|
>>> q = QueryDict('vote=yes&vote=no')
|
|
|
|
|
|
|
|
>>> q['vote']
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'no'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q['something'] = 'bar'
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.get('vote', 'default')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
u'no'
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.get('foo', 'default')
|
|
|
|
'default'
|
|
|
|
|
|
|
|
>>> q.getlist('vote')
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'yes', u'no']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
|
|
|
[]
|
|
|
|
|
|
|
|
>>> q.setlist('foo', ['bar', 'baz'])
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.appendlist('foo', ['bar'])
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.has_key('vote')
|
|
|
|
True
|
|
|
|
|
2007-04-26 13:30:48 +00:00
|
|
|
>>> 'vote' in q
|
|
|
|
True
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.has_key('foo')
|
|
|
|
False
|
|
|
|
|
2007-04-26 13:30:48 +00:00
|
|
|
>>> 'foo' in q
|
|
|
|
False
|
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
>>> q.items()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[(u'vote', u'no')]
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.lists()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[(u'vote', [u'yes', u'no'])]
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.keys()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'vote']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> q.values()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
[u'no']
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
>>> len(q)
|
|
|
|
1
|
|
|
|
|
|
|
|
>>> q.update({'foo': 'bar'})
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.pop('foo')
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.popitem()
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.clear()
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.setdefault('foo', 'bar')
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
|
|
|
>>> q.urlencode()
|
|
|
|
'vote=yes&vote=no'
|
|
|
|
|
2007-05-11 08:22:06 +00:00
|
|
|
>>> del q['vote']
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
AttributeError: This QueryDict instance is immutable
|
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
# QueryDicts must be able to handle invalid input encoding (in this case, bad
|
|
|
|
# UTF-8 encoding).
|
|
|
|
>>> q = QueryDict('foo=bar&foo=\xff')
|
|
|
|
|
|
|
|
>>> q['foo']
|
|
|
|
u'\ufffd'
|
|
|
|
|
|
|
|
>>> q.getlist('foo')
|
|
|
|
[u'bar', u'\ufffd']
|
|
|
|
|
2007-12-17 08:05:51 +00:00
|
|
|
|
2008-08-21 13:55:21 +00:00
|
|
|
########################
|
|
|
|
# Pickling a QueryDict #
|
|
|
|
########################
|
|
|
|
>>> import pickle
|
|
|
|
>>> q = QueryDict('a=b&c=d')
|
|
|
|
>>> q1 = pickle.loads(pickle.dumps(q))
|
|
|
|
>>> q == q1
|
|
|
|
True
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# HttpResponse with Unicode headers #
|
|
|
|
######################################
|
|
|
|
|
|
|
|
>>> r = HttpResponse()
|
|
|
|
|
2007-12-17 08:05:51 +00:00
|
|
|
If we insert a unicode value it will be converted to an ascii
|
|
|
|
string. This makes sure we comply with the HTTP specifications.
|
2008-08-21 13:55:21 +00:00
|
|
|
|
|
|
|
>>> r['value'] = u'test value'
|
|
|
|
>>> isinstance(r['value'], str)
|
2007-12-17 08:05:51 +00:00
|
|
|
True
|
|
|
|
|
|
|
|
An error is raised When a unicode object with non-ascii is assigned.
|
|
|
|
|
|
|
|
>>> r['value'] = u't\xebst value' # doctest:+ELLIPSIS
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format
|
2008-08-21 13:55:21 +00:00
|
|
|
|
|
|
|
The response also converts unicode keys to strings.
|
|
|
|
|
|
|
|
>>> r[u'test'] = 'testing key'
|
2007-12-17 08:50:19 +00:00
|
|
|
>>> l = list(r.items())
|
|
|
|
>>> l.sort()
|
|
|
|
>>> l[1]
|
2007-12-17 08:05:51 +00:00
|
|
|
('test', 'testing key')
|
|
|
|
|
|
|
|
It will also raise errors for keys with non-ascii data.
|
|
|
|
|
|
|
|
>>> r[u't\xebst'] = 'testing key' # doctest:+ELLIPSIS
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format
|
2008-08-21 13:55:21 +00:00
|
|
|
|
2005-11-30 04:08:46 +00:00
|
|
|
"""
|
|
|
|
|
2007-12-17 08:05:51 +00:00
|
|
|
from django.http import QueryDict, HttpResponse
|
2005-11-30 04:08:46 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import doctest
|
|
|
|
doctest.testmod()
|