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

Method open

scapy/layers/can.py:559–588  ·  view source on GitHub ↗

Open function to handle three types of input data. If filename of a regular candump log file is provided, this function opens the file and returns the file object. If filename of a gzip compressed candump log file is provided, the required gzip open function is used

(filename)

Source from the content-addressed store, hash-verified

557
558 @staticmethod
559 def open(filename):
560 # type: (Union[IO[bytes], str]) -> Tuple[str, _ByteStream]
561 """Open function to handle three types of input data.
562
563 If filename of a regular candump log file is provided, this function
564 opens the file and returns the file object.
565 If filename of a gzip compressed candump log file is provided, the
566 required gzip open function is used to obtain the necessary file
567 object, which gets returned.
568 If a fileobject or ByteIO is provided, the filename is gathered for
569 internal use. No further steps are performed on this object.
570
571 :param filename: Can be a string, specifying a candump log file or a
572 gzip compressed candump log file. Also already opened
573 file objects are allowed.
574 :return: A opened file object for further use.
575 """
576 """Open (if necessary) filename."""
577 if isinstance(filename, str):
578 try:
579 fdesc = gzip.open(filename, "rb") # type: _ByteStream
580 # try read to cause exception
581 fdesc.read(1)
582 fdesc.seek(0)
583 except IOError:
584 fdesc = open(filename, "rb")
585 return filename, fdesc
586 else:
587 name = getattr(filename, "name", "No name")
588 return name, filename
589
590 def next(self):
591 # type: () -> Packet

Callers 8

__init__Method · 0.95
get_long_descriptionFunction · 0.45
loadFunction · 0.45
_read_config_fileFunction · 0.45
list_contribFunction · 0.45
get_dev_bpfFunction · 0.45
getMethod · 0.45
putMethod · 0.45

Calls 1

readMethod · 0.45

Tested by

no test coverage detected