99import io
1010import os
1111
12+ from pvlib .tools import _file_context_manager
13+ from pvlib ._deprecation import deprecated
14+
1215BSRN_FTP_URL = "ftp.bsrn.awi.de"
1316
1417BSRN_LR0100_COL_SPECS = [(0 , 3 ), (4 , 9 ), (10 , 16 ), (16 , 22 ), (22 , 27 ),
@@ -136,7 +139,7 @@ def get_bsrn(station, start, end, username, password,
136139
137140 See Also
138141 --------
139- pvlib.iotools.read_bsrn, pvlib.iotools.parse_bsrn
142+ pvlib.iotools.read_bsrn
140143
141144 References
142145 ----------
@@ -191,7 +194,7 @@ def get_bsrn(station, start, end, username, password,
191194 bio .seek (0 ) # reset buffer to start of file
192195 gzip_file = io .TextIOWrapper (gzip .GzipFile (fileobj = bio ),
193196 encoding = 'latin1' )
194- dfi , metadata = parse_bsrn (gzip_file , logical_records )
197+ dfi , metadata = _parse_bsrn (gzip_file , logical_records )
195198 dfs .append (dfi )
196199 # FTP client raises an error if the file does not exist on server
197200 except ftplib .error_perm as e :
@@ -217,7 +220,7 @@ def get_bsrn(station, start, end, username, password,
217220 return data , metadata
218221
219222
220- def parse_bsrn (fbuf , logical_records = ('0100' ,)):
223+ def _parse_bsrn (fbuf , logical_records = ('0100' ,)):
221224 """
222225 Parse a file-like buffer of a BSRN station-to-archive file.
223226
@@ -382,7 +385,7 @@ def read_bsrn(filename, logical_records=('0100',)):
382385 Parameters
383386 ----------
384387 filename: str or path-like
385- Name or path of a BSRN station-to-archive data file
388+ Name, path, or in-memory buffer of a BSRN station-to-archive data file
386389 logical_records: list or tuple, default: ('0100',)
387390 List of the logical records (LR) to parse. Options include: '0100',
388391 '0300', and '0500'.
@@ -439,7 +442,7 @@ def read_bsrn(filename, logical_records=('0100',)):
439442
440443 See Also
441444 --------
442- pvlib.iotools.parse_bsrn, pvlib.iotools. get_bsrn
445+ pvlib.iotools.get_bsrn
443446
444447 References
445448 ----------
@@ -457,7 +460,11 @@ def read_bsrn(filename, logical_records=('0100',)):
457460 if str (filename ).endswith ('.gz' ): # check if file is a gzipped (.gz) file
458461 open_func , mode = gzip .open , 'rt'
459462 else :
460- open_func , mode = open , 'r'
463+ open_func , mode = _file_context_manager , 'r'
461464 with open_func (filename , mode ) as f :
462- content = parse_bsrn (f , logical_records )
465+ content = _parse_bsrn (f , logical_records )
463466 return content
467+
468+
469+ parse_bsrn = deprecated (since = "0.13.0" , name = "parse_bsrn" ,
470+ alternative = "read_bsrn" )(read_bsrn )
0 commit comments