| 927 | complete_browse = complete_dump |
| 928 | |
| 929 | def dictdump(self, dict, resource): |
| 930 | superexec = False # TBD: experimental privilege escalation |
| 931 | if not dict: # dump whole dictstack if optional dict parameter is empty |
| 932 | # dict = 'superdict' |
| 933 | # self.chitchat("No dictionary given - dumping everything (might take some time)") |
| 934 | return self.onecmd("help dump") |
| 935 | # recursively dump contents of a postscript dictionary and convert them to json |
| 936 | str_send = '/superdict {<< /universe countdictstack array dictstack >>} def\n' \ |
| 937 | '/strcat {exch dup length 2 index length add string dup\n' \ |
| 938 | 'dup 4 2 roll copy length 4 -1 roll putinterval} def\n' \ |
| 939 | '/remove {exch pop () exch 3 1 roll exch strcat strcat} def\n' \ |
| 940 | '/escape { {(") search {remove}{exit} ifelse} loop \n' \ |
| 941 | ' {(/) search {remove}{exit} ifelse} loop \n' \ |
| 942 | ' {(\\\) search {remove}{exit} ifelse} loop } def\n' \ |
| 943 | '/clones 220 array def /counter 0 def % performance drawback\n' \ |
| 944 | '/redundancy { /redundant false def\n' \ |
| 945 | ' clones {exch dup 3 1 roll eq {/redundant true def} if} forall\n' \ |
| 946 | ' redundant not {\n' \ |
| 947 | ' dup clones counter 3 2 roll put % put item into clonedict\n' \ |
| 948 | ' /counter counter 1 add def % auto-increment counter\n' \ |
| 949 | ' } if redundant} def % return true or false\n' \ |
| 950 | '/wd {redundancy {pop q (<redundant dict>) p q bc s}\n' \ |
| 951 | '{bo n {t exch q 128 a q c dump n} forall bc bc s} ifelse } def\n' \ |
| 952 | '/wa {q q bc s} def\n' \ |
| 953 | '% /wa {ao n {t dump n} forall ac bc s} def\n' \ |
| 954 | '/n {(\\n) print} def % newline\n' \ |
| 955 | '/t {(\\t) print} def % tabulator\n' \ |
| 956 | '/bo {({) print} def % bracket open\n' \ |
| 957 | '/bc {(}) print} def % bracket close\n' \ |
| 958 | '/ao {([) print} def % array open\n' \ |
| 959 | '/ac {(]) print} def % array close\n' \ |
| 960 | '/q {(") print} def % quote\n' \ |
| 961 | '/s {(,) print} def % comma\n' \ |
| 962 | '/c {(: ) print} def % colon\n' \ |
| 963 | '/p { print} def % print string\n' \ |
| 964 | '/a {string cvs print} def % print any\n' \ |
| 965 | '/pe {escape print} def % print escaped string\n' \ |
| 966 | '/ae {string cvs escape print} def % print escaped any\n' \ |
| 967 | '/perms { readable {(r) p}{(-) p} ifelse\n' \ |
| 968 | ' writeable {(w) p}{(-) p} ifelse } def\n' \ |
| 969 | '/rwcheck { % readable/writeable check\n' \ |
| 970 | ' dup rcheck not {/readable false def} if\n' \ |
| 971 | ' dup wcheck not {/writeable false def} if perms } def\n' \ |
| 972 | '/dump {\n' \ |
| 973 | ' /readable true def /writeable true def\n' \ |
| 974 | ' dup type bo ("type": ) p q 16 a q s\n' \ |
| 975 | ' %%%% check permissions %%%\n' \ |
| 976 | ' ( "perms": ) p q\n' \ |
| 977 | ' dup type /stringtype eq {rwcheck} {\n' \ |
| 978 | ' dup type /dicttype eq {rwcheck} {\n' \ |
| 979 | ' dup type /arraytype eq {rwcheck} {\n' \ |
| 980 | ' dup type /packedarraytype eq {rwcheck} {\n' \ |
| 981 | ' dup type /filetype eq {rwcheck} {\n' \ |
| 982 | ' perms } % inherit perms from parent\n' \ |
| 983 | ' ifelse} ifelse} ifelse} ifelse} ifelse\n' \ |
| 984 | ' dup xcheck {(x) p}{(-) p} ifelse\n' \ |
| 985 | ' %%%% convert values to strings %%%\n' \ |
| 986 | ' q s ( "value": ) p\n' \ |