@@ -176,6 +176,15 @@ def _load_resources(self, resources, options=None, **new_options):
176176 for resource in resources :
177177 yield self ._load_resource (resource , options = options )
178178
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+
179188 def _load_resource (self , resource , options = None , ** new_options ):
180189 """http links, filesystem locations, and file-like objects"""
181190 options = options or self ._get_options (Resource , ** new_options )
@@ -185,16 +194,12 @@ def _load_resource(self, resource, options=None, **new_options):
185194
186195 if isinstance (resource , basestring ):
187196 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 )
190198
191199 else :
192200 directory = options .get ('directory' ,'' )
193201 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 )
198203
199204 # StringIO implements a fuller file-like object
200205 resource_name = resource
0 commit comments