Commit 0676217e authored by Philip Withnall's avatar Philip Withnall Committed by Bastien Nocera
Browse files

Add text/x-python3 content type

This derives from the text/x-python content type, and is attached to
files with a .py3 extension, or which have a python3 shebang line.
Otherwise, text/x-python is preferred.

This is necessary because Python 3 is not compatible with Python 2, and
introduces some new keywords (such as ‘nonlocal’) which need to be
syntax highlighted differently (for example).

https://bugs.freedesktop.org/show_bug.cgi?id=100034
parent 4ab969c3
......@@ -6024,6 +6024,25 @@ command to generate the output files.
<glob pattern="SConscript"/>
<glob pattern="SConscript.*"/>
</mime-type>
<mime-type type="text/x-python3">
<_comment>Python 3 script</_comment>
<sub-class-of type='text/x-python'/>
<magic priority="60"><!-- higher priority than text/x-python -->
<match type="string" value="#!/bin/python3" offset="0"/>
<match type="string" value="#! /bin/python3" offset="0"/>
<match type="string" value='eval \"exec /bin/python3' offset="0"/>
<match type="string" value="#!/usr/bin/python3" offset="0"/>
<match type="string" value="#! /usr/bin/python3" offset="0"/>
<match type="string" value='eval \"exec /usr/bin/python3' offset="0"/>
<match type="string" value="#!/usr/local/bin/python3" offset="0"/>
<match type="string" value="#! /usr/local/bin/python3" offset="0"/>
<match type="string" value='eval \"exec /usr/local/bin/python3' offset="0"/>
<match type="string" value='/bin/env python3' offset="2:16"/>
</magic>
<glob pattern="*.py" weight="50"/><!-- lower priority than in text/x-python -->
<glob pattern="*.py3" weight="60"/>
<glob pattern="*.py3x" weight="60"/>
</mime-type>
<mime-type type="text/x-python">
<_comment>Python script</_comment>
<sub-class-of type='application/x-executable'/>
......@@ -6040,9 +6059,9 @@ command to generate the output files.
<match type="string" value='eval \"exec /usr/local/bin/python' offset="0"/>
<match type="string" value='/bin/env python' offset="2:16"/>
</magic>
<glob pattern="*.py"/>
<glob pattern="*.pyx"/>
<glob pattern="*.wsgi"/>
<glob pattern="*.py" weight="60"/>
<glob pattern="*.pyx" weight="60"/>
<glob pattern="*.wsgi" weight="60"/>
</mime-type>
<mime-type type="text/x-lua">
<_comment>Lua script</_comment>
......
......@@ -314,6 +314,9 @@ test.jnlp application/x-java-jnlp-file
# Python script
test.py text/x-python
test.pyx text/x-python ox
# Python 3 script
test3.py text/x-python3 x
test.py3 text/x-python3
# Perl
test.pl application/x-perl
test.pm application/x-perl
......
#!/usr/bin/env python3
from math import sin, pi
def f(x):
return sin(x ** 2)
def integrate_f(a, b, N):
s = 0
dx = (b - a) / N
for i in range(N):
s += f(a + i * dx)
return s * dx
if __name__ == '__main__':
print(integrate_f(0, pi, 1000))
#!/usr/bin/env python3
from math import sin, pi
def f(x):
return sin(x ** 2)
def integrate_f(a, b, N):
s = 0
dx = (b - a) / N
for i in range(N):
s += f(a + i * dx)
return s * dx
if __name__ == '__main__':
print(integrate_f(0, pi, 1000))
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