py.lib

Yohn Y. 2022-08-14 Parent:cab7fedf8432

34:84b54a8a6d4c Go to Latest

py.lib/webapp/win.py

+ Возможность обработки параметров конфигурации перед добавлением в класс конфигурации . Переформатирование части кода по PEP

History
     1.1 --- a/webapp/win.py	Sat Aug 13 20:06:47 2022 +0300
     1.2 +++ b/webapp/win.py	Sun Aug 14 12:19:08 2022 +0300
     1.3 @@ -6,67 +6,70 @@
     1.4  from bottle import Bottle as App, request as Req, response as Ans, SimpleTemplate as BottleTemplate, abort as Abort
     1.5  from os.path import dirname, abspath as pAbs, split as pSplit, join as pJoin
     1.6  
     1.7 +
     1.8  # --- CLASSES ---
     1.9  class ReqEnv:
    1.10 -	def __init__(self):
    1.11 -		self.urlBase = Req.environ.get('SCRIPT_NAME', '')
    1.12 -		
    1.13 -	def getUrl(self, url):
    1.14 -		url = str(url)
    1.15 -		buf = self.urlBase
    1.16 -		buf += url if url.startswith('/') else '/' + url
    1.17 -		return buf
    1.18 -	
    1.19 -	def __getitem__(self, key):
    1.20 -		return Req.environ[key]
    1.21 -		
    1.22 -	def __iter__(self):
    1.23 -		for key in Req.environ.keys():
    1.24 -			yield key
    1.25 -			
    1.26 -	@staticmethod
    1.27 -	def abort(*a, **ka):
    1.28 -		Abort(*a, **ka)
    1.29 -	
    1.30 -	@staticmethod	
    1.31 -	def get(self):
    1.32 -		return Req.GET
    1.33 -		
    1.34 -	@staticmethod	
    1.35 -	def post():
    1.36 -		return Req.POST
    1.37 -		
    1.38 +    def __init__(self):
    1.39 +        self.urlBase = Req.environ.get('SCRIPT_NAME', '')
    1.40 +
    1.41 +    def getUrl(self, url):
    1.42 +        url = str(url)
    1.43 +        buf = self.urlBase
    1.44 +        buf += url if url.startswith('/') else '/' + url
    1.45 +        return buf
    1.46 +
    1.47 +    def __getitem__(self, key):
    1.48 +        return Req.environ[key]
    1.49 +
    1.50 +    def __iter__(self):
    1.51 +        for key in Req.environ.keys():
    1.52 +            yield key
    1.53 +
    1.54 +    @staticmethod
    1.55 +    def abort(*a, **ka):
    1.56 +        Abort(*a, **ka)
    1.57 +
    1.58 +    @staticmethod
    1.59 +    def get(self):
    1.60 +        return Req.GET
    1.61 +
    1.62 +    @staticmethod
    1.63 +    def post():
    1.64 +        return Req.POST
    1.65 +
    1.66 +
    1.67  class Env:
    1.68 -	def __init__(self, scFile):
    1.69 -		self.wd = pSplit(dirname(pAbs(scFile)))[0]
    1.70 -		self.static = pJoin(self.wd, 'static')
    1.71 -		
    1.72 -	def http(self, tplName):
    1.73 -		return BottleTemplate(name=pJoin(self.wd, 'http', '%s.html' % tplName)).render
    1.74 -		
    1.75 -	def db(self):
    1.76 -		""" 
    1.77 +    def __init__(self, scFile):
    1.78 +        self.wd = pSplit(dirname(pAbs(scFile)))[0]
    1.79 +        self.static = pJoin(self.wd, 'static')
    1.80 +
    1.81 +    def http(self, tplName):
    1.82 +        return BottleTemplate(name=pJoin(self.wd, 'http', '%s.html' % tplName)).render
    1.83 +
    1.84 +    def db(self):
    1.85 +        """
    1.86  		Путь к базе SQLite, иные типы БД дожны иметь более
    1.87  		серьёзные средства авторизации
    1.88  		"""
    1.89 -		return pJoin(self.wd, 'db.sqlite')
    1.90 -	
    1.91 -	@staticmethod
    1.92 -	def httpTpl(buf):
    1.93 -		return BottleTemplate(buf).render
    1.94 -	
    1.95 -	@staticmethod
    1.96 -	def app():
    1.97 -		return App()
    1.98 -		
    1.99 -	@staticmethod
   1.100 -	def appRun(app):
   1.101 -		app.run(server='cgi')
   1.102 -	
   1.103 +        return pJoin(self.wd, 'db.sqlite')
   1.104 +
   1.105 +    @staticmethod
   1.106 +    def httpTpl(buf):
   1.107 +        return BottleTemplate(buf).render
   1.108 +
   1.109 +    @staticmethod
   1.110 +    def app():
   1.111 +        return App()
   1.112 +
   1.113 +    @staticmethod
   1.114 +    def appRun(app):
   1.115 +        app.run(server='cgi')
   1.116 +
   1.117 +
   1.118  # --- PROCS ---
   1.119  def runApp(app):
   1.120 -	Env.appRun(app)
   1.121 -	
   1.122 +    Env.appRun(app)
   1.123 +
   1.124 +
   1.125  def Template(buf):
   1.126 -	return Env.httpTpl(buf)
   1.127 -	
   1.128 \ No newline at end of file
   1.129 +    return Env.httpTpl(buf)