def detect_periodical(toc, log=None):
 if ((toc.count() < 1) or (not (toc[0].klass == u'periodical'))):
  return False
 for node in toc.iterdescendants():
  if ((node.depth() == 1) and (node.klass != u'article')):
   if (log is not None):
    log.debug(u'Not a periodical: Deepest node does not have class="article"')
   return False
  if ((node.depth() == 2) and (node.klass != u'section')):
   if (log is not None):
    log.debug(u'Not a periodical: Second deepest node does not have class="section"')
   return False
  if ((node.depth() == 3) and (node.klass != u'periodical')):
   if (log is not None):
    log.debug(u'Not a periodical: Third deepest node does not have class="periodical"')
   return False
  if (node.depth() > 3):
   if (log is not None):
    log.debug(u'Not a periodical: Has nodes of depth > 3')
   return False
 return True

def detect_periodical ( toc , log = None ) : if ( ( toc . count ( ) < 1 ) or ( not ( toc [ 0 ] . klass == u'periodical' ) ) ) : return False for node in toc . iterdescendants ( ) : if ( ( node . depth ( ) == 1 ) and ( node . klass != u'article' ) ) : if ( log is not None ) : log . debug ( u'Not a periodical: Deepest node does not have class="article"' ) return False if ( ( node . depth ( ) == 2 ) and ( node . klass != u'section' ) ) : if ( log is not None ) : log . debug ( u'Not a periodical: Second deepest node does not have class="section"' ) return False if ( ( node . depth ( ) == 3 ) and ( node . klass != u'periodical' ) ) : if ( log is not None ) : log . debug ( u'Not a periodical: Third deepest node does not have class="periodical"' ) return False if ( node . depth ( ) > 3 ) : if ( log is not None ) : log . debug ( u'Not a periodical: Has nodes of depth > 3' ) return False return True
detect if the toc object toc contains a periodical that conforms to the structure required by kindlegen to generate a periodical .