def s3_set_extension(url, extension=None):
 if (extension == None):
  extension = s3_get_extension()
 u = urlparse.urlparse(url)
 path = u.path
 if path:
  if ('.' in path):
   elements = [p.split('.')[0] for p in path.split('/')]
  else:
   elements = path.split('/')
  if (extension and elements[(-1)]):
   elements[(-1)] += ('.%s' % extension)
  path = '/'.join(elements)
 return urlparse.urlunparse((u.scheme, u.netloc, path, u.params, u.query, u.fragment))

def s3_set_extension ( url , extension = None ) : if ( extension == None ) : extension = s3_get_extension ( ) u = urlparse . urlparse ( url ) path = u . path if path : if ( '.' in path ) : elements = [ p . split ( '.' ) [ 0 ] for p in path . split ( '/' ) ] else : elements = path . split ( '/' ) if ( extension and elements [ ( - 1 ) ] ) : elements [ ( - 1 ) ] += ( '.%s' % extension ) path = '/' . join ( elements ) return urlparse . urlunparse ( ( u . scheme , u . netloc , path , u . params , u . query , u . fragment ) )
add a file extension to the path of a url .