def resolve():
 filename = '/'.join(request.args)
 path = apath(filename, r=request)
 a = safe_read(path).split('\n')
 try:
  b = safe_read((path + '.1')).split('\n')
 except IOError:
  session.flash = 'Other file, no longer there'
  redirect(URL('edit', args=request.args))
 d = difflib.ndiff(a, b)
 def leading(line):
  '  '
  z = ''
  for (k, c) in enumerate(line):
   if (c == ' '):
    z += '&nbsp;'
   elif (c == '  DCTB '):
    z += '&nbsp;'
   elif ((k == 0) and (c == '?')):
    pass
   else:
    break
  return XML(z)
 def getclass(item):
  ' Determine item class '
  operators = {' ': 'normal', '+': 'plus', '-': 'minus'}
  return operators[item[0]]
 if request.vars:
  c = '\n'.join([item[2:].rstrip() for (i, item) in enumerate(d) if ((item[0] == ' ') or (('line%i' % i) in request.vars))])
  safe_write(path, c)
  session.flash = 'files merged'
  redirect(URL('edit', args=request.args))
 else:
  gen_data = (lambda index, item: (((not (item[:1] in ['+', '-'])) and '') or INPUT(_type='checkbox', _name=('line%i' % index), value=(item[0] == '+'))))
  diff = TABLE(*[TR(TD(gen_data(i, item)), TD(item[0]), TD(leading(item[2:]), TT(item[2:].rstrip())), _class=getclass(item)) for (i, item) in enumerate(d) if (item[0] != '?')])
 return dict(diff=diff, filename=filename)

def resolve ( ) : filename = '/' . join ( request . args ) path = apath ( filename , r = request ) a = safe_read ( path ) . split ( '\n' ) try : b = safe_read ( ( path + '.1' ) ) . split ( '\n' ) except IOError : session . flash = 'Other file, no longer there' redirect ( URL ( 'edit' , args = request . args ) ) d = difflib . ndiff ( a , b ) def leading ( line ) : z = '' for ( k , c ) in enumerate ( line ) : if ( c == ' ' ) : z += '&nbsp;' elif ( c == '  DCTB ' ) : z += '&nbsp;' elif ( ( k == 0 ) and ( c == '?' ) ) : pass else : break return XML ( z ) def getclass ( item ) : operators = { ' ' : 'normal' , '+' : 'plus' , '-' : 'minus' } return operators [ item [ 0 ] ] if request . vars : c = '\n' . join ( [ item [ 2 : ] . rstrip ( ) for ( i , item ) in enumerate ( d ) if ( ( item [ 0 ] == ' ' ) or ( ( 'line%i' % i ) in request . vars ) ) ] ) safe_write ( path , c ) session . flash = 'files merged' redirect ( URL ( 'edit' , args = request . args ) ) else : gen_data = ( lambda index , item : ( ( ( not ( item [ : 1 ] in [ '+' , '-' ] ) ) and '' ) or INPUT ( _type = 'checkbox' , _name = ( 'line%i' % index ) , value = ( item [ 0 ] == '+' ) ) ) ) diff = TABLE ( * [ TR ( TD ( gen_data ( i , item ) ) , TD ( item [ 0 ] ) , TD ( leading ( item [ 2 : ] ) , TT ( item [ 2 : ] . rstrip ( ) ) ) , _class = getclass ( item ) ) for ( i , item ) in enumerate ( d ) if ( item [ 0 ] != '?' ) ] ) return dict ( diff = diff , filename = filename )
given an object or a path to an object .