docs: def mkdir(self, mdir, parents=False):
          """Make a directory.
  
          Note that this will not error out if the directory already exists
          (that is how the PutDirectory Manta API behaves).
  
          @param mdir {str} A manta path, e.g. '/trent/stor/mydir'.
          @param parents {bool} Optional. Default false. Like 'mkdir -p', this
              will create parent dirs as necessary.
          """
          assert mdir.startswith('/'), "%s: invalid manta path" % mdir
          parts = mdir.split('/')
          assert len(parts) > 3, "%s: cannot create top-level dirs" % mdir
          if not parents:
              self.put_directory(mdir)
          else:
              # Find the first non-existant dir: binary search. Because
              # PutDirectory doesn't error on 'mkdir .../already-exists' we
              # don't have a way to detect a miss on `start`. So basically we
              # keep doing the binary search until we hit and close the `start`
              # to `end` gap.
              # Example:
              # - mdir: /trent/stor/builds/a/b/c  (need to mk a/b/c)
              #   parts: ['', 'trent', 'stor', 'builds', 'a', 'b', 'c']
              #   start: 4
              #   end: 8
              # - idx: 6
              #   d: /trent/stor/builds/a/b    (put_directory fails)
              #   end: 6
              # - idx: 5
              #   d: /trent/stor/builds/a   (put_directory succeeds)
              #   start: 5
              #   (break out of loop)
              # - for i in range(6, 8):
              #       i=6 -> d: /trent/stor/builds/a/b
              #       i=7 -> d: /trent/stor/builds/a/b/c
              end = len(parts) + 1
              start = 3  # Index of the first possible dir to create.
              while start < end - 1:
                  idx = int((end - start) // 2 + start)
                  d = '/'.join(parts[:idx])
                  try:
                      self.put_directory(d)
                  except errors.MantaAPIError:
                      _, ex, _ = sys.exc_info()
                      if ex.code == 'DirectoryDoesNotExist':
                          end = idx
                      else:
                          raise
                  else:
                      start = idx
  
              # Now need to create from (end-1, len(parts)].
              for i in range(end, len(parts) + 1):
                  d = '/'.join(parts[:i])
                  self.put_directory(d)