code: def parse_slice(crop, allow_step=True):
      if crop is None:
          return slice(None)
      start, stop, *extra = (
          int(val) if val else None for val in crop.split(":")
      )
      if len(extra) > 1:
          raise ValueError(f"Cannot parse specification: {crop}")
      if not allow_step and extra and extra[0] not in (1, None):
          raise ValueError(f"Step entry not permitted: {crop}")
  
      step = extra[0] if extra else None
      if step not in (1, -1, None):
          raise ValueError(f"Downsampling is not supported: {crop}")
  
      return slice(start, stop, step)
  
file_path: nibabel/nibabel/cmdline/roi.py
imports: import argparse
  import os
  import sys
  import nibabel
label_desc: Use image node_id 2 for calling a global function with example usage: parse_slice(crop, allow_step) and returns: slice, slice