-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
71 lines (60 loc) · 2.38 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
###################################################################################
# progressbar.py - description
# -------------------
# begin : Oct 4, 2005
# last update : Jul 14, 2007
# copyright : (C) 2005, 2006, 2007 by Luis Useche
# email : [email protected]
#
###################################################################################
# This file is part of Postzilla.
#
# Postzilla is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Foobar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
###################################################################################
import os
import sys
from urlparse import urlparse
from httplib import HTTPConnection
from ftplib import FTP
import string, base64
from download import HttpDownloadPart, FtpDownloadPart
def get_download_protocol(url):
parsedURL = urlparse(url)
if parsedURL[0] == 'http':
return HttpDownloadPart
else:
return FtpDownloadPart
def verify_http_response(res):
if res.status!=200 and res.status!=206:
if res.status==401:
error_exit('You must supply the corrects user and password')
else:
error_exit('There is some error with the server reques. HTTP error: %s'%res.status)
def verify_ftp_response(response):
if not '230' in response:
error_exit('Error make login in ftp server. Verify your user, password and url')
def error_exit(msg):
print >> sys.stderr, msg
sys.exit(-1)
#Python 2.2 and previous do not have enumerate
if(sys.version_info < (2,3)):
def enumerate(list):
out = []
i = 0
for x in list:
out.append((i,x))
i = i + 1
return out