# HG changeset patch # User wenzelm # Date 1526063729 -7200 # Node ID 619de043389fda7a08361623e60e62bffaccacd4 # Parent 3c321783bae31048a9e8c9d551db3af09b5e44aa guard result exports via export_pattern -- avoid bombing client via huge blobs; diff -r 3c321783bae3 -r 619de043389f src/Doc/System/Server.thy --- a/src/Doc/System/Server.thy Fri May 11 20:22:20 2018 +0200 +++ b/src/Doc/System/Server.thy Fri May 11 20:35:29 2018 +0200 @@ -892,8 +892,9 @@ \quad\{session_id: uuid,\ \\ \quad~~\theories: [string],\ \\ \quad~~\master_dir?: string,\ & \<^bold>\default:\ session \tmp_dir\ \\ - \quad~~\pretty_margin?: double\ & \<^bold>\default:\ \<^verbatim>\76\ \\ - \quad~~\unicode_symbols?: bool}\ \\[2ex] + \quad~~\pretty_margin?: double,\ & \<^bold>\default:\ \<^verbatim>\76\ \\ + \quad~~\unicode_symbols?: bool,\ \\ + \quad~~\export_pattern?: string}\ \\[2ex] \end{tabular} \begin{tabular}{ll} @@ -921,13 +922,13 @@ that with different values for \pretty_margin\ or \unicode_symbols\ to get different formatting for \errors\ or \messages\. - The \exports\ can be arbitrary binary resources produced by a theory. An - \export\ \name\ roughly follows file-system standards: ``\<^verbatim>\/\'' separated - list of base names (excluding special names like ``\<^verbatim>\.\'' or ``\<^verbatim>\..\''). The - \base64\ field specifies the format of the \body\ string: it is true for a - byte vector that cannot be represented as plain text in UTF-8 encoding, - which means the string needs to be decoded as in - \<^verbatim>\java.util.Base64.getDecoder.decode(String)\. + \<^medskip> A non-empty \export_pattern\ means that theory \exports\ are retrieved + (see \secref{sec:tool-export}). An \export\ \name\ roughly follows + file-system standards: ``\<^verbatim>\/\'' separated list of base names (excluding + special names like ``\<^verbatim>\.\'' or ``\<^verbatim>\..\''). The \base64\ field specifies the + format of the \body\ string: it is true for a byte vector that cannot be + represented as plain text in UTF-8 encoding, which means the string needs to + be decoded as in \<^verbatim>\java.util.Base64.getDecoder.decode(String)\. \ diff -r 3c321783bae3 -r 619de043389f src/Doc/System/Sessions.thy --- a/src/Doc/System/Sessions.thy Fri May 11 20:22:20 2018 +0200 +++ b/src/Doc/System/Sessions.thy Fri May 11 20:35:29 2018 +0200 @@ -546,7 +546,7 @@ \ -section \Retrieve theory exports\ +section \Retrieve theory exports \label{sec:tool-export}\ text \ The @{tool_def "export"} tool retrieves theory exports from the session diff -r 3c321783bae3 -r 619de043389f src/Pure/Tools/server_commands.scala --- a/src/Pure/Tools/server_commands.scala Fri May 11 20:22:20 2018 +0200 +++ b/src/Pure/Tools/server_commands.scala Fri May 11 20:35:29 2018 +0200 @@ -156,7 +156,8 @@ theories: List[String], master_dir: String = "", pretty_margin: Double = Pretty.default_margin, - unicode_symbols: Boolean = false) + unicode_symbols: Boolean = false, + export_pattern: String = "") def unapply(json: JSON.T): Option[Args] = for { @@ -165,10 +166,11 @@ master_dir <- JSON.string_default(json, "master_dir") pretty_margin <- JSON.double_default(json, "pretty_margin", Pretty.default_margin) unicode_symbols <- JSON.bool_default(json, "unicode_symbols") + export_pattern <- JSON.string_default(json, "export_pattern") } yield { - Args(session_id, theories, master_dir = master_dir, - pretty_margin = pretty_margin, unicode_symbols) + Args(session_id, theories, master_dir = master_dir, pretty_margin = pretty_margin, + unicode_symbols = unicode_symbols, export_pattern = export_pattern) } def command(args: Args, @@ -214,11 +216,14 @@ (tree, pos) <- result.messages(name) if Protocol.is_exported(tree) } yield output_message(tree, pos))) + ("exports" -> - (for { entry <- result.exports(name) } - yield { - val (base64, body) = entry.body.join.maybe_base64 - JSON.Object("name" -> entry.name, "base64" -> base64, "body" -> body) - })))) + (if (args.export_pattern == "") Nil else { + val matcher = Export.make_matcher(args.export_pattern) + for { entry <- result.exports(name) if matcher(entry.theory_name, entry.name) } + yield { + val (base64, body) = entry.body.join.maybe_base64 + JSON.Object("name" -> entry.name, "base64" -> base64, "body" -> body) + } + })))) (result_json, result) }