Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: net/tools/testserver/testserver.py

Issue 201083: Cache login identity for NewFTP transactions. (Closed)
Patch Set: better Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/python2.4
2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This is a simple HTTP server used for testing Chrome. 6 """This is a simple HTTP server used for testing Chrome.
7 7
8 It supports several test URLs, as specified by the handlers in TestPageHandler. 8 It supports several test URLs, as specified by the handlers in TestPageHandler.
9 It defaults to living on localhost:8888. 9 It defaults to living on localhost:8888.
10 It can use https if you specify the flag --https=CERT where CERT is the path 10 It can use https if you specify the flag --https=CERT where CERT is the path
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 print 'shutting down server' 1106 print 'shutting down server'
1107 sys.exit(0) 1107 sys.exit(0)
1108 1108
1109 # Instantiate a dummy authorizer for managing 'virtual' users 1109 # Instantiate a dummy authorizer for managing 'virtual' users
1110 authorizer = pyftpdlib.ftpserver.DummyAuthorizer() 1110 authorizer = pyftpdlib.ftpserver.DummyAuthorizer()
1111 1111
1112 # Define a new user having full r/w permissions and a read-only 1112 # Define a new user having full r/w permissions and a read-only
1113 # anonymous user 1113 # anonymous user
1114 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') 1114 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw')
1115 1115
1116 authorizer.add_anonymous(my_data_dir) 1116 if options.ftp_enable_anonymous:
1117 authorizer.add_anonymous(my_data_dir)
1117 1118
1118 # Instantiate FTP handler class 1119 # Instantiate FTP handler class
1119 ftp_handler = pyftpdlib.ftpserver.FTPHandler 1120 ftp_handler = pyftpdlib.ftpserver.FTPHandler
1120 ftp_handler.authorizer = authorizer 1121 ftp_handler.authorizer = authorizer
1121 pyftpdlib.ftpserver.logline = line_logger 1122 pyftpdlib.ftpserver.logline = line_logger
1122 1123
1123 # Define a customized banner (string returned when client connects) 1124 # Define a customized banner (string returned when client connects)
1124 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." % 1125 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." %
1125 pyftpdlib.ftpserver.__ver__) 1126 pyftpdlib.ftpserver.__ver__)
1126 1127
1127 # Instantiate FTP server class and listen to 127.0.0.1:port 1128 # Instantiate FTP server class and listen to 127.0.0.1:port
1128 address = ('127.0.0.1', port) 1129 address = ('127.0.0.1', port)
1129 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) 1130 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler)
1130 print 'FTP server started on port %d...' % port 1131 print 'FTP server started on port %d...' % port
1131 1132
1132 try: 1133 try:
1133 server.serve_forever() 1134 server.serve_forever()
1134 except KeyboardInterrupt: 1135 except KeyboardInterrupt:
1135 print 'shutting down server' 1136 print 'shutting down server'
1136 server.stop = True 1137 server.stop = True
1137 1138
1138 if __name__ == '__main__': 1139 if __name__ == '__main__':
1139 option_parser = optparse.OptionParser() 1140 option_parser = optparse.OptionParser()
1140 option_parser.add_option("-f", '--ftp', action='store_const', 1141 option_parser.add_option('--ftp', action='store_const',
1141 const=SERVER_FTP, default=SERVER_HTTP, 1142 const=SERVER_FTP, default=SERVER_HTTP,
1142 dest='server_type', 1143 dest='server_type',
1143 help='FTP or HTTP server default HTTP') 1144 help='FTP or HTTP server default HTTP')
1145 option_parser.add_option('--ftp-enable-anonymous', action='store_true',
eroman 2009/09/22 07:42:24 It might be more convenient to invert the directio
1146 default=False, dest='ftp_enable_anonymous',
1147 help='Enable anonymous FTP')
1144 option_parser.add_option('--forking', action='store_true', default=False, 1148 option_parser.add_option('--forking', action='store_true', default=False,
1145 dest='forking', 1149 dest='forking',
1146 help='Serve each request in a separate process') 1150 help='Serve each request in a separate process')
1147 option_parser.add_option('', '--port', default='8888', type='int', 1151 option_parser.add_option('', '--port', default='8888', type='int',
1148 help='Port used by the server') 1152 help='Port used by the server')
1149 option_parser.add_option('', '--data-dir', dest='data_dir', 1153 option_parser.add_option('', '--data-dir', dest='data_dir',
1150 help='Directory from which to read the files') 1154 help='Directory from which to read the files')
1151 option_parser.add_option('', '--https', dest='cert', 1155 option_parser.add_option('', '--https', dest='cert',
1152 help='Specify that https should be used, specify ' 1156 help='Specify that https should be used, specify '
1153 'the path to the cert containing the private key ' 1157 'the path to the cert containing the private key '
1154 'the server should use') 1158 'the server should use')
1155 option_parser.add_option('', '--file-root-url', default='/files/', 1159 option_parser.add_option('', '--file-root-url', default='/files/',
1156 help='Specify a root URL for files served.') 1160 help='Specify a root URL for files served.')
1157 options, args = option_parser.parse_args() 1161 options, args = option_parser.parse_args()
1158 1162
1159 sys.exit(main(options, args)) 1163 sys.exit(main(options, args))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698