code: def parse(class_, f, allow_segwit=None):
          
          if allow_segwit is None:
              allow_segwit = class_.ALLOW_SEGWIT
          txs_in = []
          txs_out = []
          version, = parse_struct("L", f)
          v1 = ord(f.read(1))
          is_segwit = allow_segwit and (v1 == 0)
          v2 = None
          if is_segwit:
              flag = f.read(1)
              if flag == b'\0':
                  raise ValueError("bad flag in segwit")
              if flag == b'\1':
                  v1 = None
              else:
                  is_segwit = False
                  v2 = ord(flag)
          count = parse_satoshi_int(f, v=v1)
          txs_in = []
          for i in range(count):
              txs_in.append(class_.TxIn.parse(f))
          count = parse_satoshi_int(f, v=v2)
          txs_out = []
          for i in range(count):
              txs_out.append(class_.TxOut.parse(f))
  
          if is_segwit:
              for tx_in in txs_in:
                  stack = []
                  count = parse_satoshi_int(f)
                  for i in range(count):
                      stack.append(parse_satoshi_string(f))
                  tx_in.witness = stack
          lock_time, = parse_struct("L", f)
          return class_(version, txs_in, txs_out, lock_time)
docs: Parse a Bitcoin transaction Tx.
  
          :param f: a file-like object that contains a binary streamed transaction
          :param allow_segwit: (optional) set to True to allow parsing of segwit transactions.
              The default value is defined by the class variable ALLOW_SEGWIT