# -*- coding: latin-1 -*-
import EasyDialogs as g
import urllib as url
import sys
sys.path.append( gBase + "/library.zip" )
class Descarga :
    def __init__( self, urlP, destinoP, tituloP=None ) :
        self.progreso = None
        self.error = False
        self.titulo = tituloP
        try :
            if tituloP :
                url.urlretrieve( urlP, destinoP, self.hook )
            else :
                url.urlretrieve( urlP, destinoP )
        except  :
            self.error = True
    def hook( self, bloques, tambloque, tamfichero ) :
        if self.progreso is None :
            self.progreso = g.ProgressBar( "{CAPTION}", tamfichero/tambloque, self.titulo, cancel = "{CANCELAR}" )
        self.progreso.inc(  )
d = Descarga( "{URL}", "{DESTINO}", "{TITULO}" )
f = open( "{ERROR}", "wb" )
f.write( "S" if d.error else "N" )
f.close()
