text
stringlengths
0
601k
let error_of_errno e = Uring . error_of_errno ( abs e )
module Uri_re = struct open Re module Raw = struct let ( ) + a b = seq [ a ; b ] let ( ) / a b = alt [ a ; b ] let gen_delims = Posix . re " [ [ ] ] " :/?#\\\\@ let sub_delims = Posix . re " [ ' ( ) , ; ] " !$&*+= let c_at = char ' ' @ let c_colon = char ' ' : let c_slash = char ' ' / let c_slash2 = Posix . re " " // l...
type component = [ | ` Scheme | ` Authority | ` Userinfo | ` Host | ` Path | ` Query | ` Query_key | ` Query_value | ` Fragment ]
let rec iter_concat fn sep buf = function | last [ ] :: -> fn buf last | el :: rest -> fn buf el ; Buffer . add_string buf sep ; iter_concat fn sep buf rest | [ ] -> ( )
let rev_interject e lst = let rec aux acc = function | [ ] -> acc | x :: xs -> aux ( x :: e :: acc ) xs in match lst with | [ ] -> [ ] | h :: t -> aux [ h ] t
let compare_opt c t t ' = match t , t ' with | None , None -> 0 | Some _ , None -> 1 | None , Some _ -> - 1 | Some a , Some b -> c a b
let rec compare_list f t t ' = match t , t ' with | [ ] , [ ] -> 0 | _ :: _ , [ ] -> 1 | [ ] , _ :: _ -> - 1 | x :: xs , y :: ys -> match f x y with 0 -> compare_list f xs ys | c -> c
type safe_chars = bool array
module type Scheme = sig val safe_chars_for_component : component -> safe_chars val normalize_host : string option -> string option val canonicalize_port : int option -> int option val canonicalize_path : string list -> string list end
module Generic : Scheme = struct let sub_delims a = let subd = " ' ( ) , ; " !$&*+= in for i = 0 to String . length subd - 1 do let c = Char . code subd . [ i ] in a . ( c ) <- true done ; a let safe_chars : safe_chars = let a = Array . make 256 false in let always_safe = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs...
module Http : Scheme = struct include Generic let normalize_host = function | Some hs -> Some ( String . lowercase_ascii hs ) | None -> None let canonicalize_port = function | None -> None | Some 80 -> None | Some x -> Some x let canonicalize_path = function | [ ] -> [ " " ] / | x -> x end
module Https : Scheme = struct include Http let canonicalize_port = function | None -> None | Some 443 -> None | Some x -> Some x end
module File : Scheme = struct include Generic let normalize_host = function | Some hs -> let hs = String . lowercase_ascii hs in if hs " = localhost " then Some " " else Some hs | None -> None end
module Urn : Scheme = struct include Generic end
let module_of_scheme = function | Some s -> begin match String . lowercase_ascii s with | " http " -> ( module Http : Scheme ) | " https " -> ( module Https : Scheme ) | " file " -> ( module File : Scheme ) | " urn " -> ( module Urn : Scheme ) | _ -> ( module Generic : Scheme ) end | None -> ( module Generic : Scheme )
module Pct : sig type encoded type decoded val encode : ? scheme : string -> ? component : component -> decoded -> encoded val decode : encoded -> decoded val empty_decoded : decoded val cast_encoded : string -> encoded val cast_decoded : string -> decoded val uncast_encoded : encoded -> string val uncast_decoded : dec...
let pct_encode ? scheme ( ? component ` = Path ) s = Pct . ( uncast_encoded ( encode ? scheme ~ component ( cast_decoded s ) ) )
let pct_decode s = Pct . ( uncast_decoded ( decode ( cast_encoded s ) ) )
module Userinfo = struct type t = string * string option let compare ( u , p ) ( u ' , p ' ) = match String . compare u u ' with | 0 -> compare_opt String . compare p p ' | c -> c let userinfo_of_encoded us = match Stringext . split ~ max : 2 ~ on ' ' :: us with | [ ] -> ( " " , None ) | [ u ] -> ( pct_decode u , None ...
let encoded_of_userinfo ? scheme = Userinfo . encoded_of_userinfo ? scheme
module Path = struct type t = string list let compare = compare_list String . compare let path_of_encoded ps = let tokl = Stringext . full_split ps ~ on ' ' :/ in List . map pct_decode tokl let remove_dot_segments p = let revp = List . rev p in let rec loop ascension outp = function | " " " . . " /:::: r | " . . " :: r...
let encoded_of_path ? scheme = Path . encoded_of_path ? scheme
module Query = struct type kv = ( string * string list ) list type t = | KV of kv | Raw of string option * kv Lazy . t let compare x y = match x , y with | KV kvl , KV kvl ' | Raw ( _ , lazy kvl ) , KV kvl ' | KV kvl , Raw ( _ , lazy kvl ' ) -> compare_list ( fun ( k , vl ) ( k ' , vl ' ) -> match String . compare k k ...
let encoded_of_query ? scheme = Query . encoded_of_query ? scheme
type t = { scheme : Pct . decoded option ; userinfo : Userinfo . t option ; host : Pct . decoded option ; port : int option ; path : Path . t ; query : Query . t ; fragment : Pct . decoded option ; }
let empty = { scheme = None ; userinfo = None ; host = None ; port = None ; path = [ ] ; query = Query . Raw ( None , Lazy . from_val [ ] ) ; fragment = None ; }
let compare_decoded = Pct . unlift_decoded2 String . compare
let compare_decoded_opt = compare_opt compare_decoded
let compare t t ' = ( match compare_decoded_opt t . host t ' . host with | 0 -> ( match compare_decoded_opt t . scheme t ' . scheme with | 0 -> ( match compare_opt ( fun p p ' -> if p < p ' then - 1 else if p > p ' then 1 else 0 ) t . port t ' . port with | 0 -> ( match compare_opt Userinfo . compare t . userinfo t ' ....
let equal t t ' = compare t t ' = 0
let uncast_opt = function | Some h -> Some ( Pct . uncast_decoded h ) | None -> None
let cast_opt = function | Some h -> Some ( Pct . cast_decoded h ) | None -> None
let normalize schem uri = let module Scheme = ( val ( module_of_scheme ( uncast_opt schem ) ) : Scheme ) in let dob f = function | Some x -> Some ( Pct . unlift_decoded f x ) | None -> None in { uri with scheme = dob String . lowercase_ascii uri . scheme ; host = cast_opt ( Scheme . normalize_host ( uncast_opt uri . ho...
let make ? scheme ? userinfo ? host ? port ? path ? query ? fragment ( ) = let decode = function | Some x -> Some ( Pct . cast_decoded x ) | None -> None in let host = match userinfo , host , port with | _ , Some _ , _ | None , None , None -> host | Some _ , None , _ | _ , None , Some _ -> Some " " in let userinfo = ma...
let of_string s = let get_opt_encoded s n = try Some ( Pct . cast_encoded ( Re . Group . get s n ) ) with Not_found -> None in let get_opt s n = try let pct = Pct . cast_encoded ( Re . Group . get s n ) in Some ( Pct . decode pct ) with Not_found -> None in let subs = Re . exec Uri_re . uri_reference s in let scheme = ...
let to_string uri = let scheme = match uri . scheme with | Some s -> Some ( Pct . uncast_decoded s ) | None -> None in let buf = Buffer . create 128 in let add_pct_string ( ? component ` = Path ) x = Buffer . add_string buf ( Pct . uncast_encoded ( Pct . encode ? scheme ~ component x ) ) in ( match uri . scheme with | ...
let get_decoded_opt = function None -> None | Some x -> Some ( Pct . uncast_decoded x )
let scheme uri = get_decoded_opt uri . scheme
let with_scheme uri = function | Some scheme -> { uri with scheme = Some ( Pct . cast_decoded scheme ) } | None -> { uri with scheme = None }
let host uri = get_decoded_opt uri . host
let with_host uri = function | Some host -> { uri with host = Some ( Pct . cast_decoded host ) } | None -> { uri with host = None }
let host_with_default ( ? default " = localhost " ) uri = match host uri with | None -> default | Some h -> h
let userinfo uri = match uri . userinfo with | None -> None | Some userinfo -> Some ( Pct . uncast_encoded ( match uri . scheme with | None -> encoded_of_userinfo userinfo | Some s -> encoded_of_userinfo ~ scheme ( : Pct . uncast_decoded s ) userinfo ) )
let with_userinfo uri userinfo = let userinfo = match userinfo with | Some u -> Some ( userinfo_of_encoded u ) | None -> None in match host uri with | None -> { uri with host = Some ( Pct . cast_decoded " " ) ; userinfo = userinfo } | Some _ -> { uri with userinfo = userinfo }
let user uri = match uri . userinfo with | None -> None | Some ( user , _ ) -> Some user
let password uri = match uri . userinfo with | None | Some ( _ , None ) -> None | Some ( _ , Some pass ) -> Some pass
let with_password uri password = let result userinfo = match host uri with | None -> { uri with host = Some ( Pct . cast_decoded " " ) ; userinfo = userinfo } | Some _ -> { uri with userinfo = userinfo } in match uri . userinfo , password with | None , None -> uri | None , Some _ -> result ( Some ( " " , password ) ) |...
let port uri = uri . port
let with_port uri port = match host uri with | Some _ -> { uri with port = port } | None -> begin match port with | None -> { uri with host = None ; port = None } | Some _ -> { uri with host = Some ( Pct . cast_decoded " " ) ; port = port } end
let path uri = Pct . uncast_encoded ( match uri . scheme with | None -> encoded_of_path uri . path | Some s -> encoded_of_path ~ scheme ( : Pct . uncast_decoded s ) uri . path )
let with_path uri path = let path = path_of_encoded path in match host uri , path with | None , _ | Some _ , " " /:: _ | Some _ , [ ] -> { uri with path = path } | Some _ , _ -> { uri with path " " =/:: path }
let fragment uri = get_decoded_opt uri . fragment
let with_fragment uri = function | None -> { uri with fragment = None } | Some frag -> { uri with fragment = Some ( Pct . cast_decoded frag ) }
let query uri = Query . kv uri . query
let verbatim_query uri = Query . ( match uri . query with | Raw ( qs , _ ) -> qs | KV [ ] -> None | KV kv -> Some ( encoded_of_query ? scheme ( : scheme uri ) kv ) )
let get_query_param ' uri k = Query . ( find ( kv uri . query ) k )
let get_query_param uri k = match get_query_param ' uri k with | None -> None | Some v -> Some ( String . concat " , " v )
let with_query uri query = { uri with query = Query . KV query }
let q_s q = List . map ( fun ( k , v ) -> k , [ v ] ) q
let with_query ' uri query = with_query uri ( q_s query )
let add_query_param uri p = Query . ( { uri with query = KV ( p ( :: kv uri . query ) ) } )
let add_query_param ' uri ( k , v ) = Query . ( { uri with query = KV ( ( k , [ v ] ) ( :: kv uri . query ) ) } )
let add_query_params uri ps = Query . ( { uri with query = KV ( ps ( @ kv uri . query ) ) } )
let add_query_params ' uri ps = Query . ( { uri with query = KV ( ( q_s ps ) ( @ kv uri . query ) ) } )
let remove_query_param uri k = Query . ( { uri with query = KV ( List . filter ( fun ( k ' , _ ) -> k <> k ' ) ( kv uri . query ) ) } )
let with_uri ? scheme ? userinfo ? host ? port ? path ? query ? fragment uri = let with_path_opt u o = match o with | None -> with_path u " " | Some p -> with_path u p in let with_query_opt u o = match o with | None -> with_query u [ ] | Some q -> with_query u q in let with_ f o u = match o with | None -> u | Some x ->...
let path_and_query uri = match ( path uri ) , ( query uri ) with " " , | [ ] -> " " / " " , | q -> let scheme = uncast_opt uri . scheme in Printf . sprintf " /?% s " ( encoded_of_query ? scheme q ) | p , [ ] -> p | p , q -> let scheme = uncast_opt uri . scheme in Printf . sprintf " % s ?% s " p ( encoded_of_query ? sch...
let resolve schem base uri = let schem = Some ( Pct . cast_decoded ( match scheme base with | None -> schem | Some scheme -> scheme ) ) in normalize schem Path . ( match scheme uri , userinfo uri , host uri with | Some _ , _ , _ -> { uri with path = remove_dot_segments uri . path } | None , Some _ , _ | None , _ , Some...
let canonicalize uri = let uri = resolve " " empty uri in let module Scheme = ( val ( module_of_scheme ( uncast_opt uri . scheme ) ) : Scheme ) in { uri with port = Scheme . canonicalize_port uri . port ; path = Scheme . canonicalize_path uri . path ; }
let pp ppf uri = Format . pp_print_string ppf ( to_string uri )
let pp_hum ppf uri = Format . pp_print_string ppf ( to_string uri )
open Re module Raw = struct let ( ) + a b = seq [ a ; b ] let ( ) / a b = alt [ a ; b ] let sub_delims = Posix . re " [ ' ( ) , ; ] " !$&*+= let c_at = char ' ' @ let c_colon = char ' ' : let c_dot = char ' . ' let unreserved = Posix . re " [ A - Za - z0 - 9 . - _ ] " ~ let hexdig = Posix . re " [ 0 - 9A - Fa - f ] " l...
let search_string keys k = let rec loop keys k low high = if low > high then ( - 1 ) else begin let mid = ( high + low ) / 2 in let diff = String . compare k keys . ( mid ) in if diff < 0 then loop keys k low ( mid - 1 ) else if diff > 0 then loop keys k ( mid + 1 ) high else mid end in loop keys k 0 ( Array . length k...
let search_int keys k = let rec loop keys k low high = if low > high then ( - 1 ) else begin let mid = ( high + low ) / 2 in let diff = k - keys . ( mid ) in if diff < 0 then loop keys k low ( mid - 1 ) else if diff > 0 then loop keys k ( mid + 1 ) high else mid end in loop keys k 0 ( Array . length keys - 1 )
let lookup search ( keys , values ) k = let i = search keys k in if i < 0 then [ ] else values . ( i )
let service_of_tcp_port p = lookup search_int service_of_tcp_port_tables p
let service_of_udp_port p = lookup search_int service_of_udp_port_tables p
let tcp_port_of_service s = lookup search_string tcp_port_of_service_tables s
let udp_port_of_service s = lookup search_string udp_port_of_service_tables s
let port_of_uri ? default lookupfn uri = match Uri . port uri with | Some _port as x -> x | None -> begin match Uri . scheme uri , default with | None , None -> None | None , Some scheme | Some scheme , _ -> begin match lookupfn scheme with [ ] | -> None | hd :: _ -> Some hd end end
let tcp_port_of_uri ? default uri = port_of_uri ? default tcp_port_of_service uri
let udp_port_of_uri ? default uri = port_of_uri ? default udp_port_of_service uri
module Derived = struct | ` Generic | ` Custom of ( component * string * string ) scheme : string option [ @ default None ] [ @ sexp_drop_default . sexp ] ; userinfo : string option [ @ default None ] [ @ sexp_drop_default . sexp ] ; host : string option [ @ default None ] [ @ sexp_drop_default . sexp ] ; port : int op...
let t_of_sexp sexp = Uri . make ? scheme : t . scheme ? userinfo : t . userinfo ? host : t . host ? port : t . port ~ path : t . path ~ query : t . query ? fragment : t . fragment ( )
let sexp_of_t t = }
let compare a b = Uri . compare a b
let equal a b = Uri . equal a b
let resolve url_to_string directories reference = let resolver = Resolver . create ~ important_digests : false ~ directories ~ open_modules [ ] : in let reference = let open Odoc_model in let warnings_options = { Error . warn_error = true ; print_warnings = true } in Semantics . parse_reference reference |> Error . han...
let reference_to_url_html root_url = let url_to_string url = let base = match root_url with | None | Some " " -> " " | Some base -> if base . [ String . length base - 1 ] = ' ' / then base else base ^ " " / in Odoc_html . Link . ( href ~ resolve ( : Base base ) url ) in resolve url_to_string
let reference_to_url_latex = let url_to_string url = Odoc_latex . Generator . Link . label url in resolve url_to_string
let rec map_html_hrefs f html = List . ( rev ( rev_map ( map_html_element_hrefs f ) html ) ) | Nethtml . Data _ as d -> d | Nethtml . Element ( ( " a " | " link " ) as e , args , sub ) -> let href , args = List . partition ( fun ( a , _ ) -> a = " href " ) args in begin match href with | [ ] -> Nethtml . Element ( e , ...
let map_html_file f in_file out_file = let fh = open_in in_file in let html = Nethtml . parse_document ( Lexing . from_channel fh ) ~ dtd : Utils . relaxed_html40_dtd in close_in fh ; let html = map_html_hrefs f html in let fh = open_out out_file in let out = new Netchannels . output_channel fh in out # output_string "...
let map_css_file f in_file out_file = let fh = open_in in_file in let ch = new Netchannels . input_channel fh in let css = Netchannels . string_of_in_obj_channel ch in close_in fh ; let url_re = Str . regexp " url ( ( [ ( ) ] ) ) " \\^*\\ in let css = Str . global_substitute url_re ( fun css -> Printf . sprintf " url (...
let map_file f in_file out_file = if Filename . check_suffix in_file " . html " || Filename . check_suffix in_file " . xhtml " then map_html_file f in_file out_file else if Filename . check_suffix in_file " . css " then map_css_file f in_file out_file else raise ( Unknown_file_type in_file )
let rec remove_common_prefix p1 p2 = match p1 , p2 with | d1 :: p1 , d2 :: p2 when d1 = d2 -> remove_common_prefix p1 p2 | _ -> p1 , p2
let revert_path = let rec revert filename = match filename with | [ ] | [ _ ] -> [ ] | _ :: tl -> " . . " :: revert tl in fun to_base filename -> let filename = Neturl . norm_path ( Neturl . split_path filename ) in let to_base , filename = remove_common_prefix to_base filename in revert filename @ to_base
match xs with | [ ] -> ys | x :: xs -> x :: append xs ys } ] | | [ ] -> [ ] | xs :: xss -> append xs ( flatten xss ) ^^^^^^^^^^^^^^^^^^^^^^^ } ] | | [ ] -> [ ] | xs :: xss -> let [ @ tail_mod_cons ] rec append_flatten xs xss = match xs with | [ ] -> flatten xss | x :: xs -> x :: append_flatten xs xss in append_flatten ...
let rec flatten = function | [ ] -> [ ] | xs :: xss -> let [ @ tail_mod_cons ] rec append_flatten xs xss = match xs with | [ ] -> flatten xss | x :: xs -> x :: append_flatten xs xss in append_flatten xs xss ^^^^^^^^^^^ } ] |
module Tail_calls_to_non_specialized_functions = struct let list_id = function | [ ] -> [ ] | x :: xs -> x :: xs let [ @ tail_mod_cons ] rec filter_1 f li = match li with | [ ] -> [ ] | x :: xs -> if f x then x :: filter_1 f xs else list_id ( filter_1 f xs ) let [ @ tail_mod_cons ] rec filter_2 f li = match li with | [...
module Tail_calls_to_non_specialized_functions : sig val list_id : ' a list -> ' a list val filter_1 : ( ' a -> bool ) -> ' a list -> ' a list val filter_2 : ( ' a -> bool ) -> ' a list -> ' a list end } ] |