diff --git a/instana/agent.py b/instana/agent.py index 9db01f38..5d3174ed 100644 --- a/instana/agent.py +++ b/instana/agent.py @@ -161,7 +161,7 @@ def announce(self, discovery): headers={"Content-Type": "application/json"}, timeout=0.8) - if response.status_code is 200: + if response.status_code == 200: self.last_seen = datetime.now() except (requests.ConnectTimeout, requests.ConnectionError): logger.debug("announce", exc_info=True) @@ -175,7 +175,7 @@ def is_agent_ready(self): try: response = self.client.head(self.__data_url(), timeout=0.8) - if response.status_code is 200: + if response.status_code == 200: return True return False except (requests.ConnectTimeout, requests.ConnectionError): @@ -194,7 +194,7 @@ def report_data(self, entity_data): # logger.warn("report_data: response.status_code is %s" % response.status_code) - if response.status_code is 200: + if response.status_code == 200: self.last_seen = datetime.now() except (requests.ConnectTimeout, requests.ConnectionError): logger.debug("report_data: Instana host agent connection error") @@ -219,7 +219,7 @@ def report_traces(self, spans): # logger.warn("report_traces: response.status_code is %s" % response.status_code) - if response.status_code is 200: + if response.status_code == 200: self.last_seen = datetime.now() except (requests.ConnectTimeout, requests.ConnectionError): logger.debug("report_traces: Instana host agent connection error") diff --git a/instana/fsm.py b/instana/fsm.py index e1b7c80f..cf368fcd 100644 --- a/instana/fsm.py +++ b/instana/fsm.py @@ -156,7 +156,7 @@ def announce_sensor(self, e): response = self.agent.announce(d) - if response and (response.status_code is 200) and (len(response.content) > 2): + if response and (response.status_code == 200) and (len(response.content) > 2): self.agent.set_from(response.content) self.fsm.pending() logger.debug("Announced pid: %s (true pid: %s). Waiting for Agent Ready...", str(pid), str(self.agent.from_.pid)) diff --git a/instana/instrumentation/aiohttp/server.py b/instana/instrumentation/aiohttp/server.py index 9638bd3c..2e6ccef3 100644 --- a/instana/instrumentation/aiohttp/server.py +++ b/instana/instrumentation/aiohttp/server.py @@ -44,7 +44,7 @@ async def stan_middleware(request, handler): if 500 <= response.status <= 511: scope.span.set_tag("error", True) ec = scope.span.tags.get('ec', 0) - if ec is 0: + if ec == 0: scope.span.set_tag("ec", ec + 1) scope.span.set_tag("http.status_code", response.status) diff --git a/instana/instrumentation/django/middleware.py b/instana/instrumentation/django/middleware.py index 15bb7c42..98593e94 100644 --- a/instana/instrumentation/django/middleware.py +++ b/instana/instrumentation/django/middleware.py @@ -55,7 +55,7 @@ def process_response(self, request, response): if 500 <= response.status_code <= 511: request.iscope.span.set_tag("error", True) ec = request.iscope.span.tags.get('ec', 0) - if ec is 0: + if ec == 0: request.iscope.span.set_tag("ec", ec+1) request.iscope.span.set_tag(ext.HTTP_STATUS_CODE, response.status_code) diff --git a/instana/instrumentation/flask/vanilla.py b/instana/instrumentation/flask/vanilla.py index aeb5d3df..e92766e4 100644 --- a/instana/instrumentation/flask/vanilla.py +++ b/instana/instrumentation/flask/vanilla.py @@ -66,7 +66,7 @@ def after_request_with_instana(response): if 500 <= response.status_code <= 511: span.set_tag("error", True) ec = span.tags.get('ec', 0) - if ec is 0: + if ec == 0: span.set_tag("ec", ec+1) span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code)) diff --git a/instana/instrumentation/flask/with_blinker.py b/instana/instrumentation/flask/with_blinker.py index b9f0a906..81e74e3b 100644 --- a/instana/instrumentation/flask/with_blinker.py +++ b/instana/instrumentation/flask/with_blinker.py @@ -64,7 +64,7 @@ def request_finished_with_instana(sender, response, **extra): if 500 <= response.status_code <= 511: span.set_tag("error", True) ec = span.tags.get('ec', 0) - if ec is 0: + if ec == 0: span.set_tag("ec", ec+1) span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code)) diff --git a/instana/instrumentation/sqlalchemy.py b/instana/instrumentation/sqlalchemy.py index 3aa0426f..387099d6 100644 --- a/instana/instrumentation/sqlalchemy.py +++ b/instana/instrumentation/sqlalchemy.py @@ -10,7 +10,7 @@ from sqlalchemy import event from sqlalchemy.engine import Engine - url_regexp = re.compile('\/\/(\S+@)') + url_regexp = re.compile(r"\/\/(\S+@)") @event.listens_for(Engine, 'before_cursor_execute', named=True) def receive_before_cursor_execute(**kw): diff --git a/instana/instrumentation/tornado/server.py b/instana/instrumentation/tornado/server.py index d4bb2b88..c2e99512 100644 --- a/instana/instrumentation/tornado/server.py +++ b/instana/instrumentation/tornado/server.py @@ -79,7 +79,7 @@ def on_finish_with_instana(wrapped, instance, argv, kwargs): if 500 <= status_code <= 511: scope.span.set_tag("error", True) ec = scope.span.tags.get('ec', 0) - if ec is 0: + if ec == 0: scope.span.set_tag("ec", ec + 1) scope.span.set_tag("http.status_code", status_code) diff --git a/instana/instrumentation/urllib3.py b/instana/instrumentation/urllib3.py index 2d5d992c..a54327d1 100644 --- a/instana/instrumentation/urllib3.py +++ b/instana/instrumentation/urllib3.py @@ -18,7 +18,7 @@ def collect(instance, args, kwargs): kvs['host'] = instance.host kvs['port'] = instance.port - if args is not None and len(args) is 2: + if args is not None and len(args) == 2: kvs['method'] = args[0] kvs['path'] = args[1] else: @@ -31,7 +31,7 @@ def collect(instance, args, kwargs): if kvs.get('path') is not None and ('?' in kvs['path']): parts = kvs['path'].split('?') kvs['path'] = parts[0] - if len(parts) is 2: + if len(parts) == 2: kvs['query'] = strip_secrets(parts[1], agent.secrets_matcher, agent.secrets_list) if type(instance) is urllib3.connectionpool.HTTPSConnectionPool: diff --git a/instana/meter.py b/instana/meter.py index d8c064a5..1665632d 100644 --- a/instana/meter.py +++ b/instana/meter.py @@ -188,10 +188,10 @@ def metric_work(): def process(self): """ Collects, processes & reports metrics """ try: - if self.agent.machine.fsm.current is "wait4init": + if self.agent.machine.fsm.current == "wait4init": # Test the host agent if we're ready to send data if self.agent.is_agent_ready(): - if self.agent.machine.fsm.current is not "good2go": + if self.agent.machine.fsm.current != "good2go": self.agent.machine.fsm.ready() else: return @@ -216,7 +216,7 @@ def process(self): response = self.agent.report_data(ed) if response: - if response.status_code is 200 and len(response.content) > 2: + if response.status_code == 200 and len(response.content) > 2: # The host agent returned something indicating that is has a request for us that we # need to process. self.handle_agent_tasks(json.loads(response.content)[0]) diff --git a/instana/tracer.py b/instana/tracer.py index ea0b4fe6..fc334667 100644 --- a/instana/tracer.py +++ b/instana/tracer.py @@ -154,5 +154,5 @@ def __add_stack(self, span, limit=None): # Used by __add_stack -re_tracer_frame = re.compile('/instana/.*\.py$') +re_tracer_frame = re.compile(r"/instana/.*\.py$") re_with_stan_frame = re.compile('with_instana') diff --git a/instana/util.py b/instana/util.py index 2c8a753e..2d73f924 100644 --- a/instana/util.py +++ b/instana/util.py @@ -16,7 +16,7 @@ from .log import logger -if sys.version_info.major is 2: +if sys.version_info.major == 2: string_types = basestring else: string_types = str @@ -227,7 +227,7 @@ def sql_sanitizer(sql): # Used by sql_sanitizer -regexp_sql_values = re.compile('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)') +regexp_sql_values = re.compile(r"('[\s\S][^']*'|\d*\.\d+|\d+|NULL)") def get_default_gateway(): @@ -247,7 +247,7 @@ def get_default_gateway(): if '00000000' == parts[1]: hip = parts[2] - if hip is not None and len(hip) is 8: + if hip is not None and len(hip) == 8: # Reverse order, convert hex to int 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)) @@ -280,7 +280,7 @@ def get_py_source(file): # Used by get_py_source -regexp_py = re.compile('\.py$') +regexp_py = re.compile(r"\.py$") def every(delay, task, name): diff --git a/tests/test_id_management.py b/tests/test_id_management.py index 055aaec0..77660ae2 100644 --- a/tests/test_id_management.py +++ b/tests/test_id_management.py @@ -5,7 +5,7 @@ import instana.util -if sys.version_info.major is 2: +if sys.version_info.major == 2: string_types = basestring else: string_types = str diff --git a/tests/test_secrets.py b/tests/test_secrets.py index 6d2f3c25..583a3f71 100644 --- a/tests/test_secrets.py +++ b/tests/test_secrets.py @@ -84,7 +84,7 @@ def test_contains_no_match(self): def test_regex(self): matcher = 'regex' - kwlist = ['\d'] + kwlist = [r"\d"] query_params = "one=1&Two=two&THREE=&4='+'&five='okyeah'" @@ -94,7 +94,7 @@ def test_regex(self): def test_regex_no_match(self): matcher = 'regex' - kwlist = ['\d\d\d'] + kwlist = [r"\d\d\d"] query_params = "one=1&Two=two&THREE=&4='+'&five='okyeah'"