Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/io/backends/spickle.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-03-07 11:54 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6''' 

7Squirrel IO adaptor to read YAML files. 

8''' 

9 

10import logging 

11 

12from pyrocko.io.io_common import get_stats, touch # noqa 

13from pyrocko import guts 

14from pyrocko.io.io_common import FileLoadError 

15 

16logger = logging.getLogger('psq.io.spickle') 

17 

18 

19def provided_formats(): 

20 return ['spickle'] 

21 

22 

23def detect(first512): 

24 return 'spickle' if first512.startswith(b'SPICKLE') else None 

25 

26 

27def iload(format, file_path, segment, content): 

28 from pyrocko.io import stationxml 

29 

30 with open(file_path, 'rb') as f: 

31 for obj, segment in guts._iload_all_spickle_internal( 

32 f, offset=segment): 

33 

34 if isinstance(obj, stationxml.FDSNStationXML): 

35 from .stationxml import iload_stationxml 

36 yield from iload_stationxml(obj, segment, content) 

37 else: 

38 raise FileLoadError( 

39 'Stored object of type %s is not supported by Squirrel ' 

40 'framework. Found at offset %s in spickle file: %s' 

41 % (str(type(obj)), segment, file_path))