FTS3Utilities

Some utilities for FTS3…

class DIRAC.DataManagementSystem.private.FTS3Utilities.FTS3JSONDecoder(*args, **kargs)

Bases: json.decoder.JSONDecoder

This class is an decoder for the FTS3 objects

__init__(*args, **kargs)

encoding determines the encoding used to interpret any str objects decoded by this instance (utf-8 by default). It has no effect when decoding unicode objects.

Note that currently only encodings that are a superset of ASCII work, strings of other encodings should be passed in as unicode.

object_hook, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given dict. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting).

object_pairs_hook, if specified will be called with the result of every JSON object decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.OrderedDict will remember the order of insertion). If object_hook is also defined, the object_pairs_hook takes priority.

parse_float, if specified, will be called with the string of every JSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for JSON floats (e.g. decimal.Decimal).

parse_int, if specified, will be called with the string of every JSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for JSON integers (e.g. float).

parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN. This can be used to raise an exception if invalid JSON numbers are encountered.

If strict is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'.

decode(s, _w=<built-in method match of _sre.SRE_Pattern object>)

Return the Python representation of s (a str or unicode instance containing a JSON document)

dict_to_object(dataDict)

Convert the dictionary into an object

raw_decode(s, idx=0)

Decode a JSON document from s (a str or unicode beginning with a JSON document) and return a 2-tuple of the Python representation and the index in s where the document ended.

This can be used to decode a JSON document from a string that may have extraneous data at the end.

class DIRAC.DataManagementSystem.private.FTS3Utilities.FTS3JSONEncoder(*args, **kwargs)

Bases: json.encoder.JSONEncoder

This class is an encoder for the FTS3 objects

__init__(*args, **kwargs)

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, long, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true (the default), all non-ASCII characters in the output are escaped with uXXXX sequences, and the results are str instances consisting of ASCII characters only. If ensure_ascii is False, a result may be a unicode instance. This usually happens if the input contains unicode strings or the encoding parameter is used.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. Since the default item separator is ‘, ‘, the output might include trailing whitespace when indent is specified. You can use separators=(‘,’, ‘: ‘) to avoid this.

If specified, separators should be a (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘). To get the most compact JSON representation you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to JSON-encoding. The default is UTF-8.

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
encode(o)

Return a JSON string representation of a Python data structure.

>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
item_separator = ', '
iterencode(o, _one_shot=False)

Encode the given object and yield each string representation as available.

For example:

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)
key_separator = ': '
class DIRAC.DataManagementSystem.private.FTS3Utilities.FTS3Serializable

Bases: object

This is the base class for all the FTS3 objects that needs to be serialized, so FTS3Operation, FTS3File and FTS3Job

The inheriting classes just have to define a class attribute called _attrToSerialize, which is a list of strings, which correspond to the name of the attribute they want to serialize

__init__

x.__init__(…) initializes x; see help(type(x)) for signature

toJSON(forPrint=False)

Returns the JSON formated string

Parameters:forPrint – if set to True, we don’t include the ‘magic’ arguments used for rebuilding the object
class DIRAC.DataManagementSystem.private.FTS3Utilities.FTS3ServerPolicy(serverDict, serverPolicy='Random')

Bases: object

This class manages the policy for choosing a server

__init__(serverDict, serverPolicy='Random')

Call the init of the parent, and initialize the list of FTS3 servers

chooseFTS3Server()

Choose the appropriate FTS3 server depending on the policy

DIRAC.DataManagementSystem.private.FTS3Utilities.generatePossibleTransfersBySources(*args, **kwargs)

For a list of FTS3files object, group the transfer possible sources CAUTION ! a given LFN can be in multiple source

You still have to choose your source !

:param allowedSources : list of allowed sources :param ftsFiles : list of FTS3File object :return S_OK({ sourceSE: [ FTS3Files] })

DIRAC.DataManagementSystem.private.FTS3Utilities.groupFilesByTarget(ftsFiles)

For a list of FTS3files object, group the Files by target

:param ftsFiles : list of FTS3File object :return: {targetSE : [ ftsFiles] } }

DIRAC.DataManagementSystem.private.FTS3Utilities.selectUniqueRandomSource(ftsFiles, allowedSources=None)

For a list of FTS3files object, select a random source, and group the files by source.

:param allowedSources : list of allowed sources :param ftsFiles : list of FTS3File object

Returns:S_OK({ sourceSE: [ FTS3Files] })
DIRAC.DataManagementSystem.private.FTS3Utilities.selectUniqueSourceforTransfers(*args, **kwargs)

When we have several possible source for a given SE, choose one. In this particular case, we always choose the one that has the biggest amount of replicas,

:param multipleSourceTransfers : { sourceSE : [FTSFiles] }

:return { source SE : [ FTSFiles] } where each LFN appears only once