Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def row2table(soup, table, row):
"""ad a row to the table"""
tr = Tag(soup, name="tr")
table.append(tr)
for attr in row:
td = Tag(soup, name="td")
tr.append(td)
td.append(attr)
def tag(self):
tt=Tag(name='table')
for r in self.cells:
rt=Tag(name='tr')
for c in r:
rt.append(c.tag())
tt.append(rt)
return tt
def heading2table(soup, table, row):
"""add heading row to table"""
tr = Tag(soup, name="tr")
table.append(tr)
for attr in row:
th = Tag(soup, name="th")
tr.append(th)
th.append(attr)
def _parse_sample_tag(self, tag: bs4.Tag) -> Optional[Tuple[str, str]]:
assert isinstance(tag, bs4.Tag)
assert tag.name == 'pre'
prv = utils.previous_sibling_tag(tag)
pprv = tag.parent and utils.previous_sibling_tag(tag.parent)
if prv.name == 'h6' and tag.parent.name == 'div' and tag.parent['class'] == ['paragraph'] and pprv.name == 'h5':
log.debug('h6: %s', str(prv))
log.debug('name.encode(): %s', prv.string.encode())
s = utils.parse_content(tag)
return utils.textfile(s.lstrip()), pprv.string + ' ' + prv.string
return None
def div_tag(self):
t=Tag(name='div')
t['class']=self.cls+['comment']
t['title']=self.text
return t
def parse_verse_block(self, verse_block):
lyric = ''
for elem in verse_block.childGenerator():
if isinstance(elem, Comment):
pass
elif isinstance(elem, NavigableString):
lyric += elem.strip()
elif isinstance(elem, Tag):
if elem.name == 'a':
lyric += elem.text.strip()
else:
lyric += '\n'
return lyric.strip()
def wd_phon_nam(self):
"""
:return: pre_fix, phon
"""
try:
_tag_phn = self.tag_phon_nam.find('span', self._cls_dic('phon')).contents[3]
phon = '/{}/'.format(_tag_phn.text if isinstance(_tag_phn, Tag) else _tag_phn)
except:
phon = ''
try:
prefix = self.tag_phon_nam.find('span', self._cls_dic('prefix')).string
except:
prefix = ''
return "{} {}".format(
prefix,
phon
)
amount=charge_total
)
new_charge.save()
offset = 0.0
# iterate regular users
remaining_users = [u for u in users if u.number != number]
for user in remaining_users:
charge_total = 0.0
name, number = user.name, user.number
# charge section starts with user name followed by his/her number
target = soup.find('div',
string=re.compile('{} {}'.format(name, number)))
for tag in target.parent.next_siblings:
# all charge data are in divs
if not isinstance(tag, Tag) or tag.name != 'div':
continue
# charge section ends with Total for number
if 'Total for {}'.format(number) in tag.text:
break
# each charge type has 'accSummary' as one of its css classes
if 'accSummary' in tag.get('class', []):
charge_type_text = tag.find('div').text.strip('\n\t')
if charge_type_text.startswith('Monthly Charges'):
charge_type_text = 'Monthly Charges'
m = re.search(
r'Total {}.*?\$([0-9.]+)'.format(charge_type_text),
tag.text,
flags=re.DOTALL
def _get_first_tag(tree):
"""Get first tag among children of tree"""
for child in tree.children:
if isinstance(child, Tag):
return child
return None
def process_heading_contents(heading, tocitem):
"""
Run through each item in the heading contents
and try to pull out the toc item data.
"""
accumulator = '' # We'll use this to build up the title.
for child in heading.contents:
if child != '' + '\n':
if isinstance(child, Tag):
try:
epub_type = child['epub:type']
except KeyError:
epub_type = 'blank'
if child.name == 'abbr':
accumulator += extract_strings(child)
continue # Skip following and go to next child.
if 'z3998:roman' in epub_type:
tocitem.roman = extract_strings(child)
accumulator += str(child)
elif 'subtitle' in epub_type:
tocitem.subtitle = extract_strings(child)
elif 'title' in epub_type:
tocitem.title = extract_strings(child)
elif 'noteref' in epub_type: