desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'attributes: data: aid - aid type - type count - count date - date name - anime name fid - comma separated list of fids'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NOTIFYGET_NOTIFY' self.codehead = () self.codetail = ('aid', 'type', 'count', 'date', 'name', 'fid') self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'SENDMSG_SUCCESSFUL' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data: uid - user id'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'USER' self.codehead = () self.codetail = ('uid',) self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'PONG' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'AUTHPONG' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_RESOURCE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'API_PASSWORD_NOT_DEFINED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'FILE_ALREADY_IN_MYLIST' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data: entries - number of entries edited'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'MYLIST_ENTRY_EDITED' self.codehead = () self.codetail = ('entries',) self.coderep = ()
'attributes: data: name - anime title eps - episodes unknowneps - eps with state unknown hddeps - eps with state on hdd cdeps - eps with state on cd deletedeps - eps with state deleted watchedeps - watched eps gshortname - group short name geps - eps for group'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'MULTIPLE_MYLIST_ENTRIES' self.codehead = () self.codetail = ('name', 'eps', 'unknowneps', 'hddeps', 'cdeps', 'deletedeps', 'watchedeps') self.coderep = ('gshortname', 'geps')
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'SIZE_HASH_EXISTS' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'INVALID_DATA' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'STREAMNOID_USED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_FILE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_ENTRY' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data: fid - file id'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'MULTIPLE_FILES_FOUND' self.codehead = () self.codetail = () self.coderep = ('fid',)
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_NOTIFICATION' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO GROUPS FOUND' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_ANIME' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_EPISODE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_PRODUCER' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_GROUP' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'BUDDY_ALREADY_ADDED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_BUDDY' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'BUDDY_ALREADY_ACCEPTED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'BUDDY_ALREADY_DENIED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_VOTE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'INVALID_VOTE_TYPE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'INVALID_VOTE_VALUE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data: aname - name of the anime'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'PERMVOTE_NOT_ALLOWED' self.codehead = () self.codetail = ('aname',) self.coderep = ()
'attributes: data: name - aname/ename/gname'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'ALREADY_PERMVOTED' self.codehead = () self.codetail = ('name',) self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NOTIFICATION_DISABLED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_PACKET_PENDING' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_ENTRY_M' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_ENTRY_N' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_MESSAGE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_NOTIFY' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_USER' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_CHANGES' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NOT_LOGGED_IN' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_MYLIST_FILE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_MYLIST_ENTRY' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'LOGIN_FAILED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'LOGIN_FIRST' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'ACCESS_DENIED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'CLIENT_VERSION_OUTDATED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'CLIENT_BANNED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'ILLEGAL_INPUT_OR_ACCESS_DENIED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'INVALID_SESSION' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'NO_SUCH_ENCRYPTION_TYPE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'ENCODING_NOT_SUPPORTED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'BANNED' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'UNKNOWN_COMMAND' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'INTERNAL_SERVER_ERROR' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'ANIDB_OUT_OF_SERVICE' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'SERVER_BUSY' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data:'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'API_VIOLATION' self.codehead = () self.codetail = () self.coderep = ()
'attributes: data: version - server version'
def __init__(self, cmd, restag, rescode, resstr, datalines):
Response.__init__(self, cmd, restag, rescode, resstr, datalines) self.codestr = 'VERSION' self.codehead = () self.codetail = ('version',) self.coderep = ()
'The Soup object is initialized as the \'root tag\', and the provided markup (which can be a string or a file-like object) is fed into the underlying parser.'
def __init__(self, markup='', features=None, builder=None, parse_only=None, from_encoding=None, exclude_encodings=None, **kwargs):
if ('convertEntities' in kwargs): warnings.warn('BS4 does not respect the convertEntities argument to the BeautifulSoup constructor. Entities are always converted to Unicode characters.') if ('markupMassage' in kwargs): del kwargs['markupMassage...
'Check if markup looks like it\'s actually a url and raise a warning if so. Markup can be unicode or str (py2) / bytes (py3).'
@staticmethod def _check_markup_is_url(markup):
if isinstance(markup, bytes): space = ' ' cant_start_with = ('http:', 'https:') elif isinstance(markup, unicode): space = u' ' cant_start_with = (u'http:', u'https:') else: return if any((markup.startswith(prefix) for prefix in cant_start_with)): if ...
'Create a new tag associated with this soup.'
def new_tag(self, name, namespace=None, nsprefix=None, **attrs):
return Tag(None, self.builder, name, namespace, nsprefix, attrs)
'Create a new NavigableString associated with this soup.'
def new_string(self, s, subclass=NavigableString):
return subclass(s)
'Add an object to the parse tree.'
def object_was_parsed(self, o, parent=None, most_recent_element=None):
parent = (parent or self.currentTag) previous_element = (most_recent_element or self._most_recent_element) next_element = previous_sibling = next_sibling = None if isinstance(o, Tag): next_element = o.next_element next_sibling = o.next_sibling previous_sibling = o.previous_siblin...
'Pops the tag stack up to and including the most recent instance of the given tag. If inclusivePop is false, pops the tag stack up to but *not* including the most recent instqance of the given tag.'
def _popToTag(self, name, nsprefix=None, inclusivePop=True):
if (name == self.ROOT_TAG_NAME): return most_recently_popped = None stack_size = len(self.tagStack) for i in range((stack_size - 1), 0, (-1)): t = self.tagStack[i] if ((name == t.name) and (nsprefix == t.prefix)): if inclusivePop: most_recently_popped ...
'Push a start tag on to the stack. If this method returns None, the tag was rejected by the SoupStrainer. You should proceed as if the tag had not occurred in the document. For instance, if this was a self-closing tag, don\'t call handle_endtag.'
def handle_starttag(self, name, namespace, nsprefix, attrs):
self.endData() if (self.parse_only and (len(self.tagStack) <= 1) and (self.parse_only.text or (not self.parse_only.search_tag(name, attrs)))): return None tag = Tag(self, self.builder, name, namespace, nsprefix, attrs, self.currentTag, self._most_recent_element) if (tag is None): return ...
'Returns a string or Unicode representation of this document. To get Unicode, pass None for encoding.'
def decode(self, pretty_print=False, eventual_encoding=DEFAULT_OUTPUT_ENCODING, formatter='minimal'):
if self.is_xml: encoding_part = '' if (eventual_encoding != None): encoding_part = (' encoding="%s"' % eventual_encoding) prefix = (u'<?xml version="1.0"%s?>\n' % encoding_part) else: prefix = u'' if (not pretty_print): indent_level = None else: ...
'Unlike most tree builders, HTMLParserTreeBuilder and will be restored after pickling.'
def test_builder_is_pickled(self):
tree = self.soup('<a><b>foo</a>') dumped = pickle.dumps(tree, 2) loaded = pickle.loads(dumped) self.assertTrue(isinstance(loaded.builder, type(tree.builder)))
'There\'s no need to do this except inside attribute values.'
def test_quotes_not_html_substituted(self):
text = 'Bob\'s "bar"' self.assertEqual(self.sub.substitute_html(text), text)
'html5lib inserts <tbody> tags where other parsers don\'t.'
def test_correctly_nested_tables(self):
markup = '<table id="1"><tr><td>Here\'s another table:<table id="2"><tr><td>foo</td></tr></table></td>' self.assertSoupEquals(markup, '<table id="1"><tbody><tr><td>Here\'s another table:<table id="2"><tbody><tr><td>foo</td></tr></tbody></table></td></tr></tbody></table>') self.assert...
'Verify that we keep the two whitespace nodes in this document distinct when reparenting the adjacent <tbody> tags.'
def test_reparented_markup_containing_identical_whitespace_nodes(self):
markup = '<table> <tbody><tbody><ims></tbody> </table>' soup = self.soup(markup) (space1, space2) = soup.find_all(string=' ') (tbody1, tbody2) = soup.find_all('tbody') assert (space1.next_element is tbody1) assert (tbody2.next_element is space2)
'Processing instructions become comments.'
def test_processing_instruction(self):
markup = '<?PITarget PIContent?>' soup = self.soup(markup) assert str(soup).startswith('<!--?PITarget PIContent?-->')
'Make sure that the given tags have the correct text. This is used in tests that define a bunch of tags, each containing a single string, and then select certain strings by some mechanism.'
def assertSelects(self, tags, should_match):
self.assertEqual([tag.string for tag in tags], should_match)
'Make sure that the given tags have the correct IDs. This is used in tests that define a bunch of tags, each containing a single string, and then select certain strings by some mechanism.'
def assertSelectsIDs(self, tags, should_match):
self.assertEqual([tag['id'] for tag in tags], should_match)
'Test an optimization that finds all tags.'
def test_find_everything(self):
soup = self.soup('<a>foo</a><b>bar</b>') self.assertEqual(2, len(soup.find_all()))
'Test an optimization that finds all tags with a given name.'
def test_find_everything_with_name(self):
soup = self.soup('<a>foo</a><b>bar</b><a>baz</a>') self.assertEqual(2, len(soup.find_all('a')))
'You can search the tree for text nodes.'
def test_find_all_text_nodes(self):
soup = self.soup('<html>Foo<b>bar</b>\xbb</html>') self.assertEqual(soup.find_all(string='bar'), [u'bar']) self.assertEqual(soup.find_all(text='bar'), [u'bar']) self.assertEqual(soup.find_all(text=['Foo', 'bar']), [u'Foo', u'bar']) self.assertEqual(soup.find_all(text=re.compile('.*')), [u'Foo', u'ba...
'You can limit the number of items returned by find_all.'
def test_find_all_limit(self):
soup = self.soup('<a>1</a><a>2</a><a>3</a><a>4</a><a>5</a>') self.assertSelects(soup.find_all('a', limit=3), ['1', '2', '3']) self.assertSelects(soup.find_all('a', limit=1), ['1']) self.assertSelects(soup.find_all('a', limit=10), ['1', '2', '3', '4', '5']) self.assertSelects(soup.find_all('a', limit...
'All find_all calls return a ResultSet'
def test_find_all_resultset(self):
soup = self.soup('<a></a>') result = soup.find_all('a') self.assertTrue(hasattr(result, 'source')) result = soup.find_all(True) self.assertTrue(hasattr(result, 'source')) result = soup.find_all(text='foo') self.assertTrue(hasattr(result, 'source'))
'Tag.clear()'
def test_clear(self):
soup = self.soup('<p><a>String <em>Italicized</em></a> and another</p>') a = soup.a soup.p.clear() self.assertEqual(len(soup.p.contents), 0) self.assertTrue(hasattr(a, 'contents')) em = a.em a.clear(decompose=True) self.assertEqual(0, len(em.contents))
'Tag.string = \'string\''
def test_string_set(self):
soup = self.soup('<a></a> <b><c></c></b>') soup.a.string = 'foo' self.assertEqual(soup.a.contents, ['foo']) soup.b.string = 'bar' self.assertEqual(soup.b.contents, ['bar'])
'The length of an element is its number of children.'
def test_len(self):
soup = self.soup('<top>1<b>2</b>3</top>') self.assertEqual(len(soup.contents), 1) self.assertEqual(len(soup), 1) self.assertEqual(len(soup.top), 3) self.assertEqual(len(soup.top.contents), 3)
'Accessing a Python member .foo invokes find(\'foo\')'
def test_member_access_invokes_find(self):
soup = self.soup('<b><i></i></b>') self.assertEqual(soup.b, soup.find('b')) self.assertEqual(soup.b.i, soup.find('b').find('i')) self.assertEqual(soup.a, None)
'has_attr() checks for the presence of an attribute. Please note note: has_attr() is different from __in__. has_attr() checks the tag\'s attributes and __in__ checks the tag\'s chidlren.'
def test_has_attr(self):
soup = self.soup("<foo attr='bar'>") self.assertTrue(soup.foo.has_attr('attr')) self.assertFalse(soup.foo.has_attr('attr2'))
'Only a tag containing a single text node has a .string.'
def test_lack_of_string(self):
soup = self.soup('<b>f<i>e</i>o</b>') self.assertFalse(soup.b.string) soup = self.soup('<b></b>') self.assertFalse(soup.b.string)
'Tag.text and Tag.get_text(sep=u"") -> all child text, concatenated'
def test_all_text(self):
soup = self.soup('<a>a<b>r</b> <r> t </r></a>') self.assertEqual(soup.a.text, 'ar t ') self.assertEqual(soup.a.get_text(strip=True), 'art') self.assertEqual(soup.a.get_text(','), 'a,r, , t ') self.assertEqual(soup.a.get_text(',', strip=True), 'a,r,t')
'Text inside a CData object is passed into the formatter. But the return value is ignored.'
def test_cdata_is_never_formatted(self):
self.count = 0 def increment(*args): self.count += 1 return 'BITTER FAILURE' soup = self.soup('') cdata = CData('<><><>') soup.insert(1, cdata) self.assertEqual('<![CDATA[<><><>]]>', soup.encode(formatter=increment)) self.assertEqual(1, self.count)
':return: A 4-tuple (markup, original encoding, encoding declared within markup, whether any characters had to be replaced with REPLACEMENT CHARACTER).'
def prepare_markup(self, markup, user_specified_encoding=None, document_declared_encoding=None, exclude_encodings=None):
if isinstance(markup, unicode): (yield (markup, None, None, False)) return try_encodings = [user_specified_encoding, document_declared_encoding] dammit = UnicodeDammit(markup, try_encodings, is_html=True, exclude_encodings=exclude_encodings) (yield (dammit.markup, dammit.original_encodin...
'See `TreeBuilder`.'
def test_fragment_to_document(self, fragment):
return (u'<html><head></head><body>%s</body></html>' % fragment)
'Move all of this tag\'s children into another tag.'
def reparentChildren(self, new_parent):
element = self.element new_parent_element = new_parent.element final_next_element = element.next_sibling new_parents_last_descendant = new_parent_element._last_descendant(False, False) if (len(new_parent_element.contents) > 0): new_parents_last_child = new_parent_element.contents[(-1)] ...
':yield: A series of 4-tuples. (markup, encoding, declared encoding, has undergone character replacement) Each 4-tuple represents a strategy for parsing the document.'
def prepare_markup(self, markup, user_specified_encoding=None, exclude_encodings=None, document_declared_encoding=None):
is_html = (not self.is_xml) if is_html: self.processing_instruction_class = ProcessingInstruction else: self.processing_instruction_class = XMLProcessingInstruction if isinstance(markup, unicode): (yield (markup, None, document_declared_encoding, False)) if isinstance(markup,...
'Find the currently active prefix for the given namespace.'
def _prefix_for_namespace(self, namespace):
if (namespace is None): return None for inverted_nsmap in reversed(self.nsmaps): if ((inverted_nsmap is not None) and (namespace in inverted_nsmap)): return inverted_nsmap[namespace] return None
'Handle comments as Comment objects.'
def comment(self, content):
self.soup.endData() self.soup.handle_data(content) self.soup.endData(Comment)
'See `TreeBuilder`.'
def test_fragment_to_document(self, fragment):
return (u'<?xml version="1.0" encoding="utf-8"?>\n%s' % fragment)
'See `TreeBuilder`.'
def test_fragment_to_document(self, fragment):
return (u'<html><body>%s</body></html>' % fragment)
'Register a treebuilder based on its advertised features.'
def register(self, treebuilder_class):
for feature in treebuilder_class.features: self.builders_for_feature[feature].insert(0, treebuilder_class) self.builders.insert(0, treebuilder_class)
'Might a tag with this name be an empty-element tag? The final markup may or may not actually present this tag as self-closing. For instance: an HTMLBuilder does not consider a <p> tag to be an empty-element tag (it\'s not in HTMLBuilder.empty_element_tags). This means an empty <p> tag will be presented as "<p></p>", n...
def can_be_empty_element(self, tag_name):
if (self.empty_element_tags is None): return True return (tag_name in self.empty_element_tags)
'Wrap an HTML fragment to make it look like a document. Different parsers do this differently. For instance, lxml introduces an empty <head> tag, and html5lib doesn\'t. Abstracting this away lets us write simple tests which run HTML fragments through the parser and compare the results against other HTML fragments. This...
def test_fragment_to_document(self, fragment):
return fragment
'Replaces class="foo bar" with class=["foo", "bar"] Modifies its input in place.'
def _replace_cdata_list_attribute_values(self, tag_name, attrs):
if (not attrs): return attrs if self.cdata_list_attributes: universal = self.cdata_list_attributes.get('*', []) tag_specific = self.cdata_list_attributes.get(tag_name.lower(), None) for attr in attrs.keys(): if ((attr in universal) or (tag_specific and (attr in tag_sp...
'Build a Beautiful Soup object from markup.'
def soup(self, markup, **kwargs):
builder = kwargs.pop('builder', self.default_builder) return BeautifulSoup(markup, builder=builder, **kwargs)
'Turn an HTML fragment into a document. The details depend on the builder.'
def document_for(self, markup):
return self.default_builder.test_fragment_to_document(markup)