Mercurial > p > roundup > code
comparison roundup/rest.py @ 5690:4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
and uses POST.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 03 Apr 2019 07:04:29 -0400 |
| parents | 2c516d113620 |
| children | dbf422a8cff7 |
comparison
equal
deleted
inserted
replaced
| 5689:2c516d113620 | 5690:4aae822e2cb4 |
|---|---|
| 1607 | 1607 |
| 1608 object['prop'].value | 1608 object['prop'].value |
| 1609 | 1609 |
| 1610 references used when accessing a FieldStorage structure. | 1610 references used when accessing a FieldStorage structure. |
| 1611 | 1611 |
| 1612 That's what this class does. | 1612 That's what this class does with all names and values as native |
| 1613 strings. Note that json is UTF-8, so we convert any unicode to | |
| 1614 string. | |
| 1613 | 1615 |
| 1614 ''' | 1616 ''' |
| 1615 def __init__(self, json_string): | 1617 def __init__(self, json_string): |
| 1616 ''' Parse the json string into an internal dict. ''' | 1618 ''' Parse the json string into an internal dict. ''' |
| 1617 def raise_error_on_constant(x): | 1619 def raise_error_on_constant(x): |
| 1623 class FsValue: | 1625 class FsValue: |
| 1624 '''Class that does nothing but response to a .value property ''' | 1626 '''Class that does nothing but response to a .value property ''' |
| 1625 def __init__(self, name, val): | 1627 def __init__(self, name, val): |
| 1626 self.name=u2s(name) | 1628 self.name=u2s(name) |
| 1627 if is_us(val): | 1629 if is_us(val): |
| 1630 # handle most common type first | |
| 1628 self.value=u2s(val) | 1631 self.value=u2s(val) |
| 1629 elif type(val) == type([]): | 1632 elif type(val) == type([]): |
| 1633 # then lists of strings | |
| 1630 self.value = [ u2s(v) for v in val ] | 1634 self.value = [ u2s(v) for v in val ] |
| 1631 else: | 1635 else: |
| 1636 # then stringify anything else (int, float) | |
| 1632 self.value = str(val) | 1637 self.value = str(val) |
| 1633 | 1638 |
| 1634 def __getitem__(self, index): | 1639 def __getitem__(self, index): |
| 1635 '''Return an FsValue created from the value of self.json_dict[index] | 1640 '''Return an FsValue created from the value of self.json_dict[index] |
| 1636 ''' | 1641 ''' |
