Return 'extractRAWDICT' converted to JSON format.
(self, cb=None, sort=False)
| 16567 | return val |
| 16568 | |
| 16569 | def extractRAWJSON(self, cb=None, sort=False) -> str: |
| 16570 | """Return 'extractRAWDICT' converted to JSON format.""" |
| 16571 | import base64 |
| 16572 | import json |
| 16573 | val = self._textpage_dict(raw=True) |
| 16574 | |
| 16575 | class b64encode(json.JSONEncoder): |
| 16576 | def default(self,s): |
| 16577 | if type(s) in (bytes, bytearray): |
| 16578 | return base64.b64encode(s).decode() |
| 16579 | |
| 16580 | if cb is not None: |
| 16581 | val["width"] = cb.width |
| 16582 | val["height"] = cb.height |
| 16583 | if sort: |
| 16584 | blocks = val["blocks"] |
| 16585 | blocks.sort(key=lambda b: (b["bbox"][3], b["bbox"][0])) |
| 16586 | val["blocks"] = blocks |
| 16587 | val = json.dumps(val, separators=(",", ":"), cls=b64encode, indent=1) |
| 16588 | return val |
| 16589 | |
| 16590 | def extractSelection(self, pointa, pointb): |
| 16591 | a = JM_point_from_py(pointa) |
no test coverage detected