Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: Resolve some bug risks and code quality issues #497

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

Merged
merged 1 commit into from
Nov 4, 2019
Merged
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
25 changes: 25 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version = 1

exclude_patterns = [
'examples/**',

# auto-generated files
'twilio/rest/**',
'twilio/twiml/**',
'tests/integration/**',

# compat files
'twilio/compat.py',
]

test_patterns = [
'tests/**'
]

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
max_line_length = 100
skip_doc_coverage = ["module", "magic", "class"]
4 changes: 1 addition & 3 deletions tests/unit/http/test_http_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
import six

import unittest

from mock import patch, Mock
from requests import Request, Session
from requests import Session

from twilio.http.http_client import TwilioHttpClient
from twilio.http.response import Response
Expand Down
1 change: 0 additions & 1 deletion tests/unit/http/test_validation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import unittest

import mock
from mock import patch, Mock
from requests import Request
from requests import Session
Expand Down
2 changes: 1 addition & 1 deletion twilio/base/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def next(self):
return self.get_instance(next(self._records))

@classmethod
def process_response(self, response):
def process_response(cls, response):
"""
Load a JSON response.

Expand Down
9 changes: 8 additions & 1 deletion twilio/base/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ def prefixed_collapsible_map(m, prefix):
if m == values.unset:
return {}

def flatten_dict(d, result={}, prv_keys=[]):
def flatten_dict(d, result=None, prv_keys=None):

if result is None:
result = {}

if prv_keys is None:
prv_keys = []

for k, v in d.items():
if isinstance(v, dict):
flatten_dict(v, result, prv_keys + [k])
Expand Down
4 changes: 2 additions & 2 deletions twilio/jwt/validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def _generate_payload(self):
}

@classmethod
def _sort_and_join(self, values, joiner):
def _sort_and_join(cls, values, joiner):
if isinstance(values, string_types):
return values
return joiner.join(sorted(values))

@classmethod
def _hash(self, input_str):
def _hash(cls, input_str):
if not input_str:
return input_str

Expand Down
6 changes: 3 additions & 3 deletions twilio/request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def add_port(uri):
"""
if uri.port:
return uri.geturl()

port = 443 if uri.scheme == "https" else 80
new_netloc = uri.netloc + ":" + str(port)
new_uri = uri._replace(netloc=new_netloc)
Expand All @@ -75,7 +75,7 @@ def compute_signature(self, uri, params, utf=PY3):
:returns: The computed signature
"""
s = uri
if len(params) > 0:
if params:
for k, v in sorted(params.items()):
s += k + v

Expand Down Expand Up @@ -117,7 +117,7 @@ def validate(self, uri, params, signature):
valid_body_hash = compare(self.compute_hash(params), query["bodySHA256"][0])
params = {}

# check signature of uri with and without port,
# check signature of uri with and without port,
# since sig generation on back end is inconsistent
valid_signature = compare(self.compute_signature(uri_without_port, params), signature)
valid_signature_with_port = compare(self.compute_signature(uri_with_port, params), signature)
Expand Down