@@ -225,180 +225,3 @@ def set_data(self, path, data):
225225 raise NotImplementedError
226226
227227_register (SourceLoader , machinery .SourceFileLoader )
228-
229- class PyLoader (SourceLoader ):
230-
231- """Implement the deprecated PyLoader ABC in terms of SourceLoader.
232-
233- This class has been deprecated! It is slated for removal in Python 3.4.
234- If compatibility with Python 3.1 is not needed then implement the
235- SourceLoader ABC instead of this class. If Python 3.1 compatibility is
236- needed, then use the following idiom to have a single class that is
237- compatible with Python 3.1 onwards::
238-
239- try:
240- from importlib.abc import SourceLoader
241- except ImportError:
242- from importlib.abc import PyLoader as SourceLoader
243-
244-
245- class CustomLoader(SourceLoader):
246- def get_filename(self, fullname):
247- # Implement ...
248-
249- def source_path(self, fullname):
250- '''Implement source_path in terms of get_filename.'''
251- try:
252- return self.get_filename(fullname)
253- except ImportError:
254- return None
255-
256- def is_package(self, fullname):
257- filename = os.path.basename(self.get_filename(fullname))
258- return os.path.splitext(filename)[0] == '__init__'
259-
260- """
261-
262- @abc .abstractmethod
263- def is_package (self , fullname ):
264- raise NotImplementedError
265-
266- @abc .abstractmethod
267- def source_path (self , fullname ):
268- """Abstract method. Accepts a str module name and returns the path to
269- the source code for the module."""
270- raise NotImplementedError
271-
272- def get_filename (self , fullname ):
273- """Implement get_filename in terms of source_path.
274-
275- As get_filename should only return a source file path there is no
276- chance of the path not existing but loading still being possible, so
277- ImportError should propagate instead of being turned into returning
278- None.
279-
280- """
281- warnings .warn ("importlib.abc.PyLoader is deprecated and is "
282- "slated for removal in Python 3.4; "
283- "use SourceLoader instead. "
284- "See the importlib documentation on how to be "
285- "compatible with Python 3.1 onwards." ,
286- DeprecationWarning )
287- path = self .source_path (fullname )
288- if path is None :
289- raise ImportError (name = fullname )
290- else :
291- return path
292-
293-
294- class PyPycLoader (PyLoader ):
295-
296- """Abstract base class to assist in loading source and bytecode by
297- requiring only back-end storage methods to be implemented.
298-
299- This class has been deprecated! Removal is slated for Python 3.4. Implement
300- the SourceLoader ABC instead. If Python 3.1 compatibility is needed, see
301- PyLoader.
302-
303- The methods get_code, get_source, and load_module are implemented for the
304- user.
305-
306- """
307-
308- def get_filename (self , fullname ):
309- """Return the source or bytecode file path."""
310- path = self .source_path (fullname )
311- if path is not None :
312- return path
313- path = self .bytecode_path (fullname )
314- if path is not None :
315- return path
316- raise ImportError ("no source or bytecode path available for "
317- "{0!r}" .format (fullname ), name = fullname )
318-
319- def get_code (self , fullname ):
320- """Get a code object from source or bytecode."""
321- warnings .warn ("importlib.abc.PyPycLoader is deprecated and slated for "
322- "removal in Python 3.4; use SourceLoader instead. "
323- "If Python 3.1 compatibility is required, see the "
324- "latest documentation for PyLoader." ,
325- DeprecationWarning )
326- source_timestamp = self .source_mtime (fullname )
327- # Try to use bytecode if it is available.
328- bytecode_path = self .bytecode_path (fullname )
329- if bytecode_path :
330- data = self .get_data (bytecode_path )
331- try :
332- magic = data [:4 ]
333- if len (magic ) < 4 :
334- raise ImportError (
335- "bad magic number in {}" .format (fullname ),
336- name = fullname , path = bytecode_path )
337- raw_timestamp = data [4 :8 ]
338- if len (raw_timestamp ) < 4 :
339- raise EOFError ("bad timestamp in {}" .format (fullname ))
340- pyc_timestamp = _bootstrap ._r_long (raw_timestamp )
341- raw_source_size = data [8 :12 ]
342- if len (raw_source_size ) != 4 :
343- raise EOFError ("bad file size in {}" .format (fullname ))
344- # Source size is unused as the ABC does not provide a way to
345- # get the size of the source ahead of reading it.
346- bytecode = data [12 :]
347- # Verify that the magic number is valid.
348- if imp .get_magic () != magic :
349- raise ImportError (
350- "bad magic number in {}" .format (fullname ),
351- name = fullname , path = bytecode_path )
352- # Verify that the bytecode is not stale (only matters when
353- # there is source to fall back on.
354- if source_timestamp :
355- if pyc_timestamp < source_timestamp :
356- raise ImportError ("bytecode is stale" , name = fullname ,
357- path = bytecode_path )
358- except (ImportError , EOFError ):
359- # If source is available give it a shot.
360- if source_timestamp is not None :
361- pass
362- else :
363- raise
364- else :
365- # Bytecode seems fine, so try to use it.
366- return marshal .loads (bytecode )
367- elif source_timestamp is None :
368- raise ImportError ("no source or bytecode available to create code "
369- "object for {0!r}" .format (fullname ),
370- name = fullname )
371- # Use the source.
372- source_path = self .source_path (fullname )
373- if source_path is None :
374- message = "a source path must exist to load {0}" .format (fullname )
375- raise ImportError (message , name = fullname )
376- source = self .get_data (source_path )
377- code_object = compile (source , source_path , 'exec' , dont_inherit = True )
378- # Generate bytecode and write it out.
379- if not sys .dont_write_bytecode :
380- data = bytearray (imp .get_magic ())
381- data .extend (_bootstrap ._w_long (source_timestamp ))
382- data .extend (_bootstrap ._w_long (len (source ) & 0xFFFFFFFF ))
383- data .extend (marshal .dumps (code_object ))
384- self .write_bytecode (fullname , data )
385- return code_object
386-
387- @abc .abstractmethod
388- def source_mtime (self , fullname ):
389- """Abstract method. Accepts a str filename and returns an int
390- modification time for the source of the module."""
391- raise NotImplementedError
392-
393- @abc .abstractmethod
394- def bytecode_path (self , fullname ):
395- """Abstract method. Accepts a str filename and returns the str pathname
396- to the bytecode for the module."""
397- raise NotImplementedError
398-
399- @abc .abstractmethod
400- def write_bytecode (self , fullname , bytecode ):
401- """Abstract method. Accepts a str filename and bytes object
402- representing the bytecode for the module. Returns a boolean
403- representing whether the bytecode was written or not."""
404- raise NotImplementedError
0 commit comments