<s> from . import BaseCommand <EOL> from flask import redirect , render_template <EOL> from ... notebook_parser import NotebookParser <EOL> from ... merge import notebook_merge <EOL> from nbdiff . server . database . nbdiffModel import nbdiffModel <EOL> from werkzeug . exceptions import BadRequestKeyError <EOL> from sqlalchemy . exc import OperationalError <EOL> import urllib2 <EOL> import json <EOL> import bitarray <EOL> import IPython . nbformat . current as nbformat <EOL> class MergeURLCommand ( BaseCommand ) : <EOL> def process ( self , request , filename , db_session ) : <EOL> errMsg = "<STR_LIT>" <EOL> parser = NotebookParser ( ) <EOL> max_size = <NUM_LIT:20> * <NUM_LIT> * <NUM_LIT> <EOL> try : <EOL> localURL = request . form [ '<STR_LIT>' ] <EOL> baseURL = request . form [ '<STR_LIT>' ] <EOL> remoteURL = request . form [ '<STR_LIT>' ] <EOL> except BadRequestKeyError : <EOL> errMsg = """<STR_LIT>""" <EOL> return render_template ( '<STR_LIT>' , err = errMsg ) <EOL> try : <EOL> localFile = urllib2 . urlopen ( localURL ) <EOL> if int ( localFile . info ( ) [ '<STR_LIT>' ] ) > max_size : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> except : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> try : <EOL> baseFile = urllib2 . urlopen ( baseURL ) <EOL> if int ( baseFile . info ( ) [ '<STR_LIT>' ] ) > max_size : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> except : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> try : <EOL> remoteFile = urllib2 . urlopen ( remoteURL ) <EOL> if int ( remoteFile . info ( ) [ '<STR_LIT>' ] ) > max_size : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> except : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> if len ( errMsg ) == <NUM_LIT:0> : <EOL> try : <EOL> nb_local = parser . parse ( localFile ) <EOL> except nbformat . NotJSONError : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> try : <EOL> nb_base = parser . parse ( baseFile ) <EOL> except nbformat . NotJSONError : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> try : <EOL> nb_remote = parser . parse ( remoteFile ) <EOL> except nbformat . NotJSONError : <EOL> errMsg = errMsg + """<STR_LIT>""" <EOL> localFile . close ( ) <EOL> baseFile . close ( ) <EOL> remoteFile . close ( ) <EOL> if len ( errMsg ) == <NUM_LIT:0> : <EOL> mergedNotebook = notebook_merge ( nb_local , nb_base , nb_remote ) <EOL> ba = bitarray . bitarray ( ) <EOL> ba . fromstring ( json . dumps ( mergedNotebook , indent = <NUM_LIT:2> ) ) <EOL> obj = nbdiffModel ( ba . to01 ( ) ) <EOL> try : <EOL> db_session . add ( obj ) <EOL> db_session . commit ( ) <EOL> except OperationalError : <EOL> db_session . rollback ( ) <EOL> print """<STR_LIT>""" <EOL> errMsg = """<STR_LIT>""" <EOL> return render_template ( '<STR_LIT>' , err = errMsg ) <EOL> except : <EOL> db_session . rollback ( ) <EOL> errMsg = """<STR_LIT>""" <EOL> return render_template ( '<STR_LIT>' , err = errMsg ) <EOL> nb_id = obj . id <EOL> return redirect ( "<STR_LIT>" + str ( nb_id ) , code = <NUM_LIT> ) <EOL> else : <EOL> return render_template ( '<STR_LIT>' , err = errMsg ) <EOL> def newInstance ( ) : <EOL> return MergeURLCommand ( ) </s>
