#import copy import os #import sys #import base64 #import hashlib import re import docing import filing import lxml.etree as etree from lxml.builder import ElementMaker from nitpo import Nitpo from sheets import Sheets from inces import Inces class Webenv(Nitpo): def __init__(self, do_verbose=False): """web class""" super().__init__() self.N = "{%s}" % self.const['ns'] self.E = ElementMaker(nsmap={None: self.const['ns']}) self.env = None self.sheets = Sheets() self.inces = Inces() self.do_verbose = do_verbose def prepare(self): """this is the stuff we prepare at start of server""" preps = {} preps['sheets'] = {} # # fixme: this loads the sheets in conf, but not the sheet # # defined in the empro directory #for sheet_name in self.conf['sheets']: # # # fixMe: there should be a better way to say what sheets need # # # to be loaded at the start of the web server # if not sheet_name.startswith('terew'): # continue for name in ('anpro', 'terew'): for part in ('head', 'html', 'text'): conc = f"{name}_{part}" preps['sheets'][conc] = self.sheets.return_sheet(conc) # # should be the kolar sheet preps['sheets']['web'] = self.sheets.return_sheet('web') preps['sheets']['fecha'] = self.sheets.return_sheet('fecha') # # compiled regular expressions res = {} surid = r'[-_0-9a-zA-Z]{22}' res['surid'] = re.compile(surid) # # for called urls we have two acods, u and w res['called_url'] = re.compile(r'//[uw]/' + surid) # # for fetched urls res['fetched_url'] = re.compile(r'//a/.*') # # fixme: only for backward compatifility res['url'] = res['called_url'] # # subscriptions: repcode / email # # the same regex for emad is used in mulsu.js res['re'] = re.compile(r'//([^/]+)/([^@]+@[^@]+\.[^@]+)') # # subscriptions: repcode / email / id, abandoned # res['rei'] = re.compile(r'//([^/]+)/([^@]+@[^@]+\.[^@]+)/([^ ]+)$') res['sub'] = res['called_url'] if not self.has_conf('regex', 'reports'): raise Exception("I need ะค[regex][reports]") res['repcode'] = re.compile(self.conf['regex']['reports']) # res['main_param_name'] = re.compile(r'[A-Z_]+') preps['res'] = res # # event track by token preps['events'] = {} # # constants preps['const'] = {} # # maximum requests for a faild kisu to reload vakis preps['count_reload_vakis'] = {} # # read the locs used to run the inces filter preps['locs'] = self.inces.read_locs() if not self.has_conf('files', 'vakis'): raise Exception("webenv needs a vakis file.") vakis_fufi = self.conf['files']['vakis'] preps['vakis'] = {} if os.path.isfile(vakis_fufi): preps['vakis'] = filing.load(vakis_fufi) preps['conf'] = self.read_config() preps['const'] = self.set_constants() preps['web_ele'] = self.E(self.N + 'web') return preps