Skip to content

Commit

Permalink
getContent should read file: url's also
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Apr 27, 2024
1 parent 77ab182 commit 11b7c69
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions sarracenia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import time
import types
import urllib
import urllib.parse
import urllib.request

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -877,20 +878,27 @@ def getContent(msg,options=None):
else:
return msg['content']['value'].encode('utf-8')

# local file shortcut
if options and hasattr(options,'baseDir') and options.baseDir:
path=options.baseDir + '/' + msg['relPath']
if os.path.exists(path):
logger.info( f"path: {path} exists?: {os.path.exists(path)}" )
with open(path,'rb') as f:
return f.read()
path=''
if msg['baseUrl'].startswith('file:'):
pu = urllib.parse.urlparse(msg['baseUrl'])
path=pu.path + msg['relPath']
logger.info( f"path: {path}")
elif options and hasattr(options,'baseDir') and options.baseDir:
# local file shortcut
path=options.baseDir + os.sep + msg['relPath']

if os.path.exists(path):
logger.info( f"reading local file path: {path} exists?: {os.path.exists(path)}" )
with open(path,'rb') as f:
return f.read()

# case requiring resolution.
if 'retrievePath' in msg:
retUrl = msg['baseUrl'] + '/' + msg['retrievePath']
else:
retUrl = msg['baseUrl'] + '/' + msg['relPath']

logger.info( f"retrieving from: {retUrl}" )
with urllib.request.urlopen(retUrl) as response:
return response.read()

1 comment on commit 11b7c69

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report •
FileStmtsMissCoverMissing
__init__.py4164688%70–71, 73, 80, 83, 87–88, 90–91, 98, 104, 107, 109–110, 112–113, 115–116, 320, 431, 464, 531–532, 561–562, 608, 621, 623, 633–635, 645–646, 675, 684, 780, 813, 829, 883–885, 888, 891–893, 899
TOTAL154401259918% 

Test Results

Tests Skipped Failures Errors Time
209 8 💤 0 ❌ 0 🔥 15.749s ⏱️

Please sign in to comment.