Package flumotion :: Package component :: Package misc :: Package httpserver :: Package httpcached :: Module common
[hide private]

Source Code for Module flumotion.component.misc.httpserver.httpcached.common

  1  # -*- Mode: Python; test-case-name: flumotion.test.test_component_providers -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import time 
 19   
 20   
 21  # Stream Errors 
 22  INTERNAL_ERROR = 500 
 23  NOT_IMPLEMENTED = 501 
 24  SERVER_UNAVAILABLE = 503 
 25  RANGE_NOT_SATISFIABLE = 416 
 26  STREAM_NOTFOUND = 404 
 27  STREAM_FORBIDDEN = 403 
 28  # The following error codes should only be used 
 29  # when the connection with the server has been established. 
 30  SERVER_DISCONNECTED = 502 
 31  SERVER_TIMEOUT = 504 
 32   
 33  # Condition Errors 
 34  STREAM_NOT_MODIFIED = 304 
 35  STREAM_MODIFIED = 412 
 36   
 37   
38 -class StreamConsumer(object):
39 """ 40 Interface of the stream consumer object. 41 No need to inherit from this class, 42 it's here just for documentation. 43 """ 44
45 - def serverError(self, getter, code, message):
46 pass
47
48 - def conditionFail(self, getter, code, message):
49 pass
50
51 - def streamNotAvailable(self, getter, code, message):
52 pass
53
54 - def onInfo(self, getter, info):
55 pass
56
57 - def onData(self, getter, data):
58 pass
59
60 - def streamDone(self, getter):
61 pass
62 63
64 -class StreamInfo(object):
65 """ 66 Base stream's information container. 67 No need to inherit from this class, 68 it's here just for documentation. 69 """ 70 expires = None 71 mtime = None 72 length = 0 73 start = 0 74 size = 0
75 76
77 -class ServerInfo(object):
78
79 - def __init__(self):
80 self.adress = None 81 self.protocol = "http"
82 83
84 -def log_id(obj):
85 """ 86 Gives a unique string identifier for an instance. 87 Used in the log to trace instances. 88 """ 89 result = id(obj) 90 if result < 0: 91 result += 1L << 32 92 if result < 0: 93 # 64bit, not sure how to detect the machine address width 94 result -= 1L << 32 95 result += 1L << 64 96 assert result > 0, "Address space fatter than 64 bits" 97 result = (result << 16) + (int(time.time()) & 0xFFFF) 98 return hex(result)[2:]
99