Package magma :: Package magma :: Module magma_list :: Class MagmaFile
[hide private]
[frames] | no frames]

Class MagmaFile

source code

object --+
         |
        MagmaFile

A file inside the magma list.

Provides some abstractions for files inside Magma objects.

>>> magma_file = MagmaFile({FILENAME_PARAMETER: "input_file.txt", "urn": {"sha1": "3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G"}})
>>> print magma_file.data
{'urn': {'sha1': '3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G'}, 'Filename': 'input_file.txt'}
>>> print magma_file.sha1_hash
3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G
>>> print magma_file.name
input_file.txt
>>> print magma_file.magnet
magnet:?xt=urn:sha1:3UJCLAOIZVCNAIT7TQYFLAP7ZNFW6G2G&dn=input_file.txt
Instance Methods [hide private]
 
__init__(self, data, *args, **kwds)
A file inside the magma list.
source code
 
__str__(self)
Show nicely readable information about the file.
source code
 
readout_urls(self)
Readout alternate urls from the data
source code
 
readout_gnet_alt_locs(self)
Readout the Alt-Locs from the data
source code
 
parse_magnet(self)
Parse the magnet link from the data inside the file.
source code
 
remove_empty_entries(self)
Remove empty entries from the file, for example empty alt-locs.
source code

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

Instance Variables [hide private]
  data
All data of the file
  name
The name of the file, so we can easily print it.
  sha1_hash
The sha1 hash of the file.
  urls
The list of alternate urls.
  Gnutella_alt_locs
The Other Gnutella clients who have the file.
Properties [hide private]
  magnet
The magnet link of the file

Inherited from object: __class__

Method Details [hide private]

__init__(self, data, *args, **kwds)
(Constructor)

source code 

A file inside the magma list.

Parameters:
  • data (Dict) - The data of this file.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Show nicely readable information about the file.

Returns:
Nicely readable information about the file (String).
Overrides: object.__str__

readout_urls(self)

source code 

Readout alternate urls from the data

Returns:
A list of URLs which can be used as alternate fallback sources (which are unsafe, though, since it isn't sure that they will point to the same file when times change).

readout_gnet_alt_locs(self)

source code 

Readout the Alt-Locs from the data

Returns:
A list of IPs with Port numbers which can be used together with the sha1 hash to construct alt-locs for Gnutella.

parse_magnet(self)

source code 

Parse the magnet link from the data inside the file.

Returns:
A magnet link for the file (String).

Instance Variable Details [hide private]

name

The name of the file, so we can easily print it. Every MagmaFile needs a filename.

sha1_hash

The sha1 hash of the file. Every MagmaFile needs a sha1 hash.


Property Details [hide private]

magnet

The magnet link of the file

Get Method:
parse_magnet(self) - Parse the magnet link from the data inside the file.
Set Method:
unreachable.setattr(object, name, value) - Set a named attribute on an object; setattr(x, 'y', v) is equivalent to ``x.y = v''.