chiark / gitweb /
catacomb/__init__.py: Print group elements properly.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 4 May 2017 11:07:10 +0000 (12:07 +0100)
Slightly grim: add a method to group objects to export their elements as
some useful type, and then call that from the element print function.

catacomb/__init__.py

index bc050be8a40ba99009511e0661fedcdd01b4195b..28b4f85dfd6cd25988801809ff2f9f090781dffa 100644 (file)
@@ -589,6 +589,7 @@ class _tmp:
     h ^= 2*hash(info.r) & 0xffffffff
     h ^= 5*hash(info.g) & 0xffffffff
     return h
+  def _get_geval(me, x): return MP(x)
 _augment(PrimeGroup, _tmp)
 
 class _tmp:
@@ -599,16 +600,19 @@ class _tmp:
     h ^= 2*hash(info.r) & 0xffffffff
     h ^= 5*hash(info.g) & 0xffffffff
     return h
+  def _get_geval(me, x): return GF(x)
 _augment(BinGroup, _tmp)
 
 class _tmp:
   def __hash__(me): return 0x0ec23dab ^ hash(me.info)
+  def _get_geval(me, x): return x.toec()
 _augment(ECGroup, _tmp)
 
 class _tmp:
   def __repr__(me):
     return '%r(%r)' % (me.group, str(me))
-  _repr_pretty_ = _pp_str
+  def _repr_pretty_(me, pp, cyclep):
+    pp.pretty(type(me)._get_geval(me))
 _augment(GE, _tmp)
 
 ###--------------------------------------------------------------------------