Package elisa :: Package core :: Module media_uri :: Class MediaUri
[hide private]
[frames] | no frames]

Class MediaUri

source code


Media URI management

An URI is structured like this:
  scheme://[user:password@]host[:port]/path[/][?params][#fragment]
This class is able to parse that and wrap access to all found attributes. When I'm parsing file:// URIs I'm allowed to replace paths like:
  ./path/to/foo
With the following:
  "%s/path/to/foo" % os.curdir


Nested Classes [hide private]
  __metaclass__
Instance Methods [hide private]
 
__init__(self, data)
Create an Uri from various representations.
source code
 
_uri_re(self) source code
 
path__get(self) source code
 
path__set(self, value) source code
 
_parse(self, location) source code
 
set_params(self, values)
Set a lot of parameters at one time.
source code
 
set_param(self, name, value)
Set the parameter 'name' to 'value'.
source code
unquoted Unicode
get_param(self, name, default=u'')
Get the value for the parameter 'name'.
source code
dict
get_params(self)
Get all params as a dict.
source code
unicode
get_params_string(self)
Get the params as a one-line string (excluding a leading '?').
source code
 
del_param(self, name)
Delete the paramter with the name 'name' (and it's value), if it is found in the list of parameters.
source code
 
extension__get(self) source code
 
filename__get(self)
Return the filename of the Uri.
source code
 
label__set(self, value) source code
 
label__get(self)
Return a displayable string designing the Uri.
source code
 
parent__get(self)
Return the parent URI.
source code
MediaUri
join(self, path)
Append the given path to my path attribute
source code
unicode
_to_unicode(self)
Textual representation of the URI
source code
unicode
__unicode__(self)
Textual representation of the URI
source code
string
__str__(self)
Byte string representation of the URI
source code
string
__repr__(self)
Byte string representation of the URI
source code
int
__cmp__(self, other_uri)
Compare myself with another uri.
source code
 
__eq__(self, other_uri) source code
 
__ne__(self, other_uri) source code
 
__nonzero__(self) source code
 
__contains__(self, component) source code
 
__add__(self, path) source code
 
endswith(self, character) source code
 
__getslice__(self, i, j) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Static Methods [hide private]
 
__classinit__(cls, new_attrs)
Given a class and a new set of attributes (as passed in by __classinit__), create or modify properties based on functions with special names ending in __get, __set, and __del.
source code
Class Variables [hide private]
  name = 'media_uri'
Instance Variables [hide private]
unicode extension
the extension of the uri or empty
unicode filename
the filename of the uri, means the part behind the last slash.
string fragment
optional URI fragment
string host
the URI hostname
unicode or elisa.extern.translator.Translateable label
the label for this uri (per default the same as the filename)
MediaUri parent
the parent uri (means the last part of the path is removed)
string password
the optional password
string path
the URI path, delimitted by slashes (/)
int port
URI optional port.
string scheme
the URI scheme
string user
the optional username
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data)
(Constructor)

source code 

Create an Uri from various representations.

Representation can be either a string containing the uri or the components of the uri stored in a dictionary.
Parameters:
  • data (string or dict) - An uri stored in a unicode string or described by its components (scheme, user, password, host, port, path, params, fragment), each of them being a string
Raises:
  • TypeError - If none of location or parts has been provided
  • ParseException - If the location wasn't correctly parsed
Overrides: object.__init__

set_params(self, values)

source code 
Set a lot of parameters at one time. Attention: it simply overrides already existing values!
Parameters:
  • values (dict) - a dictionary, where the parameter names are pointing to the unquoted values.

set_param(self, name, value)

source code 
Set the parameter 'name' to 'value'. If this parameter is already existing it is overritten. The value shouldn't be quoted yet, because it is quoted here. That might lead to very bad parameter values!
Parameters:
  • name (Unicode) - the name of the paramter
  • value (Unicode) - unquoted value for the parameter

get_param(self, name, default=u'')

source code 
Get the value for the parameter 'name'. If there is none found, return the value of 'default'. If 'default' is not set it is an empty unicode.
Parameters:
  • name (Unicode) - the name of the parameter
  • default (Unicode) - value that should be returned, if the parameter is not found (per default that is an empty Unicode)
Returns: unquoted Unicode
paramter or the value of default, if the paramter was not found

get_params(self)

source code 
Get all params as a dict.
Returns: dict
of quoted key value pairs

get_params_string(self)

source code 
Get the params as a one-line string (excluding a leading '?').
Returns: unicode
key1=value1&key2=value2

del_param(self, name)

source code 
Delete the paramter with the name 'name' (and it's value), if it is found in the list of parameters.
Parameters:
  • name (Unicode) - the name of the paramter to delete

filename__get(self)

source code 

Return the filename of the Uri.

Returns last path component label parameter like uri://path/to/foo then 'foo' is returned.

If there is no path, like in uri://host:port/ or in uri:// an empty unicode is returned

label__get(self)

source code 
Return a displayable string designing the Uri. Return last path component if the URI has no predetermined label instance attribute set.

parent__get(self)

source code 

Return the parent URI.

If the URI is like uri://path/to/foo return uri://path/to/

join(self, path)

source code 
Append the given path to my path attribute
Parameters:
  • path (string) - the path to append at the end of my path
Returns: MediaUri

__str__(self)
(Informal representation operator)

source code 
Byte string representation of the URI
Returns: string
Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 
Byte string representation of the URI
Returns: string
Overrides: object.__repr__

__cmp__(self, other_uri)
(Comparison operator)

source code 

Compare myself with another uri.

@see help of builtin cmp()
Parameters:
  • other_uri (MediaUri) - The URI I'm comparing myself with
Returns: int
Raises:
  • TypeError - When trying to compare with non-MediaUri object

__eq__(self, other_uri)
(Equality operator)

source code 
Raises:
  • TypeError - When trying to compare with non-MediaUri object

__ne__(self, other_uri)

source code 
Raises:
  • TypeError - When trying to compare with non-MediaUri object

Instance Variable Details [hide private]

extension

the extension of the uri or empty
Get Method:
elisa.core.media_uri.MediaUri.extension__get(self)
Set Method:
'frontend'
Delete Method:
'frontend'

filename

the filename of the uri, means the part behind the last slash. Could be empty!
Get Method:
elisa.core.media_uri.MediaUri.filename__get(self) - Return the filename of the Uri.
Set Method:
'frontend'
Delete Method:
'frontend'

label

the label for this uri (per default the same as the filename)
Get Method:
elisa.core.media_uri.MediaUri.label__get(self) - Return a displayable string designing the Uri.
Set Method:
elisa.core.media_uri.MediaUri.label__set(self, value)
Delete Method:
'frontend'

parent

the parent uri (means the last part of the path is removed)
Get Method:
elisa.core.media_uri.MediaUri.parent__get(self) - Return the parent URI.
Set Method:
'frontend'
Delete Method:
'frontend'

path

the URI path, delimitted by slashes (/)
Get Method:
elisa.core.media_uri.MediaUri.path__get(self)
Set Method:
elisa.core.media_uri.MediaUri.path__set(self, value)
Delete Method:
'frontend'

port

URI optional port. Set to 0 if not found
Type:
int