File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 25
25
import sys
26
26
import typing
27
27
28
- from .opener import Opener
28
+ from .opener import Opener , FileOpener
29
29
30
30
_VALID_VERSIONS = ["v0" ]
31
31
@@ -155,11 +155,6 @@ def _check_config_valid(
155
155
raise
156
156
157
157
158
- class _FileOpener :
159
- def open (self , path : str ) -> typing .IO :
160
- return _open (path , "rb" )
161
-
162
-
163
158
def read_config_files (
164
159
fnames : list [str ],
165
160
* ,
@@ -175,7 +170,7 @@ def read_config_files(
175
170
# users will be split from the main config (for security reasons) but
176
171
# it would be nicer to have a good merge algorithm handle everything
177
172
# smarter at some point.
178
- opener = opener or _FileOpener ()
173
+ opener = opener or FileOpener ()
179
174
gconfig = GlobalConfig ()
180
175
readfiles = set ()
181
176
for fname in fnames :
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ def __init__(
43
43
open_fn : typing .Optional [typing .Callable [..., typing .IO ]] = None ,
44
44
) -> None :
45
45
self ._openers = openers
46
- self ._open_fn = open_fn or open
46
+ self ._open_fn = open_fn or FileOpener . open
47
47
48
48
def open (self , path_or_uri : str ) -> typing .IO :
49
49
for opener in self ._openers :
@@ -55,3 +55,11 @@ def open(self, path_or_uri: str) -> typing.IO:
55
55
56
56
def _open (self , path : str ) -> typing .IO :
57
57
return self ._open_fn (path )
58
+
59
+
60
+ class FileOpener :
61
+ """Minimal opener that only supports opening local files."""
62
+
63
+ @staticmethod
64
+ def open (path : str ) -> typing .IO :
65
+ return open (path , "rb" )
Original file line number Diff line number Diff line change 22
22
import unittest
23
23
24
24
import sambacc .config
25
+ import sambacc .opener
25
26
26
27
config1 = """
27
28
{
@@ -451,7 +452,7 @@ def test_tesd_config_files_realerr_rootok(monkeypatch):
451
452
def err_open (* args ):
452
453
raise OSError ("test!" )
453
454
454
- monkeypatch .setattr (sambacc .config , "_open " , err_open )
455
+ monkeypatch .setattr (sambacc .opener . FileOpener , "open " , err_open )
455
456
fname = "/etc/foobar"
456
457
with pytest .raises (OSError ):
457
458
sambacc .config .read_config_files ([fname ])
You can’t perform that action at this time.
0 commit comments