summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnteru <bitbucket@ca.sh13.net>2019-01-16 19:40:16 +0000
committerAnteru <bitbucket@ca.sh13.net>2019-01-16 19:40:16 +0000
commitd11aa5d00081aec00405f1b54a00363caa7c28e7 (patch)
treeedb494b75db09ffc27bbbbc580e8000f09348513
parentea47446222a927e88e1223e0218c2088baf0bec7 (diff)
parentd585e35ff170d0c0d08be43e33aa45646d08262f (diff)
downloadpygments-d11aa5d00081aec00405f1b54a00363caa7c28e7.tar.gz
Merged in felixfontein/pygments-main/improve-yaml (pull request #797)
Improve YAML mapping lexing: fix problems with quoted colons.
-rw-r--r--pygments/formatters/__init__.py3
-rw-r--r--pygments/formatters/html.py7
-rw-r--r--pygments/lexers/__init__.py3
-rw-r--r--pygments/lexers/_cocoa_builtins.py3
-rw-r--r--pygments/lexers/_php_builtins.py28
-rw-r--r--pygments/lexers/templates.py2
-rwxr-xr-xscripts/check_sources.py3
-rw-r--r--tests/test_html_formatter.py10
8 files changed, 30 insertions, 29 deletions
diff --git a/pygments/formatters/__init__.py b/pygments/formatters/__init__.py
index 965c5f1a..457d76ec 100644
--- a/pygments/formatters/__init__.py
+++ b/pygments/formatters/__init__.py
@@ -98,7 +98,8 @@ def load_formatter_from_file(filename, formattername="CustomFormatter",
try:
# This empty dict will contain the namespace for the exec'd file
custom_namespace = {}
- exec(open(filename, 'rb').read(), custom_namespace)
+ with open(filename, 'rb') as f:
+ exec(f.read(), custom_namespace)
# Retrieve the class `formattername` from that namespace
if formattername not in custom_namespace:
raise ClassNotFound('no valid %s class found in %s' %
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index 2969d502..7d7605eb 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -535,10 +535,9 @@ class HtmlFormatter(Formatter):
# write CSS file only if noclobber_cssfile isn't given as an option.
try:
if not os.path.exists(cssfilename) or not self.noclobber_cssfile:
- cf = open(cssfilename, "w")
- cf.write(CSSFILE_TEMPLATE %
- {'styledefs': self.get_style_defs('body')})
- cf.close()
+ with open(cssfilename, "w") as cf:
+ cf.write(CSSFILE_TEMPLATE %
+ {'styledefs': self.get_style_defs('body')})
except IOError as err:
err.strerror = 'Error writing CSS file: ' + err.strerror
raise
diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py
index 328e072c..50f39d4e 100644
--- a/pygments/lexers/__init__.py
+++ b/pygments/lexers/__init__.py
@@ -133,7 +133,8 @@ def load_lexer_from_file(filename, lexername="CustomLexer", **options):
try:
# This empty dict will contain the namespace for the exec'd file
custom_namespace = {}
- exec(open(filename, 'rb').read(), custom_namespace)
+ with open(filename, 'rb') as f:
+ exec(f.read(), custom_namespace)
# Retrieve the class `lexername` from that namespace
if lexername not in custom_namespace:
raise ClassNotFound('no valid %s class found in %s' %
diff --git a/pygments/lexers/_cocoa_builtins.py b/pygments/lexers/_cocoa_builtins.py
index f55e9dd7..f17ea876 100644
--- a/pygments/lexers/_cocoa_builtins.py
+++ b/pygments/lexers/_cocoa_builtins.py
@@ -40,7 +40,8 @@ if __name__ == '__main__': # pragma: no cover
continue
headerFilePath = frameworkHeadersDir + f
- content = open(headerFilePath).read()
+ with open(headerFilePath) as f:
+ content = f.read()
res = re.findall(r'(?<=@interface )\w+', content)
for r in res:
all_interfaces.add(r)
diff --git a/pygments/lexers/_php_builtins.py b/pygments/lexers/_php_builtins.py
index bd4b7d99..c6084003 100644
--- a/pygments/lexers/_php_builtins.py
+++ b/pygments/lexers/_php_builtins.py
@@ -4698,18 +4698,19 @@ if __name__ == '__main__': # pragma: no cover
for file in get_php_references():
module = ''
- for line in open(file):
- if not module:
- search = module_re.search(line)
- if search:
- module = search.group(1)
- modules[module] = []
+ with open(file) as f:
+ for line in f:
+ if not module:
+ search = module_re.search(line)
+ if search:
+ module = search.group(1)
+ modules[module] = []
- elif 'href="function.' in line:
- for match in function_re.finditer(line):
- fn = match.group(1)
- if '-&gt;' not in fn and '::' not in fn and fn not in modules[module]:
- modules[module].append(fn)
+ elif 'href="function.' in line:
+ for match in function_re.finditer(line):
+ fn = match.group(1)
+ if '-&gt;' not in fn and '::' not in fn and fn not in modules[module]:
+ modules[module].append(fn)
if module:
# These are dummy manual pages, not actual functions
@@ -4726,9 +4727,8 @@ if __name__ == '__main__': # pragma: no cover
def get_php_references():
download = urlretrieve(PHP_MANUAL_URL)
- tar = tarfile.open(download[0])
- tar.extractall()
- tar.close()
+ with tarfile.open(download[0]) as tar:
+ tar.extractall()
for file in glob.glob("%s%s" % (PHP_MANUAL_DIR, PHP_REFERENCE_GLOB)):
yield file
os.remove(download[0])
diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py
index c184b2dd..8000deba 100644
--- a/pygments/lexers/templates.py
+++ b/pygments/lexers/templates.py
@@ -375,7 +375,7 @@ class DjangoLexer(RegexLexer):
(r'\.\w+', Name.Variable),
(r':?"(\\\\|\\"|[^"])*"', String.Double),
(r":?'(\\\\|\\'|[^'])*'", String.Single),
- (r'([{}()\[\]+\-*/,:~]|[><=]=?)', Operator),
+ (r'([{}()\[\]+\-*/%,:~]|[><=]=?|!=)', Operator),
(r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
r"0[xX][0-9a-fA-F]+[Ll]?", Number),
],
diff --git a/scripts/check_sources.py b/scripts/check_sources.py
index db09de42..c0524b6c 100755
--- a/scripts/check_sources.py
+++ b/scripts/check_sources.py
@@ -185,7 +185,8 @@ def main(argv):
print("Checking %s..." % fn)
try:
- lines = open(fn, 'rb').read().decode('utf-8').splitlines()
+ with open(fn, 'rb') as f:
+ lines = f.read().decode('utf-8').splitlines()
except (IOError, OSError) as err:
print("%s: cannot open: %s" % (fn, err))
num += 1
diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py
index 10450c56..670a5be9 100644
--- a/tests/test_html_formatter.py
+++ b/tests/test_html_formatter.py
@@ -132,9 +132,8 @@ class HtmlFormatterTest(unittest.TestCase):
outencoding='utf-8')
handle, pathname = tempfile.mkstemp('.html')
- tfile = os.fdopen(handle, 'w+b')
- fmt.format(tokensource, tfile)
- tfile.close()
+ with os.fdopen(handle, 'w+b') as tfile:
+ fmt.format(tokensource, tfile)
catname = os.path.join(TESTDIR, 'dtds', 'HTML4.soc')
try:
import subprocess
@@ -173,9 +172,8 @@ class HtmlFormatterTest(unittest.TestCase):
cssstyles=u'div:before { content: \'bäz\' }',
encoding='utf-8')
handle, pathname = tempfile.mkstemp('.html')
- tfile = os.fdopen(handle, 'w+b')
- fmt.format(tokensource, tfile)
- tfile.close()
+ with os.fdopen(handle, 'w+b') as tfile:
+ fmt.format(tokensource, tfile)
def test_ctags(self):
try: