Skip to content

Commit 9134eb8

Browse files
author
hhas
committed
* fixed a bug in Objects' DictionaryCollection where getKeys and getKeysAndValues methods returned date keys without copying them first (since date values are mutable, this could corrupt dictionary's internal state if user subsequently modified those dates)
* in Web, renamed `escape/unescape URL characters` and `parse/format JSON` handlers; added `encode/decode Base64` handlers; tidied `send HTTP request` implementation * in File and Web, rejigged `_NSStringEncodings` to eliminate magic numbers * updated TO DOs
1 parent 68ea228 commit 9134eb8

File tree

10 files changed

+75
-22
lines changed

10 files changed

+75
-22
lines changed

File.scptd/Contents/Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
<key>bundleDividerCollapsed</key>
1616
<false/>
1717
<key>bundlePositionOfDivider</key>
18-
<real>839</real>
18+
<real>755</real>
1919
<key>dividerCollapsed</key>
2020
<false/>
2121
<key>eventLogLevel</key>
2222
<integer>0</integer>
2323
<key>name</key>
2424
<string>ScriptWindowState</string>
2525
<key>positionOfDivider</key>
26-
<real>524</real>
26+
<real>683</real>
2727
<key>savedFrame</key>
28-
<string>116 33 1088 744 0 0 1280 777 </string>
28+
<string>719 140 1004 903 0 0 1920 1057 </string>
2929
<key>selectedTab</key>
3030
<string>log</string>
3131
</dict>
562 Bytes
Binary file not shown.

Objects.scptd/Contents/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
<key>name</key>
2424
<string>ScriptWindowState</string>
2525
<key>positionOfDivider</key>
26-
<real>521</real>
26+
<real>800</real>
2727
<key>savedFrame</key>
28-
<string>123 33 982 744 0 0 1280 777 </string>
28+
<string>538 34 982 1023 0 0 1920 1057 </string>
2929
<key>selectedTab</key>
3030
<string>log</string>
3131
</dict>

Objects.scptd/Contents/Resources/Objects.sdef

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<documentation>
1212
<html><![CDATA[
1313
14-
<p>Unlike AppleScript records, which are predefined groups of properties whose values are identified by keyword or identifier, dictionary objects are dynamic collections of key-value pairs that can be added and removed at any time. Dictionary keys are typically text values, though numbers, dates, and type and constant symbols can also be used.</p>
14+
<p>Unlike AppleScript records, which are predefined groups of properties whose values are identified by keyword or identifier, dictionary objects are dynamic collections of key-value pairs that can be added and removed at any time. Dictionary keys can be text, numbers, dates, and/or type and constant symbols.</p>
1515
1616
1717
<h3>Examples</h3>
@@ -55,31 +55,31 @@ log obj's getItem("banana") -- Error -1728: "Item not found."</code></pre>
5555
<dt><code>containsItem(<var>theKey</var>)</code></dt>
5656
<dd><p>Does the collection contain a key-value pair with the specified key?</p>
5757
<ul>
58-
<li><var>theKey</var> : <tt>text</tt></li>
58+
<li><var>theKey</var> : <tt>text, number, date, type or constant</tt></li>
5959
<li>Result: <tt>boolean</tt></li>
6060
</ul>
6161
</dd>
6262
6363
<dt><code>addItem(<var>theKey</var>, <var>theValue</var>)</code></dt>
6464
<dd><p>Add a key-value pair to the collection</p>
6565
<ul>
66-
<li><var>theKey</var> : <tt>text</tt></li>
66+
<li><var>theKey</var> : <tt>text, number, date, type or constant</tt></li>
6767
<li><var>theValue</var> : <tt>anything</tt></li>
6868
</ul>
6969
</dd>
7070
7171
<dt><code>removeItem(<var>theKey</var>)</code></dt>
7272
<dd><p>Remove a key-value pair from the collection</p>
7373
<ul>
74-
<li><var>theKey</var> : <tt>text</tt></li>
74+
<li><var>theKey</var> : <tt>text, number, date, type or constant</tt></li>
7575
<li>Result: <tt>anything</tt> – the removed value</li>
7676
</ul>
7777
</dd>
7878
7979
<dt><code>getItem(<var>theKey</var>)</code></dt>
8080
<dd><p>Get the value for the given key from the collection</p>
8181
<ul>
82-
<li><var>theKey</var> : <tt>text</tt></li>
82+
<li><var>theKey</var> : <tt>text, number, date, type or constant</tt></li>
8383
<li>Result: <tt>anything</tt> – the removed value</li>
8484
</ul>
8585
</dd>
-214 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf410
1+
{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf460
22
{\fonttbl}
33
{\colortbl;\red255\green255\blue255;}
44
}

TODOs.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ File
2020
----------------------------------------------------------------------
2121

2222

23+
- add support for enumeration type in `parse command line arguments`, where valueType is a list of allowed text values, e.g. {"yes", "no", "maybe"}; allowed chars would be same as for long option names (Q. should it be case sensitive?)
24+
2325
- Standard Additions' `read` and `write` commands don't always provide good explanatory error messages (e.g. passing wrong `as` parameter just gives 'Parameter error.' -50); Cocoa error messages often aren't very helpful either. Not sure there's anything can be done about this.
2426

2527
- is there any benefit to adding `with UTF8 byte order mark` option to `write to file`? (NSString automatically adds UTF16/32 BOMs, but doesn't add UTF8 BOM for compatibility's sake; however, users might want to add UTF8 BOM to improve portability of files they intend to distribute)
@@ -144,7 +146,22 @@ Text
144146

145147

146148
----------------------------------------------------------------------
147-
Other libraries
149+
Web
150+
----------------------------------------------------------------------
151+
152+
153+
- in `send HTTP request`:
154+
155+
-how to support authentication, e.g. tie into keychain? (might be best to leave that for now)
156+
157+
- requestBodyData/responseBodyType could also be file object/`file`, in which case upload/download tasks could be used (Q. will NSSession supply Content-Length automatically when a file is given? also, will it supply Content-Type automatically, or is there a way to get file's MIME type via Cocoa APIs?)
158+
159+
- if responseBodyType is `text` and requestHeaders doesn't include "Accept*" headers, add appropriate content negotiation header (e.g. "Accept: text/*") automatically? (what about common application/… headers, e.g. application/json, application/xml? TBH, it'd be a shot in the dark; probably best to leave it entirely to user)
160+
161+
162+
163+
----------------------------------------------------------------------
164+
Additional libraries
148165
----------------------------------------------------------------------
149166

150167

@@ -158,3 +175,16 @@ Other libraries
158175

159176

160177

178+
----------------------------------------------------------------------
179+
Other issues
180+
----------------------------------------------------------------------
181+
182+
183+
- Should (and can?) ALL ObjC class, method, enum, etc names always be enclosed in pipes? e.g. The File library was accidentally recompiled and resaved after AS converted 'NSURL' identifiers to 'nsurl', causing handlers that used it to break as ASOC, unlike AS, is case-sensitive.
184+
185+
Normalizing identifier case in not just current script but all imported scripts too is a fundamental AS flaw that will continue to break users' ASOC code until fixed at source, but these libraries need to be as robust as possible, even if that means crudding up the ASOC parts with pipes.
186+
187+
The big annoyance is that unless identical names but with different case are also defined without pipes, AS will remove the pipes from names that do have them on compilation, whereupon the library code is right back where it started, at risk of breaking in future use.
188+
189+
190+

Web.scptd/Contents/Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
<key>bundleDividerCollapsed</key>
1616
<false/>
1717
<key>bundlePositionOfDivider</key>
18-
<real>622</real>
18+
<real>886</real>
1919
<key>dividerCollapsed</key>
2020
<false/>
2121
<key>eventLogLevel</key>
2222
<integer>2</integer>
2323
<key>name</key>
2424
<string>ScriptWindowState</string>
2525
<key>positionOfDivider</key>
26-
<real>522</real>
26+
<real>802</real>
2727
<key>savedFrame</key>
28-
<string>41 33 871 744 0 0 1280 777 </string>
28+
<string>217 33 1135 1024 0 0 1920 1057 </string>
2929
<key>selectedTab</key>
3030
<string>result</string>
3131
</dict>
5.33 KB
Binary file not shown.

Web.scptd/Contents/Resources/Web.sdef

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,28 @@
5454
</record-type>
5555

5656

57-
<command name="escape URL characters" code="Web:EscU" description="Replace “non-safe” characters in a text value with the corresponding “%XX” escapes suitable for use in a URL">
57+
<command name="encode URL characters" code="Web:EscU" description="Replace “non-safe” characters in a text value with the corresponding “%XX” escapes suitable for use in a URL">
5858
<direct-parameter type="text"/>
5959
<parameter name="preserving" code="Safe" type="text" description="any additional ASCII characters that should not be escaped (default: &quot;&quot;)"/>
6060
<result type="text"/>
6161
<documentation>
6262
<html><![CDATA[
6363
<p>By default, this converts all characters except <code>A-Za-z0-9_.-</code> to UTF8-based <code>%<var>XX</var></code> escape codes. For example, to escape a resource path, preserving path separators:</p>
6464
65-
<pre><code>escape URL characters "/foo bar/ø.txt" preserving "/" → "/foo%20bar/%C3%B8.txt"</code></pre>
65+
<pre><code>encode URL characters "/foo bar/ø.txt" preserving "/" → "/foo%20bar/%C3%B8.txt"</code></pre>
6666
]]></html>
6767
</documentation>
6868
</command>
6969

7070

71-
<command name="unescape URL characters" code="Web:UneU" description="Replace “%XX” escapes in a text value with the corresponding characters">
71+
<command name="decode URL characters" code="Web:UneU" description="Replace “%XX” escapes in a text value with the corresponding characters">
7272
<direct-parameter type="text"/>
7373
<result type="text"/>
7474
<documentation>
7575
<html><![CDATA[
7676
<p>All UTF8-based <code>%<var>XX</var></code> escape codes will be automatically replaced with the corresponding characters. If an escape sequence does not represent a valid UTF8 codepoint, an error is raised instead.</p>
7777
78-
<pre><code></code></pre>
78+
<pre><code>decode URL characters "/foo%20bar/%C3%B8.txt" → "/foo bar/ø.txt"</code></pre>
7979
]]></html>
8080
</documentation>
8181
</command>
@@ -111,18 +111,30 @@
111111

112112
<suite name="Convert Data" code="****">
113113

114-
<command name="parse JSON" code="Web:PJSN" description="Parse JSON text as an AppleScript value">
114+
<command name="decode Base64" code="Web:PB64" description="Convert text from Base64 encoding">
115+
<direct-parameter type="text"/>
116+
<result type="text"/>
117+
</command>
118+
119+
<command name="encode Base64" code="Web:FB64" description="Convert text to Base64 encoding">
120+
<direct-parameter type="text"/>
121+
<result type="text"/>
122+
</command>
123+
124+
<command name="decode JSON" code="Web:PJSN" description="Convert JSON text to an AppleScript value">
115125
<direct-parameter type="text"/>
116126
<parameter name="fragments allowed" code="Frag" type="boolean" optional="yes" description="(default: false)"/>
117127
<result type="any"/>
118128
</command>
119129

120-
<command name="format JSON" code="Web:FJSN" description="Format an AppleScript value as JSON text">
130+
<command name="encode JSON" code="Web:FJSN" description="Convert an AppleScript value to JSON text">
121131
<direct-parameter type="any"/>
122132
<parameter name="extra white space" code="EWSp" type="boolean" optional="yes" description="(default: false)"/>
123133
<result type="text"/>
124134
</command>
125135

136+
<!-- TO DO: what else? e.g. HTML entitites? -->
137+
126138
</suite>
127139

128140

@@ -162,6 +174,10 @@
162174
<html><![CDATA[
163175
<pre><code>{ headerName:<var>text</var>,
164176
headerValue:<var>text</var> }</code></pre>
177+
178+
<p>For example:</p>
179+
180+
<pre><code>{headerName:"Content-Type", headerValue:"application/json; charset=utf-8"}</code></pre>
165181
]]></html>
166182
</documentation>
167183
</record-type>
@@ -178,9 +194,16 @@
178194
</record-type>
179195

180196

181-
<command name="describe HTTP status code" code="Web:DStC" description="Get a short description of the given HTTP status code (e.g. 404 → “not found”)">
197+
<command name="HTTP status name" code="Web:DStC" description="Get a short description of the given HTTP status code">
182198
<direct-parameter type="integer"/>
183199
<result type="text"/>
200+
<documentation>
201+
<html><![CDATA[
202+
<p>For example:</p>
203+
204+
<pre><code>HTTP status name 404 → “not found”</code></pre>
205+
]]></html>
206+
</documentation>
184207
</command>
185208

186209
</suite>

0 commit comments

Comments
 (0)