19
19
log = logging .getLogger (__name__ )
20
20
21
21
22
- def path_from_uri (uri ) :
22
+ def path_from_uri (uri : str ) -> str :
23
23
# Convert file uri to path (strip html like head part)
24
24
if not uri .startswith ("file://" ):
25
25
return os .path .abspath (uri )
@@ -30,7 +30,7 @@ def path_from_uri(uri):
30
30
return os .path .normpath (unquote (path ))
31
31
32
32
33
- def path_to_uri (path ) :
33
+ def path_to_uri (path : str ) -> str :
34
34
# Convert path to file uri (add html like head part)
35
35
if os .name == "nt" :
36
36
return "file:///" + quote (path .replace ("\\ " , "/" ))
@@ -88,9 +88,7 @@ def _read_header_content_length(self, line):
88
88
try :
89
89
return int (value )
90
90
except ValueError :
91
- raise JSONRPC2ProtocolError (
92
- "Invalid Content-Length header: {0}" .format (value )
93
- )
91
+ raise JSONRPC2ProtocolError (f"Invalid Content-Length header: { value } " )
94
92
95
93
def _receive (self ):
96
94
line = self .conn .readline ()
@@ -130,9 +128,9 @@ def _send(self, body):
130
128
body = json .dumps (body , separators = ("," , ":" ))
131
129
content_length = len (body )
132
130
response = (
133
- "Content-Length: {0 }\r \n "
131
+ f "Content-Length: { content_length } \r \n "
134
132
"Content-Type: application/vscode-jsonrpc; charset=utf8\r \n \r \n "
135
- "{1}" . format ( content_length , body )
133
+ f" { body } "
136
134
)
137
135
self .conn .write (response )
138
136
log .debug ("SEND %s" , body )
@@ -239,9 +237,9 @@ def write_rpc_request(rid, method, params):
239
237
body = json .dumps (body , separators = ("," , ":" ))
240
238
content_length = len (body )
241
239
return (
242
- "Content-Length: {0 }\r \n "
240
+ f "Content-Length: { content_length } \r \n "
243
241
"Content-Type: application/vscode-jsonrpc; charset=utf8\r \n \r \n "
244
- "{1}" . format ( content_length , body )
242
+ f" { body } "
245
243
)
246
244
247
245
@@ -254,9 +252,9 @@ def write_rpc_notification(method, params):
254
252
body = json .dumps (body , separators = ("," , ":" ))
255
253
content_length = len (body )
256
254
return (
257
- "Content-Length: {0 }\r \n "
255
+ f "Content-Length: { content_length } \r \n "
258
256
"Content-Type: application/vscode-jsonrpc; charset=utf8\r \n \r \n "
259
- "{1}" . format ( content_length , body )
257
+ f" { body } "
260
258
)
261
259
262
260
@@ -270,9 +268,7 @@ def read_header_content_length(line):
270
268
try :
271
269
return int (value )
272
270
except ValueError :
273
- raise JSONRPC2ProtocolError (
274
- "Invalid Content-Length header: {0}" .format (value )
275
- )
271
+ raise JSONRPC2ProtocolError (f"Invalid Content-Length header: { value } " )
276
272
277
273
def receive_next ():
278
274
line = content .readline ()
0 commit comments