MCPcopy Create free account
hub / github.com/python-hyper/uritemplate / _string_expansion

Method _string_expansion

uritemplate/variable.py:423–451  ·  view source on GitHub ↗
(
        self,
        name: str,
        value: VariableValue,
        explode: bool,
        prefix: t.Optional[int],
    )

Source from the content-addressed store, hash-verified

421 return name
422
423 def _string_expansion(
424 self,
425 name: str,
426 value: VariableValue,
427 explode: bool,
428 prefix: t.Optional[int],
429 ) -> t.Optional[str]:
430 if value is None:
431 return None
432
433 tuples, items = is_list_of_tuples(value)
434
435 if list_test(value) and not tuples:
436 value = t.cast(t.Sequence[ScalarVariableValue], value)
437 return ",".join(self.operator.quote(v) for v in value)
438
439 if dict_test(value) or tuples:
440 value = t.cast(t.Mapping[str, ScalarVariableValue], value)
441 items = items or sorted(value.items())
442 format_str = "%s=%s" if explode else "%s,%s"
443
444 return ",".join(
445 format_str % (self.operator.quote(k), self.operator.quote(v))
446 for k, v in items
447 )
448
449 value = t.cast(t.Text, value)
450 value = value[:prefix] if prefix else value
451 return self.operator.quote(value)
452
453 def expand(
454 self, var_dict: t.Optional[VariableValueDict] = None

Callers 1

test_string_expansionMethod · 0.80

Calls 4

is_list_of_tuplesFunction · 0.85
list_testFunction · 0.85
dict_testFunction · 0.85
quoteMethod · 0.80

Tested by 1

test_string_expansionMethod · 0.64