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

Method __init__

scapy/volatile.py:1175–1254  ·  view source on GitHub ↗
(self,
                 template=None,  # type: Optional[Any]
                 node=None,  # type: Optional[int]
                 clock_seq=None,  # type: Optional[int]
                 namespace=None,  # type: Optional[uuid.UUID]
                 name=None,  # type: Optional[str]
                 version=None,  # type: Optional[Any]
                 )

Source from the content-addressed store, hash-verified

1173 VERSIONS = [1, 3, 4, 5]
1174
1175 def __init__(self,
1176 template=None, # type: Optional[Any]
1177 node=None, # type: Optional[int]
1178 clock_seq=None, # type: Optional[int]
1179 namespace=None, # type: Optional[uuid.UUID]
1180 name=None, # type: Optional[str]
1181 version=None, # type: Optional[Any]
1182 ):
1183 # type: (...) -> None
1184 self._template = template
1185 self._ori_version = version
1186
1187 self.uuid_template = None
1188 self.clock_seq = None
1189 self.namespace = None
1190 self.name = None
1191 self.node = None
1192 self.version = None
1193
1194 if template:
1195 if node or clock_seq or namespace or name or version:
1196 raise ValueError("UUID template must be the only parameter, "
1197 "if specified")
1198 tmp = RandUUID._REG.match(template)
1199 if tmp:
1200 template = tmp.groups()
1201 else:
1202 # Invalid template
1203 raise ValueError("UUID template is invalid")
1204 rnd_f = [RandInt] + [RandShort] * 2 + [RandByte] * 8
1205 uuid_template = [] # type: List[Union[int, RandNum]]
1206 for i, t in enumerate(template):
1207 if t == "*":
1208 uuid_template.append(rnd_f[i]())
1209 elif ":" in t:
1210 mini, maxi = t.split(":")
1211 uuid_template.append(
1212 RandNum(int(mini, 16), int(maxi, 16))
1213 )
1214 else:
1215 uuid_template.append(int(t, 16))
1216
1217 self.uuid_template = tuple(uuid_template)
1218 else:
1219 if version:
1220 if version not in RandUUID.VERSIONS:
1221 raise ValueError("version is not supported")
1222 else:
1223 self.version = version
1224 else:
1225 # No version specified, try to guess...
1226 # This could be wrong, and cause an error later!
1227 if node or clock_seq:
1228 self.version = 1
1229 elif namespace and name:
1230 self.version = 5
1231 else:
1232 # Don't know, random!

Callers

nothing calls this directly

Calls 3

RandNumClass · 0.85
appendMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected