@@ -376,7 +376,7 @@ We'll start by writing a function ``get_inspection_page``
376376
377377 * It will accept keyword arguments for each of the possible query values
378378 * It will build a dictionary of request query parameters from incoming
379- keywords
379+ keywords, using INSPECTION_PARAMS as a template
380380 * It will make a request to the inspection service search page using this
381381 query
382382 * It will return the encoded content and the encoding used as a tuple
@@ -713,19 +713,18 @@ print the first of the many divs that match):
713713Parsing Restaurant Data
714714-----------------------
715715
716- Now that we have the records we want, we need to parse them. We want to preserve:
716+ Now that we have the records we want, we need to parse them.
717717
718718.. rst-class:: build
719719.. container::
720720
721- We' ll start by parsing out the information about the restaurant themselves :
721+ We' ll start by extracting information about the restaurants :
722722
723723 .. rst-class:: build
724724
725725 * Name
726726 * Address
727727 * Location
728- * ...
729728
730729 How is this information contained in our records?
731730
@@ -1133,7 +1132,7 @@ interaction over a network" - W3C
11331132
11341133.. nextslide:: Early Web Services
11351134
1136- RSS is one of the earliest forms of Web Services
1135+ ** RSS** is one of the earliest forms of Web Services
11371136
11381137.. rst-class:: build
11391138.. container::
@@ -1162,10 +1161,11 @@ procedures and pass arguments.
11621161 * Calls are made via HTTP GET, by passing an XML document
11631162 * Returns from a call are sent to the client in XML
11641163
1165- In python, you can access XML-RPC services using ` xmlrpclib` _ from the
1166- standard library
1164+ In python, you can access XML-RPC services using ` xmlrpc` _ from the
1165+ standard library. It has two libraries, ` ` xmlrpc.client` ` and
1166+ ` ` xmlrpc.server` `
11671167
1168- .. _xmlrpclib : https://docs.python.org/2 /library/xmlrpclib .html
1168+ .. _xmlrpc : https://docs.python.org/3.5 /library/xmlrpc .html
11691169
11701170.. nextslide:: SOAP
11711171
@@ -1189,129 +1189,11 @@ SOAP extends XML-RPC in a couple of useful ways:
11891189 * The best-known and best-supported module available is **Suds**
11901190 * The homepage is https://fedorahosted.org/suds/
11911191 * It can be installed using ` ` easy_install` ` or ` ` pip install` `
1192- * But it hasn't been updated since Sept. 2010.
1193-
1194- So we're going to move on
1195-
1196- .. nextslide:: If Not XML, Then What?
1197-
1198- XML is a pretty inefficient medium for transmitting data. There's a lot of
1199- extra characters transmitted that lack any meaning.
1200-
1201- .. rst-class:: build large centered
1202-
1203- **Let's Use JSON**
1204-
1205-
1206- JSON
1207- ----
1208-
1209- JavaScript Object Notation:
1210-
1211- .. rst-class:: build
1212- .. container::
1213-
1214- .. rst-class:: build
1215-
1216- * a lightweight data-interchange format
1217- * easy for humans to read and write
1218- * easy for machines to parse and generate
1219-
1220- Based on Two Structures:
1221-
1222- * object: ` ` { string: value, ...}` `
1223- * array: ` ` [value, value, ]` `
1224-
1225- .. rst-class:: centered
1226-
1227- pythonic, no?
1192+ * A ` fork of the library` _ compatible with Python 3 does exist
12281193
1194+ **I HATE SOAP**
12291195
1230- .. nextslide:: JSON Data Types
1231-
1232- JSON provides a few basic data types (see http://json.org/):
1233-
1234- .. rst-class:: build
1235- .. container::
1236-
1237- .. rst-class:: build
1238-
1239- * string: unicode, anything but " , \\ and control characters
1240- * number: any number, but json does not use octal or hexadecimal
1241- * object, array (we' ve seen these above)
1242- * true
1243- * false
1244- * null
1245-
1246- .. rst-class:: centered
1247-
1248- **No date type? OMGWTF??!!1!1**
1249-
1250- .. nextslide:: Dates in JSON
1251-
1252- You have two options:
1253-
1254- .. rst-class:: build
1255- .. container::
1256-
1257- .. container::
1258-
1259- Option 1 - Unix Epoch Time (number):
1260-
1261- .. code-block:: python
1262-
1263- >>> import time
1264- >>> time.time()
1265- 1358212616.7691269
1266-
1267- .. container::
1268-
1269- Option 2 - ISO 8661 (string):
1270-
1271- .. code-block:: python
1272-
1273- >>> import datetime
1274- >>> datetime.datetime.now().isoformat()
1275- ' 2013-01-14T17:18:10.727240'
1276-
1277-
1278- JSON in Python
1279- --------------
1280-
1281- You can encode python to json, and decode json back to python:
1282-
1283- .. rst-class:: build
1284- .. container::
1285-
1286- .. code-block:: python
1287-
1288- In [1]: import json
1289- In [2]: array = [1, 2, 3]
1290- In [3]: json.dumps(array)
1291- Out[3]: ' [1, 2, 3]'
1292- In [4]: orig = {' foo' : [1,2,3], ' bar' : ' my resumé' , ' baz' : True}
1293- In [5]: encoded = json.dumps(orig)
1294- In [6]: encoded
1295- Out[6]: ' {" foo" : [1, 2, 3], " bar" : " my resum\\ u00e9" , " baz" : true}'
1296- In [7]: decoded = json.loads(encoded)
1297- In [8]: decoded == orig
1298- Out[8]: True
1299-
1300- Customizing the encoder or decoder class allows for specialized serializations
1301-
1302-
1303- .. nextslide::
1304-
1305- the json module also supports reading and writing to *file-like objects* via
1306- ``json.dump(fp)`` and ``json.load(fp)`` (note the missing ' s' )
1307-
1308- .. rst-class:: build
1309- .. container::
1310-
1311- Remember duck-typing. Anything with a ``.write`` and a ``.read`` method is
1312- *file-like*
1313-
1314- This usage can be much more memory-friendly with large files/sources
1196+ .. _fork of the library` : https://github.com/cackharot/suds-py3
13151197
13161198.. nextslide:: What about WSDL?
13171199
@@ -1325,24 +1207,45 @@ interoperability.
13251207
13261208 .. rst-class:: centered
13271209
1328- Hardly ever
1210+ ** Hardly ever**
13291211
13301212 Another reason was to provide extensibility via custom types
13311213
13321214 * Does that really work in real life?*
13331215
13341216 .. rst-class:: centered
13351217
1336- Hardly ever
1218+ ** Hardly ever**
1219+
1220+ .. nextslide:: I have to write XML?
1221+
1222+ In addition, XML is a pretty inefficient medium for transmitting data. There' s
1223+ a lot of extra characters transmitted that lack any meaning.
1224+
1225+ .. code-block:: xml
1226+
1227+ <?xml version="1.0"?>
1228+ <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
1229+ <soap:Header>
1230+ </soap:Header>
1231+ <soap:Body>
1232+ <m:GetStockPrice xmlns:m="http://www.example.org/stock/Surya">
1233+ <m:StockName>IBM</m:StockName>
1234+ </m:GetStockPrice>
1235+ </soap:Body>
1236+ </soap:Envelope>
13371237
13381238.. nextslide:: Why Do All The Work?
13391239
1340- So, if neither of these goals is really achieved by using SOAP, why pay all
1341- the overhead required to use the protocol?
1240+ So, if neither of the original goals is really achieved by using SOAP
13421241
13431242.. rst-class:: build
13441243.. container::
13451244
1245+ And if the transmission medium is too bloated to use
1246+
1247+ why pay all the overhead required to use the protocol?
1248+
13461249 Is there another way we could consider approaching the problem?
13471250
13481251 .. rst-class:: centered
@@ -1434,6 +1337,116 @@ REST is a **Resource Oriented Architecture**
14341337
14351338 * Success: ``HTTP/1.1 204 No Content``
14361339
1340+ REST uses JSON
1341+ --------------
1342+
1343+ JavaScript Object Notation:
1344+
1345+ .. rst-class:: build
1346+ .. container::
1347+
1348+ .. rst-class:: build
1349+
1350+ * a lightweight data-interchange format
1351+ * easy for humans to read and write
1352+ * easy for machines to parse and generate
1353+
1354+ Based on Two Structures:
1355+
1356+ * object: ``{ string: value, ...}``
1357+ * array: ``[value, value, ]``
1358+
1359+ .. rst-class:: centered
1360+
1361+ pythonic, no?
1362+
1363+
1364+ .. nextslide:: JSON Data Types
1365+
1366+ JSON provides a few basic data types (see http://json.org/):
1367+
1368+ .. rst-class:: build
1369+ .. container::
1370+
1371+ .. rst-class:: build
1372+
1373+ * string: unicode, anything but ", \\ and control characters
1374+ * number: any number, but json does not use octal or hexadecimal
1375+ * object, array (we' ve seen these above)
1376+ * true
1377+ * false
1378+ * null
1379+
1380+ .. rst-class:: centered
1381+
1382+ ** No date type? OMGWTF?? !! 1! 1**
1383+
1384+ .. nextslide:: Dates in JSON
1385+
1386+ You have two options:
1387+
1388+ .. rst-class:: build
1389+ .. container::
1390+
1391+ .. container::
1392+
1393+ Option 1 - Unix Epoch Time (number):
1394+
1395+ .. code-block:: python
1396+
1397+ >>> import time
1398+ >>> time.time ()
1399+ 1358212616.7691269
1400+
1401+ .. container::
1402+
1403+ Option 2 - ISO 8661 (string):
1404+
1405+ .. code-block:: python
1406+
1407+ >>> import datetime
1408+ >>> datetime.datetime.now().isoformat ()
1409+ ' 2013-01-14T17:18:10.727240'
1410+
1411+
1412+ JSON in Python
1413+ --------------
1414+
1415+ You can encode python to json, and decode json back to python:
1416+
1417+ .. rst-class:: build
1418+ .. container::
1419+
1420+ .. code-block:: python
1421+
1422+ In [1]: import json
1423+ In [2]: array = [1, 2, 3]
1424+ In [3]: json.dumps(array)
1425+ Out[3]: ' [1, 2, 3]'
1426+ In [4]: orig = {' foo' : [1,2,3], ' bar' : ' my resumé' , ' baz' : True}
1427+ In [5]: encoded = json.dumps(orig)
1428+ In [6]: encoded
1429+ Out[6]: ' {"foo": [1, 2, 3], "bar": "my resum\\u00e9", "baz": true}'
1430+ In [7]: decoded = json.loads(encoded)
1431+ In [8]: decoded == orig
1432+ Out[8]: True
1433+
1434+ Customizing the encoder or decoder class allows for specialized serializations
1435+
1436+
1437+ .. nextslide::
1438+
1439+ the json module also supports reading and writing to * file-like objects* via
1440+ ` ` json.dump(fp)` ` and ` ` json.load(fp)` ` (note the missing ' s' )
1441+
1442+ .. rst-class:: build
1443+ .. container::
1444+
1445+ Remember duck-typing. Anything with a ` ` .write` ` and a ` ` .read` ` method is
1446+ * file-like*
1447+
1448+ This usage can be much more memory-friendly with large files/sources
1449+
14371450
14381451Playing With REST
14391452-----------------
0 commit comments