def get(self, key, default=defaultdict, force_set=False): """ Change get with setdefault :param force_set: :type key: object :type default: object """ if default == defaultdict: default = BetterDict() if isinstance(default, BaseException) and key not in self: raise default if force_set: value = self.setdefault(key, default) else: value = defaultdict.get(self, key, default) if isinstance(value, string_types): if isinstance(value, str): # this is a trick for python v2/v3 compatibility return value else: return text_type(value) else: return value
def get(self, key, default=defaultdict, force_set=False): """ Change get with setdefault :param force_set: :type key: object :type default: object """ if default == defaultdict: default = BetterDict() if isinstance(default, BaseException) and key not in self: raise default if force_set: value = self.setdefault(key, default) else: value = defaultdict.get(self, key, default) if isinstance(value, string_types): if isinstance( value, str): # this is a trick for python v2/v3 compatibility return value else: return text_type(value) else: return value
def test_bza_py3_unicode_token(self): mock = BZMock() mock.mock_get.update({ 'https://a.blazemeter.com/api/v4/web/version': {"result": {}}, }) user = User() mock.apply(user) user.token = text_type("something:something") user.ping()
def int_prop(name, value): """ JMX int property :param name: :param value: :return: """ res = etree.Element("intProp", name=name) res.text = text_type(value) return res
def set_text(self, sel, text): """ Set text value :type sel: str :type text: str """ items = self.get(sel) for item in items: item.text = text_type(text)
def set_text(self, sel, text): """ Set text value :type sel: str :type text: str """ items = self.get(sel) for item in items: item.text = text_type(text)
def int_prop(name, value): """ JMX int property :param name: :param value: :return: """ res = etree.Element("intProp", name=name) res.text = text_type(value) return res
def _long_prop(name, value): """ Generates long property node :param name: :param value: :return: """ res = etree.Element("longProp", name=name) res.text = text_type(value) return res
def custom_expandvars(value): parts = re.split(r'(\$\{.*?\})', value) value = '' for item in parts: if item and item.startswith("${") and item.endswith("}"): key = item[2:-1] if key in envs: item = envs[key] if item is not None: value += text_type(item) return value
def _long_prop(name, value): """ Generates long property node :param name: :param value: :return: """ res = etree.Element("longProp", name=name) res.text = text_type(value) return res
def custom_expandvars(value): parts = re.split(r'(\$\{.*?\})', value) value = '' for item in parts: if item and item.startswith("${") and item.endswith("}"): key = item[2:-1] if key in envs: item = envs[key] if item is not None: value += text_type(item) return value
def test_bza_py3_unicode_token(self): mock = BZMock() mock.mock_get.update({ 'https://a.blazemeter.com/api/v4/web/version': { "result": {} }, }) user = User() mock.apply(user) user.token = text_type("something:something") user.ping()
def _get_resp_assertion(field, contains, is_regexp, is_invert, assume_success=False): """ :type field: str :type contains: list[str] :type is_regexp: bool :type is_invert: bool :rtype: lxml.etree.Element """ tname = "Assert %s %s" % ("hasn't" if is_invert else "has", "[" + ", ".join('"' + text_type(x) + '"' for x in contains) + "]") element = etree.Element("ResponseAssertion", guiclass="AssertionGui", testclass="ResponseAssertion", testname=tname) if field == Scenario.FIELD_HEADERS: fld = "Assertion.response_headers" elif field == Scenario.FIELD_RESP_CODE: fld = "Assertion.response_code" else: fld = "Assertion.response_data" if is_regexp: if is_invert: mtype = 6 # not contains else: mtype = 2 # contains else: if is_invert: mtype = 20 # not substring else: mtype = 16 # substring element.append(JMX._string_prop("Assertion.test_field", fld)) element.append(JMX._string_prop("Assertion.test_type", mtype)) element.append( JMX._bool_prop("Assertion.assume_success", assume_success)) coll_prop = etree.Element("collectionProp", name="Asserion.test_strings") for string in contains: coll_prop.append(JMX._string_prop("", string)) element.append(coll_prop) return element
def get_host_ips(filter_loopbacks=True): """ Returns a list of all IP addresses assigned to this host. :param filter_loopbacks: filter out loopback addresses """ ips = [] for _, interfaces in iteritems(psutil.net_if_addrs()): for iface in interfaces: addr = text_type(iface.address) try: ip = ipaddress.ip_address(addr) if filter_loopbacks and ip.is_loopback: continue except ValueError: continue ips.append(iface.address) return ips
def get_host_ips(filter_loopbacks=True): """ Returns a list of all IP addresses assigned to this host. :param filter_loopbacks: filter out loopback addresses """ ips = [] for _, interfaces in iteritems(psutil.net_if_addrs()): for iface in interfaces: addr = text_type(iface.address) try: ip = ipaddress.ip_address(addr) if filter_loopbacks and ip.is_loopback: continue except ValueError: continue ips.append(iface.address) return ips
def _get_resp_assertion(field, contains, is_regexp, is_invert, assume_success=False): """ :type field: str :type contains: list[str] :type is_regexp: bool :type is_invert: bool :rtype: lxml.etree.Element """ tname = "Assert %s has %s" % ("not" if is_invert else "", [text_type(x) for x in contains]) element = etree.Element("ResponseAssertion", guiclass="AssertionGui", testclass="ResponseAssertion", testname=tname) if field == Scenario.FIELD_HEADERS: fld = "Assertion.response_headers" elif field == Scenario.FIELD_RESP_CODE: fld = "Assertion.response_code" else: fld = "Assertion.response_data" if is_regexp: if is_invert: mtype = 6 # not contains else: mtype = 2 # contains else: if is_invert: mtype = 20 # not substring else: mtype = 16 # substring element.append(JMX._string_prop("Assertion.test_field", fld)) element.append(JMX._string_prop("Assertion.test_type", mtype)) element.append(JMX._bool_prop("Assertion.assume_success", assume_success)) coll_prop = etree.Element("collectionProp", name="Asserion.test_strings") for string in contains: coll_prop.append(JMX._string_prop("", string)) element.append(coll_prop) return element
def apply(self, template): self.tmpl.template = template self.tmpl.variables = self.variables return text_type(self.tmpl)
def apply(self, template): self.tmpl.template = template self.tmpl.variables = self.variables return text_type(self.tmpl)