From d89f8c0d70195d1ee707426ac7f3bdab870e0a18 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Mon, 24 Apr 2017 08:22:56 +0100 Subject: [PATCH] Fix up Appveyor testing --- HISTORY.rst | 2 ++ Makefile | 1 + appveyor.yml | 16 ++++++++-------- requests/sessions.py | 18 +++++++++++++++--- setup.py | 1 + 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c26036c1..b2a710f3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,8 @@ Release History ``get_redirect_target(response)`` instead of directly querying ``Response.is_redirect`` and ``Response.headers['location']``. Advanced users will be able to process malformed redirects more easily. +- Changed the internal calculation of elapsed request time to have higher + resolution on Windows. 2.13.0 (2017-01-24) +++++++++++++++++++ diff --git a/Makefile b/Makefile index ee737f9e..34dbe6a3 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ init: pip install pipenv pipenv lock pipenv install --dev + pipenv run pip install -e .[socks] test: # This runs all of the tests. To run an individual test, run py.test with diff --git a/appveyor.yml b/appveyor.yml index 880e011c..0fc1a1d6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,11 +5,6 @@ build: off environment: matrix: - - PYTHON: "C:\\Python266-x64" - PYTHON_VERSION: "2.6.6" - PYTHON_ARCH: "64" - TOXENV: "py26" - - PYTHON: "C:\\Python27-x64" PYTHON_VERSION: "2.7.x" PYTHON_ARCH: "64" @@ -30,6 +25,11 @@ environment: PYTHON_ARCH: "64" TOXENV: "py35" + - PYTHON: "C:\\Python36-x64" + PYTHON_VERSION: "3.6.x" + PYTHON_ARCH: "64" + TOXENV: "py36" + install: # Install Python (from the official .msi of http://python.org) and pip when # not already installed. @@ -47,10 +47,10 @@ install: # Upgrade to the latest version of pip to avoid it displaying warnings # about it being out of date. - "pip install --disable-pip-version-check --user --upgrade pip" - - "mingw32-make" + - "C:\\MinGW\\bin\\mingw32-make" test_script: - - "mingw32-make coverage" + - "C:\\MinGW\\bin\\mingw32-make coverage" on_success: - - "pipenv run codecov" + - "pipenv run codecov -f coverage.xml" diff --git a/requests/sessions.py b/requests/sessions.py index f3e65b80..3ae42f99 100755 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -8,8 +8,10 @@ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). """ import os +import platform +import time from collections import Mapping -from datetime import datetime +from datetime import timedelta from .auth import _basic_auth_str from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse @@ -38,6 +40,15 @@ from .models import REDIRECT_STATI REDIRECT_CACHE_SIZE = 1000 +# Preferred clock, based on which one is more accurate on a given system. +if platform.system() == 'Windows': + try: # Python 3.3+ + preferred_clock = time.perf_counter + except AttributeError: # Earlier than Python 3. + preferred_clock = time.clock +else: + preferred_clock = time.time + def merge_setting(request_setting, session_setting, dict_class=OrderedDict): """Determines appropriate setting for a given request, taking into account @@ -622,13 +633,14 @@ class Session(SessionRedirectMixin): adapter = self.get_adapter(url=request.url) # Start time (approximately) of the request - start = datetime.utcnow() + start = preferred_clock() # Send the request r = adapter.send(request, **kwargs) # Total elapsed time of the request (approximately) - r.elapsed = datetime.utcnow() - start + elapsed = preferred_clock() - start + r.elapsed = timedelta(seconds=elapsed) # Response manipulation hooks r = dispatch_hook('response', hooks, r, **kwargs) diff --git a/setup.py b/setup.py index b1623489..10d19116 100755 --- a/setup.py +++ b/setup.py @@ -97,6 +97,7 @@ setup( extras_require={ 'security': ['pyOpenSSL>=0.14', 'cryptography>=1.3.4', 'idna>=2.0.0'], 'socks': ['PySocks>=1.5.6, !=1.5.7'], + 'socks:platform_system == "Windows" and python_version<"3.3"': ['win_inet_pton'], }, )