-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
As a module-level list named `__mapping__`, and as a compressed delta encoding for production use as ``__gzmapping__``. The compressed version is the base-84 representation of a gzipped stream of packed integer bytes defining the difference in line number from line to line.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
# encoding: utf-8 | ||
|
||
from __future__ import unicode_literals | ||
|
||
from gzip import compress, decompress | ||
from base64 import b85encode, b85decode | ||
from pprint import pformat | ||
from collections import deque | ||
|
||
from ..util import py, Line | ||
from ..util import py, Line, iterate | ||
|
||
|
||
def red(numbers): | ||
"""Encode the deltas to reduce entropy.""" | ||
|
||
line = 0 | ||
deltas = [] | ||
|
||
for value in numbers: | ||
deltas.append(value - line) | ||
line = value | ||
|
||
return b85encode(compress(b''.join(chr(i).encode('latin1') for i in deltas))).decode('latin1') | ||
|
||
|
||
|
||
class Module(object): | ||
|
@@ -55,15 +73,14 @@ def __call__(self, context): | |
context.templates = [] | ||
|
||
# Snapshot the line number mapping. | ||
# TODO: Run-length encode the line number deltas, 'cause damn, this is a lot of data. | ||
mapping = deque(context.mapping) | ||
mapping.reverse() | ||
|
||
mapping = deque(pformat(list(mapping), indent=0, width=105).split('\n')) | ||
|
||
yield Line(0, '') | ||
yield Line(0, '__mapping__ = ' + mapping.popleft()) | ||
for line in mapping: | ||
yield Line(0, line) | ||
|
||
if __debug__: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
amcgregor
Author
Member
|
||
yield Line(0, '__mapping__ = [' + ','.join(str(i) for i in mapping) + ']') | ||
|
||
yield Line(0, '__gzmapping__ = rb"""' + red(mapping) + '"""') | ||
|
||
context.flag.remove('init') |
This check appears to cause latin-1 encoding to occur when debug is False; special chars will throw an exception not thrown when debug is True.