@@ -67,7 +67,7 @@ def rados_open(self, req: urllib.request.Request) -> typing.IO:
67
67
"""Open a rados-style url. Called from urllib."""
68
68
if self ._interface is None :
69
69
raise RADOSUnsupported ()
70
- rinfo = self . _parse_req (req )
70
+ rinfo = parse_rados_uri (req )
71
71
if rinfo .get ("subtype" ) == "mon-config-key" :
72
72
return _get_mon_config_key (self ._interface , rinfo ["path" ])
73
73
return RADOSObjectRef (
@@ -83,7 +83,7 @@ def get_object(
83
83
"""
84
84
if self ._interface is None :
85
85
raise RADOSUnsupported ()
86
- rinfo = self . _parse_req (urllib .request .Request (uri ))
86
+ rinfo = parse_rados_uri (urllib .request .Request (uri ))
87
87
if rinfo .get ("type" ) != "rados" :
88
88
raise ValueError ("only rados URI values supported" )
89
89
if rinfo .get ("subtype" ) == "mon-config-key" :
@@ -96,29 +96,6 @@ def get_object(
96
96
must_exist = must_exist ,
97
97
)
98
98
99
- def _parse_req (self , req : urllib .request .Request ) -> dict [str , str ]:
100
- """Parse a urlib request into useful components."""
101
- subtype = "mon-config-key"
102
- if req .selector .startswith (subtype + ":" ):
103
- return {
104
- "type" : req .type ,
105
- "subtype" : subtype ,
106
- "path" : req .selector .split (":" , 1 )[1 ],
107
- }
108
- sel = req .selector .lstrip ("/" )
109
- if req .host :
110
- pool = req .host
111
- ns , key = sel .split ("/" , 1 )
112
- else :
113
- pool , ns , key = sel .split ("/" , 2 )
114
- return {
115
- "type" : req .type ,
116
- "subtype" : "object" ,
117
- "pool" : pool ,
118
- "ns" : ns ,
119
- "key" : key ,
120
- }
121
-
122
99
123
100
# it's quite annoying to have a read-only typing.IO we're forced to
124
101
# have so many stub methods. Go's much more granular io interfaces for
@@ -388,6 +365,35 @@ def is_rados_uri(uri: str) -> bool:
388
365
return uri .startswith ("rados:" )
389
366
390
367
368
+ def parse_rados_uri (
369
+ uri : typing .Union [str , urllib .request .Request ]
370
+ ) -> dict [str , str ]:
371
+ """Given a rados uri-like value return a dict containing a breakdown of the
372
+ components of the uri.
373
+ """
374
+ req = uri if not isinstance (uri , str ) else urllib .request .Request (uri )
375
+ subtype = "mon-config-key"
376
+ if req .selector .startswith (subtype + ":" ):
377
+ return {
378
+ "type" : req .type ,
379
+ "subtype" : subtype ,
380
+ "path" : req .selector .split (":" , 1 )[1 ],
381
+ }
382
+ sel = req .selector .lstrip ("/" )
383
+ if req .host :
384
+ pool = req .host
385
+ ns , key = sel .split ("/" , 1 )
386
+ else :
387
+ pool , ns , key = sel .split ("/" , 2 )
388
+ return {
389
+ "type" : req .type ,
390
+ "subtype" : "object" ,
391
+ "pool" : pool ,
392
+ "ns" : ns ,
393
+ "key" : key ,
394
+ }
395
+
396
+
391
397
def enable_rados (
392
398
cls : typing .Type [url_opener .URLOpener ],
393
399
* ,
0 commit comments