Commit 231b341b authored by Jérome Perrin's avatar Jérome Perrin

administration: fix BT's "Check Python Code" with coding flag

According to pep-0263, python scripts can define encoding magic on
first or second line.
If we use for example such a script:

```python
  # coding: utf-8
  return "héhé"
```

then using .read() was wrong, because it return the script with headers,
ie:

```python
  ## Script (Python) "test_coding"
  ##bind container=container
  ##bind context=context
  ##bind namespace=
  ##bind script=script
  ##bind subpath=traverse_subpath
  ##parameters=
  ##title=
  ##
  # coding: utf-8
  return "héhé"
```

so the coding magic is no longer in first line and pylint complains
with error like:

Cannot decode using encoding "ascii", unexpected byte at position 11 (invalid-encoded-data)]
parent 082aa95e
......@@ -33,7 +33,7 @@ def checkPythonScript(script_instance, script_path):
{'bound_names': extra_builtins +
script_instance.getBindingAssignments().getAssignedNamesInOrder(),
'params': script_instance.params(),
'code': unicode(script_instance.read(), 'utf8')
'code': unicode(script_instance.body(), 'utf8')
}))['annotations']:
annotation["script_path"] = script_path
line_list.append(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment