MCPcopy
hub / github.com/csev/py4e / decode

Method decode

code3/bs4/element.py:1065–1156  ·  view source on GitHub ↗

Returns a Unicode representation of this tag and its contents. :param eventual_encoding: The tag is destined to be encoded into this encoding. This method is _not_ responsible for performing that encoding. This information is passed in so that it can be subs

(self, indent_level=None,
               eventual_encoding=DEFAULT_OUTPUT_ENCODING,
               formatter="minimal")

Source from the content-addressed store, hash-verified

1063 or self._is_xml))
1064
1065 def decode(self, indent_level=None,
1066 eventual_encoding=DEFAULT_OUTPUT_ENCODING,
1067 formatter="minimal"):
1068 """Returns a Unicode representation of this tag and its contents.
1069
1070 :param eventual_encoding: The tag is destined to be
1071 encoded into this encoding. This method is _not_
1072 responsible for performing that encoding. This information
1073 is passed in so that it can be substituted in if the
1074 document contains a <META> tag that mentions the document&#x27;s
1075 encoding.
1076 """
1077
1078 # First off, turn a string formatter into a function. This
1079 # will stop the lookup from happening over and over again.
1080 if not isinstance(formatter, collections.Callable):
1081 formatter = self._formatter_for_name(formatter)
1082
1083 attrs = []
1084 if self.attrs:
1085 for key, val in sorted(self.attrs.items()):
1086 if val is None:
1087 decoded = key
1088 else:
1089 if isinstance(val, list) or isinstance(val, tuple):
1090 val = ' '.join(val)
1091 elif not isinstance(val, str):
1092 val = str(val)
1093 elif (
1094 isinstance(val, AttributeValueWithCharsetSubstitution)
1095 and eventual_encoding is not None):
1096 val = val.encode(eventual_encoding)
1097
1098 text = self.format_string(val, formatter)
1099 decoded = (
1100 str(key) + '='
1101 + EntitySubstitution.quoted_attribute_value(text))
1102 attrs.append(decoded)
1103 close = ''
1104 closeTag = ''
1105
1106 prefix = ''
1107 if self.prefix:
1108 prefix = self.prefix + ":"
1109
1110 if self.is_empty_element:
1111 close = '/'
1112 else:
1113 closeTag = '</%s%s>' % (prefix, self.name)
1114
1115 pretty_print = self._should_pretty_print(indent_level)
1116 space = ''
1117 indent_space = ''
1118 if indent_level is not None:
1119 indent_space = (' ' * (indent_level - 1))
1120 if pretty_print:
1121 space = indent_space
1122 indent_contents = indent_level + 1

Callers 15

__repr__Method · 0.95
__unicode__Method · 0.95
__str__Method · 0.95
encodeMethod · 0.95
prettifyMethod · 0.95
__unicode__Method · 0.45
__unicode__Method · 0.45
__unicode__Method · 0.45
urlwords.pyFile · 0.45
twitter1.pyFile · 0.45
urljpeg.pyFile · 0.45
twfriends.pyFile · 0.45

Calls 8

_should_pretty_printMethod · 0.95
decode_contentsMethod · 0.95
_formatter_for_nameMethod · 0.45
itemsMethod · 0.45
encodeMethod · 0.45
format_stringMethod · 0.45
appendMethod · 0.45