code: def get_lock_request(name, version, patch_lock, weak=True):
      
      ch = '~' if weak else ''
      if patch_lock == PatchLock.lock:
          s = "%s%s==%s" % (ch, name, str(version))
          return PackageRequest(s)
      elif (patch_lock == PatchLock.no_lock) or (not version):
          return None
      version_ = version.trim(patch_lock.rank)
      s = "%s%s-%s" % (ch, name, str(version_))
      return PackageRequest(s)
docs: Given a package and patch lock, return the equivalent request.
  
      For example, for object 'foo-1.2.1' and lock type 'lock_3', the equivalent
      request is '~foo-1.2'. This restricts updates to foo to patch-or-lower
      version changes only.
  
      For objects not versioned down to a given lock level, the closest possible
      lock is applied. So 'lock_3' applied to 'foo-1' would give '~foo-1'.
  
      Args:
          name (str): Package name.
          version (Version): Package version.
          patch_lock (PatchLock): Lock type to apply.
  
      Returns:
          `PackageRequest` object, or None if there is no equivalent request.