Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
yield f
elif fn.suffix == '.gz':
with gzip.open(fn, 'rt') as f:
yield f
elif fn.suffix == '.zip':
with zipfile.ZipFile(fn, 'r') as z:
flist = z.namelist()
for rinexfn in flist:
with z.open(rinexfn, 'r') as bf:
f = io.TextIOWrapper(bf, newline=None)
yield f
elif fn.suffix == '.Z':
if unlzw is None:
raise ImportError('pip install unlzw')
with fn.open('rb') as zu:
with io.StringIO(unlzw.unlzw(zu.read()).decode('ascii')) as f:
yield f
else:
with fn.open('r') as f:
yield f
def rinexinfo(f: Union[Path, TextIO]) -> Dict[str, Any]:
"""verify RINEX version"""
if isinstance(f, (str, Path)):
fn = Path(f).expanduser()
if fn.suffixes == ['.crx', '.gz']:
with gzip.open(fn, 'rt') as z:
return rinexinfo(io.StringIO(z.read(80)))
elif fn.suffix == '.crx':
with fn.open('r') as f:
return rinexinfo(io.StringIO(f.read(80)))
else:
with opener(fn) as f:
return rinexinfo(f)
try:
line = f.readline(80) # don't choke on binary files
if not isinstance(line, str) or line[60:80] not in ('RINEX VERSION / TYPE', 'CRINEX VERS / TYPE'):
raise ValueError
info = {'version': float(line[:9]), # yes :9
'filetype': line[20],
'systems': line[40],
'hatanaka': line[20:40] == 'COMPACT RINEX FORMAT'}