pygmentize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/LICENSE +19 -0
  2. data/lib/pygments.rb +23 -0
  3. data/pygmentize.gemspec +11 -0
  4. data/test/pygments.rb +19 -0
  5. data/vendor/pygmentize.py +7 -0
  6. data/vendor/pygments/AUTHORS +73 -0
  7. data/vendor/pygments/LICENSE +25 -0
  8. data/vendor/pygments/__init__.py +91 -0
  9. data/vendor/pygments/__init__.pyc +0 -0
  10. data/vendor/pygments/cmdline.py +430 -0
  11. data/vendor/pygments/cmdline.pyc +0 -0
  12. data/vendor/pygments/console.py +74 -0
  13. data/vendor/pygments/console.pyc +0 -0
  14. data/vendor/pygments/filter.py +74 -0
  15. data/vendor/pygments/filter.pyc +0 -0
  16. data/vendor/pygments/filters/__init__.py +357 -0
  17. data/vendor/pygments/filters/__init__.pyc +0 -0
  18. data/vendor/pygments/formatter.py +92 -0
  19. data/vendor/pygments/formatter.pyc +0 -0
  20. data/vendor/pygments/formatters/__init__.py +68 -0
  21. data/vendor/pygments/formatters/__init__.pyc +0 -0
  22. data/vendor/pygments/formatters/_mapping.py +92 -0
  23. data/vendor/pygments/formatters/_mapping.pyc +0 -0
  24. data/vendor/pygments/formatters/bbcode.py +109 -0
  25. data/vendor/pygments/formatters/bbcode.pyc +0 -0
  26. data/vendor/pygments/formatters/html.py +723 -0
  27. data/vendor/pygments/formatters/html.pyc +0 -0
  28. data/vendor/pygments/formatters/img.py +553 -0
  29. data/vendor/pygments/formatters/img.pyc +0 -0
  30. data/vendor/pygments/formatters/latex.py +354 -0
  31. data/vendor/pygments/formatters/latex.pyc +0 -0
  32. data/vendor/pygments/formatters/other.py +117 -0
  33. data/vendor/pygments/formatters/other.pyc +0 -0
  34. data/vendor/pygments/formatters/rtf.py +136 -0
  35. data/vendor/pygments/formatters/rtf.pyc +0 -0
  36. data/vendor/pygments/formatters/svg.py +154 -0
  37. data/vendor/pygments/formatters/svg.pyc +0 -0
  38. data/vendor/pygments/formatters/terminal.py +109 -0
  39. data/vendor/pygments/formatters/terminal.pyc +0 -0
  40. data/vendor/pygments/formatters/terminal256.py +219 -0
  41. data/vendor/pygments/formatters/terminal256.pyc +0 -0
  42. data/vendor/pygments/lexer.py +660 -0
  43. data/vendor/pygments/lexer.pyc +0 -0
  44. data/vendor/pygments/lexers/__init__.py +226 -0
  45. data/vendor/pygments/lexers/__init__.pyc +0 -0
  46. data/vendor/pygments/lexers/_asybuiltins.py +1645 -0
  47. data/vendor/pygments/lexers/_clbuiltins.py +232 -0
  48. data/vendor/pygments/lexers/_luabuiltins.py +256 -0
  49. data/vendor/pygments/lexers/_mapping.py +234 -0
  50. data/vendor/pygments/lexers/_mapping.pyc +0 -0
  51. data/vendor/pygments/lexers/_phpbuiltins.py +3389 -0
  52. data/vendor/pygments/lexers/_vimbuiltins.py +3 -0
  53. data/vendor/pygments/lexers/agile.py +1485 -0
  54. data/vendor/pygments/lexers/agile.pyc +0 -0
  55. data/vendor/pygments/lexers/asm.py +353 -0
  56. data/vendor/pygments/lexers/compiled.py +2365 -0
  57. data/vendor/pygments/lexers/dotnet.py +355 -0
  58. data/vendor/pygments/lexers/functional.py +756 -0
  59. data/vendor/pygments/lexers/functional.pyc +0 -0
  60. data/vendor/pygments/lexers/math.py +461 -0
  61. data/vendor/pygments/lexers/other.py +2297 -0
  62. data/vendor/pygments/lexers/parsers.py +695 -0
  63. data/vendor/pygments/lexers/special.py +100 -0
  64. data/vendor/pygments/lexers/special.pyc +0 -0
  65. data/vendor/pygments/lexers/templates.py +1387 -0
  66. data/vendor/pygments/lexers/text.py +1586 -0
  67. data/vendor/pygments/lexers/web.py +1619 -0
  68. data/vendor/pygments/lexers/web.pyc +0 -0
  69. data/vendor/pygments/plugin.py +74 -0
  70. data/vendor/pygments/plugin.pyc +0 -0
  71. data/vendor/pygments/scanner.py +104 -0
  72. data/vendor/pygments/style.py +117 -0
  73. data/vendor/pygments/style.pyc +0 -0
  74. data/vendor/pygments/styles/__init__.py +68 -0
  75. data/vendor/pygments/styles/__init__.pyc +0 -0
  76. data/vendor/pygments/styles/autumn.py +65 -0
  77. data/vendor/pygments/styles/borland.py +51 -0
  78. data/vendor/pygments/styles/bw.py +49 -0
  79. data/vendor/pygments/styles/colorful.py +81 -0
  80. data/vendor/pygments/styles/default.py +73 -0
  81. data/vendor/pygments/styles/default.pyc +0 -0
  82. data/vendor/pygments/styles/emacs.py +72 -0
  83. data/vendor/pygments/styles/friendly.py +72 -0
  84. data/vendor/pygments/styles/fruity.py +43 -0
  85. data/vendor/pygments/styles/manni.py +75 -0
  86. data/vendor/pygments/styles/monokai.py +106 -0
  87. data/vendor/pygments/styles/murphy.py +80 -0
  88. data/vendor/pygments/styles/native.py +65 -0
  89. data/vendor/pygments/styles/pastie.py +75 -0
  90. data/vendor/pygments/styles/perldoc.py +69 -0
  91. data/vendor/pygments/styles/tango.py +141 -0
  92. data/vendor/pygments/styles/trac.py +63 -0
  93. data/vendor/pygments/styles/vim.py +63 -0
  94. data/vendor/pygments/styles/vs.py +38 -0
  95. data/vendor/pygments/token.py +198 -0
  96. data/vendor/pygments/token.pyc +0 -0
  97. data/vendor/pygments/unistring.py +130 -0
  98. data/vendor/pygments/unistring.pyc +0 -0
  99. data/vendor/pygments/util.py +226 -0
  100. data/vendor/pygments/util.pyc +0 -0
  101. metadata +166 -0
@@ -0,0 +1,226 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.util
4
+ ~~~~~~~~~~~~~
5
+
6
+ Utility functions.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import re
13
+ import sys
14
+ import codecs
15
+
16
+
17
+ split_path_re = re.compile(r'[/\\ ]')
18
+ doctype_lookup_re = re.compile(r'''(?smx)
19
+ (<\?.*?\?>)?\s*
20
+ <!DOCTYPE\s+(
21
+ [a-zA-Z_][a-zA-Z0-9]*\s+
22
+ [a-zA-Z_][a-zA-Z0-9]*\s+
23
+ "[^"]*")
24
+ [^>]*>
25
+ ''')
26
+ tag_re = re.compile(r'<(.+?)(\s.*?)?>.*?</.+?>(?uism)')
27
+
28
+
29
+ class ClassNotFound(ValueError):
30
+ """
31
+ If one of the get_*_by_* functions didn't find a matching class.
32
+ """
33
+
34
+
35
+ class OptionError(Exception):
36
+ pass
37
+
38
+
39
+ def get_choice_opt(options, optname, allowed, default=None, normcase=False):
40
+ string = options.get(optname, default)
41
+ if normcase:
42
+ string = string.lower()
43
+ if string not in allowed:
44
+ raise OptionError('Value for option %s must be one of %s' %
45
+ (optname, ', '.join(map(str, allowed))))
46
+ return string
47
+
48
+
49
+ def get_bool_opt(options, optname, default=None):
50
+ string = options.get(optname, default)
51
+ if isinstance(string, bool):
52
+ return string
53
+ elif isinstance(string, int):
54
+ return bool(string)
55
+ elif not isinstance(string, basestring):
56
+ raise OptionError('Invalid type %r for option %s; use '
57
+ '1/0, yes/no, true/false, on/off' % (
58
+ string, optname))
59
+ elif string.lower() in ('1', 'yes', 'true', 'on'):
60
+ return True
61
+ elif string.lower() in ('0', 'no', 'false', 'off'):
62
+ return False
63
+ else:
64
+ raise OptionError('Invalid value %r for option %s; use '
65
+ '1/0, yes/no, true/false, on/off' % (
66
+ string, optname))
67
+
68
+
69
+ def get_int_opt(options, optname, default=None):
70
+ string = options.get(optname, default)
71
+ try:
72
+ return int(string)
73
+ except TypeError:
74
+ raise OptionError('Invalid type %r for option %s; you '
75
+ 'must give an integer value' % (
76
+ string, optname))
77
+ except ValueError:
78
+ raise OptionError('Invalid value %r for option %s; you '
79
+ 'must give an integer value' % (
80
+ string, optname))
81
+
82
+
83
+ def get_list_opt(options, optname, default=None):
84
+ val = options.get(optname, default)
85
+ if isinstance(val, basestring):
86
+ return val.split()
87
+ elif isinstance(val, (list, tuple)):
88
+ return list(val)
89
+ else:
90
+ raise OptionError('Invalid type %r for option %s; you '
91
+ 'must give a list value' % (
92
+ val, optname))
93
+
94
+
95
+ def docstring_headline(obj):
96
+ if not obj.__doc__:
97
+ return ''
98
+ res = []
99
+ for line in obj.__doc__.strip().splitlines():
100
+ if line.strip():
101
+ res.append(" " + line.strip())
102
+ else:
103
+ break
104
+ return ''.join(res).lstrip()
105
+
106
+
107
+ def make_analysator(f):
108
+ """
109
+ Return a static text analysation function that
110
+ returns float values.
111
+ """
112
+ def text_analyse(text):
113
+ rv = f(text)
114
+ if not rv:
115
+ return 0.0
116
+ return min(1.0, max(0.0, float(rv)))
117
+ text_analyse.__doc__ = f.__doc__
118
+ return staticmethod(text_analyse)
119
+
120
+
121
+ def shebang_matches(text, regex):
122
+ """
123
+ Check if the given regular expression matches the last part of the
124
+ shebang if one exists.
125
+
126
+ >>> from pygments.util import shebang_matches
127
+ >>> shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?')
128
+ True
129
+ >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?')
130
+ True
131
+ >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?')
132
+ False
133
+ >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?')
134
+ False
135
+ >>> shebang_matches('#!/usr/bin/startsomethingwith python',
136
+ ... r'python(2\.\d)?')
137
+ True
138
+
139
+ It also checks for common windows executable file extensions::
140
+
141
+ >>> shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\.\d)?')
142
+ True
143
+
144
+ Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does
145
+ the same as ``'perl -e'``)
146
+
147
+ Note that this method automatically searches the whole string (eg:
148
+ the regular expression is wrapped in ``'^$'``)
149
+ """
150
+ index = text.find('\n')
151
+ if index >= 0:
152
+ first_line = text[:index].lower()
153
+ else:
154
+ first_line = text.lower()
155
+ if first_line.startswith('#!'):
156
+ try:
157
+ found = [x for x in split_path_re.split(first_line[2:].strip())
158
+ if x and not x.startswith('-')][-1]
159
+ except IndexError:
160
+ return False
161
+ regex = re.compile('^%s(\.(exe|cmd|bat|bin))?$' % regex, re.IGNORECASE)
162
+ if regex.search(found) is not None:
163
+ return True
164
+ return False
165
+
166
+
167
+ def doctype_matches(text, regex):
168
+ """
169
+ Check if the doctype matches a regular expression (if present).
170
+ Note that this method only checks the first part of a DOCTYPE.
171
+ eg: 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
172
+ """
173
+ m = doctype_lookup_re.match(text)
174
+ if m is None:
175
+ return False
176
+ doctype = m.group(2)
177
+ return re.compile(regex).match(doctype.strip()) is not None
178
+
179
+
180
+ def html_doctype_matches(text):
181
+ """
182
+ Check if the file looks like it has a html doctype.
183
+ """
184
+ return doctype_matches(text, r'html\s+PUBLIC\s+"-//W3C//DTD X?HTML.*')
185
+
186
+
187
+ _looks_like_xml_cache = {}
188
+ def looks_like_xml(text):
189
+ """
190
+ Check if a doctype exists or if we have some tags.
191
+ """
192
+ key = hash(text)
193
+ try:
194
+ return _looks_like_xml_cache[key]
195
+ except KeyError:
196
+ m = doctype_lookup_re.match(text)
197
+ if m is not None:
198
+ return True
199
+ rv = tag_re.search(text[:1000]) is not None
200
+ _looks_like_xml_cache[key] = rv
201
+ return rv
202
+
203
+ # Python 2/3 compatibility
204
+
205
+ if sys.version_info < (3,0):
206
+ b = bytes = str
207
+ u_prefix = 'u'
208
+ import StringIO, cStringIO
209
+ BytesIO = cStringIO.StringIO
210
+ StringIO = StringIO.StringIO
211
+ uni_open = codecs.open
212
+ else:
213
+ import builtins
214
+ bytes = builtins.bytes
215
+ u_prefix = ''
216
+ def b(s):
217
+ if isinstance(s, str):
218
+ return bytes(map(ord, s))
219
+ elif isinstance(s, bytes):
220
+ return s
221
+ else:
222
+ raise TypeError("Invalid argument %r for b()" % (s,))
223
+ import io
224
+ BytesIO = io.BytesIO
225
+ StringIO = io.StringIO
226
+ uni_open = builtins.open
Binary file
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pygmentize
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Damian Janowski
13
+ - Michel Martens
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-24 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A Ruby gem that vendors Pygments
23
+ email:
24
+ - djanowski@dimaion.com
25
+ - michel@soveran.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - pygmentize.gemspec
34
+ - LICENSE
35
+ - lib/pygments.rb
36
+ - test/pygments.rb
37
+ - vendor/pygmentize.py
38
+ - vendor/pygments/__init__.py
39
+ - vendor/pygments/__init__.pyc
40
+ - vendor/pygments/AUTHORS
41
+ - vendor/pygments/cmdline.py
42
+ - vendor/pygments/cmdline.pyc
43
+ - vendor/pygments/console.py
44
+ - vendor/pygments/console.pyc
45
+ - vendor/pygments/filter.py
46
+ - vendor/pygments/filter.pyc
47
+ - vendor/pygments/filters/__init__.py
48
+ - vendor/pygments/filters/__init__.pyc
49
+ - vendor/pygments/formatter.py
50
+ - vendor/pygments/formatter.pyc
51
+ - vendor/pygments/formatters/__init__.py
52
+ - vendor/pygments/formatters/__init__.pyc
53
+ - vendor/pygments/formatters/_mapping.py
54
+ - vendor/pygments/formatters/_mapping.pyc
55
+ - vendor/pygments/formatters/bbcode.py
56
+ - vendor/pygments/formatters/bbcode.pyc
57
+ - vendor/pygments/formatters/html.py
58
+ - vendor/pygments/formatters/html.pyc
59
+ - vendor/pygments/formatters/img.py
60
+ - vendor/pygments/formatters/img.pyc
61
+ - vendor/pygments/formatters/latex.py
62
+ - vendor/pygments/formatters/latex.pyc
63
+ - vendor/pygments/formatters/other.py
64
+ - vendor/pygments/formatters/other.pyc
65
+ - vendor/pygments/formatters/rtf.py
66
+ - vendor/pygments/formatters/rtf.pyc
67
+ - vendor/pygments/formatters/svg.py
68
+ - vendor/pygments/formatters/svg.pyc
69
+ - vendor/pygments/formatters/terminal.py
70
+ - vendor/pygments/formatters/terminal.pyc
71
+ - vendor/pygments/formatters/terminal256.py
72
+ - vendor/pygments/formatters/terminal256.pyc
73
+ - vendor/pygments/lexer.py
74
+ - vendor/pygments/lexer.pyc
75
+ - vendor/pygments/lexers/__init__.py
76
+ - vendor/pygments/lexers/__init__.pyc
77
+ - vendor/pygments/lexers/_asybuiltins.py
78
+ - vendor/pygments/lexers/_clbuiltins.py
79
+ - vendor/pygments/lexers/_luabuiltins.py
80
+ - vendor/pygments/lexers/_mapping.py
81
+ - vendor/pygments/lexers/_mapping.pyc
82
+ - vendor/pygments/lexers/_phpbuiltins.py
83
+ - vendor/pygments/lexers/_vimbuiltins.py
84
+ - vendor/pygments/lexers/agile.py
85
+ - vendor/pygments/lexers/agile.pyc
86
+ - vendor/pygments/lexers/asm.py
87
+ - vendor/pygments/lexers/compiled.py
88
+ - vendor/pygments/lexers/dotnet.py
89
+ - vendor/pygments/lexers/functional.py
90
+ - vendor/pygments/lexers/functional.pyc
91
+ - vendor/pygments/lexers/math.py
92
+ - vendor/pygments/lexers/other.py
93
+ - vendor/pygments/lexers/parsers.py
94
+ - vendor/pygments/lexers/special.py
95
+ - vendor/pygments/lexers/special.pyc
96
+ - vendor/pygments/lexers/templates.py
97
+ - vendor/pygments/lexers/text.py
98
+ - vendor/pygments/lexers/web.py
99
+ - vendor/pygments/lexers/web.pyc
100
+ - vendor/pygments/LICENSE
101
+ - vendor/pygments/plugin.py
102
+ - vendor/pygments/plugin.pyc
103
+ - vendor/pygments/scanner.py
104
+ - vendor/pygments/style.py
105
+ - vendor/pygments/style.pyc
106
+ - vendor/pygments/styles/__init__.py
107
+ - vendor/pygments/styles/__init__.pyc
108
+ - vendor/pygments/styles/autumn.py
109
+ - vendor/pygments/styles/borland.py
110
+ - vendor/pygments/styles/bw.py
111
+ - vendor/pygments/styles/colorful.py
112
+ - vendor/pygments/styles/default.py
113
+ - vendor/pygments/styles/default.pyc
114
+ - vendor/pygments/styles/emacs.py
115
+ - vendor/pygments/styles/friendly.py
116
+ - vendor/pygments/styles/fruity.py
117
+ - vendor/pygments/styles/manni.py
118
+ - vendor/pygments/styles/monokai.py
119
+ - vendor/pygments/styles/murphy.py
120
+ - vendor/pygments/styles/native.py
121
+ - vendor/pygments/styles/pastie.py
122
+ - vendor/pygments/styles/perldoc.py
123
+ - vendor/pygments/styles/tango.py
124
+ - vendor/pygments/styles/trac.py
125
+ - vendor/pygments/styles/vim.py
126
+ - vendor/pygments/styles/vs.py
127
+ - vendor/pygments/token.py
128
+ - vendor/pygments/token.pyc
129
+ - vendor/pygments/unistring.py
130
+ - vendor/pygments/unistring.pyc
131
+ - vendor/pygments/util.py
132
+ - vendor/pygments/util.pyc
133
+ has_rdoc: true
134
+ homepage: http://github.com/djanowski/pygments
135
+ licenses: []
136
+
137
+ post_install_message:
138
+ rdoc_options: []
139
+
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project:
161
+ rubygems_version: 1.3.7
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: A Ruby gem that vendors Pygments
165
+ test_files: []
166
+