Skip to content

Commit

Permalink
Merge pull request #1507 from bstaletic/no-requests
Browse files Browse the repository at this point in the history
[READY] Drop the dependency on requests
  • Loading branch information
mergify[bot] committed Nov 25, 2020
2 parents 3aa00ae + c8620a2 commit 64a4eaf
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 42 deletions.
15 changes: 0 additions & 15 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "third_party/waitress"]
path = third_party/waitress
url = https://github.com/Pylons/waitress
[submodule "third_party/requests"]
path = third_party/requests_deps/requests
url = https://github.com/requests/requests
[submodule "third_party/jedi"]
path = third_party/jedi_deps/jedi
url = https://github.com/davidhalter/jedi
Expand All @@ -16,18 +13,6 @@
[submodule "third_party/parso"]
path = third_party/jedi_deps/parso
url = https://github.com/davidhalter/parso
[submodule "third_party/urllib3"]
path = third_party/requests_deps/urllib3
url = https://github.com/urllib3/urllib3
[submodule "third_party/chardet"]
path = third_party/requests_deps/chardet
url = https://github.com/chardet/chardet
[submodule "third_party/certifi"]
path = third_party/requests_deps/certifi
url = https://github.com/certifi/python-certifi
[submodule "third_party/idna"]
path = third_party/requests_deps/idna
url = https://github.com/kjd/idna
[submodule "third_party/watchdog_deps/pathtools"]
path = third_party/watchdog_deps/pathtools
url = https://github.com/gorakhargosh/pathtools
Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ codecov >= 2.0.5
pytest
pytest-cov
pytest-rerunfailures
requests
1 change: 0 additions & 1 deletion third_party/requests_deps/certifi
Submodule certifi deleted from 21abb9
1 change: 0 additions & 1 deletion third_party/requests_deps/chardet
Submodule chardet deleted from 9b8c5c
1 change: 0 additions & 1 deletion third_party/requests_deps/idna
Submodule idna deleted from 1cdf17
1 change: 0 additions & 1 deletion third_party/requests_deps/requests
Submodule requests deleted from aeda65
1 change: 0 additions & 1 deletion third_party/requests_deps/urllib3
Submodule urllib3 deleted from 2a57bc
20 changes: 15 additions & 5 deletions ycmd/completers/cs/cs_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
from collections import defaultdict
import os
import errno
import json
import time
import requests
import urllib.request
import urllib.error
import threading
from urllib.parse import urljoin

Expand All @@ -30,7 +32,8 @@
CodepointOffsetToByteOffset,
FindExecutable,
FindExecutableWithFallback,
LOGGER )
LOGGER,
ToBytes )
from ycmd import responses
from ycmd import utils

Expand Down Expand Up @@ -841,9 +844,16 @@ def _GetResponse( self, handler, parameters = {}, timeout = None ):
""" Handle communication with server """
target = urljoin( self._ServerLocation(), handler )
LOGGER.debug( 'TX (%s): %s', handler, parameters )
response = requests.post( target, json = parameters, timeout = timeout )
LOGGER.debug( 'RX: %s', response.json() )
return response.json()
try:
response = urllib.request.urlopen(
target,
data = ToBytes( json.dumps( parameters ) ),
timeout = timeout )
response = json.loads( response.read() )
except urllib.error.HTTPError as response:
response = json.loads( response.fp.read() )
LOGGER.debug( 'RX: %s', response )
return response


def _ChooseOmnisharpPort( self ):
Expand Down
28 changes: 16 additions & 12 deletions ycmd/completers/javascript/tern_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@

import logging
import os
import requests
import urllib.request
import urllib.error
import json
import threading

from subprocess import PIPE
from ycmd import utils, responses
from ycmd.completers.completer import Completer
from ycmd.completers.completer_utils import GetFileLines
from ycmd.utils import LOGGER
from ycmd.utils import LOGGER, ToBytes, ToUnicode

HTTP_OK = 200

PATH_TO_TERN_BINARY = os.path.abspath(
os.path.join(
Expand Down Expand Up @@ -286,9 +290,9 @@ def ServerIsHealthy( self ):

try:
target = self._GetServerAddress() + '/ping'
response = requests.get( target )
return response.status_code == requests.codes.ok
except requests.ConnectionError:
response = urllib.request.urlopen( target )
return response.code == HTTP_OK
except urllib.error.URLError:
return False


Expand Down Expand Up @@ -320,14 +324,14 @@ def MakeIncompleteFile( name, file_data ):
if 'javascript' in file_data[ x ][ 'filetypes' ] ],
}
full_request.update( request )
try:
response = urllib.request.urlopen(
self._GetServerAddress(),
data = ToBytes( json.dumps( full_request ) ) )

response = requests.post( self._GetServerAddress(),
json = full_request )

if response.status_code != requests.codes.ok:
raise RuntimeError( response.text )

return response.json()
return json.loads( response.read() )
except urllib.error.HTTPError as response:
raise RuntimeError( ToUnicode( response.fp.read() ) )


def _GetResponse( self, query, codepoint, request_data ):
Expand Down
8 changes: 4 additions & 4 deletions ycmd/hmac_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with ycmd. If not, see <http://www.gnu.org/licenses/>.

import requests
from base64 import b64decode, b64encode
from bottle import request, abort, response
from hmac import compare_digest
from urllib.parse import urlparse
from ycmd import hmac_utils
from ycmd.utils import LOGGER, ToBytes, ToUnicode

HTTP_UNAUTHORIZED = 401

_HMAC_HEADER = 'x-ycm-hmac'
_HOST_HEADER = 'host'

Expand All @@ -49,15 +50,14 @@ def __call__( self, callback ):
def wrapper( *args, **kwargs ):
if not HostHeaderCorrect( request ):
LOGGER.info( 'Dropping request with bad Host header' )
abort( requests.codes.unauthorized,
'Unauthorized, received bad Host header.' )
abort( HTTP_UNAUTHORIZED, 'Unauthorized, received bad Host header.' )
return

body = ToBytes( request.body.read() )
if not RequestAuthenticated( request.method, request.path, body,
self._hmac_secret ):
LOGGER.info( 'Dropping request with bad HMAC' )
abort( requests.codes.unauthorized, 'Unauthorized, received bad HMAC.' )
abort( HTTP_UNAUTHORIZED, 'Unauthorized, received bad HMAC.' )
return
body = callback( *args, **kwargs )
SetHmacHeader( body, self._hmac_secret )
Expand Down
2 changes: 1 addition & 1 deletion ycmd/tests/tern/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def Subcommands_GoToReferences_Unicode_test( app ):


@SharedYcmd
def Subcommands_GetDocWithNoItendifier_test( app ):
def Subcommands_GetDocWithNoIdentifier_test( app ):
RunTest( app, {
'description': 'GetDoc works when no identifier',
'request': {
Expand Down

0 comments on commit 64a4eaf

Please sign in to comment.