Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Delta Between Two Patch Sets: Lib/xmlrpclib.py

Issue 26147: Encoding errors in xmlrpc
Left Patch Set: Created 4 years, 1 month ago
Right Patch Set: Created 4 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_xmlrpc.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 # 1 #
2 # XML-RPC CLIENT LIBRARY 2 # XML-RPC CLIENT LIBRARY
3 # $Id$ 3 # $Id$
4 # 4 #
5 # an XML-RPC client interface for Python. 5 # an XML-RPC client interface for Python.
6 # 6 #
7 # the marshalling and response parser code can also be used to 7 # the marshalling and response parser code can also be used to
8 # implement XML-RPC servers. 8 # implement XML-RPC servers.
9 # 9 #
10 # Notes: 10 # Notes:
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 dispatch[FloatType] = dump_double 696 dispatch[FloatType] = dump_double
697 697
698 def dump_string(self, value, write, escape=escape): 698 def dump_string(self, value, write, escape=escape):
699 write("<value><string>") 699 write("<value><string>")
700 write(escape(value)) 700 write(escape(value))
701 write("</string></value>\n") 701 write("</string></value>\n")
702 dispatch[StringType] = dump_string 702 dispatch[StringType] = dump_string
703 703
704 if unicode: 704 if unicode:
705 def dump_unicode(self, value, write, escape=escape): 705 def dump_unicode(self, value, write, escape=escape):
706 value = value.encode(self.encoding)
707 write("<value><string>") 706 write("<value><string>")
708 write(escape(value)) 707 write(escape(value).encode(self.encoding, 'xmlcharrefreplace'))
709 write("</string></value>\n") 708 write("</string></value>\n")
710 dispatch[UnicodeType] = dump_unicode 709 dispatch[UnicodeType] = dump_unicode
711 710
712 def dump_array(self, value, write): 711 def dump_array(self, value, write):
713 i = id(value) 712 i = id(value)
714 if i in self.memo: 713 if i in self.memo:
715 raise TypeError, "cannot marshal recursive sequences" 714 raise TypeError, "cannot marshal recursive sequences"
716 self.memo[i] = None 715 self.memo[i] = None
717 dump = self.__dump 716 dump = self.__dump
718 write("<value><array><data>\n") 717 write("<value><array><data>\n")
719 for v in value: 718 for v in value:
720 dump(v, write) 719 dump(v, write)
721 write("</data></array></value>\n") 720 write("</data></array></value>\n")
722 del self.memo[i] 721 del self.memo[i]
723 dispatch[TupleType] = dump_array 722 dispatch[TupleType] = dump_array
724 dispatch[ListType] = dump_array 723 dispatch[ListType] = dump_array
725 724
726 def dump_struct(self, value, write, escape=escape): 725 def dump_struct(self, value, write, escape=escape):
727 i = id(value) 726 i = id(value)
728 if i in self.memo: 727 if i in self.memo:
729 raise TypeError, "cannot marshal recursive dictionaries" 728 raise TypeError, "cannot marshal recursive dictionaries"
730 self.memo[i] = None 729 self.memo[i] = None
731 dump = self.__dump 730 dump = self.__dump
732 write("<value><struct>\n") 731 write("<value><struct>\n")
733 for k, v in value.items(): 732 for k, v in value.items():
734 write("<member>\n") 733 write("<member>\n")
735 if type(k) is not StringType: 734 if type(k) is StringType:
736 if unicode and type(k) is UnicodeType: 735 k = escape(k)
737 k = k.encode(self.encoding) 736 elif unicode and type(k) is UnicodeType:
738 else: 737 k = escape(k).encode(self.encoding, 'xmlcharrefreplace')
739 raise TypeError, "dictionary key must be string" 738 else:
740 write("<name>%s</name>\n" % escape(k)) 739 raise TypeError, "dictionary key must be string"
740 write("<name>%s</name>\n" % k)
741 dump(v, write) 741 dump(v, write)
742 write("</member>\n") 742 write("</member>\n")
743 write("</struct></value>\n") 743 write("</struct></value>\n")
744 del self.memo[i] 744 del self.memo[i]
745 dispatch[DictType] = dump_struct 745 dispatch[DictType] = dump_struct
746 746
747 if datetime: 747 if datetime:
748 def dump_datetime(self, value, write): 748 def dump_datetime(self, value, write):
749 write("<value><dateTime.iso8601>") 749 write("<value><dateTime.iso8601>")
750 write(_strftime(value)) 750 write(_strftime(value))
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1092
1093 if encoding != "utf-8": 1093 if encoding != "utf-8":
1094 xmlheader = "<?xml version='1.0' encoding='%s'?>\n" % str(encoding) 1094 xmlheader = "<?xml version='1.0' encoding='%s'?>\n" % str(encoding)
1095 else: 1095 else:
1096 xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default 1096 xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default
1097 1097
1098 # standard XML-RPC wrappings 1098 # standard XML-RPC wrappings
1099 if methodname: 1099 if methodname:
1100 # a method call 1100 # a method call
1101 if not isinstance(methodname, StringType): 1101 if not isinstance(methodname, StringType):
1102 methodname = methodname.encode(encoding) 1102 methodname = methodname.encode(encoding, 'xmlcharrefreplace')
1103 data = ( 1103 data = (
1104 xmlheader, 1104 xmlheader,
1105 "<methodCall>\n" 1105 "<methodCall>\n"
1106 "<methodName>", methodname, "</methodName>\n", 1106 "<methodName>", methodname, "</methodName>\n",
1107 data, 1107 data,
1108 "</methodCall>\n" 1108 "</methodCall>\n"
1109 ) 1109 )
1110 elif methodresponse: 1110 elif methodresponse:
1111 # a method response, or a fault structure 1111 # a method response, or a fault structure
1112 data = ( 1112 data = (
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 1644
1645 multi = MultiCall(server) 1645 multi = MultiCall(server)
1646 multi.pow(2, 9) 1646 multi.pow(2, 9)
1647 multi.add(5, 1) 1647 multi.add(5, 1)
1648 multi.add(24, 11) 1648 multi.add(24, 11)
1649 try: 1649 try:
1650 for response in multi(): 1650 for response in multi():
1651 print response 1651 print response
1652 except Error, v: 1652 except Error, v:
1653 print "ERROR", v 1653 print "ERROR", v
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+