Compare commits

..

No commits in common. "eb10f28d952836b310b79efba5f4c19ce846ecdd" and "666854a198047db7eeea3949b435d3fec9237f37" have entirely different histories.

5 changed files with 14 additions and 31 deletions

View File

@ -9,7 +9,7 @@ from appPublic.folderUtils import ProgramPath
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from appPublic.jsonConfig import getConfig from appPublic.jsonConfig import getConfig
from appPublic.log import info, debug, warning, error, critical, exception from appPublic.log import info, debug, warning, error, critical, exception
from appPublic.registerfunction import RegisterFunction from appPublic.registerfunction import RegisterCoroutine
from sqlor.dbpools import DBPools from sqlor.dbpools import DBPools
@ -24,8 +24,7 @@ from .real_ip import real_ip_middleware
class AHApp(web.Application): class AHApp(web.Application):
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
if not kw.get('client_max_size'): kw['client_max_size'] = 1024000000
kw['client_max_size'] = 1024000000
super().__init__(*args, **kw) super().__init__(*args, **kw)
self.user_data = DictObject() self.user_data = DictObject()
self.middlewares.insert(0, real_ip_middleware()) self.middlewares.insert(0, real_ip_middleware())
@ -37,7 +36,7 @@ class AHApp(web.Application):
return self.user_data.get(k) return self.user_data.get(k)
class ConfiguredServer: class ConfiguredServer:
def __init__(self, auth_klass=AuthAPI, workdir=None, app=None): def __init__(self, auth_klass=AuthAPI, workdir=None):
self.auth_klass = auth_klass self.auth_klass = auth_klass
self.workdir = workdir self.workdir = workdir
if self.workdir is not None: if self.workdir is not None:
@ -55,16 +54,13 @@ class ConfiguredServer:
if config.website.client_max_size: if config.website.client_max_size:
client_max_size = config.website.client_max_size client_max_size = config.website.client_max_size
if app: self.app = AHApp(client_max_size=client_max_size)
self.app = app
else:
self.app = AHApp(client_max_size=client_max_size)
load_plugins(self.workdir) load_plugins(self.workdir)
g = ServerEnv() g = ServerEnv()
g.workdir = workdir g.workdir = workdir
async def build_app(self): async def build_app(self):
rf = RegisterFunction() rf = RegisterCoroutine()
await rf.exe('ahapp_built', self.app) await rf.exe('ahapp_built', self.app)
auth = self.auth_klass() auth = self.auth_klass()
await auth.setupAuth(self.app) await auth.setupAuth(self.app)
@ -92,7 +88,7 @@ class ConfiguredServer:
def configPath(self,config): def configPath(self,config):
for p,prefix in config.website.paths: for p,prefix in config.website.paths:
res = ProcessorResource(prefix, p, show_index=True, res = ProcessorResource(prefix,p,show_index=True,
follow_symlinks=True, follow_symlinks=True,
indexes=config.website.indexes, indexes=config.website.indexes,
processors=config.website.processors) processors=config.website.processors)

View File

@ -75,7 +75,7 @@ def i18nDICT(request):
return json.dumps(i18n.getLangDict(l)).encode(c.website.coding) return json.dumps(i18n.getLangDict(l)).encode(c.website.coding)
class ProcessorResource(StaticResource,Url2File): class ProcessorResource(StaticResource,Url2File):
def __init__(self, prefix: str, directory: str, def __init__(self, prefix: str, directory: PathLike,
*, name: Optional[str]=None, *, name: Optional[str]=None,
expect_handler: Optional[_ExpectHandler]=None, expect_handler: Optional[_ExpectHandler]=None,
chunk_size: int=256 * 1024, chunk_size: int=256 * 1024,
@ -83,14 +83,14 @@ class ProcessorResource(StaticResource,Url2File):
append_version: bool=False, append_version: bool=False,
indexes:list=[], indexes:list=[],
processors:dict={}) -> None: processors:dict={}) -> None:
StaticResource.__init__(self, prefix, directory, StaticResource.__init__(self,prefix, directory,
name=name, name=name,
expect_handler=expect_handler, expect_handler=expect_handler,
chunk_size=chunk_size, chunk_size=chunk_size,
show_index=show_index, show_index=show_index,
follow_symlinks=follow_symlinks, follow_symlinks=follow_symlinks,
append_version=append_version) append_version=append_version)
Url2File.__init__(self, directory, prefix, indexes, inherit=True) Url2File.__init__(self,directory,prefix,indexes,inherit=True)
gr = self._routes.get('GET') gr = self._routes.get('GET')
self._routes.update({'POST':gr}) self._routes.update({'POST':gr})
self._routes.update({'PUT':gr}) self._routes.update({'PUT':gr})

View File

@ -21,19 +21,6 @@ class Url2File:
break break
return '/'.join(items) return '/'.join(items)
def get_ospath_by_webpath(self, path:str) -> str:
paths = url.split('/')
f = os.path.join(self.rootpath, *paths)
if not os.path.exists(f):
return None
if os.path.isdir(f):
for idx in self.indexes:
p = os.path.join(real_path,idx)
if os.path.isfile(p):
return p
return None
return f
def url2ospath(self, url: str) -> str: def url2ospath(self, url: str) -> str:
url = url.split('?')[0] url = url.split('?')[0]
if len(url) > 0 and url[-1] == '/': if len(url) > 0 and url[-1] == '/':

View File

@ -7,16 +7,16 @@ from ahserver.configuredServer import ConfiguredServer
from ahserver.serverenv import ServerEnv from ahserver.serverenv import ServerEnv
from appPublic.jsonConfig import getConfig from appPublic.jsonConfig import getConfig
def webapp(init_func, app=None): def webapp(init_func):
parser = argparse.ArgumentParser(prog="Sage") parser = argparse.ArgumentParser(prog="Sage")
parser.add_argument('-w', '--workdir') parser.add_argument('-w', '--workdir')
parser.add_argument('-p', '--port') parser.add_argument('-p', '--port')
args = parser.parse_args() args = parser.parse_args()
workdir = args.workdir or os.getcwd() workdir = args.workdir or os.getcwd()
port = args.port port = args.port
webserver(init_func, workdir, port=port, app=app) webserver(init_func, workdir, port)
def webserver(init_func, workdir, port=None, app=None): def webserver(init_func, workdir, port=None):
p = ProgramPath() p = ProgramPath()
config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p}) config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p})
if config.logger: if config.logger:
@ -29,7 +29,7 @@ def webserver(init_func, workdir, port=None, app=None):
se = ServerEnv() se = ServerEnv()
se.workdir = workdir se.workdir = workdir
se.port = port se.port = port
server = ConfiguredServer(workdir=workdir, app=app) server = ConfiguredServer(workdir=workdir)
port = port or config.website.port or 8080 port = port or config.website.port or 8080
port = int(port) port = int(port)
server.run(port=port) server.run(port=port)

View File

@ -1,7 +1,7 @@
# setup.cfg # setup.cfg
[metadata] [metadata]
name = ahserver name = ahserver
version = 1.0.15 version = 1.0.14
description = A application server base on aiohttp description = A application server base on aiohttp
author = yu moqing author = yu moqing
author_email = yumoqing@gmail.com author_email = yumoqing@gmail.com