def testComplex(self): urlQuery = ('item1={0}&item2[key1.1][][subkey1.1][]={1}&item2[key1.1][][]={1}' '&item2[key2.1]={2}&item2[key3.1][subkey3.1]={3}&item3[key1.1][subkey1.1]={4}&noValue' ).format(encode('''!D"e#m$o%'''), encode('''&D'e(m)o*'''), encode('''+D e,m-o.'''), encode('''/D[e]m>o<'''), encode('Demo')) parseDict = parseStr(urlQuery) matchDict = { 'item1': '!D"e#m$o%', 'item2': { 'key1.1': [{'subkey1.1': ["&D'e(m)o*"]}, "&D'e(m)o*"], 'key2.1': '+D e,m-o.', 'key3.1': {'subkey3.1': '/D[e]m>o<'} }, 'item3': { 'key1.1': {'subkey1.1': 'Demo'} }, 'noValue': None } self.assertDictEqual(parseDict, matchDict, 'Complex: {0}'.format(urlQuery))
def parseURLEncoded(content, charSet): return parseStr(codecs.getreader(charSet)(content).read()) b = ParseTextHandler(); yield b
def parseURLEncoded(content, charSet): return parseStr(codecs.getreader(charSet)(content).read())
def testDictList(self): urlQuery = 'list[demo][]=abc&list[demo][]=def&list[demo][]=xyz' parseDict = parseStr(urlQuery) self.assertDictEqual(parseDict, {'list': {'demo': ['abc', 'def', 'xyz']}}, 'Dict and list: {0}'.format(urlQuery))
def testSimpleList(self): urlQuery = 'list[]=demo&list[]=demo&list[]=abc' + quote('de mo+de mo') parseDict = parseStr(urlQuery) self.assertDictEqual(parseDict, {'list': ['demo', 'demo', 'abcde mo+de mo']}, 'Simple list: {0}'.format(urlQuery))
def testSimpleMore(self): urlQuery = 'simple=demo&another=' + quote('de mo') + '&last=is' self.assertDictEqual(parseStr(urlQuery), {'simple': 'demo', 'another': 'de mo', 'last': 'is'}, 'Simple more params: {0}'.format(urlQuery))
def testSimple(self): urlQuery = 'simple=demo' self.assertDictEqual(parseStr(urlQuery), {'simple': 'demo'}, 'Simple: {0}'.format(urlQuery))
def parserUrlencoded(content, charSet): return parseStr(codecs.getreader(charSet)(content).read())