99 Type ,
1010 Union ,
1111)
12+ from httpie .cli .constants import OPEN_BRACKET , CLOSE_BRACKET , BACKSLASH , HIGHLIGHTER
1213
1314
1415class HTTPieSyntaxError (ValueError ):
@@ -30,7 +31,7 @@ def __str__(self):
3031 lines .append (self .source )
3132 lines .append (
3233 ' ' * (self .token .start )
33- + '^' * (self .token .end - self .token .start )
34+ + HIGHLIGHTER * (self .token .end - self .token .start )
3435 )
3536 return '\n ' .join (lines )
3637
@@ -49,8 +50,8 @@ def to_name(self) -> str:
4950 return 'a ' + self .name .lower ()
5051
5152
52- OPERATORS = {'[' : TokenKind .LEFT_BRACKET , ']' : TokenKind .RIGHT_BRACKET }
53- SPECIAL_CHARS = OPERATORS .keys () | {' \\ ' }
53+ OPERATORS = {OPEN_BRACKET : TokenKind .LEFT_BRACKET , CLOSE_BRACKET : TokenKind .RIGHT_BRACKET }
54+ SPECIAL_CHARS = OPERATORS .keys () | {BACKSLASH }
5455
5556
5657class Token (NamedTuple ):
@@ -65,7 +66,7 @@ def assert_cant_happen() -> NoReturn:
6566
6667
6768def check_escaped_int (value : str ) -> str :
68- if not value .startswith (' \\ ' ):
69+ if not value .startswith (BACKSLASH ):
6970 raise ValueError ('Not an escaped int' )
7071
7172 try :
@@ -114,7 +115,7 @@ def can_advance() -> bool:
114115 if index in OPERATORS :
115116 yield from send_buffer ()
116117 yield Token (OPERATORS [index ], index , cursor , cursor + 1 )
117- elif index == ' \\ ' and can_advance ():
118+ elif index == BACKSLASH and can_advance ():
118119 if source [cursor + 1 ] in SPECIAL_CHARS :
119120 backslashes += 1
120121 else :
@@ -159,11 +160,11 @@ def reconstruct(self) -> str:
159160 if self .kind is PathAction .KEY :
160161 if self .is_root :
161162 return str (self .accessor )
162- return '[' + self .accessor + ']'
163+ return OPEN_BRACKET + self .accessor + CLOSE_BRACKET
163164 elif self .kind is PathAction .INDEX :
164- return '[' + str (self .accessor ) + ']'
165+ return OPEN_BRACKET + str (self .accessor ) + CLOSE_BRACKET
165166 elif self .kind is PathAction .APPEND :
166- return '[]'
167+ return OPEN_BRACKET + CLOSE_BRACKET
167168 else :
168169 assert_cant_happen ()
169170
0 commit comments