Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/client/base_catalog.py: 87%

15 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-10-06 15:01 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6''' 

7Base class for earthquake catalog clients. 

8''' 

9 

10 

11class EarthquakeCatalog(object): 

12 ''' 

13 Base class for Pyrocko's earthquake catalog clients. 

14 ''' 

15 

16 def get_event(self, name): 

17 raise NotImplementedError 

18 

19 def iter_event_names(self, time_range, **kwargs): 

20 raise NotImplementedError 

21 

22 def get_event_names(self, time_range, **kwargs): 

23 return list(self.iter_event_names(time_range, **kwargs)) 

24 

25 def get_events(self, time_range, **kwargs): 

26 return list(self.iter_events(time_range, **kwargs)) 

27 

28 def iter_events(self, time_range, **kwargs): 

29 for name in self.iter_event_names(time_range, **kwargs): 

30 yield self.get_event(name) 

31 

32 

33class NotFound(Exception): 

34 def __init__(self, url=None): 

35 Exception.__init__(self) 

36 self._url = url 

37 

38 def __str__(self): 

39 if self._url: 

40 return 'No results for request %s' % self._url 

41 else: 

42 return 'No results for request'