source: products/SimpleBlog/trunk/util.py @ 1

Last change on this file since 1 was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1import string,os,urllib,httplib,urlparse,re
2import sys
3
4def post_trackback(context,
5                   ping_url, 
6                   title = "", 
7                   src_url = "", 
8                   blog_name = "",
9                   excerpt = "",
10                   agent = "",
11                   charset = "",
12                   param_charset = ""):
13    """
14    Sending PING request to ping_url
15    """
16    params = {"title":    title,\
17              "url":      src_url,\
18              "blog_name": blog_name,\
19              "excerpt": excerpt
20             }
21    headers = ({"Content-type": "application/x-www-form-urlencoded",
22                "User-Agent": agent})
23
24
25    if param_charset:
26        params["charset"] = param_charset
27    elif charset:
28        headers["Content-type"] = headers["Content-type"] + "; charset=%s"
29
30    #if len(excerpt) > 0:
31    #    params["excerpt"] = excerpt
32
33    tb_url_t = urlparse.urlparse(ping_url)
34
35    enc_params = urllib.urlencode(params)
36
37    #check if trackback url contains parameter section(for PyDs!)
38    ut = urlparse.urlparse(ping_url)
39    if len(ut) >= 4 and ut[4]:
40        #add params to parameter section
41        enc_params = ut[4] + '&' + enc_params
42
43    host = tb_url_t[1]
44    path = tb_url_t[2]
45
46    try:
47        con = httplib.HTTPConnection(host)
48        con.request("POST", path, enc_params, headers)
49    except:
50        pass
51
52    return 0,"trackback sent"
53
54
55def addTrackBack(blog_entry, id, title, url, blog_name, excerpt):
56    """ create trackback object """
57    blog_entry.invokeFactory(id=id, type_name="TrackBack")
58    trback = getattr(blog_entry, id, None)
59    trback.update(title = title,
60                  url = url,
61                  blog_name = blog_name,
62                  excerpt = excerpt)
63
64def encodeURLData(data_dict):
65    """ encode URL data """
66    return urllib.urlencode(data_dict)
Note: See TracBrowser for help on using the repository browser.