<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_wcs(image,extnum,new_wcs,wcsname="",reusename=False,verbose=False):
 """ Updates the WCS of the specified extension number with the new WCS after archiving the original WCS. The value of 'new_wcs' needs to be the full HSTWCS object. Parameters image : str Filename of image with WCS that needs to be updated extnum : int Extension number for extension with WCS to be updated/replaced new_wcs : object Full HSTWCS object which will replace/update the existing WCS wcsname : str Label to give newly updated WCS reusename : bool User can choose whether to over-write WCS with same name or not. [Default: False] verbose : bool, int Print extra messages during processing? [Default: False] """

    # Start by insuring that the correct value of 'orientat' has been computed
    new_wcs.setOrient()

    fimg_open=False
    if not isinstance(image, fits.HDUList):
        fimg = fits.open(image, mode='update', memmap=False)
        fimg_open = True
        fimg_update = True
    else:
        fimg = image
        if fimg.fileinfo(0)['filemode'] is 'update':
            fimg_update = True
        else:
            fimg_update = False

    # Determine final (unique) WCSNAME value, either based on the default or
    # user-provided name
    if util.is_blank(wcsname):
        wcsname = 'TWEAK'
    if not reusename:
        wcsname = create_unique_wcsname(fimg, extnum, wcsname)

    idchdr = True
    if new_wcs.idcscale is None:
        idchdr = False
    # Open the file for updating the WCS
    try:
        logstr = 'Updating header for %s[%s]'%(fimg.filename(),str(extnum))
        if verbose:
            print(logstr)
        else:
            log.info(logstr)

        hdr = fimg[extnum].header

        if verbose:
            log.info('    with WCS of')
            new_wcs.printwcs()
            print("WCSNAME  : ",wcsname)

        # Insure that if a copy of the WCS has not been created yet, it will be now
        wcs_hdr = new_wcs.wcs2header(idc2hdr=idchdr, relax=True)

        for key in wcs_hdr:
            hdr[key] = wcs_hdr[key]
        hdr['ORIENTAT'] = new_wcs.orientat
        hdr['WCSNAME'] = wcsname
        util.updateNEXTENDKw(fimg)

        # Only if this image was opened in update mode should this
        # newly updated WCS be archived, as it will never be written out
        # to a file otherwise.
        if fimg_update:
            if not reusename:
                # Save the newly updated WCS as an alternate WCS as well
                wkey = wcsutil.altwcs.next_wcskey(fimg,ext=extnum)
            else:
                wkey = wcsutil.altwcs.getKeyFromName(hdr,wcsname)

            # wcskey needs to be specified so that archiveWCS will create a
            # duplicate WCS with the same WCSNAME as the Primary WCS
            wcsutil.altwcs.archiveWCS(fimg,[extnum],wcsname=wcsname,
                wcskey=wkey, reusekey=reusename)
    finally:
        if fimg_open:
            # finish up by closing the file now
            fimg.close()