Merge lp:~blueyed/pastebinit/cleanup-relink-website-var-usage into lp:pastebinit

Proposed by Daniel Hahler
Status: Merged
Merged at revision: 221
Proposed branch: lp:~blueyed/pastebinit/cleanup-relink-website-var-usage
Merge into: lp:pastebinit
Diff against target: 65 lines (+16/-15)
1 file modified
pastebinit (+16/-15)
To merge this branch: bzr merge lp:~blueyed/pastebinit/cleanup-relink-website-var-usage
Reviewer Review Type Date Requested Status
Pastebinit Developers Pending
Review via email: mp+203652@code.launchpad.net

Description of the change

NOTE: this will conflict with the 'verbose-option' branch, but easy to fix.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pastebinit'
2--- pastebinit 2014-01-18 04:51:35 +0000
3+++ pastebinit 2014-01-29 01:37:34 +0000
4@@ -378,20 +378,26 @@
5 else:
6 del params['sizelimit']
7
8- reLink = None
9- tmp_page = ""
10 if "page" in params:
11- website += params['page']
12- tmp_page = params['page']
13- del params["page"]
14+ # Use page, without leading slash: website has a trailing one.
15+ fetch_url = website + params['page'].lstrip("/")
16+ del params['page']
17+ else:
18+ fetch_url = website
19 if "regexp" in params:
20 reLink = params['regexp']
21 del params["regexp"]
22+ else:
23+ reLink = False
24+ # Get target_url for replacement, only used with reLink.
25 if "target_url" in params:
26- target_url = params["target_url"]
27+ relink_target_url = params["target_url"]
28 del params["target_url"]
29- else:
30- target_url = None
31+ if not reLink:
32+ print("Warning: using target_url without regexp.",
33+ file=sys.stderr)
34+ elif reLink:
35+ relink_target_url = website
36 if 'post_format' in params:
37 post_format = params['post_format']
38 del params['post_format']
39@@ -413,7 +419,7 @@
40
41 # Send the informations and be redirected to the final page
42 try:
43- page = url_opener.open(website, params)
44+ page = url_opener.open(fetch_url, params)
45 except Exception as e:
46 print(_("Failed to contact the server: %s") % e, file=sys.stderr)
47 sys.exit(1)
48@@ -421,16 +427,11 @@
49 try:
50 # Check if we have to apply a regexp
51 if reLink:
52- if target_url:
53- website = target_url
54- else:
55- website = website.replace(tmp_page, "")
56-
57 if reLink == '(.*)':
58 print(page.read().decode('utf-8').strip())
59 else:
60 # Print the result of the regexp
61- print(website + re.split(reLink,
62+ print(relink_target_url + re.split(reLink,
63 page.read().decode('utf-8'))[1])
64 else:
65 # Get the final page and show the url

Subscribers

People subscribed via source and target branches

to all changes: