MCPcopy Index your code
hub / github.com/secdev/scapy / _fix

Method _fix

scapy/volatile.py:858–943  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

856 return r
857
858 def _fix(self):
859 # type: () -> str
860 stack = [None]
861 index = []
862 # Give up on typing this
863 current = stack # type: Any
864 i = 0
865 regexp = self._regexp
866 for k, v in self.special_sets.items():
867 regexp = regexp.replace(k, v)
868 ln = len(regexp)
869 interp = True
870 while i < ln:
871 c = regexp[i]
872 i += 1
873
874 if c == '(':
875 current = [current]
876 current[0].append(current)
877 elif c == '|':
878 p = current[0]
879 ch = p[-1]
880 if not isinstance(ch, tuple):
881 ch = ("choice", [current])
882 p[-1] = ch
883 else:
884 ch[1].append(current)
885 current = [p]
886 elif c == ')':
887 ch = current[0][-1]
888 if isinstance(ch, tuple):
889 ch[1].append(current)
890 index.append(current)
891 current = current[0]
892 elif c == '[' or c == '{':
893 current = [current]
894 current[0].append(current)
895 interp = False
896 elif c == ']':
897 current = current[0]
898 choice = RandRegExp.choice_expand("".join(current.pop()[1:]))
899 current.append(RandChoice(*list(choice)))
900 interp = True
901 elif c == '}':
902 current = current[0]
903 num = "".join(current.pop()[1:])
904 e = current.pop()
905 if "," not in num:
906 current.append([current] + [e] * int(num))
907 else:
908 num_min, num_max = num.split(",")
909 if not num_min:
910 num_min = "0"
911 if num_max:
912 n = RandNum(int(num_min), int(num_max))
913 else:
914 n = RandNumExpo(self._lambda, base=int(num_min))
915 current.append(("repeat", n))

Callers

nothing calls this directly

Calls 10

RandChoiceClass · 0.85
RandNumClass · 0.85
RandNumExpoClass · 0.85
itemsMethod · 0.80
replaceMethod · 0.80
choice_expandMethod · 0.80
joinMethod · 0.80
popMethod · 0.80
stack_fixMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected