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