@@ -237,7 +237,6 @@ def with_watchdog(timeout_time, error_message)
237237 stop error_message
238238 state = :timeout
239239 end
240-
241240 end
242241 end : nil
243242 begin
@@ -258,7 +257,7 @@ def with_watchdog(timeout_time, error_message)
258257
259258 # Our 'rpc'-ish request to mentos. Requires a method name, and then optional
260259 # args, kwargs, code.
261- def mentos ( method , args = [ ] , kwargs = { } , original_code = nil )
260+ def mentos ( method , args = [ ] , kwargs = { } , code = nil )
262261 # Open the pipe if necessary
263262 start unless alive?
264263
@@ -273,12 +272,6 @@ def mentos(method, args = [], kwargs = {}, original_code = nil)
273272 end
274273 end
275274
276- # For sanity checking on both sides of the pipe when highlighting, we prepend and
277- # append an id. mentos checks that these are 8 character ids and that they match.
278- # It then returns the id's back to Rubyland.
279- id = ( 0 ...8 ) . map { rand ( 65 ..89 ) . chr } . join
280- code = original_code ? add_ids ( original_code , id ) : nil
281-
282275 # Add metadata to the header and generate it.
283276 bytesize = if code
284277 code . bytesize
@@ -287,7 +280,7 @@ def mentos(method, args = [], kwargs = {}, original_code = nil)
287280 end
288281
289282 kwargs . freeze
290- kwargs = kwargs . merge ( 'fd' => @out . to_i , 'id' => id , ' bytes' => bytesize )
283+ kwargs = kwargs . merge ( 'fd' => @out . to_i , 'bytes' => bytesize )
291284 out_header = JSON . generate ( method : method , args : args , kwargs : kwargs )
292285
293286 begin
@@ -315,7 +308,7 @@ def mentos(method, args = [], kwargs = {}, original_code = nil)
315308 header = @out . read ( header_len )
316309
317310 # Now handle the header, any read any more data required.
318- handle_header_and_return ( header , id )
311+ handle_header_and_return ( header )
319312 end
320313
321314 # Finally, return what we got.
@@ -341,10 +334,8 @@ def mentos(method, args = [], kwargs = {}, original_code = nil)
341334 # Based on the header we receive, determine if we need
342335 # to read more bytes, and read those bytes if necessary.
343336 #
344- # Then, do a sanity check with the ids.
345- #
346337 # Returns a result - either highlighted text or metadata.
347- def handle_header_and_return ( header , id )
338+ def handle_header_and_return ( header )
348339 if header
349340 @log . info "In header: #{ header } "
350341 header = header_to_json ( header )
@@ -356,37 +347,14 @@ def handle_header_and_return(header, id)
356347 if header [ :method ] == 'highlight'
357348 # Make sure we have a result back; else consider this an error.
358349 raise MentosError , 'No highlight result back from mentos.' if res . nil?
359-
360- @log . info 'Highlight in process.'
361-
362- # Get the id's
363- start_id = res [ 0 ..7 ]
364- end_id = res [ -8 ..-1 ]
365-
366- # Sanity check.
367- if !( ( start_id == id ) && ( end_id == id ) )
368- raise MentosError , "ID's did not match. Aborting."
369- else
370- # We're good. Remove the padding
371- res = res [ 10 ..-11 ]
372- @log . info 'Highlighting complete.'
373- res
374- end
375350 end
351+
376352 res
377353 else
378354 raise MentosError , 'No header received back.'
379355 end
380356 end
381357
382- # With the code, prepend the id (with two spaces to avoid escaping weirdness if
383- # the following text starts with a slash (like terminal code), and append the
384- # id, with two padding also. This means we are sending over the 8 characters +
385- # code + 8 characters.
386- def add_ids ( code , id )
387- ( id + " #{ code } #{ id } " ) . freeze
388- end
389-
390358 # Return the final result for the API. Return Ruby objects for the methods that
391359 # want them, text otherwise.
392360 def return_result ( res , method )
0 commit comments