MCPcopy Index your code
hub / github.com/csev/py4e / toEncoding

Method toEncoding

code/pagerank/BeautifulSoup.py:406–422  ·  view source on GitHub ↗

Encodes an object to a string in some encoding, or to Unicode. .

(self, s, encoding=None)

Source from the content-addressed store, hash-verified

404 return str.replace("%SOUP-ENCODING%", encoding)
405
406 def toEncoding(self, s, encoding=None):
407 """Encodes an object to a string in some encoding, or to Unicode.
408 ."""
409 if isinstance(s, unicode):
410 if encoding:
411 s = s.encode(encoding)
412 elif isinstance(s, str):
413 if encoding:
414 s = s.encode(encoding)
415 else:
416 s = unicode(s)
417 else:
418 if encoding:
419 s = self.toEncoding(str(s), encoding)
420 else:
421 s = unicode(s)
422 return s
423
424class NavigableString(unicode, PageElement):
425

Callers 2

__str__Method · 0.45
__str__Method · 0.45

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected