<s> '''<STR_LIT>''' <EOL> import datetime , re , os , time <EOL> from arelle import FileSource , ModelDocument <EOL> from arelle . ModelRssObject import ModelRssObject <EOL> from arelle . XmlValidate import UNVALIDATED , VALID <EOL> class SECCorrespondenceItem : <EOL> def __init__ ( self , modelXbrl , fileName , entryUrl ) : <EOL> self . cikNumber = None <EOL> self . accessionNumber = None <EOL> self . fileNumber = None <EOL> self . companyName = None <EOL> self . formType = None <EOL> pubDate = os . path . basename ( modelXbrl . uri ) . partition ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> try : <EOL> self . pubDate = datetime . datetime ( int ( pubDate [ <NUM_LIT:0> : <NUM_LIT:4> ] ) , int ( pubDate [ <NUM_LIT:4> : <NUM_LIT:6> ] ) , int ( pubDate [ <NUM_LIT:6> : <NUM_LIT:8> ] ) ) <EOL> self . acceptanceDatetime = self . pubDate <EOL> self . filingDate = self . pubDate . date ( ) <EOL> except ValueError : <EOL> self . pubDate = self . acceptanceDatetime = self . filingDate = None <EOL> self . filingDate = None <EOL> self . period = None <EOL> self . assignedSic = None <EOL> self . fiscalYearEnd = None <EOL> self . htmlUrl = None <EOL> self . url = entryUrl <EOL> self . zippedUrl = entryUrl <EOL> self . htmURLs = ( ( fileName , entryUrl ) , ) <EOL> self . status = "<STR_LIT>" <EOL> self . results = None <EOL> self . assertions = None <EOL> self . objectIndex = len ( modelXbrl . modelObjects ) <EOL> modelXbrl . modelObjects . append ( self ) <EOL> def setResults ( self , modelXbrl ) : <EOL> self . results = [ ] <EOL> self . assertionUnsuccessful = False <EOL> self . status = "<STR_LIT>" <EOL> for error in modelXbrl . errors : <EOL> if isinstance ( error , dict ) : <EOL> self . assertions = error <EOL> for countSuccessful , countNotsuccessful in error . items ( ) : <EOL> if countNotsuccessful > <NUM_LIT:0> : <EOL> self . assertionUnsuccessful = True <EOL> self . status = "<STR_LIT>" <EOL> else : <EOL> self . results . append ( error ) <EOL> self . status = "<STR_LIT>" <EOL> self . results . sort ( ) <EOL> def objectId ( self , refId = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" . format ( refId , self . objectIndex ) <EOL> def secCorrespondenceLoader ( modelXbrl , mappedUri , filepath , * args , ** kwargs ) : <EOL> if ( mappedUri . startswith ( "<STR_LIT>" ) and <EOL> mappedUri . endswith ( "<STR_LIT>" ) ) : <EOL> rssObject = ModelRssObject ( modelXbrl , uri = mappedUri , filepath = filepath ) <EOL> tempdir = os . path . join ( modelXbrl . modelManager . cntlr . userAppDir , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if os . path . exists ( tempdir ) : <EOL> os . system ( "<STR_LIT>" . format ( tempdir ) ) <EOL> os . makedirs ( tempdir , exist_ok = True ) <EOL> startedAt = time . time ( ) <EOL> modelXbrl . fileSource . open ( ) <EOL> modelXbrl . fileSource . fs . extractall ( tempdir ) <EOL> modelXbrl . info ( "<STR_LIT:info>" , "<STR_LIT>" % ( time . time ( ) - startedAt ) , <EOL> modelObject = modelXbrl ) <EOL> for instanceFile in sorted ( os . listdir ( tempdir ) ) : <EOL> if instanceFile != "<STR_LIT:.>" : <EOL> rssObject . rssItems . append ( <EOL> SECCorrespondenceItem ( modelXbrl , instanceFile , mappedUri + '<STR_LIT:/>' + instanceFile ) ) <EOL> return rssObject <EOL> elif "<STR_LIT>" in kwargs and "<STR_LIT>" in mappedUri : <EOL> rssItem = kwargs [ "<STR_LIT>" ] <EOL> text = None <EOL> try : <EOL> startedAt = time . time ( ) <EOL> file , encoding = modelXbrl . fileSource . file ( <EOL> os . path . join ( modelXbrl . modelManager . cntlr . userAppDir , "<STR_LIT>" , "<STR_LIT>" , <EOL> os . path . basename ( rssItem . url ) ) ) <EOL> s = file . read ( ) <EOL> file . close ( ) <EOL> for match in re . finditer ( r"<STR_LIT>" , s , re . MULTILINE ) : <EOL> tag = match . group ( <NUM_LIT:1> ) . lower ( ) <EOL> v = match . group ( <NUM_LIT:2> ) <EOL> if tag == "<STR_LIT>" : <EOL> rssItem . accessionNumber = v <EOL> elif tag == "<STR_LIT>" : <EOL> rssItem . formType = v <EOL> if v != "<STR_LIT>" : <EOL> rssItem . doNotProcessRSSitem = True <EOL> elif tag == "<STR_LIT>" : <EOL> try : <EOL> rssItem . filingDate = datetime . date ( int ( v [ <NUM_LIT:0> : <NUM_LIT:4> ] ) , int ( v [ <NUM_LIT:4> : <NUM_LIT:6> ] ) , int ( v [ <NUM_LIT:6> : <NUM_LIT:8> ] ) ) <EOL> except ( ValueError , IndexError ) : <EOL> pass <EOL> elif tag == "<STR_LIT>" : <EOL> rssItem . companyName = v <EOL> elif tag == "<STR_LIT>" : <EOL> rssItem . cikNumber = v <EOL> elif tag == "<STR_LIT>" : <EOL> rssItem . assignedSic = v <EOL> elif tag == "<STR_LIT>" : <EOL> try : <EOL> rssItem . fiscalYearEnd = v [ <NUM_LIT:0> : <NUM_LIT:2> ] + '<STR_LIT:->' + v [ <NUM_LIT:2> : <NUM_LIT:4> ] <EOL> except ( IndexError , TypeError ) : <EOL> pass <EOL> match = re . search ( "<STR_LIT>" , s , re . DOTALL ) <EOL> if match : <EOL> import uu , io <EOL> pageText = [ ] <EOL> uuIn = io . BytesIO ( match . group ( <NUM_LIT:1> ) . encode ( encoding ) ) <EOL> uuOut = io . BytesIO ( ) <EOL> uu . decode ( uuIn , uuOut ) <EOL> from pyPdf import PdfFileReader <EOL> uuOut . seek ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> try : <EOL> pdfIn = PdfFileReader ( uuOut ) <EOL> for pageNum in range ( pdfIn . getNumPages ( ) ) : <EOL> pageText . append ( pdfIn . getPage ( pageNum ) . extractText ( ) ) <EOL> except : <EOL> pass <EOL> uuIn . close ( ) <EOL> uuOut . close ( ) <EOL> text = '<STR_LIT>' . join ( pageText ) <EOL> else : <EOL> match = re . search ( "<STR_LIT>" , s , re . DOTALL ) <EOL> if match : <EOL> text = match . group ( <NUM_LIT:1> ) <EOL> except ( IOError , EnvironmentError ) : <EOL> pass <EOL> if not text : <EOL> rssItem . doNotProcessRSSitem = True <EOL> instDoc = ModelDocument . create ( modelXbrl , <EOL> ModelDocument . Type . UnknownXML , <EOL> rssItem . url , <EOL> isEntry = True , <EOL> base = '<STR_LIT>' , <EOL> initialXml = '<STR_LIT>' ) <EOL> else : <EOL> instDoc = ModelDocument . create ( modelXbrl , <EOL> ModelDocument . Type . INSTANCE , <EOL> rssItem . url , <EOL> isEntry = True , <EOL> base = '<STR_LIT>' , <EOL> initialXml = '''<STR_LIT>''' . format ( cik = rssItem . cikNumber , <EOL> pubDate = rssItem . pubDate . date ( ) , <EOL> text = text . strip ( ) . replace ( "<STR_LIT:&>" , "<STR_LIT>" ) . replace ( "<STR_LIT:<>" , "<STR_LIT>" ) ) ) <EOL> return instDoc <EOL> return None <EOL> def secCorrespondenceCloser ( modelDocument , * args , ** kwargs ) : <EOL> if ( modelDocument . uri . startswith ( "<STR_LIT>" ) and <EOL> modelDocument . uri . endswith ( "<STR_LIT>" ) ) : <EOL> if os . path . exists ( "<STR_LIT>" ) : <EOL> os . system ( "<STR_LIT>" ) <EOL> __pluginInfo__ = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : secCorrespondenceLoader , <EOL> '<STR_LIT>' : secCorrespondenceCloser , <EOL> } </s>
