Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 3.5, 3.6 + changes #1472

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/contributors/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def load_awesome_people() -> People:
def fetch(url: str, params: Optional[Dict[str, str]] = None) -> UserInfo:
headers = {
'Accept': 'application/vnd.github.v3+json',
'Authentication': f'token {GITHUB_TOKEN}'
'Authentication': f'token {GITHUB_TOKEN}',
}
for retry in range(1, 6):
debug(f'[{retry}/5]', f'{url = }', f'{params = }')
Expand Down
7 changes: 3 additions & 4 deletions docs/contributors/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
"""
import sys

from jinja2 import Template

from fetch import HERE, load_awesome_people
from jinja2 import Template

TPL_FILE = HERE / 'snippet.jinja2'

HTTPIE_TEAM = {
'claudiatd',
'jakubroztocil',
'jkbr',
'isidentical'
'isidentical',
}

BOT_ACCOUNTS = {
'dependabot-sr'
'dependabot-sr',
}

IGNORE_ACCOUNTS = HTTPIE_TEAM | BOT_ACCOUNTS
Expand Down
7 changes: 3 additions & 4 deletions extras/packaging/linux/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
HTTPIE_DIR = BUILD_DIR.parent.parent.parent

EXTRAS_DIR = HTTPIE_DIR / 'extras'
MAN_PAGES_DIR = EXTRAS_DIR / 'man'
MAN_PAGES_DIR = EXTRAS_DIR / 'man'

SCRIPT_DIR = BUILD_DIR / Path('scripts')
HOOKS_DIR = SCRIPT_DIR / 'hooks'
Expand All @@ -33,7 +33,7 @@ def build_binaries() -> Iterator[Tuple[str, Path]]:
HOOKS_DIR,
*extra_args,
target_script,
]
],
)

for executable_path in DIST_DIR.iterdir():
Expand Down Expand Up @@ -61,7 +61,7 @@ def build_packages(http_binary: Path, httpie_binary: Path) -> None:
# A list of additional dependencies
deps = [
'python3 >= 3.7',
'python3-pip'
'python3-pip',
]

processed_deps = [
Expand Down Expand Up @@ -104,6 +104,5 @@ def main():
binaries['httpie_cli'].rename(DIST_DIR / 'httpie')



if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions extras/packaging/linux/scripts/hooks/hook-pip.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pathlib import Path
from PyInstaller.utils.hooks import collect_all


def hook(hook_api):
for pkg in [
'pip',
'setuptools',
'distutils',
'pkg_resources'
'pkg_resources',
]:
datas, binaries, hiddenimports = collect_all(pkg)
hook_api.add_datas(datas)
Expand Down
9 changes: 5 additions & 4 deletions extras/profiling/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def log_message(self, *args, **kwargs):
@contextmanager
def start_server():
"""Create a server to serve local files. It will create the
PREDEFINED_FILES through dd."""
PREDEFINED_FILES through dd.
"""
with TemporaryDirectory() as directory:
for file_name, (block_size, count) in PREDEFINED_FILES.items():
subprocess.check_call(
Expand Down Expand Up @@ -179,8 +180,8 @@ def run(self, context: Context) -> pyperf.Benchmark:
[
'--print=HBhb',
f'--pretty={pretty}',
'httpbin.org/stream/1000'
]
'httpbin.org/stream/1000',
],
)
DownloadRunner('download', '`http --download :/big_file.txt` (3GB)', '3G')

Expand All @@ -191,7 +192,7 @@ def main() -> None:
# benchmarks 3 times to warm up (e.g especially for download benchmark, this
# is important). And then 5 actual runs where we record.
sys.argv.extend(
['--worker', '--loops=1', '--warmup=3', '--values=5', '--processes=2']
['--worker', '--loops=1', '--warmup=3', '--values=5', '--processes=2'],
)

with Context() as context:
Expand Down
11 changes: 5 additions & 6 deletions extras/profiling/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
from contextlib import contextmanager
from dataclasses import dataclass
from pathlib import Path
from typing import (IO, Dict, Generator, Iterable, List, Optional,
Tuple)
from typing import IO, Dict, Generator, Iterable, List, Optional, Tuple

BENCHMARK_SCRIPT = Path(__file__).parent / 'benchmarks.py'
CURRENT_REPO = Path(__file__).parent.parent.parent
Expand Down Expand Up @@ -119,7 +118,7 @@ def on_repo(self) -> Generator[Path, None, None]:
'wheel',
'pyperf==2.3.0',
*self.dependencies,
]
],
)

# Create a wheel distribution of HTTPie
Expand Down Expand Up @@ -148,7 +147,7 @@ def on_repo(self) -> Generator[Path, None, None]:
def dump_results(
results: List[str],
file: IO[str],
min_speed: Optional[str] = None
min_speed: Optional[str] = None,
) -> None:
for result in results:
lines = result.strip().splitlines()
Expand Down Expand Up @@ -213,7 +212,7 @@ def iterate(env_name, status):
results.append(compare(
*config.keys(),
directory=result_directory,
min_speed=min_speed
min_speed=min_speed,
))

dump_results(results, file=file, min_speed=min_speed)
Expand Down Expand Up @@ -252,7 +251,7 @@ def main() -> None:
parser.add_argument(
'--min-speed',
help='Minimum of speed in percent to consider that a '
'benchmark is significant'
'benchmark is significant',
)
parser.add_argument(
'--debug',
Expand Down
30 changes: 14 additions & 16 deletions extras/scripts/generate_man_pages.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import re
from contextlib import contextmanager
from pathlib import Path
from typing import Optional, Iterator, Iterable
from typing import Iterable, Iterator, Optional

import httpie
from httpie.cli.definition import options as core_options
from httpie.cli.options import ParserSpec
from httpie.manager.cli import options as manager_options
from httpie.output.ui.rich_help import OptionsHighlighter, to_usage
from httpie.output.ui.rich_utils import render_as_string
from httpie.utils import split_iterable


# Escape certain characters so they are rendered properly on
# all terminals.
# https://man7.org/linux/man-pages/man7/groff_char.7.html
ESCAPE_MAP = {
'"': '\[dq]',
"'": '\[aq]',
'~': '\(ti',
'’': "\(ga",
'\\': '\e',
'"': r'\[dq]',
"'": r'\[aq]',
'~': r'\(ti',
'’': r"\(ga",
'\\': r'\e',
}
ESCAPE_MAP = {ord(key): value for key, value in ESCAPE_MAP.items()}

Expand All @@ -29,9 +27,10 @@
PROJECT_ROOT = EXTRAS_DIR.parent

OPTION_HIGHLIGHT_RE = re.compile(
OptionsHighlighter.highlights[0]
OptionsHighlighter.highlights[0],
)


class ManPageBuilder:
def __init__(self):
self.source = []
Expand All @@ -45,7 +44,7 @@ def title_line(
) -> None:
self.source.append(
f'.TH {program_name} 1 "{last_edit_date}" '
f'"{full_name} {program_version}" "{full_name} Manual"'
f'"{full_name} {program_version}" "{full_name} Manual"',
)

def set_name(self, program_name: str) -> None:
Expand All @@ -65,7 +64,7 @@ def format_desc(self, desc: str) -> str:
description = OPTION_HIGHLIGHT_RE.sub(
# Boldify the option part, but don't remove the prefix (start of the match).
lambda match: match[1] + self.boldify(match['option']),
description
description,
)
return description

Expand Down Expand Up @@ -110,9 +109,9 @@ def _escape_and_dedent(text: str) -> str:
def to_man_page(program_name: str, spec: ParserSpec, *, is_top_level_cmd: bool = False) -> str:
builder = ManPageBuilder()
builder.add_comment(
f"This file is auto-generated from the parser declaration "
"This file is auto-generated from the parser declaration "
+ (f"in {Path(spec.source_file).relative_to(PROJECT_ROOT)} " if spec.source_file else "")
+ f"by {Path(__file__).relative_to(PROJECT_ROOT)}."
+ f"by {Path(__file__).relative_to(PROJECT_ROOT)}.",
)

builder.title_line(
Expand All @@ -138,7 +137,7 @@ def to_man_page(program_name: str, spec: ParserSpec, *, is_top_level_cmd: bool =
if spec.man_page_hint:
builder.write(spec.man_page_hint)

for index, group in enumerate(spec.groups, 1):
for _, group in enumerate(spec.groups, 1):
with builder.section(group.name):
if group.description:
builder.write(group.description)
Expand All @@ -153,7 +152,7 @@ def to_man_page(program_name: str, spec: ParserSpec, *, is_top_level_cmd: bool =
if raw_arg.get('is_positional'):
# In case of positional arguments, metavar is always equal
# to the list of options (e.g `METHOD`).
metavar = None
metavar = None
builder.add_options(raw_arg['options'], metavar=metavar)

desc = builder.format_desc(raw_arg.get('description', ''))
Expand All @@ -178,6 +177,5 @@ def main() -> None:
stream.write(to_man_page(program_name, spec, **config))



if __name__ == '__main__':
main()
7 changes: 4 additions & 3 deletions httpie/adapters.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from httpie.cli.dicts import HTTPHeadersDict
from requests.adapters import HTTPAdapter

from httpie.cli.dicts import HTTPHeadersDict


class HTTPieHTTPAdapter(HTTPAdapter):

def build_response(self, req, resp):
"""Wrap the original headers with the `HTTPHeadersDict`
to preserve multiple headers that have the same name"""

to preserve multiple headers that have the same name
"""
response = super().build_response(req, resp)
response.headers = HTTPHeadersDict(getattr(resp, 'headers', {}))
return response
Loading