code: def infer_compression(url):
      """
      Given a URL or filename, infer the compression code for tar.
  
      >>> infer_compression('http://foo/bar.tar.gz')
      'z'
      >>> infer_compression('http://foo/bar.tgz')
      'z'
      >>> infer_compression('file.bz')
      'j'
      >>> infer_compression('file.xz')
      'J'
      """
      # cheat and just assume it's the last two characters
      compression_indicator = url[-2:]
      mapping = dict(gz="z", bz="j", xz="J")
      # Assume 'z' (gzip) if no match
      return mapping.get(compression_indicator, "z")
  
imports: import os
  import subprocess
  import contextlib
  import functools
  import tempfile
  import shutil
  import operator
  import warnings
label_desc: Use image node_id 3 for calling a global function with example usage: infer_compression(url) and returns: mapping