@@ -56,7 +56,7 @@ def save( # type: ignore
5656 """
5757 self .branch = branch
5858 self .commit_message = commit_message
59- self .file_path = self .file_path . replace ( "/" , "%2F" )
59+ self .file_path = utils . _url_encode ( self .file_path )
6060 super (ProjectFile , self ).save (** kwargs )
6161
6262 @exc .on_http_error (exc .GitlabDeleteError )
@@ -76,7 +76,7 @@ def delete( # type: ignore
7676 GitlabAuthenticationError: If authentication is not correct
7777 GitlabDeleteError: If the server cannot perform the request
7878 """
79- file_path = self .get_id (). replace ( "/" , "%2F" )
79+ file_path = utils . _url_encode ( self .get_id ())
8080 self .manager .delete (file_path , branch , commit_message , ** kwargs )
8181
8282
@@ -144,7 +144,7 @@ def create(
144144 assert data is not None
145145 self ._check_missing_create_attrs (data )
146146 new_data = data .copy ()
147- file_path = new_data .pop ("file_path" ). replace ( "/" , "%2F" )
147+ file_path = utils . _url_encode ( new_data .pop ("file_path" ))
148148 path = f"{ self .path } /{ file_path } "
149149 server_data = self .gitlab .http_post (path , post_data = new_data , ** kwargs )
150150 if TYPE_CHECKING :
@@ -173,7 +173,7 @@ def update( # type: ignore
173173 """
174174 new_data = new_data or {}
175175 data = new_data .copy ()
176- file_path = file_path . replace ( "/" , "%2F" )
176+ file_path = utils . _url_encode ( file_path )
177177 data ["file_path" ] = file_path
178178 path = f"{ self .path } /{ file_path } "
179179 self ._check_missing_update_attrs (data )
@@ -203,7 +203,8 @@ def delete( # type: ignore
203203 GitlabAuthenticationError: If authentication is not correct
204204 GitlabDeleteError: If the server cannot perform the request
205205 """
206- path = f"{ self .path } /{ file_path .replace ('/' , '%2F' )} "
206+ file_path = utils ._url_encode (file_path )
207+ path = f"{ self .path } /{ file_path } "
207208 data = {"branch" : branch , "commit_message" : commit_message }
208209 self .gitlab .http_delete (path , query_data = data , ** kwargs )
209210
@@ -238,7 +239,7 @@ def raw(
238239 Returns:
239240 The file content
240241 """
241- file_path = file_path . replace ( "/" , "%2F" ). replace ( "." , "%2E" )
242+ file_path = utils . _url_encode ( file_path )
242243 path = f"{ self .path } /{ file_path } /raw"
243244 query_data = {"ref" : ref }
244245 result = self .gitlab .http_get (
@@ -265,7 +266,7 @@ def blame(self, file_path: str, ref: str, **kwargs: Any) -> List[Dict[str, Any]]
265266 Returns:
266267 A list of commits/lines matching the file
267268 """
268- file_path = file_path . replace ( "/" , "%2F" ). replace ( "." , "%2E" )
269+ file_path = utils . _url_encode ( file_path )
269270 path = f"{ self .path } /{ file_path } /blame"
270271 query_data = {"ref" : ref }
271272 result = self .gitlab .http_list (path , query_data , ** kwargs )
0 commit comments