A helper function to rectify the input or output of the CreateOperator interface.
(blobs, net=None)
| 328 | |
| 329 | |
| 330 | def _RectifyInputOutput(blobs, net=None): |
| 331 | """A helper function to rectify the input or output of the CreateOperator |
| 332 | interface. |
| 333 | """ |
| 334 | if isinstance(blobs, (bytes, str)): |
| 335 | # If blobs is a single string, prepend scope.CurrentNameScope() |
| 336 | # and put it as a list. |
| 337 | # TODO(jiayq): enforce using BlobReference instead of raw strings. |
| 338 | return [ScopedBlobReference(blobs, net=net)] |
| 339 | elif type(blobs) is BlobReference: |
| 340 | # If blob is a BlobReference, simply put it as a list. |
| 341 | return [blobs] |
| 342 | elif type(blobs) in (list, tuple): |
| 343 | # If blob is a list, we go through it and type check. |
| 344 | rectified = [] |
| 345 | for blob in blobs: |
| 346 | if isinstance(blob, (bytes, str)): |
| 347 | rectified.append(ScopedBlobReference(blob, net=net)) |
| 348 | elif type(blob) is BlobReference: |
| 349 | rectified.append(blob) |
| 350 | else: |
| 351 | raise TypeError( |
| 352 | "I/O blob #{} of unsupported type: {} of type {}" |
| 353 | .format(len(rectified), str(blob), type(blob))) |
| 354 | return rectified |
| 355 | else: |
| 356 | raise TypeError( |
| 357 | "Unknown input/output type: %s of type %s." % |
| 358 | (str(blobs), type(blobs)) |
| 359 | ) |
| 360 | |
| 361 | |
| 362 | def CreateOperator( |
no test coverage detected
searching dependent graphs…