Skip to content

Commit

Permalink
Oups
Browse files Browse the repository at this point in the history
  • Loading branch information
jczic committed Jan 9, 2024
1 parent 02cc86d commit 77e7975
Showing 1 changed file with 64 additions and 32 deletions.
96 changes: 64 additions & 32 deletions MicroWebSrv2/microWebSrv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class MicroWebSrv2 :
"<" : "&lt;"
}

_STAT_MODE_DIR = 1 << 14

DEBUG = 0x00
INFO = 0x01
WARNING = 0x02
Expand All @@ -79,19 +81,21 @@ class MicroWebSrv2 :
# ------------------------------------------------------------------------

def __init__(self) :
self._backlog = None
self._slotsCount = None
self._slotsSize = None
self._keepAlloc = None
self._maxContentLen = None
self._bindAddr = ('0.0.0.0', 80)
self._sslContext = None
self._rootPath = 'www'
self._timeoutSec = 2
self._notFoundURL = None
self._onLogging = None
self._xasSrv = None
self._xasPool = None
self._backlog = None
self._slotsCount = None
self._slotsSize = None
self._keepAlloc = None
self._maxContentLen = None
self._bindAddr = ('0.0.0.0', 80)
self._sslContext = None
self._rootPath = 'www'
self._timeoutSec = 2
self._notFoundURL = None
self._allowAllOrigins = False
self._corsAllowAll = False
self._onLogging = None
self._xasSrv = None
self._xasPool = None
self.SetNormalConfig()

# ------------------------------------------------------------------------
Expand All @@ -100,11 +104,15 @@ def __init__(self) :
def _physPathExists(physPath) :
try :
stat(physPath)
except OSError as ose :
return (ose.args[0] == 22)
return True
except :
return False
return True

# ------------------------------------------------------------------------

@staticmethod
def _physPathIsDir(physPath) :
return (stat(physPath)[0] & MicroWebSrv2._STAT_MODE_DIR != 0)

# ------------------------------------------------------------------------

Expand All @@ -117,7 +125,7 @@ def LoadModule(modName) :
try :
modPath = MicroWebSrv2.__module__.split('microWebSrv2')[0] \
+ ('mods.%s' % modName)
module = __import__(modPath, { }, { }, [modName])
module = getattr(__import__(modPath).mods, modName)
modClass = getattr(module, modName)
if type(modClass) is not type :
raise Exception
Expand Down Expand Up @@ -249,20 +257,18 @@ def Log(self, msg, msgType) :
def ResolvePhysicalPath(self, urlPath) :
if not isinstance(urlPath, str) or len(urlPath) == 0 :
raise ValueError('"urlPath" must be a not empty string.')
physPath = self._rootPath + urlPath.replace('..', '/')
endSlash = physPath.endswith('/')
physDir = physPath + ('/' if not endSlash else '')
if MicroWebSrv2._physPathExists(physDir) :
for filename in MicroWebSrv2._DEFAULT_PAGES :
p = physDir + filename
if MicroWebSrv2._physPathExists(p) :
return p
return physDir
elif endSlash :
return None
if MicroWebSrv2._physPathExists(physPath) :
try :
physPath = self._rootPath + urlPath.replace('..', '/')
if physPath.endswith('/') :
physPath = physPath[:-1]
if MicroWebSrv2._physPathIsDir(physPath) :
for filename in MicroWebSrv2._DEFAULT_PAGES :
p = physPath + '/' + filename
if MicroWebSrv2._physPathExists(p) :
return p
return physPath
return None
except :
return None

# ------------------------------------------------------------------------

Expand Down Expand Up @@ -368,7 +374,9 @@ def SetLargeConfig(self) :

@property
def IsRunning(self) :
return (self._xasSrv is not None)
return ( self._xasPool is not None and \
self._xasPool.WaitEventsProcessing and \
self._xasSrv is not None )

# ------------------------------------------------------------------------

Expand Down Expand Up @@ -468,7 +476,7 @@ def RootPath(self, value) :
if not isinstance(value, str) or len(value) == 0 :
raise ValueError('"RootPath" must be a not empty string.')
self._validateChangeConf('"RootPath"')
self._rootPath = value
self._rootPath = (value[:-1] if value.endswith('/') else value)

# ------------------------------------------------------------------------

Expand Down Expand Up @@ -496,6 +504,30 @@ def NotFoundURL(self, value) :

# ------------------------------------------------------------------------

@property
def AllowAllOrigins(self) :
return self._allowAllOrigins

@AllowAllOrigins.setter
def AllowAllOrigins(self, value) :
if not isinstance(value, bool) :
raise ValueError('"AllowAllOrigins" must be a boolean.')
self._allowAllOrigins = value

# ------------------------------------------------------------------------

@property
def CORSAllowAll(self) :
return self._corsAllowAll

@CORSAllowAll.setter
def CORSAllowAll(self, value) :
if not isinstance(value, bool) :
raise ValueError('"CORSAllowAll" must be a boolean.')
self._corsAllowAll = value

# ------------------------------------------------------------------------

@property
def OnLogging(self) :
return self._onLogging
Expand Down

0 comments on commit 77e7975

Please sign in to comment.