Return an encoded string of all query string arguments. `safe` specifies characters which don't require quoting, for example:: >>> q = QueryDict(mutable=True) >>> q['next'] = '/a&b/' >>> q.urlencode() 'next=%2Fa%26b%2F' >
(self, safe=None)
| 710 | return self.__deepcopy__({}) |
| 711 | |
| 712 | def urlencode(self, safe=None): |
| 713 | class="st">""" |
| 714 | Return an encoded string of all query string arguments. |
| 715 | |
| 716 | `safe` specifies characters which don&class="cm">#x27;t require quoting, for example:: |
| 717 | |
| 718 | >>> q = QueryDict(mutable=True) |
| 719 | >>> q[&class="cm">#x27;nextclass="st">'] = '/a&b/' |
| 720 | >>> q.urlencode() |
| 721 | &class="cm">#x27;next=%2Fa%26b%2F' |
| 722 | >>> q.urlencode(safe=&class="cm">#x27;/') |
| 723 | &class="cm">#x27;next=/a%26b/' |
| 724 | class="st">""" |
| 725 | output = [] |
| 726 | if safe: |
| 727 | safe = safe.encode(self.encoding) |
| 728 | |
| 729 | def encode(k, v): |
| 730 | return class="st">"%s=%s" % ((quote(k, safe), quote(v, safe))) |
| 731 | |
| 732 | else: |
| 733 | |
| 734 | def encode(k, v): |
| 735 | return urlencode({k: v}) |
| 736 | |
| 737 | for k, list_ in self.lists(): |
| 738 | output.extend( |
| 739 | encode(k.encode(self.encoding), str(v).encode(self.encoding)) |
| 740 | for v in list_ |
| 741 | ) |
| 742 | return class="st">"&".join(output) |
| 743 | |
| 744 | |
| 745 | class MediaType: |