Beispiel #1
0
 def test_clear(self):
     d=dic()
     d.update({"k1":"v1"})
     self.assertEqual(len(d), 1)
     dr=d.clear()
     self.assertEqual(len(dr), 0)
     self.assertEqual(dr, d)
Beispiel #2
0
 def test_each(self):
     d=dic()
     d.update({"K1":"V1", "K2":"V2"})
     
     f=lambda k,v: (k.lower(), v.lower())
     dr=d.map(f)
     self.assertEqual(dr, {"k1":"v1", "k2":"v2"})
Beispiel #3
0
 def test_count(self):
     d=dic()
     d.update({"K1":"V1", "K2":"V2", "A1":"AV1"})
     
     predicate=lambda k,v: k.lower().startswith("k")
     
     count=d.count(predicate)
     self.assertEqual(2, count)
Beispiel #4
0
    def test_any(self):
        
        def starts_kv(k,v):
            return k[0]=="k" and v[0]=="v"

        d=dic()
        d.update({"a1":"a1", "k2": "v2"})
        self.assertTrue(d.any(starts_kv))
Beispiel #5
0
def send_msg(question, ttype, mtype, msg_dic):
    try:
        q="?" if question else ""
        topic=q+ttype+"_"+mtype
        
        m=dic({"topic": topic}).update(msg_dic)
        
        sys.stdout.write(json.dumps(m)+"\n")
    except:
        pass
Beispiel #6
0
def process_l3(source_url, _propagate_error, format_json, batch_size):
    
    while True:
        ( (http_code, headers), (code_extract, hrefs) )=(yield)
        
        based={"source_url": source_url
           ,"http_status": http_code
           ,"etag": headers.get("etag", None)
           ,"last-modified": headers.get("last-modified", None)
           ,"extract_status": code_extract
           }

        for hrefs in batch(hrefs, batch_size):
            
            d=dic(based).update({"hrefs": hrefs})
                
            if format_json:
                stdout(json_string(d))
            else:
                if hrefs is not None:
                    for href in hrefs:
                        stdout(href)
                        
        stdout_flush()
Beispiel #7
0
    def test_do(self):
        d=dic()
        d.update({"K1":"V1", "K2":"V2"})

        dr=d.do(len)
        self.assertEqual(len(d), dr.last_value)
Beispiel #8
0
 def test_safe(self):
     d=dic()
     d.safe(True)
     
     self.assertEqual(d[0], None)
Beispiel #9
0
 def test_update(self):
     d=dic()
     dr=d.update({"k1":"v1"})
     self.assertEqual(d, dr)