Skip to content

Commit 4a62269

Browse files
author
Andrew Slotin
authored
Address warning and deprecation messages (instana#218)
* Use raw strings for regexes containing escape sequences * Use == and != to compare to literals
1 parent fd751af commit 4a62269

File tree

14 files changed

+24
-24
lines changed

14 files changed

+24
-24
lines changed

instana/agent.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def announce(self, discovery):
161161
headers={"Content-Type": "application/json"},
162162
timeout=0.8)
163163

164-
if response.status_code is 200:
164+
if response.status_code == 200:
165165
self.last_seen = datetime.now()
166166
except (requests.ConnectTimeout, requests.ConnectionError):
167167
logger.debug("announce", exc_info=True)
@@ -175,7 +175,7 @@ def is_agent_ready(self):
175175
try:
176176
response = self.client.head(self.__data_url(), timeout=0.8)
177177

178-
if response.status_code is 200:
178+
if response.status_code == 200:
179179
return True
180180
return False
181181
except (requests.ConnectTimeout, requests.ConnectionError):
@@ -194,7 +194,7 @@ def report_data(self, entity_data):
194194

195195
# logger.warn("report_data: response.status_code is %s" % response.status_code)
196196

197-
if response.status_code is 200:
197+
if response.status_code == 200:
198198
self.last_seen = datetime.now()
199199
except (requests.ConnectTimeout, requests.ConnectionError):
200200
logger.debug("report_data: Instana host agent connection error")
@@ -219,7 +219,7 @@ def report_traces(self, spans):
219219

220220
# logger.warn("report_traces: response.status_code is %s" % response.status_code)
221221

222-
if response.status_code is 200:
222+
if response.status_code == 200:
223223
self.last_seen = datetime.now()
224224
except (requests.ConnectTimeout, requests.ConnectionError):
225225
logger.debug("report_traces: Instana host agent connection error")

instana/fsm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def announce_sensor(self, e):
156156

157157
response = self.agent.announce(d)
158158

159-
if response and (response.status_code is 200) and (len(response.content) > 2):
159+
if response and (response.status_code == 200) and (len(response.content) > 2):
160160
self.agent.set_from(response.content)
161161
self.fsm.pending()
162162
logger.debug("Announced pid: %s (true pid: %s). Waiting for Agent Ready...", str(pid), str(self.agent.from_.pid))

instana/instrumentation/aiohttp/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def stan_middleware(request, handler):
4444
if 500 <= response.status <= 511:
4545
scope.span.set_tag("error", True)
4646
ec = scope.span.tags.get('ec', 0)
47-
if ec is 0:
47+
if ec == 0:
4848
scope.span.set_tag("ec", ec + 1)
4949

5050
scope.span.set_tag("http.status_code", response.status)

instana/instrumentation/django/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def process_response(self, request, response):
5555
if 500 <= response.status_code <= 511:
5656
request.iscope.span.set_tag("error", True)
5757
ec = request.iscope.span.tags.get('ec', 0)
58-
if ec is 0:
58+
if ec == 0:
5959
request.iscope.span.set_tag("ec", ec+1)
6060

6161
request.iscope.span.set_tag(ext.HTTP_STATUS_CODE, response.status_code)

instana/instrumentation/flask/vanilla.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def after_request_with_instana(response):
6666
if 500 <= response.status_code <= 511:
6767
span.set_tag("error", True)
6868
ec = span.tags.get('ec', 0)
69-
if ec is 0:
69+
if ec == 0:
7070
span.set_tag("ec", ec+1)
7171

7272
span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code))

instana/instrumentation/flask/with_blinker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def request_finished_with_instana(sender, response, **extra):
6464
if 500 <= response.status_code <= 511:
6565
span.set_tag("error", True)
6666
ec = span.tags.get('ec', 0)
67-
if ec is 0:
67+
if ec == 0:
6868
span.set_tag("ec", ec+1)
6969

7070
span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code))

instana/instrumentation/sqlalchemy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sqlalchemy import event
1111
from sqlalchemy.engine import Engine
1212

13-
url_regexp = re.compile('\/\/(\S+@)')
13+
url_regexp = re.compile(r"\/\/(\S+@)")
1414

1515
@event.listens_for(Engine, 'before_cursor_execute', named=True)
1616
def receive_before_cursor_execute(**kw):

instana/instrumentation/tornado/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def on_finish_with_instana(wrapped, instance, argv, kwargs):
7979
if 500 <= status_code <= 511:
8080
scope.span.set_tag("error", True)
8181
ec = scope.span.tags.get('ec', 0)
82-
if ec is 0:
82+
if ec == 0:
8383
scope.span.set_tag("ec", ec + 1)
8484

8585
scope.span.set_tag("http.status_code", status_code)

instana/instrumentation/urllib3.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def collect(instance, args, kwargs):
1818
kvs['host'] = instance.host
1919
kvs['port'] = instance.port
2020

21-
if args is not None and len(args) is 2:
21+
if args is not None and len(args) == 2:
2222
kvs['method'] = args[0]
2323
kvs['path'] = args[1]
2424
else:
@@ -31,7 +31,7 @@ def collect(instance, args, kwargs):
3131
if kvs.get('path') is not None and ('?' in kvs['path']):
3232
parts = kvs['path'].split('?')
3333
kvs['path'] = parts[0]
34-
if len(parts) is 2:
34+
if len(parts) == 2:
3535
kvs['query'] = strip_secrets(parts[1], agent.secrets_matcher, agent.secrets_list)
3636

3737
if type(instance) is urllib3.connectionpool.HTTPSConnectionPool:

instana/meter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ def metric_work():
188188
def process(self):
189189
""" Collects, processes & reports metrics """
190190
try:
191-
if self.agent.machine.fsm.current is "wait4init":
191+
if self.agent.machine.fsm.current == "wait4init":
192192
# Test the host agent if we're ready to send data
193193
if self.agent.is_agent_ready():
194-
if self.agent.machine.fsm.current is not "good2go":
194+
if self.agent.machine.fsm.current != "good2go":
195195
self.agent.machine.fsm.ready()
196196
else:
197197
return
@@ -216,7 +216,7 @@ def process(self):
216216
response = self.agent.report_data(ed)
217217

218218
if response:
219-
if response.status_code is 200 and len(response.content) > 2:
219+
if response.status_code == 200 and len(response.content) > 2:
220220
# The host agent returned something indicating that is has a request for us that we
221221
# need to process.
222222
self.handle_agent_tasks(json.loads(response.content)[0])

instana/tracer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ def __add_stack(self, span, limit=None):
154154

155155

156156
# Used by __add_stack
157-
re_tracer_frame = re.compile('/instana/.*\.py$')
157+
re_tracer_frame = re.compile(r"/instana/.*\.py$")
158158
re_with_stan_frame = re.compile('with_instana')

instana/util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .log import logger
1717

1818

19-
if sys.version_info.major is 2:
19+
if sys.version_info.major == 2:
2020
string_types = basestring
2121
else:
2222
string_types = str
@@ -227,7 +227,7 @@ def sql_sanitizer(sql):
227227

228228

229229
# Used by sql_sanitizer
230-
regexp_sql_values = re.compile('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)')
230+
regexp_sql_values = re.compile(r"('[\s\S][^']*'|\d*\.\d+|\d+|NULL)")
231231

232232

233233
def get_default_gateway():
@@ -247,7 +247,7 @@ def get_default_gateway():
247247
if '00000000' == parts[1]:
248248
hip = parts[2]
249249

250-
if hip is not None and len(hip) is 8:
250+
if hip is not None and len(hip) == 8:
251251
# Reverse order, convert hex to int
252252
return "%i.%i.%i.%i" % (int(hip[6:8], 16), int(hip[4:6], 16), int(hip[2:4], 16), int(hip[0:2], 16))
253253

@@ -280,7 +280,7 @@ def get_py_source(file):
280280

281281

282282
# Used by get_py_source
283-
regexp_py = re.compile('\.py$')
283+
regexp_py = re.compile(r"\.py$")
284284

285285

286286
def every(delay, task, name):

tests/test_id_management.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import instana.util
77

8-
if sys.version_info.major is 2:
8+
if sys.version_info.major == 2:
99
string_types = basestring
1010
else:
1111
string_types = str

tests/test_secrets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_contains_no_match(self):
8484

8585
def test_regex(self):
8686
matcher = 'regex'
87-
kwlist = ['\d']
87+
kwlist = [r"\d"]
8888

8989
query_params = "one=1&Two=two&THREE=&4='+'&five='okyeah'"
9090

@@ -94,7 +94,7 @@ def test_regex(self):
9494

9595
def test_regex_no_match(self):
9696
matcher = 'regex'
97-
kwlist = ['\d\d\d']
97+
kwlist = [r"\d\d\d"]
9898

9999
query_params = "one=1&Two=two&THREE=&4='+'&five='okyeah'"
100100

0 commit comments

Comments
 (0)