text stringlengths 0 601k |
|---|
let detect_esy_sandbox ~ project_root esy ( ) = let open Promise . Option . Syntax in let * esy in let open Promise . Syntax in let + esy_build_dir_exists , manifest = Promise . all2 ( Fs . exists Path . ( project_root / " _esy " |> Path . to_string ) , Esy . find_manifest_in_dir project_root ) in match ( esy_build_dir... |
let detect_opam_local_switch ~ project_root opam ( ) = let open Promise . Option . Syntax in let * opam in let * switch = Opam . switch_show ~ cwd : project_root opam in match switch with | Local _ as switch -> Promise . Option . return ( Opam ( opam , switch ) ) | Named _ -> Promise . return None |
let detect_opam_sandbox ~ project_root opam ( ) = let open Promise . Option . Syntax in let * opam in let + switch = Opam . switch_show ~ cwd : project_root opam in Opam ( opam , switch ) |
let detect ( ) = let open Promise . Option . Syntax in let * project_root = workspace_root ( ) |> Promise . return in let available = available_sandboxes ( ) in Promise . List . find_map ( fun f -> f ( ) ) [ detect_opam_local_switch ~ project_root available . opam ; detect_esy_sandbox ~ project_root available . esy ; d... |
let of_settings_or_detect ( ) = let open Promise . Syntax in let * package_manager_opt = of_settings ( ) in match package_manager_opt with | Some package_manager -> Promise . return ( Some package_manager ) | None -> detect ( ) |
let save_to_settings sandbox = let to_setting = function | Esy ( _ , root ) -> Setting . Esy root | Opam ( _ , switch ) -> Setting . Opam switch | Global -> Setting . Global | Custom template -> Setting . Custom template in Settings . set ~ section " : ocaml " Setting . t ( to_setting sandbox ) |
module Candidate = struct type nonrec t = { sandbox : t ; status : ( unit , string ) result } let to_quick_pick current_switch { sandbox ; status } = let create = QuickPickItem . create in let description = match status with | Error s -> Some ( Printf . sprintf " Invalid sandbox : % s " s ) | Ok ( ) -> ( match sandbox ... |
let select_sandbox ( choices : Candidate . t list ) = let placeHolder = " Which package manager would you like to manage the sandbox " ? in let open Promise . Syntax in let * current_switch = let open Promise . Option . Syntax in let * opam = Opam . make ( ) in let * cwd = workspace_root ( ) |> Promise . return in Opam... |
let sandbox_candidates ~ workspace_folders = let open Promise . Syntax in let available = available_sandboxes ( ) in let esy = let * esy = available . esy in match esy with | None -> Promise . return [ ] | Some esy -> let + esys = workspace_folders |> List . map ~ f ( : fun ( folder : WorkspaceFolder . t ) -> let dir =... |
let select_sandbox ( ) = let open Promise . Syntax in let workspace_folders = Workspace . workspaceFolders ( ) in let * candidates = sandbox_candidates ~ workspace_folders in let open Promise . Option . Syntax in let * candidate = select_sandbox candidates in match candidate with | { status = Ok ( ) ; sandbox = Custom ... |
let select_sandbox_and_save ( ) = let open Promise . Option . Syntax in let * sandbox = select_sandbox ( ) in let open Promise . Syntax in let + ( ) = save_to_settings sandbox in Some sandbox |
let get_command sandbox bin args : Cmd . t = match sandbox with | Opam ( opam , switch ) -> Opam . exec opam switch ~ args ( : bin :: args ) | Esy ( esy , manifest ) -> Esy . exec esy manifest ~ args ( : bin :: args ) | Global -> Spawn { bin = Path . of_string bin ; args } | Custom template -> let command = template |>... |
let get_install_command sandbox tools = match sandbox with | Opam ( opam , switch ) -> Some ( Opam . install opam switch ~ packages : tools ) | Esy ( esy , manifest ) -> Some ( Esy . install esy manifest ~ packages : tools ) | _ -> None |
let get_exec_command sandbox tools = match sandbox with | Opam ( opam , switch ) -> Some ( Opam . exec opam switch ~ args : tools ) | Esy ( esy , manifest ) -> Some ( Esy . exec esy manifest ~ args : tools ) | _ -> None |
let ocaml_version sandbox = let cmd = get_command sandbox " ocamlc " [ " -- version " ] in let open Promise . Result . Syntax in let * cmd = Cmd . check cmd in let + output = Cmd . output cmd in String . strip output |
let packages t = let open Promise . Result . Syntax in match t with | Global -> Promise . Result . return [ ] | Custom _ -> Promise . Result . return [ ] | Esy ( esy , manifest ) -> let + r = Esy . packages esy manifest in List . map r ~ f : Package . of_esy | Opam ( opam , switch ) -> let + r = Opam . packages opam sw... |
let root_packages t = let open Promise . Result . Syntax in match t with | Global -> Promise . Result . return [ ] | Custom _ -> Promise . Result . return [ ] | Esy ( esy , manifest ) -> let + r = Esy . root_packages esy manifest in List . map r ~ f : Package . of_esy | Opam ( opam , switch ) -> let + r = Opam . root_p... |
let uninstall_packages t packages = let options = ProgressOptions . create ~ location ( ` : ProgressLocation Notification ) ~ title " : Uninstalling sandbox packages " ~ cancellable : false ( ) in match t with | Global -> show_message ` Error " Uninstalling packages is not supported for Global sandboxes " ; Promise . r... |
let install_packages t packages = let options = ProgressOptions . create ~ location ( ` : ProgressLocation Notification ) ~ title " : Installing sandbox packages " ~ cancellable : false ( ) in match t with | Global -> show_message ` Error " Installing packages is not supported for Global sandboxes " ; Promise . return ... |
let upgrade_packages t = let options = ProgressOptions . create ~ location ( ` : ProgressLocation Notification ) ~ title " : Upgrading sandbox packages " ~ cancellable : false ( ) in match t with | Global -> show_message ` Error " Upgrading packages is not supported for Global sandboxes " ; Promise . return ( ) | Custo... |
let focus_on_package_command ? sandbox ( ) = match sandbox with | None | Some ( Opam _ ) -> let ( lazy output ) = Output . command_output_channel in Vscode . OutputChannel . show output ( ) | _ -> ( ) |
let no_special_requirements = of_func ( fun _ -> true ) |
let no_sandboxing = of_func Option . is_none |
let needs_sandboxing = of_func ( function | None | Some Patch_back_source_tree -> false | Some _ -> true ) |
module Partial = struct type t = bool option Sandbox_mode . Dict . t let get_unique eq l = match l with | [ ] -> Ok None | x :: xs -> if List . for_all xs ~ f ( : eq x ) then Ok ( Some x ) else Error Conflict let merge ~ loc items = let merge_field field = match get_unique Bool . equal ( List . filter_map items ~ f ( :... |
let disallow ( mode : Sandbox_mode . t ) = Sandbox_mode . Dict . of_func ( fun mode ' -> not ( Sandbox_mode . equal mode mode ' ) ) |
type some = | Symlink | Copy | Hardlink | Patch_back_source_tree |
let compare_some a b = match ( a , b ) with | Symlink , Symlink -> Eq | Symlink , _ -> Lt | _ , Symlink -> Gt | Copy , Copy -> Eq | Copy , _ -> Lt | _ , Copy -> Gt | Hardlink , Hardlink -> Eq | Hardlink , _ -> Lt | _ , Hardlink -> Gt | Patch_back_source_tree , Patch_back_source_tree -> Eq |
type t = some option |
let compare = Option . compare compare_some |
let equal a b = match compare a b with | Eq -> true | Lt | Gt -> false |
module Dict = struct type key = t type ' a t = { none : ' a ; symlink : ' a ; copy : ' a ; hardlink : ' a ; patch_back_source_tree : ' a } let compare compare { none ; symlink ; copy ; hardlink ; patch_back_source_tree } t = let open Ordering . O in let = ( ) = compare none t . none in let = ( ) = compare symlink t . s... |
module Set = struct type key = t type t = bool Dict . t let compare = Dict . compare Bool . compare let of_func = Dict . of_func let singleton k = of_func ( equal k ) let patch_back_source_tree_only = singleton ( Some Patch_back_source_tree ) let is_patch_back_source_tree_only t = match compare t patch_back_source_tree... |
let all_except_patch_back_source_tree = if Sys . win32 then [ None ; Some Copy ; Some Symlink ; Some Hardlink ] else [ None ; Some Symlink ; Some Copy ; Some Hardlink ] |
let all = all_except_patch_back_source_tree @ [ Some Patch_back_source_tree ] |
let symlink = Some Symlink |
let copy = Some Copy |
let hardlink = Some Hardlink |
let decode = let open Dune_lang . Decoder in enum [ ( " none " , None ) ; ( " symlink " , Some Symlink ) ; ( " copy " , Some Copy ) ; ( " hardlink " , Some Hardlink ) ] |
let to_string = function | None -> " none " | Some Symlink -> " symlink " | Some Copy -> " copy " | Some Hardlink -> " hardlink " | Some Patch_back_source_tree -> " patch_back_source_tree " |
let to_dyn = Dyn . option ( function | Symlink -> Variant ( " Symlink " , [ ] ) | Copy -> Variant ( " Copy " , [ ] ) | Hardlink -> Variant ( " Hardlink " , [ ] ) | Patch_back_source_tree -> Variant ( " Patch_back_source_tree " , [ ] ) ) |
let re_url = Str . regexp_case_fold " [ ^ ] ( ( ( *\\\\\\ http \\| https \\| ftp \\| feed \\| news ) [ \\:// a - z0 - 9_ . ] ( [ ] ) ) ) [ -+\\/^@*\\?\\?\\ ] " ; ; *$ |
let re_url_relative = Str . regexp_case_fold " [ ] ( [ ] ) [ *\\/^@*\\ ] " ; ; *$ |
let re_mailto = Str . regexp_case_fold " [ ^ ] ( *\\ mailto [ : a - z0 - 9_ . ] [ -+@ a - z0 - 9_ . ] ) [ -+\\? ] " ; ; *$ |
let re_safeurl = Str . regexp_case_fold " [ ^ ] ( ( ( ( *\\\\\\\\ http \\| https \\| ftp \\| feed \\| news \\| mailto ) ) ( \\:\\?//\\ www . ) ( \\\\?\\ youtube ( \\- nocookie ) . \\?\\ com \\| youtu . \\ be \\| cdn . \\ embedly . \\ com \\| api . \\ embed . \\ ly ( \\|\\ player . ) \\\\? vimeo . \\ com \\| download . ... |
let re_safeurl_or_word = Str . regexp_case_fold " [ ^ ] ( ( *\\\\ https ( ?://\\ www . ) ( \\\\?\\ youtube ( \\- nocookie ) . \\?\\ com \\| youtu . \\ be \\| cdn . \\ embedly . \\ com \\| api . \\ embed . \\ ly ( \\|\\ player . ) \\\\? vimeo . \\ com \\| download . \\ macromedia . \\ com \\| abcnews . \\ go . \\ com \\... |
let re_plainid = Str . regexp " [ ^@ a - zA - Z0 - 9 . , ; ] " ; ; /#=+-*$ |
let re_classid = Str . regexp_case_fold " [ ^ ] * clsid : d27cdb6e - ae6d - 11cf - 96b8 - 444553540000 [ ] " ; ; *$ |
let check_re re s = match Str . string_match re s 0 with |
let rec check_href_helper s = function | [ ] -> " " | re :: tail -> match Str . string_match re s 0 with | true -> Str . matched_group 1 s | false -> check_href_helper s tail ; ; |
let check_href s = check_href_helper s [ re_url ; re_mailto ; re_url_relative ] ; ; |
let check_url = check_re re_url ; ; |
let check_safeurl = check_re re_safeurl ; ; |
let check_safeurl_or_word = check_re re_safeurl_or_word ; ; |
let check_plainid = check_re re_plainid ; ; |
let check_default s = s ; ; |
let check_int_range l r s = match int_of_string s with | n when n < l -> string_of_int l | n when n > r -> string_of_int r | _ -> s ; ; |
let check_dimension = check_int_range 0 2000 ; ; |
let check_classid = check_re re_classid ; ; |
let check_css is_aggressive = CSS . sanitize ~ aggressive : is_aggressive ; ; |
let ( ) |? f n = fun x -> try f x with Not_found -> n ; ; |
let default_permitted_tags : ( string * ( string * ( string -> string ) ) list ) list = [ ; ( " rel " , check_default ) ; ( " data - resolved " , check_url ) ; ( " data - src - resolved " , check_url ) ] ) ] ) ] ) ; ( " alt " , check_default ) ; ( " data - src - preview " , check_url ) ; ( " data - src - web " , check_... |
let get_attribute_checker is_aggressive = function |
let parse_permitted_tags is_aggressive = match Str . split re_sep ( String . lowercase rule ) with let acc0 = if mem_assoc tag acc then acc else ( tag , [ ] ) :: acc in fold_left ( fun acc1 attr -> let a_spec = ( attr , get_attribute_checker is_aggressive ( tag , attr ) ) in ( tag , ( a_spec :: assoc tag acc1 ) ) :: re... |
let sanitize_attributes_white ( ? raise_on_fail = None ) perm_attrs attrs = let rewrite ( attr , value ) acc = if mem_assoc attr perm_attrs then let check_fun = assoc attr perm_attrs in try ( attr , check_fun value ) :: acc with _ -> ( match raise_on_fail with | None -> acc | Some exc -> raise exc ) else acc in fold_ri... |
let sanitize_attributes_black tag attrs = let rewrite ( attr , value ) acc = match attr with | " fscommand " -> acc | s when s . [ 0 ] = ' o ' && s . [ 1 ] = ' n ' -> acc | _ -> try let check_fun = get_attribute_checker false ( tag , attr ) in ( attr , check_fun value ) :: acc with _ -> acc in fold_right rewrite attrs ... |
let evil_tag = function | " script " | " iframe " | " layer " | " link " | " style " | " meta " -> true | " frame " | " frameset " -> true | " base " -> true | _ -> false |
let disallow_empty exc = function | [ ] -> raise exc | lst -> lst |
let permit_safe_evil exc = function | Element ( " iframe " , attributes , [ ] ) | Element ( " iframe " , attributes , [ Data " " ] ) -> Element ( " iframe " , sanitize_attributes_white [ ( " src " , check_safeurl ) ; ( " width " , check_dimension ) ; ( " height " , check_dimension ) ; ( " frameborder " , check_int_rang... |
let element_sanitize_strict erase_script_contents erase_unallowed_tags permitted_tags_map dataF parentTag = function let perm_attrs = assoc tag permitted_tags_map in with | Not_found when erase_script_contents && evil_tag tag -> permit_safe_evil TagEraseWithContents elem | Not_found when erase_unallowed_tags -> permit_... |
let element_sanitize_permissive erase_script_contents erase_unallowed_tags dataF parentTag = function | Data text -> dataF parentTag text | Element ( tag , attributes , children ) as elem when evil_tag tag -> let exc = ( match erase_script_contents , erase_unallowed_tags with | true , _ -> TagEraseWithContents | false ... |
let element_strip allow_breaks erase_script_contents dataF parentTag = function raise TagEraseWithContents ; ; |
let rec map_document_nodes parentTag ( f : string -> Nethtml . document -> Nethtml . document ) = function in | TagEraseWithContents -> map_document_nodes parentTag f xs ; ; |
let transform_string f src = ; ; |
type url_detection = Url of string | Text of string ; ; |
let re_link = Str . regexp_case_fold " ( \\ http \\| https \\| ftp \\| feed \\| news \\| mailto ) [ \\:// a - z0 - 9_ . ] ( ( [ -+\\/\\^ \ t \ r \ n , . ] [ , . ] [ <>\\|^ \ r \ n ] ) ) " ; ; \\*\\? |
let rec detect_links s start = try |
type required_sanity_level = Transparent | Permissive | Aggressive | NanoHTML of allow_breaks and allow_breaks = bool |
let sanity_levels_map = [ " transparent " , Transparent ; " permissive " , Permissive ; " agressive " , Aggressive ; " aggressive " , Aggressive ; " nanohtml " , NanoHTML true ; " nanotext " , NanoHTML false ] ; ; |
let sanity_levels = List . map fst ( List . remove_assoc " agressive " sanity_levels_map ) ; ; |
let sanity_level_of_string s = try List . assoc s sanity_levels_map with Not_found -> raise ( Failure ( " Sanity level is none of " ^ String . concat " , " sanity_levels ) ) ; ; |
type word_break_method = | NoWordBreak | NoURLWordBreak | NoStandaloneURLWordBreak | DumbWordBreak |
let wordbreak break_long_words : string -> Nethtml . document -> Nethtml . document = let wbr = " < wbr ></ wbr " > in let fmap f = function | ( Data s ) -> Data ( f s ) | _ -> raise UnexpectedNodeType in let with_detected_links f s = String . concat " " ( List . map f ( detect_links s 0 ) ) in match break_long_words w... |
type t = { sources : SanitizeTransform . SourceSet . t ; sinks : SanitizeTransform . SinkSet . t ; } |
let empty = { sources = SanitizeTransform . SourceSet . empty ; sinks = SanitizeTransform . SinkSet . empty } |
let is_empty { sources ; sinks } = SanitizeTransform . SourceSet . is_empty sources && SanitizeTransform . SinkSet . is_empty sinks |
let pp formatter { sources ; sinks } = let sources = SanitizeTransform . SourceSet . elements sources |> List . map ~ f : SanitizeTransform . Source . show in let sinks = SanitizeTransform . SinkSet . elements sinks |> List . map ~ f : SanitizeTransform . Sink . show in sources @ sinks |> String . concat ~ sep " " :: |... |
let show = Format . asprintf " % a " pp |
let from_sources sources = { sources ; sinks = SanitizeTransform . SinkSet . empty } |
let from_sinks sinks = { sources = SanitizeTransform . SourceSet . empty ; sinks } |
let union { sources = sources_left ; sinks = sinks_left } { sources = sources_right ; sinks = sinks_right } = { sources = SanitizeTransform . SourceSet . union sources_left sources_right ; sinks = SanitizeTransform . SinkSet . union sinks_left sinks_right ; } |
let diff { sources = sources_left ; sinks = sinks_left } { sources = sources_right ; sinks = sinks_right } = { sources = SanitizeTransform . SourceSet . diff sources_left sources_right ; sinks = SanitizeTransform . SinkSet . diff sinks_left sinks_right ; } |
let subset { sources = sources_left ; sinks = sinks_left } { sources = sources_right ; sinks = sinks_right } = SanitizeTransform . SourceSet . subset sources_left sources_right && SanitizeTransform . SinkSet . subset sinks_left sinks_right |
let mem { sources ; sinks } = function | SanitizeTransform . Source source -> SanitizeTransform . SourceSet . mem source sources | SanitizeTransform . Sink sink -> SanitizeTransform . SinkSet . mem sink sinks |
let test remanent p s1 = let remanent , bool , report = p remanent in let _ = match report with | Some s2 -> Printf . fprintf remanent . Sanity_test_sig . output " % s : % s \ n " s1 s2 | None -> Printf . fprintf remanent . Sanity_test_sig . output " % s : % s \ n " s1 ( if bool then " ok " else " FAIL " ) ! in remanen... |
let gen_aux parameters allocate get update = ( fun error b c d e old_handler -> let old_dictionary = get old_handler in let error , output = allocate parameters error b c d e old_dictionary in match output with | None -> error , None | Some ( i , a , b , new_dic ) -> error , Some ( i , a , b , update old_handler new_di... |
let gen parameters allocate_uniquely allocate get update x error b c d e old_handler = match x with | true -> gen_aux parameters allocate_uniquely get update error b c d e old_handler | false -> gen_aux parameters allocate get update error b c d e old_handler |
let remanent parameters = Sanity_test_sig . initial_remanent ( Boolean_mvbdu . init_remanent parameters ) ( gen parameters Boolean_mvbdu . D_mvbdu_skeleton . allocate_uniquely Boolean_mvbdu . D_mvbdu_skeleton . allocate ( fun x -> x . Memo_sig . mvbdu_dictionary ) Mvbdu_core . update_dictionary ) ( gen parameters Boole... |
module LI = ( Map_wrapper . Make ( I ) : Map_wrapper . S_with_logs with type ' a Map . t = ' a I . Map . t and type elt = int and type Set . t = I . Set . t ) |
let ( ) = let error = Exception . empty_error_handler in let parameters = Remanent_parameters . get_parameters let _ = Exception . print parameters error in let counting_test_list = Counting_test . test_counting_procedure parameters in let remanent_bdd , bdu_test_list = Mvbdu_test . bdu_test ( remanent parameters ) par... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.