266 Commits

Author SHA1 Message Date
Cosimo Lupo
09d2983fbb [classifyTools] rename 'sorted' -> 'sort' to avoid confusions with the built-in name 2016-04-08 22:08:21 +01:00
Cosimo Lupo
020acf168b [classifyTools] fixup tests after reverting commit 34d43aa 2016-04-08 21:59:05 +01:00
Cosimo Lupo
20320494de Revert "[classifyTools] 'sorted' keyword argument should be boolean"
This reverts commit 34d43aa797c8b9e4ff42782bfdd7abde7711835d.

See 34d43aa797 (commitcomment-17012817)
2016-04-08 21:54:56 +01:00
Cosimo Lupo
1aa92de366 [classifyTools] must sub-class from 'object' to use new-style classes on py2 2016-04-07 12:09:28 +01:00
Cosimo Lupo
c9db89a851 [classifyTools] fix doctest failing on pypy
It seems like sets are hashed differently in CPython and PyPy.
Because of this, the returned list of class sets may have a different sort
order (within each class size) between the two implementations.

For now, I make the test pass on both CPython and PyPy by casting the returned
list of sets into a set of (frozen) sets, and asserting that its *content* is
correct, without considering the *order* of the sets in the list.
2016-04-07 11:54:53 +01:00
Cosimo Lupo
d2aab877bb [classifyTools] fix CI doctest failures on python 3
set objects have different __repr__ on python 2 and 3

Python 3:
    >>> {1, 2, 3}
    {1, 2, 3}

Python 2
    >>> {1, 2, 3}
    set([1, 2, 3])

(one among the several reasons I don't particularly like doctest...)
2016-04-07 10:00:49 +01:00
Cosimo Lupo
69bee48a8f [classifyTools] semicolon 2016-04-07 09:33:02 +01:00
Cosimo Lupo
34d43aa797 [classifyTools] 'sorted' keyword argument should be boolean
or at least that's what the signature and the docstring imply.
2016-04-07 09:31:12 +01:00
Cosimo Lupo
da04ab2909 [py23] define __all__ variable
specifying the list of names that are imported when `from py23 import *` is used
2016-04-07 09:21:05 +01:00
Behdad Esfahbod
f70d264ef0 Add __bool__ to fontTools.misc.transform.Transform 2016-04-06 18:15:43 -07:00
Behdad Esfahbod
552b5d97fc Add fontTools.misc.classifyTools, helpers to classify things into classes
To be extended with more features / API.  API might change.
2016-04-06 18:15:43 -07:00
Behdad Esfahbod
2a0359af4d Always import * from py23
Since py23 modifies some essential builtins, it's safe to import
everything all the time.  At least, that's how it was designed.
It's a bug if importing * breaks some code.
2016-04-06 18:15:43 -07:00
Cosimo Lupo
16f29ffd6d [loggingTools] use ellipsis for doctests when printing time
appveyor can be *very* slow

https://ci.appveyor.com/project/anthrotype/fonttools/build/job/pdrl7o5ggan7qlej
2016-02-07 01:19:45 +00:00
Cosimo Lupo
7c6744e639 [py23_test] pass os.environ copy instead of empty dict to avoid issue on Windows
Otherwise I get this:
Fatal Python error: Failed to initialize Windows random API (CryptoGen)

https://ci.appveyor.com/project/anthrotype/fonttools/build/job/qhf8d89or4d5hiyd

see: http://bugs.python.org/issue20614
2016-02-07 01:19:45 +00:00
Cosimo Lupo
4a783326b8 [py23_test] need to use os.pathsep as Windows uses ";", not ":" 2016-02-07 01:19:45 +00:00
Cosimo Lupo
4874264dd9 [py23_test] pass the sys.path as PYTHONPATH to python subprocess
Apparently I need to do that, or the child python process does not see fontTools in the path.

Another workaround woud be to ensure that fontTools is installed, at least in editable or develop mode (via `pip install -e .`). But the way we temporarily extend the PYTHONPATH in run-test.sh is less intrusive.
2016-02-07 01:19:45 +00:00
Cosimo Lupo
c4d2ebca66 remove deprecated use of 'quiet' option in test modules 2016-02-01 13:39:39 +00:00
Cosimo Lupo
f65a6ec346 [loggingTools] remove _StderrHandler and Logger classes (moved to py23) 2016-02-01 13:18:06 +00:00
Cosimo Lupo
52620787d8 [py23] set the lastResort handler and custom logger class only for python 2
move _StderrHandler and _Logger classes here (previously defined in loggingTools)
2016-02-01 13:17:15 +00:00
Cosimo Lupo
bfe330e0a6 [psCharStrings] use fixedToFloat to use the shortest decimal reprentation
Fixes https://github.com/behdad/fonttools/issues/492
2016-02-01 10:52:33 +00:00
Cosimo Lupo
f3116ad4d0 [loggingTools] add Logger class with support for 'lastResort' stderr handler
Both _StderrHandler and Logger.callHandlers included here are taken from Python 3.5's
logging.py source.

I only set logging.lastResort if it's not already set (i.e. for Python < 3.2).
2016-01-29 18:36:21 +00:00
Cosimo Lupo
141cc7b6c2 [loggingTools] typo 2016-01-29 17:28:53 +00:00
Cosimo Lupo
3664462a63 [loggingTools] use ellipsis for elapsed time in doctestes to fix AppVeyor build
https://ci.appveyor.com/project/anthrotype/fonttools/build/1.0.53/job/2p08d9sbcfelvwx6
2016-01-27 19:05:05 +00:00
Cosimo Lupo
e8edfad59a [loggingTools] on Windows, warnings.warn doesn't like category=None, set it to UserWarning (which is the default) 2016-01-27 19:05:05 +00:00
Cosimo Lupo
b6145de7cb [psLib] replace print with logger 2016-01-27 19:02:48 +00:00
Cosimo Lupo
e4f0f3ec30 [psCharStrings] replace print with logger 2016-01-27 19:02:48 +00:00
Cosimo Lupo
de5dca010b [xmlReader] replace print with logger; deprecate 'quiet' argument 2016-01-27 19:01:12 +00:00
Cosimo Lupo
317d653125 [loggingTools] module containing tools for adapting the Python logging package to fontTools (and viceversa) 2016-01-27 19:01:12 +00:00
Cosimo Lupo
b63935c6f8 [py23_test] test py23.open for piping binary data through stdin/stdout 2016-01-25 18:25:07 +00:00
Cosimo Lupo
47bde21b86 [py23] add wrapper around io.open bridging py23 differences 2016-01-25 17:52:45 +00:00
Sascha Brawer
0f8882bcc3 [otlLib] Move creation of ValueRecords from feaLib to otlLib 2016-01-14 16:27:04 +01:00
Cosimo Lupo
a54a794f81 timeTools: define platform-independent 'asctime' function
Fixes https://github.com/behdad/fonttools/issues/455
2016-01-12 12:33:22 +00:00
Cosimo Lupo
e4ab85e90a macRes: fix OverflowError while reading resource on 32-bit Python
Fixes https://github.com/behdad/fonttools/issues/436
2015-12-15 11:01:26 +00:00
Cosimo Lupo
8933062db0 xmlReader: make xmlReader accept file objects
Fixes https://github.com/behdad/fonttools/issues/404

Also, fixed typo for ProgressPrinter method call: 'setlabel' -> 'setLabel'
2015-12-07 19:31:33 +00:00
Cosimo Lupo
5cf297ca44 xmlReader_test: test ProgressPrinter and reading from path vs file object 2015-12-07 19:26:04 +00:00
Cosimo Lupo
2eda1785f6 [py23] fix ImportError when trying to import unichr, basestring or unicode when already defined
When one does `from fontTools.misc.py23 import *`, everything seems to work fine.

However, linters will complain when one uses the asterisk to import all names from a module, since they can't detect when names are left undefined -- asterisks are greedy and will eat all names.

If one avoids the asterik and attempts to import explicitly, like in `from fontTools.misc.py23 import basestring`, the problem then is that, if `py23` does not re-define the name -- e.g. under python2 `basestring` or `unicode` are built-ins -- then the import statement raises `ImportError`.

The same happens for the `unichr` function on a "wide" Python 2 build (in which `sys.maxunicode == 0x10FFFF`).

Now, to work around this, we need to re-assign those built-ins to their very same names. This may look silly, but at least it works.
2015-11-23 12:02:12 +00:00
Cosimo Lupo
f10cb1f17d [macCreatorType] fix KeyError raised by old version of xattr module
in version 0.6.4 (installed on OS X 10.10 python lib/extras) it raises
KeyError, whereas in the latest version available fom PyPI (v0.7.8) it
raises IOError.

Fixes issue in https://github.com/googlei18n/nototools/issues/113
2015-11-11 00:01:50 +00:00
Cosimo Lupo
f8e8ea6e7f [macRes] use tostr(s, encoding='mac-roman') for resource types and names 2015-10-26 14:38:20 +00:00
Cosimo Lupo
2f212ac59a [macRes] add default value [] to self.get(resType)
ops!
2015-10-26 05:16:22 +00:00
Cosimo Lupo
17e757300c [macRes_test] add tests for ResourceReader 2015-10-26 04:40:00 +00:00
Cosimo Lupo
db70dee031 [macRes] new module and ResourceReader to read Mac resource/data forks
inspired by Sascha Brawer's GNU Classpath Java implementation

https://gcc.gnu.org/viewvc/gcc/trunk/libjava/classpath/gnu/java/awt/font/opentype/MacResourceFork.java?view=co&content-type=text%2Fplain
2015-10-26 04:40:00 +00:00
Cosimo Lupo
363893d1fc [macCreatorType] try to use xattr module if installed
xattr is a Python wrapper for extended filesystem attributes, which works
with both Python 2 and 3: https://pypi.python.org/pypi/xattr
2015-10-26 03:49:31 +00:00
Cosimo Lupo
8891e98920 remove MacOS-only misc/homeResFile.py module (no longer used) 2015-10-26 03:34:03 +00:00
Cosimo Lupo
d0b6bdafa0 [psLib] make PSTokenizer indipendent StringIO-like object; fix issues with python3 (bytes vs unicode)
PSTokenizer is now an indipendent object behaving like a StringIO.StringIO: it has `read` and `close` methods, as well as `buf`, `pos` and `len` attributes.

The input data is a string of bytes, and the output tokens are ascii-decoded unicode strings.

(I removed "__main__" as it was using a non-py23 EasyDialogs module)

See https://github.com/behdad/fonttools/issues/393.

Related to https://github.com/behdad/fonttools/issues/391.
2015-10-22 19:55:33 +01:00
Cosimo Lupo
1c2fe9c37c [eexec] use bytes instead of str; add doctests to encrypt and decrypt functions 2015-10-22 19:54:53 +01:00
Cosimo Lupo
565d36c511 [psLib] revert to StringIO.StringIO; temporarily drop support for py3
Reverts commit bf0e336d316518115a7b47da4f721bb8a009b3e1
Fixes https://github.com/behdad/fonttools/issues/391

...though only temporarily.
2015-10-21 13:14:48 +01:00
Sascha Brawer
582852119c Implement OTTableReader.readUShortArray()
There is currently only one single call site in the codebase,
but this function will be needed a lot for parsing `morx` and
other AAT tables.
2015-10-17 06:47:52 +02:00
Cosimo Lupo
cb36478d4b [testTools] add getXML function to get the XMLWriter content as string 2015-09-30 20:19:35 +01:00
Sascha Brawer
d63885e337 [otTables] Use XML snippets for testing fromXML() methods
This should make the unit tests more readable, and it also prevents
failures where a changed fromXML() implementation fails to ignore
interspersed whitespace. This has recently caused some developer
nuisance; see https://github.com/behdad/fonttools/pull/367.

Instead of having a custom parser implementation, it would be nicer
to call the actual XMLReader. However, XMLReader has a deeply built-in
assumption that it is processing an entire TTX file. Changing this
assumption would certainly be possible, but it would need a re-write
of the XMLReader code; having a custom parser just for unit tests
seems less involved.
2015-09-11 15:44:29 +02:00
Cosimo Lupo
895c54cf92 [textTools] reduce usage of str concat in pad function 2015-09-09 09:52:31 +01:00