KXStudio Website https://kx.studio/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

python.php 12KB

11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /*************************************************************************************
  3. * python.php
  4. * ----------
  5. * Author: Roberto Rossi (rsoftware@altervista.org)
  6. * Copyright: (c) 2004 Roberto Rossi (http://rsoftware.altervista.org), Nigel McNie (http://qbnz.com/highlighter)
  7. * Release Version: 1.0.8.10
  8. * Date Started: 2004/08/30
  9. *
  10. * Python language file for GeSHi.
  11. *
  12. * CHANGES
  13. * -------
  14. * 2008/12/18
  15. * - Added missing functions and keywords. Also added two new Python 3.0 types. SF#2441839
  16. * 2005/05/26
  17. * - Modifications by Tim (tim@skreak.com): added more keyword categories, tweaked colors
  18. * 2004/11/27 (1.0.1)
  19. * - Added support for multiple object splitters
  20. * 2004/08/30 (1.0.0)
  21. * - First Release
  22. *
  23. * TODO (updated 2004/11/27)
  24. * -------------------------
  25. *
  26. *************************************************************************************
  27. *
  28. * This file is part of GeSHi.
  29. *
  30. * GeSHi is free software; you can redistribute it and/or modify
  31. * it under the terms of the GNU General Public License as published by
  32. * the Free Software Foundation; either version 2 of the License, or
  33. * (at your option) any later version.
  34. *
  35. * GeSHi is distributed in the hope that it will be useful,
  36. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. * GNU General Public License for more details.
  39. *
  40. * You should have received a copy of the GNU General Public License
  41. * along with GeSHi; if not, write to the Free Software
  42. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  43. *
  44. ************************************************************************************/
  45. $language_data = array (
  46. 'LANG_NAME' => 'Python',
  47. 'COMMENT_SINGLE' => array(1 => '#'),
  48. 'COMMENT_MULTI' => array(),
  49. 'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
  50. //Longest quotemarks ALWAYS first
  51. 'QUOTEMARKS' => array('"""', "'''", '"', "'"),
  52. 'ESCAPE_CHAR' => '\\',
  53. 'NUMBERS' =>
  54. GESHI_NUMBER_INT_BASIC | GESHI_NUMBER_BIN_PREFIX_0B |
  55. GESHI_NUMBER_OCT_PREFIX_0O | GESHI_NUMBER_HEX_PREFIX |
  56. GESHI_NUMBER_FLT_NONSCI | GESHI_NUMBER_FLT_NONSCI_F |
  57. GESHI_NUMBER_FLT_SCI_SHORT | GESHI_NUMBER_FLT_SCI_ZERO,
  58. 'KEYWORDS' => array(
  59. /*
  60. ** Set 1: reserved words
  61. ** http://python.org/doc/current/ref/keywords.html
  62. */
  63. 1 => array(
  64. 'and', 'del', 'for', 'is', 'raise', 'assert', 'elif', 'from', 'lambda', 'return', 'break',
  65. 'else', 'global', 'not', 'try', 'class', 'except', 'if', 'or', 'while', 'continue', 'exec',
  66. 'import', 'pass', 'yield', 'def', 'finally', 'in', 'print', 'with', 'as', 'nonlocal'
  67. ),
  68. /*
  69. ** Set 2: builtins
  70. ** http://python.org/doc/current/lib/built-in-funcs.html
  71. */
  72. 2 => array(
  73. '__import__', 'abs', 'basestring', 'bool', 'callable', 'chr', 'classmethod', 'cmp',
  74. 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile',
  75. 'file', 'filter', 'float', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help',
  76. 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'list', 'locals',
  77. 'long', 'map', 'max', 'min', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'range',
  78. 'raw_input', 'reduce', 'reload', 'reversed', 'round', 'set', 'setattr', 'slice',
  79. 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode',
  80. 'vars', 'xrange', 'zip',
  81. // Built-in constants: http://python.org/doc/current/lib/node35.html
  82. 'False', 'True', 'None', 'NotImplemented', 'Ellipsis',
  83. // Built-in Exceptions: http://python.org/doc/current/lib/module-exceptions.html
  84. 'Exception', 'StandardError', 'ArithmeticError', 'LookupError', 'EnvironmentError',
  85. 'AssertionError', 'AttributeError', 'EOFError', 'FloatingPointError', 'IOError',
  86. 'ImportError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'MemoryError', 'NameError',
  87. 'NotImplementedError', 'OSError', 'OverflowError', 'ReferenceError', 'RuntimeError',
  88. 'StopIteration', 'SyntaxError', 'SystemError', 'SystemExit', 'TypeError',
  89. 'UnboundlocalError', 'UnicodeError', 'UnicodeEncodeError', 'UnicodeDecodeError',
  90. 'UnicodeTranslateError', 'ValueError', 'WindowsError', 'ZeroDivisionError', 'Warning',
  91. 'UserWarning', 'DeprecationWarning', 'PendingDeprecationWarning', 'SyntaxWarning',
  92. 'RuntimeWarning', 'FutureWarning',
  93. // self: this is a common python convention (but not a reserved word)
  94. 'self',
  95. // other
  96. 'any', 'all'
  97. ),
  98. /*
  99. ** Set 3: standard library
  100. ** http://python.org/doc/current/lib/modindex.html
  101. */
  102. 3 => array(
  103. '__builtin__', '__future__', '__main__', '_winreg', 'aifc', 'AL', 'al', 'anydbm',
  104. 'array', 'asynchat', 'asyncore', 'atexit', 'audioop', 'base64', 'BaseHTTPServer',
  105. 'Bastion', 'binascii', 'binhex', 'bisect', 'bsddb', 'bz2', 'calendar', 'cd', 'cgi',
  106. 'CGIHTTPServer', 'cgitb', 'chunk', 'cmath', 'cmd', 'code', 'codecs', 'codeop',
  107. 'collections', 'colorsys', 'commands', 'compileall', 'compiler',
  108. 'ConfigParser', 'Cookie', 'cookielib', 'copy', 'copy_reg', 'cPickle', 'crypt',
  109. 'cStringIO', 'csv', 'curses', 'datetime', 'dbhash', 'dbm', 'decimal', 'DEVICE',
  110. 'difflib', 'dircache', 'dis', 'distutils', 'dl', 'doctest', 'DocXMLRPCServer', 'dumbdbm',
  111. 'dummy_thread', 'dummy_threading', 'email', 'encodings', 'errno', 'exceptions', 'fcntl',
  112. 'filecmp', 'fileinput', 'FL', 'fl', 'flp', 'fm', 'fnmatch', 'formatter', 'fpectl',
  113. 'fpformat', 'ftplib', 'gc', 'gdbm', 'getopt', 'getpass', 'gettext', 'GL', 'gl', 'glob',
  114. 'gopherlib', 'grp', 'gzip', 'heapq', 'hmac', 'hotshot', 'htmlentitydefs', 'htmllib',
  115. 'HTMLParser', 'httplib', 'imageop', 'imaplib', 'imgfile', 'imghdr', 'imp', 'inspect',
  116. 'itertools', 'jpeg', 'keyword', 'linecache', 'locale', 'logging', 'mailbox', 'mailcap',
  117. 'marshal', 'math', 'md5', 'mhlib', 'mimetools', 'mimetypes', 'MimeWriter', 'mimify',
  118. 'mmap', 'msvcrt', 'multifile', 'mutex', 'netrc', 'new', 'nis', 'nntplib', 'operator',
  119. 'optparse', 'os', 'ossaudiodev', 'parser', 'pdb', 'pickle', 'pickletools', 'pipes',
  120. 'pkgutil', 'platform', 'popen2', 'poplib', 'posix', 'posixfile', 'pprint', 'profile',
  121. 'pstats', 'pty', 'pwd', 'py_compile', 'pyclbr', 'pydoc', 'Queue', 'quopri', 'random',
  122. 're', 'readline', 'repr', 'resource', 'rexec', 'rfc822', 'rgbimg', 'rlcompleter',
  123. 'robotparser', 'sched', 'ScrolledText', 'select', 'sets', 'sgmllib', 'sha', 'shelve',
  124. 'shlex', 'shutil', 'signal', 'SimpleHTTPServer', 'SimpleXMLRPCServer', 'site', 'smtpd',
  125. 'smtplib', 'sndhdr', 'socket', 'SocketServer', 'stat', 'statcache', 'statvfs', 'string',
  126. 'StringIO', 'stringprep', 'struct', 'subprocess', 'sunau', 'SUNAUDIODEV', 'sunaudiodev',
  127. 'symbol', 'sys', 'syslog', 'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'termios',
  128. 'test', 'textwrap', 'thread', 'threading', 'time', 'timeit', 'Tix', 'Tkinter', 'token',
  129. 'tokenize', 'traceback', 'tty', 'turtle', 'types', 'unicodedata', 'unittest', 'urllib2',
  130. 'urllib', 'urlparse', 'user', 'UserDict', 'UserList', 'UserString', 'uu', 'warnings',
  131. 'wave', 'weakref', 'webbrowser', 'whichdb', 'whrandom', 'winsound', 'xdrlib', 'xml',
  132. 'xmllib', 'xmlrpclib', 'zipfile', 'zipimport', 'zlib',
  133. // Python 3.0
  134. 'bytes', 'bytearray'
  135. ),
  136. /*
  137. ** Set 4: special methods
  138. ** http://python.org/doc/current/ref/specialnames.html
  139. */
  140. 4 => array(
  141. /*
  142. // Iterator types: http://python.org/doc/current/lib/typeiter.html
  143. '__iter__', 'next',
  144. // String types: http://python.org/doc/current/lib/string-methods.html
  145. 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs',
  146. 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle',
  147. 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust',
  148. 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title',
  149. 'translate', 'upper', 'zfill',
  150. */
  151. // Basic customization: http://python.org/doc/current/ref/customization.html
  152. '__new__', '__init__', '__del__', '__repr__', '__str__',
  153. '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__cmp__', '__rcmp__',
  154. '__hash__', '__nonzero__', '__unicode__', '__dict__',
  155. // Attribute access: http://python.org/doc/current/ref/attribute-access.html
  156. '__setattr__', '__delattr__', '__getattr__', '__getattribute__', '__get__', '__set__',
  157. '__delete__', '__slots__',
  158. // Class creation, callable objects
  159. '__metaclass__', '__call__',
  160. // Container types: http://python.org/doc/current/ref/sequence-types.html
  161. '__len__', '__getitem__', '__setitem__', '__delitem__', '__iter__', '__contains__',
  162. '__getslice__', '__setslice__', '__delslice__',
  163. // Numeric types: http://python.org/doc/current/ref/numeric-types.html
  164. '__abs__','__add__','__and__','__coerce__','__div__','__divmod__','__float__',
  165. '__hex__','__iadd__','__isub__','__imod__','__idiv__','__ipow__','__iand__',
  166. '__ior__','__ixor__', '__ilshift__','__irshift__','__invert__','__int__',
  167. '__long__','__lshift__',
  168. '__mod__','__mul__','__neg__','__oct__','__or__','__pos__','__pow__',
  169. '__radd__','__rdiv__','__rdivmod__','__rmod__','__rpow__','__rlshift__','__rrshift__',
  170. '__rshift__','__rsub__','__rmul__','__rand__','__rxor__','__ror__',
  171. '__sub__','__xor__'
  172. )
  173. ),
  174. 'SYMBOLS' => array(
  175. '<', '>', '=', '!', '<=', '>=', //·comparison·operators
  176. '~', '@', //·unary·operators
  177. ';', ',' //·statement·separator
  178. ),
  179. 'CASE_SENSITIVE' => array(
  180. GESHI_COMMENTS => false,
  181. 1 => true,
  182. 2 => true,
  183. 3 => true,
  184. 4 => true
  185. ),
  186. 'STYLES' => array(
  187. 'KEYWORDS' => array(
  188. 1 => 'color: #ff7700;font-weight:bold;', // Reserved
  189. 2 => 'color: #008000;', // Built-ins + self
  190. 3 => 'color: #dc143c;', // Standard lib
  191. 4 => 'color: #0000cd;' // Special methods
  192. ),
  193. 'COMMENTS' => array(
  194. 1 => 'color: #808080; font-style: italic;',
  195. 'MULTI' => 'color: #808080; font-style: italic;'
  196. ),
  197. 'ESCAPE_CHAR' => array(
  198. 0 => 'color: #000099; font-weight: bold;'
  199. ),
  200. 'BRACKETS' => array(
  201. 0 => 'color: black;'
  202. ),
  203. 'STRINGS' => array(
  204. 0 => 'color: #483d8b;'
  205. ),
  206. 'NUMBERS' => array(
  207. 0 => 'color: #ff4500;'
  208. ),
  209. 'METHODS' => array(
  210. 1 => 'color: black;'
  211. ),
  212. 'SYMBOLS' => array(
  213. 0 => 'color: #66cc66;'
  214. ),
  215. 'REGEXPS' => array(
  216. ),
  217. 'SCRIPT' => array(
  218. )
  219. ),
  220. 'URLS' => array(
  221. 1 => '',
  222. 2 => '',
  223. 3 => '',
  224. 4 => ''
  225. ),
  226. 'OOLANG' => true,
  227. 'OBJECT_SPLITTERS' => array(
  228. 1 => '.'
  229. ),
  230. 'REGEXPS' => array(
  231. ),
  232. 'STRICT_MODE_APPLIES' => GESHI_NEVER,
  233. 'SCRIPT_DELIMITERS' => array(
  234. ),
  235. 'HIGHLIGHT_STRICT_BLOCK' => array(
  236. )
  237. );
  238. ?>