def transform_ipynb_uri(uri, uri_rewrite_list):
 for (reg, rewrite) in uri_rewrite_list:
  matches = re.match(reg, uri)
  if matches:
   return rewrite.format(*matches.groups())
 if ('?' in uri):
  (uri, query) = uri.split('?', 1)
  uri = ('%s/%s' % (uri, quote(('?' + query))))
 return uri

def transform_ipynb_uri ( uri , uri_rewrite_list ) : for ( reg , rewrite ) in uri_rewrite_list : matches = re . match ( reg , uri ) if matches : return rewrite . format ( * matches . groups ( ) ) if ( '?' in uri ) : ( uri , query ) = uri . split ( '?' , 1 ) uri = ( '%s/%s' % ( uri , quote ( ( '?' + query ) ) ) ) return uri
transform a given uri into an app url state-free part of transforming uris to nbviewer urls .