From 418b12bbd6072585118c06c5c4e17996d7f0b085 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Tue, 7 Jun 2022 14:31:15 +0200 Subject: [PATCH] Cleanup --- httpie/cli/constants.py | 7 ------- httpie/cli/nested_json.py | 22 +++++++++++++++++----- httpie/client.py | 3 ++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/httpie/cli/constants.py b/httpie/cli/constants.py index 61e61f40..09ca19e4 100644 --- a/httpie/cli/constants.py +++ b/httpie/cli/constants.py @@ -132,10 +132,3 @@ class RequestType(enum.Enum): FORM = enum.auto() MULTIPART = enum.auto() JSON = enum.auto() - - -EMPTY_STRING = '' -OPEN_BRACKET = '[' -CLOSE_BRACKET = ']' -BACKSLASH = '\\' -HIGHLIGHTER = '^' diff --git a/httpie/cli/nested_json.py b/httpie/cli/nested_json.py index c7579892..6616e9ac 100644 --- a/httpie/cli/nested_json.py +++ b/httpie/cli/nested_json.py @@ -9,8 +9,14 @@ from typing import ( Type, Union, ) -from httpie.cli.dicts import NestedJSONArray -from httpie.cli.constants import EMPTY_STRING, OPEN_BRACKET, CLOSE_BRACKET, BACKSLASH, HIGHLIGHTER +from .dicts import NestedJSONArray + + +EMPTY_STRING = '' +HIGHLIGHTER = '^' +OPEN_BRACKET = '[' +CLOSE_BRACKET = ']' +BACKSLASH = '\\' class HTTPieSyntaxError(ValueError): @@ -31,7 +37,7 @@ class HTTPieSyntaxError(ValueError): if self.token is not None: lines.append(self.source) lines.append( - ' ' * (self.token.start) + ' ' * self.token.start + HIGHLIGHTER * (self.token.end - self.token.start) ) return '\n'.join(lines) @@ -51,9 +57,15 @@ class TokenKind(Enum): return 'a ' + self.name.lower() -OPERATORS = {OPEN_BRACKET: TokenKind.LEFT_BRACKET, CLOSE_BRACKET: TokenKind.RIGHT_BRACKET} +OPERATORS = { + OPEN_BRACKET: TokenKind.LEFT_BRACKET, + CLOSE_BRACKET: TokenKind.RIGHT_BRACKET, +} SPECIAL_CHARS = OPERATORS.keys() | {BACKSLASH} -LITERAL_TOKENS = [TokenKind.TEXT, TokenKind.NUMBER] +LITERAL_TOKENS = [ + TokenKind.TEXT, + TokenKind.NUMBER, +] class Token(NamedTuple): diff --git a/httpie/client.py b/httpie/client.py index 047b7856..97608e78 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -13,7 +13,8 @@ import urllib3 from . import __version__ from .adapters import HTTPieHTTPAdapter from .context import Environment -from .cli.constants import EMPTY_STRING, HTTP_OPTIONS +from .cli.constants import HTTP_OPTIONS +from .cli.nested_json import EMPTY_STRING from .cli.dicts import HTTPHeadersDict, NestedJSONArray from .encoding import UTF8 from .models import RequestsMessage