A wrapper around a blob in a net. BlobReference gives us a way to refer to the network that the blob is generated from. Note that blobs are, essentially, just strings in the current workspace.
| 202 | |
| 203 | |
| 204 | class BlobReference: |
| 205 | """A wrapper around a blob in a net. |
| 206 | |
| 207 | BlobReference gives us a way to refer to the network that the blob is |
| 208 | generated from. Note that blobs are, essentially, just strings in the |
| 209 | current workspace. |
| 210 | """ |
| 211 | |
| 212 | def __init__(self, name, net=None): |
| 213 | """Initializes a blob reference. |
| 214 | |
| 215 | Note that this does not prepends the namescope. If needed, use |
| 216 | ScopedBlobReference() to prepend the existing namespace. |
| 217 | """ |
| 218 | if isinstance(name, str): |
| 219 | self._name = name |
| 220 | elif isinstance(name, bytes): |
| 221 | self._name = name.decode('utf-8') |
| 222 | else: |
| 223 | self._name = str(name) |
| 224 | self._from_net = net |
| 225 | # meta allows helper functions to put whatever metainformation needed |
| 226 | # there. |
| 227 | self.meta = {} |
| 228 | |
| 229 | def __hash__(self): |
| 230 | return hash(self._name) |
| 231 | |
| 232 | def __eq__(self, other): |
| 233 | if isinstance(other, str): |
| 234 | return self._name == other |
| 235 | elif isinstance(other, bytes): |
| 236 | return self._name == other.decode('utf-8') |
| 237 | elif isinstance(other, BlobReference): |
| 238 | return self._name == other._name |
| 239 | else: |
| 240 | return False |
| 241 | |
| 242 | def __ne__(self, other): |
| 243 | return not(self == other) |
| 244 | |
| 245 | def __str__(self): |
| 246 | return self._name |
| 247 | |
| 248 | def __repr__(self): |
| 249 | return 'BlobReference("{}")'.format(self._name) |
| 250 | |
| 251 | def __add__(self, other): |
| 252 | if not isinstance(other, str): |
| 253 | raise RuntimeError('Cannot add BlobReference to a non-string.') |
| 254 | return BlobReference(self._name + other, self._from_net) |
| 255 | |
| 256 | def __radd__(self, other): |
| 257 | if not isinstance(other, str): |
| 258 | raise RuntimeError('Cannot add a non-string to BlobReference.') |
| 259 | return BlobReference(other + self._name, self._from_net) |
| 260 | |
| 261 | def Net(self): |
no outgoing calls
no test coverage detected
searching dependent graphs…