Пример #1
0
def lazy_keys(dikt):
    """Return lazy-evaluated string representation of a dictionary's keys
    
    Key list is only constructed if it will actually be used.
    Used for debug-logging.
    """
    return LazyEvaluate(lambda d: list(d.keys()))
Пример #2
0
 def test_lazy_eval_nonascii_bytes(self):
     u = 'ünicødé'
     b = u.encode('utf8')
     lz = LazyEvaluate(lambda: b)
     # unicode(lz) would fail
     self.assertEqual(str(lz), str(b))
     self.assertEqual(format(lz), str(b))
Пример #3
0
    def test_lazy_eval_float(self):
        f = 0.503
        lz = LazyEvaluate(lambda: f)

        self.assertEqual(str(lz), str(f))
        self.assertEqual(format(lz), str(f))
        self.assertEqual(format(lz, '.1'), '0.5')
Пример #4
0
 def IPythonColorPrompt(shell):
     from IPython.core.prompts import LazyEvaluate
     shell.prompt_manager.in_template = 'In [\\#] {burst}'
     shell.prompt_manager.in2_template = '  .\\D. {burst}'
     shell.prompt_manager.out_template = 'Out[\\#] {burst}'
     shell.prompt_manager.lazy_evaluate_fields = {
         'burst': LazyEvaluate(ColorPrompt().__str__)
     }
Пример #5
0
def configure_prompt(ipydb):
    from IPython.core.prompts import LazyEvaluate
    global _backup_prompt1
    ip = ipydb.shell
    ip.prompt_manager.lazy_evaluate_fields['_ipydb'] = LazyEvaluate(
        ipydb.get_db_ps1)
    ip.prompt_manager.lazy_evaluate_fields['_reflecting'] = LazyEvaluate(
        ipydb.get_reflecting_ps1)
    ip.prompt_manager.lazy_evaluate_fields['_tx'] = LazyEvaluate(
        ipydb.get_transaction_ps1)
    tmpl = ip.prompt_manager.in_template
    _backup_prompt1 = tmpl
    tmpl = tmpl.rstrip(': ')
    tmpl += '{color.LightPurple}{_reflecting}' \
            '{color.Cyan}{_ipydb}' \
            '{color.LightRed}{_tx}' \
            '{color.Green}: '
    ip.prompt_manager.in_template = tmpl
Пример #6
0
 def test_lazy_eval_unicode(self):
     u = 'ünicødé'
     lz = LazyEvaluate(lambda: u)
     # str(lz) would fail
     self.assertEqual(str(lz), u)
     self.assertEqual(format(lz), u)
Пример #7
0
 def test_lazy_eval_unicode(self):
     u = u"ünicødé"
     lz = LazyEvaluate(lambda: u)
     self.assertEqual(str(lz), u)
     self.assertEqual(format(lz), u)