43
43
update_path_extents )
44
44
from numpy .linalg import inv
45
45
46
+ import re
46
47
import weakref
47
48
import warnings
48
49
52
53
DEBUG = False
53
54
54
55
56
+ def _indent_str (obj ): # textwrap.indent(str(obj), 4) on Py3.
57
+ return re .sub ("(^|\n )" , r"\1 " , str (obj ))
58
+
59
+
55
60
class TransformNode (object ):
56
61
"""
57
62
:class:`TransformNode` is the base class for anything that
@@ -1053,8 +1058,15 @@ def __init__(self, bbox, transform, **kwargs):
1053
1058
self .set_children (bbox , transform )
1054
1059
self ._points = None
1055
1060
1056
- def __repr__ (self ):
1057
- return "TransformedBbox(%r, %r)" % (self ._bbox , self ._transform )
1061
+ def __str__ (self ):
1062
+ return ("{}(\n "
1063
+ "{},\n "
1064
+ "{})"
1065
+ .format (type (self ).__name__ ,
1066
+ _indent_str (self ._bbox ),
1067
+ _indent_str (self ._transform )))
1068
+
1069
+ __repr__ = __str__
1058
1070
1059
1071
def get_points (self ):
1060
1072
if self ._invalid :
@@ -1134,8 +1146,15 @@ def __init__(self, bbox, x0=None, y0=None, x1=None, y1=None, **kwargs):
1134
1146
self ._locked_points = np .ma .array (fp , np .float_ ,
1135
1147
mask = mask ).reshape ((2 , 2 ))
1136
1148
1137
- def __repr__ (self ):
1138
- return "LockableBbox(%r, %r)" % (self ._bbox , self ._locked_points )
1149
+ def __str__ (self ):
1150
+ return ("{}(\n "
1151
+ "{},\n "
1152
+ "{})"
1153
+ .format (type (self ).__name__ ,
1154
+ _indent_str (self ._bbox ),
1155
+ _indent_str (self ._locked_points )))
1156
+
1157
+ __repr__ = __str__
1139
1158
1140
1159
def get_points (self ):
1141
1160
if self ._invalid :
@@ -1686,8 +1705,13 @@ def __setstate__(self, state):
1686
1705
self ._parents = dict ((k , weakref .ref (v )) for (k , v ) in
1687
1706
six .iteritems (state ['parents' ]) if v is not None )
1688
1707
1689
- def __repr__ (self ):
1690
- return "TransformWrapper(%r)" % self ._child
1708
+ def __str__ (self ):
1709
+ return ("{}(\n "
1710
+ "{})"
1711
+ .format (type (self ).__name__ ,
1712
+ _indent_str (self ._child )))
1713
+
1714
+ __repr__ = __str__
1691
1715
1692
1716
def frozen (self ):
1693
1717
return self ._child .frozen ()
@@ -1914,8 +1938,13 @@ def __init__(self, matrix=None, **kwargs):
1914
1938
self ._mtx = matrix
1915
1939
self ._invalid = 0
1916
1940
1917
- def __repr__ (self ):
1918
- return "Affine2D(%s)" % repr (self ._mtx )
1941
+ def __str__ (self ):
1942
+ return ("{}(\n "
1943
+ "{})"
1944
+ .format (type (self ).__name__ ,
1945
+ _indent_str (self ._mtx )))
1946
+
1947
+ __repr__ = __str__
1919
1948
1920
1949
@staticmethod
1921
1950
def from_values (a , b , c , d , e , f ):
@@ -2119,8 +2148,11 @@ def frozen(self):
2119
2148
return self
2120
2149
frozen .__doc__ = Affine2DBase .frozen .__doc__
2121
2150
2122
- def __repr__ (self ):
2123
- return "IdentityTransform()"
2151
+ def __str__ (self ):
2152
+ return ("{}()"
2153
+ .format (type (self ).__name__ ))
2154
+
2155
+ __repr__ = __str__
2124
2156
2125
2157
def get_matrix (self ):
2126
2158
return self ._mtx
@@ -2219,8 +2251,15 @@ def frozen(self):
2219
2251
return blended_transform_factory (self ._x .frozen (), self ._y .frozen ())
2220
2252
frozen .__doc__ = Transform .frozen .__doc__
2221
2253
2222
- def __repr__ (self ):
2223
- return "BlendedGenericTransform(%s,%s)" % (self ._x , self ._y )
2254
+ def __str__ (self ):
2255
+ return ("{}(\n "
2256
+ "{},\n "
2257
+ "{})"
2258
+ .format (type (self ).__name__ ,
2259
+ _indent_str (self ._x ),
2260
+ _indent_str (self ._y )))
2261
+
2262
+ __repr__ = __str__
2224
2263
2225
2264
def transform_non_affine (self , points ):
2226
2265
if self ._x .is_affine and self ._y .is_affine :
@@ -2324,8 +2363,15 @@ def contains_branch_seperately(self, transform):
2324
2363
# Note, this is an exact copy of BlendedTransform.contains_branch_seperately
2325
2364
return self ._x .contains_branch (transform ), self ._y .contains_branch (transform )
2326
2365
2327
- def
F438
span> __repr__ (self ):
2328
- return "BlendedAffine2D(%s,%s)" % (self ._x , self ._y )
2366
+ def __str__ (self ):
2367
+ return ("{}(\n "
2368
+ "{},\n "
2369
+ "{})"
2370
+ .format (type (self ).__name__ ,
2371
+ _indent_str (self ._x ),
2372
+ _indent_str (self ._y )))
2373
+
2374
+ __repr__ = __str__
2329
2375
2330
2376
def get_matrix (self ):
2331
2377
if self ._invalid :
@@ -2439,12 +2485,15 @@ def _get_is_separable(self):
2439
2485
return self ._a .is_separable and self ._b .is_separable
2440
2486
is_separable = property (_get_is_separable )
2441
2487
2442
- if DEBUG :
2443
- def __str__ (self ):
2444
- return '(%s, %s)' % (self ._a , self ._b )
2488
+ def __str__ (self ):
2489
+ return ("{}(\n "
2490
+ "{},\n "
2491
+ "{})"
2492
+ .format (type (self ).__name__ ,
2493
+ _indent_str (self ._a ),
2494
+ _indent_str (self ._b )))
2445
2495
2446
- def __repr__ (self ):
2447
- return "CompositeGenericTransform(%r, %r)" % (self ._a , self ._b )
2496
+ __repr__ = __str__
2448
2497
2449
2498
def transform_affine (self , points ):
2450
2499
return self .get_affine ().transform (points )
@@ -2535,8 +2584,15 @@ def _iter_break_from_left_to_right(self):
2535
2584
for lh_compliment , rh_compliment in self ._b ._iter_break_from_left_to_right ():
2536
2585
yield self ._a + lh_compliment , rh_compliment
2537
2586
2538
- def __repr__ (self ):
2539
- return "CompositeAffine2D(%r, %r)" % (self ._a , self ._b )
2587
+ def __str__ (self ):
2588
+ return ("{}(\n "
2589
+ "{},\n "
2590
+ "{})"
2591
+ .format (type (self ).__name__ ,
2592
+ _indent_str (self ._a ),
2593
+ _indent_str (self ._b )))
2594
+
2595
+ __repr__ = __str__
2540
2596
2541
2597
def get_matrix (self ):
2542
2598
if self ._invalid :
@@ -2599,8 +2655,15 @@ def __init__(self, boxin, boxout, **kwargs):
2599
2655
self ._mtx = None
2600
2656
self ._inverted = None
2601
2657
2602
- def __repr__ (self ):
2603
- return "BboxTransform(%r, %r)" % (self ._boxin , self ._boxout )
2658
+ def __str__ (self ):
2659
+ return ("{}(\n "
2660
+ "{},\n "
2661
+ "{})"
2662
+ .format (type (self ).__name__ ,
2663
+ _indent_str (self ._boxin ),
2664
+ _indent_str (self ._boxout )))
2665
+
2666
+ __repr__ = __str__
2604
2667
2605
2668
def get_matrix (self ):
2606
2669
if self ._invalid :
@@ -2642,8 +2705,13 @@ def __init__(self, boxout, **kwargs):
2642
2705
self ._mtx = None
2643
2706
self ._inverted = None
2644
2707
2645
- def __repr__ (self ):
2646
- return "BboxTransformTo(%r)" % (self ._boxout )
2708
+ def __str__ (self ):
2709
+ return ("{}(\n "
2710
+ "{})"
2711
+ .format (type (self ).__name__ ,
2712
+ _indent_str (self ._boxout )))
2713
+
2714
+ __repr__ = __str__
2647
2715
2648
2716
def get_matrix (self ):
2649
2717
if self ._invalid :
@@ -2666,9 +2734,6 @@ class BboxTransformToMaxOnly(BboxTransformTo):
2666
2734
transforms points from the unit bounding box to a given
2667
2735
:class:`Bbox` with a fixed upper left of (0, 0).
2668
2736
"""
2669
- def __repr__ (self ):
2670
- return "BboxTransformToMaxOnly(%r)" % (self ._boxout )
2671
-
2672
2737
def get_matrix (self ):
2673
2738
if self ._invalid :
2674
2739
xmax , ymax = self ._boxout .max
@@ -2701,8 +2766,13 @@ def __init__(self, boxin, **kwargs):
2701
2766
self ._mtx = None
2702
2767
self ._inverted = None
2703
2768
2704
- def __repr__ (self ):
2705
- return "BboxTransformFrom(%r)" % (self ._boxin )
2769
+ def __str__ (self ):
2770
+ return ("{}(\n "
2771
+ "{})"
2772
+ .format (type (self ).__name__ ,
2773
+ _indent_str (self ._boxin )))
2774
+
2775
+ __repr__ = __str__
2706
2776
2707
2777
def get_matrix (self ):
2708
2778
if self ._invalid :
@@ -2734,8 +2804,13 @@ def __init__(self, xt, yt, scale_trans, **kwargs):
2734
2804
self ._mtx = None
2735
2805
self ._inverted = None
2736
2806
2737
- def __repr__ (self ):
2738
- return "ScaledTranslation(%r)" % (self ._t ,)
2807
+ def __str__ (self ):
2808
+ return ("{}(\n "
2809
+ "{})"
2810
+ .format (type (self ).__name__ ,
2811
+ _indent_str (self ._t )))
2812
+
2813
+ __repr__ = __str__
2739
2814
2740
2815
def get_matrix (self ):
2741
2816
if self ._invalid :
0 commit comments