@@ -176,6 +176,15 @@ def _load_resources(self, resources, options=None, **new_options):
176
176
for resource in resources :
177
177
yield self ._load_resource (resource , options = options )
178
178
179
+ def load_remote_resource_contents (self , resource , ** options ):
180
+ self .logger .info ("Fetching remote resource: " + resource )
181
+ return urllib2 .urlopen (resource ).read ()
182
+
183
+ def load_local_resource_contents (self , location , ** options ):
184
+ # Extract the contents so we can close the file
185
+ with open (location , 'rb' ) as resource_file :
186
+ return resource_file .read ()
187
+
179
188
def _load_resource (self , resource , options = None , ** new_options ):
180
189
"""http links, filesystem locations, and file-like objects"""
181
190
options = options or self ._get_options (Resource , ** new_options )
@@ -185,16 +194,12 @@ def _load_resource(self, resource, options=None, **new_options):
185
194
186
195
if isinstance (resource , basestring ):
187
196
if re .match (r'https?://' ,resource ):
188
- self .logger .info ("Fetching remote resource: " + resource )
189
- contents = urllib2 .urlopen (resource ).read ()
197
+ contents = self .load_remote_resource_contents (resource , ** options )
190
198
191
199
else :
192
200
directory = options .get ('directory' ,'' )
193
201
location = os .path .join (directory , resource )
194
-
195
- # Extract the contents so we can close the file
196
- with open (location , 'rb' ) as resource_file :
197
- contents = resource_file .read ()
202
+ contents = self .load_local_resource_contents (location , ** options )
198
203
199
204
# StringIO implements a fuller file-like object
200
205
resource_name = resource
0 commit comments