
import pyxnat


def __pyxnat_assessor_type():
    return pyxnat.core.resources.Assessor


def full_label(project_id, subject_id, session_id,
               assessor_label):
    return '-x-'.join([project_id, subject_id, session_id, assessor_label])


# TODO: BenM/assessor_of_assessor/behaviour contingent on assessor version;
# the name shouldn't be used to test this
def full_label_from_assessor(assessor):
    assessor_label = assessor.label()
    if '-x-' in assessor_label:
        return assessor_label

    components = list()
    components.append(assessor_label)
    entity = assessor
    while True:
        entity = entity.parent()
        if entity is None:
            break
        components.append(entity.label())
    return '-x-'.join(reversed(components))


def parse_full_assessor_name(assessor_name):
    elements = assessor_name.split('-x-')
    assrdict = dict()

    if len(elements) == 5:
        # relabel is in use or old style with scan id in label
        assrdict = zip(
            ['project_id', 'subject_label', 'session_label', 'label'],
            [elements[0], elements[1], elements[2], assessor_name])

    if len(elements) != 4:
        raise ValueError(("'assessor_name' parameter '{}' is not a valid full "
                          "assessor name".format(assessor_name)))

    if len(elements[3]) == 36:
        # new style label with uuid
        assrdict = zip(
            ['project_id', 'subject_label', 'session_label', 'label'],
            elements)
    else:
        # old style label
        assrdict = zip(
            ['project_id', 'subject_label', 'session_label', 'label'],
            [elements[0], elements[1], elements[2], assessor_name])

    return assrdict

@@ -1129,25 +1129,24 @@
 ssor_name%5D)%0A
-%0A
     if len(e
@@ -1158,9 +1158,9 @@
 ts) 
-!
+=
 = 4:
@@ -1168,151 +1168,8 @@
     
-    raise ValueError((%22'assessor_name' parameter '%7B%7D' is not a valid full %22%0A                          %22assessor name%22.format(assessor_name)))%0A%0A
     
@@ -1203,16 +1203,20 @@
         
+  
+  
 # new st
@@ -1235,32 +1235,36 @@
 th uuid%0A        
+    
 assrdict = zip(%0A
@@ -1255,32 +1255,36 @@
 assrdict = zip(%0A
+    
             %5B'pr
@@ -1346,24 +1346,28 @@
             
+ 
+   
 elements)%0A  
@@ -1368,16 +1368,20 @@
 ts)%0A    
+  
+  
 else:%0A  
@@ -1386,16 +1386,20 @@
         
+   
+ 
 # old st
@@ -1408,32 +1408,36 @@
 e label%0A        
+    
 assrdict = zip(%0A
@@ -1428,32 +1428,36 @@
 assrdict = zip(%0A
+    
             %5B'pr
@@ -1515,32 +1515,36 @@
 '%5D,%0A            
+  
+  
 %5Belements%5B0%5D, el
@@ -1582,16 +1582,172 @@
 r_name%5D)
+%0A    else:%0A        raise ValueError((%22'assessor_name' parameter '%7B%7D' is not a valid full %22%0A                          %22assessor name%22.format(assessor_name)))
 %0A%0A    re

Fix assr label handling