@@ -351,8 +351,7 @@ def serverSidePath(self, path=None):
351351 server side directory to form a path relative to the object.
352352 """
353353 if path :
354- if path .startswith ('/' ):
355- path = path [1 :]
354+ path = path .removeprefix ('/' )
356355 return os .path .normpath (os .path .join (
357356 os .path .dirname (self ._serverSidePath ), path ))
358357 return self ._serverSidePath
@@ -367,8 +366,7 @@ def serverSideContextPath(self, path=None):
367366 if the request is in a subdirectory of the main context directory.
368367 """
369368 if path :
370- if path .startswith ('/' ):
371- path = path [1 :]
369+ path = path .removeprefix ('/' )
372370 return os .path .normpath (os .path .join (
373371 self ._serverSideContextPath , path ))
374372 return self ._serverSideContextPath
@@ -385,15 +383,11 @@ def servletURI(self):
385383 """Return servlet URI without any query strings or extra path info."""
386384 p = self ._pathInfo
387385 if not self ._extraURLPath :
388- if p .endswith ('/' ):
389- p = p [:- 1 ]
390- return p
386+ return p .removesuffix ('/' )
391387 i = p .rfind (self ._extraURLPath )
392388 if i >= 0 :
393389 p = p [:i ]
394- if p .endswith ('/' ):
395- p = p [:- 1 ]
396- return p
390+ return p .removesuffix ('/' )
397391
398392 def uriWebwareRoot (self ):
399393 """Return relative URL path of the Webware root location."""
@@ -494,11 +488,9 @@ def siteRoot(self):
494488 of the servlet that you have forwarded to.
495489 """
496490 url = self .originalURLPath ()
497- if url .startswith ('/' ):
498- url = url [1 :]
491+ url = url .removeprefix ('/' )
499492 contextName = self .contextName () + '/'
500- if url .startswith (contextName ):
501- url = url [len (contextName ):]
493+ url = url .removeprefix (contextName )
502494 numStepsBack = url .count ('/' )
503495 return '../' * numStepsBack
504496
@@ -512,11 +504,9 @@ def siteRootFromCurrentServlet(self):
512504 relative to the _current_ servlet, not the _original_ servlet.
513505 """
514506 url = self .urlPath ()
515- if url .startswith ('/' ):
516- url = url [1 :]
507+ url = url .removeprefix ('/' )
517508 contextName = self .contextName () + '/'
518- if url .startswith (contextName ):
519- url = url [len (contextName ):]
509+ url = url .removeprefix (contextName )
520510 numStepsBackward = url .count ('/' )
521511 return '../' * numStepsBackward
522512
@@ -529,8 +519,7 @@ def servletPathFromSiteRoot(self):
529519 servlet in a database, for example.
530520 """
531521 urlPath = self .urlPath ()
532- if urlPath .startswith ('/' ):
533- urlPath = urlPath [1 :]
522+ urlPath = urlPath .removeprefix ('/' )
534523 parts = urlPath .split ('/' )
535524 newParts = []
536525 for part in parts :
0 commit comments