code: def parse_intervals(path, as_context=False):
      def _regions_from_range():
          if as_context:
              ctxs = list(set(pf.lines[start - 1: stop - 1]))
              return [
                  ContextInterval(filename, ctx)
                  for ctx in ctxs
              ]
          else:
              return [LineInterval(filename, start, stop)]
      if ':' in path:
          path, subpath = path.split(':')
      else:
          subpath = ''
      pf = PythonFile.from_modulename(path)
      filename = pf.filename
      rng = NUMBER_RE.match(subpath)
      if rng:
          start, stop = map(int, rng.groups(0))
          stop = stop or start + 1
          return _regions_from_range()
      elif not subpath:
          if as_context:
              return [ContextInterval(filename, pf.prefix)]
          start, stop = 1, pf.line_count + 1
          return _regions_from_range()
      else:
          context = pf.prefix + ':' + subpath
          if context not in pf.lines:
              raise ValueError("%s is not a valid context for %s"
                               % (context, pf.prefix))
          if as_context:
              return [ContextInterval(filename, context)]
          else:
              start, stop = pf.context_range(context)
              return [LineInterval(filename, start, stop)]