55# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66
77import cgi
8- import re
98import json
109import logging
1110import os
@@ -1628,22 +1627,24 @@ def findModelIdx():
16281627 self .model_file_description ["models" ].pop (modelSearchIdx )
16291628
16301629 def _extract_oci_uri_components (self , uri : str ):
1631- # Define the regular expression pattern to match the URI format
1632- pattern = r"oci://(?P<bucket_name>[^@]+)@(?P<namespace>[^/]+)(?:/(?P<prefix>.*))?" # todo: remove regex
1633-
1634- # Use re.match to apply the pattern to the URI
1635- match = re . match ( pattern , uri )
1636-
1637- if match :
1638- # Extract named groups using the groupdict() method
1639- components = match . groupdict ()
1640- prefix = components . get ( 'prefix' , '' )
1641- # Treat a single trailing slash as no prefix
1642- if prefix == "" :
1643- return components [ 'bucket_name' ], components [ 'namespace' ], ''
1644- elif prefix == "/" :
1645- return components [ 'bucket_name' ], components [ 'namespace' ], ''
1646- else :
1647- return components [ 'bucket_name' ], components [ 'namespace' ], prefix
1630+ if not uri . startswith ( "oci://" ):
1631+ raise ValueError ( "Invalid URI format" )
1632+
1633+ # Remove the "oci://" prefix
1634+ uri = uri [ len ( "oci://" ):]
1635+
1636+ # Split by "@" to get bucket_name and the rest
1637+ bucket_and_rest = uri . split ( "@" , 1 )
1638+ if len ( bucket_and_rest ) != 2 :
1639+ raise ValueError ( "Invalid URI format" )
1640+
1641+ bucket_name = bucket_and_rest [ 0 ]
1642+
1643+ # Split the rest by "/" to get namespace and prefix
1644+ namespace_and_prefix = bucket_and_rest [ 1 ]. split ( "/" , 1 )
1645+ if len ( namespace_and_prefix ) == 1 :
1646+ namespace , prefix = namespace_and_prefix [ 0 ], ""
16481647 else :
1649- raise ValueError ("The URI format is incorrect" )
1648+ namespace , prefix = namespace_and_prefix
1649+
1650+ return bucket_name , namespace , None if prefix == '' else prefix
0 commit comments