def test_special_document_handling(IndivoClient):
  CONTACT = 'contact'
  DEMOGRAPHICS = 'demographics'

  try:
    admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
    record_id = admin_client.create_record(data=data.contact).response[PRD]['Record'][0]
    admin_client.set_app_id(data.app_email)
    admin_client.set_record_owner(data=data.account['account_id'])
  
    chrome_client = IndivoClient('chrome', 'chrome')
    chrome_client.create_session(data.account)
    chrome_client.read_record(record_id=record_id)
    chrome_client.put_special_document(special_document=DEMOGRAPHICS, data=data.demographics)
    chrome_client.read_special_document(special_document=DEMOGRAPHICS)
    chrome_client.put_special_document(special_document=CONTACT, data=data.contact)
    chrome_client.read_special_document(special_document=CONTACT)

    # replace the contact document
    chrome_client.put_special_document(special_document=CONTACT, data=data.contact02)
    record_doc = parse_xml(chrome_client.read_record())

    # make sure the label of the record was updated
    record_label = xpath(record_doc,'/Record/@label')[0]
    contact_fullname = xpath(parse_xml(data.contact02), '/ns:Contact/ns:name/ns:fullName/text()', namespaces={'ns':'http://indivo.org/vocab/xml/documents#'})[0]
    assert record_label == contact_fullname, "record label is %s while contact_fullname is %s" % (record_label, contact_fullname)

  except Exception, e:
    return False, e
Example #2
0
    def admin_setup(bob_account_id):

        admin_client = IndivoClient(data.machine_app_email,
                                    data.machine_app_secret)
        admin_client.set_app_id(data.app_email)

        # Create a record for Alice and set her at the owner
        record_id = admin_client.create_record(
            data=data.demographics).response[PRD]['Record'][0]
        admin_client.set_record_owner(data=data.account['account_id'])

        # Create a basic set of carenets
        carenet_names = ['Family2', 'Friends2', 'School/Office']
        for cname in carenet_names:
            admin_client.create_carenet(data='name=' + cname)

        # Check to make sure the admin can list the carenets and the accounts within each one
        carenets = xpath(
            parse_xml(admin_client.get_record_carenets(record_id=record_id)),
            '/Carenets/Carenet/@id')

        for carenet_id in carenets:
            assert len(
                xpath(
                    parse_xml(
                        admin_client.get_carenet_accounts(
                            carenet_id=carenet_id)), '/CarenetAccounts')) > 0

        return record_id
Example #3
0
 def load_data(self):
     files = os.listdir(self.datadir)
     wikifiles = [f for f in files if "wiktionary" in f and "xml" in f]
     lexentries = [
         f for f in files if f.startswith("nomen") or f.startswith("verben")
         or f.startswith("adj")
     ]
     ilifiles = [f for f in files if "interLingua" in f]
     pbar = progressbar.ProgressBar(widgets=[Percentage(),
                                             Bar()],
                                    maxval=len(files)).start()
     for i in range(len(lexentries)):
         f = lexentries[i]
         tree = parse_xml(self.datadir, f)
         load_lexunits(germanet=self, tree=tree)
         pbar.update(i + 1)
     tree = parse_xml(self.datadir, "gn_relations.xml")
     load_relations(germanet=self, tree=tree)
     if self.addWictionary:
         for i in range(len(wikifiles)):
             tree = parse_xml(self.datadir, wikifiles[i])
             load_wiktionary(germanet=self, tree=tree)
             pbar.update(i + 1)
     if self.addiliRecords:
         for i in range(len(ilifiles)):
             tree = parse_xml(self.datadir, ilifiles[i])
             load_ili(germanet=self, tree=tree)
             pbar.update(i + 1)
     pbar.finish()
Example #4
0
def chip_image():
    """
    save the image block into local path
    :return: None
    """
    for file in os.listdir(imgs_path):
        name = file.split('.')[0]
        ann = anns_file % name
        if not os.path.isfile(ann):
            continue
        # print(ann)
        image = cv2.imread(imgs_file % name)
        # id = name.split('_')
        for i, (img, shape) in enumerate(chips(image)):
            obj_list = parse_xml(ann, shape)
            if len(obj_list) == 0:
                continue
            # index = int(id[1]) + i + 1
            # index = "%04d" % index
            index = "%04d" % i
            img_name = index + "_" + name  # id[0] + "_" + index + "_" + id[2]
            new_img = imgs_file % img_name
            new_ann = anns_file % img_name
            print(new_ann)
            build_xml(obj_list, img_name, new_img, img.shape, new_ann)
            cv2.imwrite(new_img, img)
def test_special_document_handling(IndivoClient):
    DEMOGRAPHICS = "demographics"

    try:
        admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
        record_id = admin_client.create_record(data=data.demographics).response[PRD]["Record"][0]
        admin_client.set_app_id(data.app_email)
        admin_client.set_record_owner(data=data.account["account_id"])

        chrome_client = IndivoClient("chrome", "chrome")
        chrome_client.create_session(data.account)
        chrome_client.read_record(record_id=record_id)
        chrome_client.put_special_document(
            special_document=DEMOGRAPHICS, data=data.demographics
        )  # TODO: change client away from "special document" for demograhics
        chrome_client.read_special_document(special_document=DEMOGRAPHICS)

        # replace the demographics document
        chrome_client.put_special_document(special_document=DEMOGRAPHICS, data=data.demographics2)
        record_doc = parse_xml(chrome_client.read_record())

        # make sure the label of the record was updated
        record_label = xpath(record_doc, "/Record/@label")[0]
        # TODO: update below to work with new smart demographics
    #    contact_fullname = xpath(parse_xml(data.contact02), '/ns:Contact/ns:name/ns:fullName/text()', namespaces={'ns':'http://indivo.org/vocab/xml/documents#'})[0]
    #    assert record_label == contact_fullname, "record label is %s while contact_fullname is %s" % (record_label, contact_fullname)

    except Exception, e:
        return False, e
Example #6
0
    def load(self, npcs_dir, monster_groups, fail_fast):
        result = True

        # load all the monster groups
        for root, dirs, files in os.walk(npcs_dir, topdown=False):

            for name in files:
                if not name.endswith(".xml"):
                    continue

                if name.startswith(".#"):
                    continue

                xml_fname = os.path.join(root, name)

                doc = parse_xml(xml_fname)
                doc_root = doc.getroot()
                if doc_root.tag == "npcs":
                    npcs = NPCGang(monster_groups=monster_groups)
                    npcs.parse(doc_root)
                    if not npcs.validate():
                        result = False
                        if fail_fast:
                            raise Exception("Errors in %s" % xml_fname)
                    else:
                        self.npc_gang_lookup[npcs.npcs_id] = npcs
        return result
Example #7
0
    def load(cls, npcs_dir, monster_groups, fail_fast):
        result = True

        for root, dirs, files in walk(npcs_dir, topdown=False):
            for name in files:
                if not name.endswith(".xml"):
                    continue

                if name.startswith(".#"):
                    continue

                xml_fname = join(root, name)
                #print xml_fname

                doc = parse_xml(xml_fname)
                root = doc.getroot()

                #print root.tag

                if root.tag == "npcs":
                    #print "XXX"

                    npcs = NPCs(monster_groups=monster_groups)
                    npcs.parse(root)
                    if not npcs.validate():
                        result = False
                        if fail_fast:
                            raise Exception("Errors in %s" % xml_fname)
                    else:
                        cls.npc_like_lookup[npcs.npcs_id] = npcs
        return result
def test_special_document_handling(IndivoClient):
    DEMOGRAPHICS = 'demographics'

    try:
        admin_client = IndivoClient(data.machine_app_email,
                                    data.machine_app_secret)
        record_id = admin_client.create_record(
            data=data.demographics).response[PRD]['Record'][0]
        admin_client.set_app_id(data.app_email)
        admin_client.set_record_owner(data=data.account['account_id'])

        chrome_client = IndivoClient('chrome', 'chrome')
        chrome_client.create_session(data.account)
        chrome_client.read_record(record_id=record_id)
        chrome_client.put_special_document(
            special_document=DEMOGRAPHICS, data=data.demographics
        )  #TODO: change client away from "special document" for demograhics
        chrome_client.read_special_document(special_document=DEMOGRAPHICS)

        # replace the demographics document
        chrome_client.put_special_document(special_document=DEMOGRAPHICS,
                                           data=data.demographics2)
        record_doc = parse_xml(chrome_client.read_record())

        # make sure the label of the record was updated
        record_label = xpath(record_doc, '/Record/@label')[0]
        #TODO: update below to work with new smart demographics


#    contact_fullname = xpath(parse_xml(data.contact02), '/ns:Contact/ns:name/ns:fullName/text()', namespaces={'ns':'http://indivo.org/vocab/xml/documents#'})[0]
#    assert record_label == contact_fullname, "record label is %s while contact_fullname is %s" % (record_label, contact_fullname)

    except Exception, e:
        return False, e
    def load_archetypes_from_xml(self, xml_fname, abilities, fail_fast):
        """
        Load all the archetypes in an xml file.

        """
        archetypes_in_file = []

        # parse the xml
        doc = parse_xml(xml_fname)

        if doc is None:
            raise Exception("Errors in %s" % xml_fname)

        # validate
        error_log = validate_xml(doc)
        if error_log is not None:
            print("Errors (XSD)!")
            print(error_log)
            raise Exception("Errors in %s" % xml_fname)

        root = doc.getroot()
        archetype_nodes = root.xpath("//archetype")

        for archetype_node in archetype_nodes:
            archetype = Archetype(abilities, xml_fname)
            archetype.load(archetype_node, fail_fast)
            archetypes_in_file.append(archetype)
        return archetypes_in_file
Example #10
0
def index(request):
    if request.method == 'POST':
        xml = request.body
        print xml

        data = utils.parse_xml(xml)
        utils.exchange_src_des(data)
        
        if data['MsgType'] == 'event':
            if data['Event'] == 'subscribe':
                response = generate_subscribe_response(data)
            return HttpResponse(response, content_type="application/xml")

        elif data['MsgType'] == 'text':
            content = data['Content']
            if content == u'价格':
                data['Content'] = u'每平方米5元'
            if content == u'介绍':
                data['Content'] = u'这里是简介'
                rsp_dict = {'to_user_name': data['ToUserName'],
                            'to_from_name': data['FromUserName'],
                            'create_time': time.time(),
                            'msg_type': 'news',
                            'article_count': 1,
                            'title1': 'title',
                            'description1': 'description',
                            'pic_url': 'http://mmbiz.qpic.cn/mmbiz/50Rsp4bm4ickDPcw0lJnMnaZOib1zssoNSB1VGUPyicUk4JkrWeNgshfrbIPJ5py4DuZNGhctEiblohQgyU6fPictAw/0',
                            'url': ''
                        }
                return render(request, "response/reply_with_news.xml", rsp_dict, content_type = "application/xml")
            #data['Content'] = u"一诺保洁欢迎您"
            rsp_dict = {'to_user_name': data['ToUserName'],
                        'to_from_name': data['FromUserName'],
                        'create_time': time.time(),
                        'msg_type': data['MsgType'],
                        'content': data['Content']
                        }

            return render(request, "response/reply_text.xml", rsp_dict, content_type = "application/xml")
            


        elif data['MsgType'] == 'image':
            rsp_dict = {'to_user_name': data['ToUserName'],
                        'to_from_name': data['FromUserName'],
                        'create_time': time.time(),
                        'msg_type': data['MsgType'],
                        'media_id': data['MediaId']
                        }
            return render(request, "response/reply_image.xml", rsp_dict, content_type = "application/xml")

        elif data['MsgType'] == 'link':
            response = """ <xml>
            <ToUserName><![CDATA[%s]]></ToUserName>
            <FromUserName><![CDATA[%s]]></FromUserName> 
            <CreateTime>%s</CreateTime>
            <MsgType><![CDATA[%s]]></MsgType>
            <Content><![CDATA[%s]]></Content>
            </xml>""" % (data['ToUserName'], data['FromUserName'], str(int(time.time())), 'text', u"这是一个链接" + data['Title'])
            return HttpResponse(response, content_type="application/xml")
Example #11
0
def cumTpFp(gtFile, detFile, label, overlapRatio, file_format):
    # gtRect: label, xmin, ymin, xmax, ymax
    gtRects = []
    # gtRect: label, xmin, ymin, xmax, ymax, score
    detRects = []
    # scores: scores for label
    scores = []
    num_pos = 0
    if file_format[0] == '.txt':
        gtCon = open(gtFile)
        gtLines = gtCon.readlines()
        for gtLine in gtLines:
            if gtLine.split(' ')[0] == str(label):
                gtRects.append((int(float(gtLine.split(' ')[1])),
                                int(float(gtLine.split(' ')[2])),
                                int(float(gtLine.split(' ')[3])),
                                int(float(gtLine.split(' ')[4].strip('\n')))))
                num_pos += 1
    elif file_format[0] == '.xml':
        rects_xml = utils.parse_xml(gtFile)
        for rect_xml in rects_xml:
            if rect_xml[0] == str(label):
                gtRects.append(
                    (rect_xml[0], rect_xml[1], rect_xml[2], rect_xml[3]))
                num_pos += 1

    detCon = open(detFile)
    detLines = detCon.readlines()
    for detLine in detLines:
        if detLine.split(' ')[0] == str(label):
            detRects.append(
                (int(detLine.split(' ')[1]), int(detLine.split(' ')[2]),
                 int(detLine.split(' ')[3]), int(detLine.split(' ')[4])))
            scores.append(float(detLine.split(' ')[5].strip('\n')))
    # det_state: [label, score, tp, fp], tp, fp = 0 or 1
    det_state = [(label, 0., 0, 1)] * len(detRects)
    iou_max = 0
    maxIndex = -1
    blockIdx = -1
    for cnt in range(len(det_state)):
        det_state[cnt] = (label, scores[cnt], 0, 1)
    visited = [0] * len(gtLines)
    if len(detRects) != len(scores):
        print("Num of scores does not match detection results!")
    for indexDet, deti in enumerate(detRects):
        iou_max = 0
        maxIndex = -1
        blockIdx = -1
        for indexGt, gti in enumerate(gtRects):
            iou = JaccardOverlap(detRects[indexDet], gtRects[indexGt])
            if iou > iou_max:
                iou_max = iou
                maxIndex = indexDet
                blockIdx = indexGt
        if iou_max >= overlapRatio and visited[blockIdx] == 0:
            det_state[maxIndex] = (label, scores[indexDet], 1, 0)
            visited[blockIdx] = 1

    return det_state, num_pos
Example #12
0
 def __init__(self, fname):
     self.fname = fname
     self.weapons = []
     self.doc = parse_xml(fname)
     result = validate_xml(self.doc)
     if result is not None:
         raise Exception(result)
     return
Example #13
0
 def __getitem__(self, index):
     file_name = self.list_file_names[index]
     boxes, labels, _ = parse_xml(self.annotation_dir, file_name,
                                  self.dict_class)
     target = {"box": boxes, "label": labels}
     image = Image.open(os.path.join(self.image_dir, file_name + ".jpg"))
     image, target = self.transforms(image, target)
     return image, target
Example #14
0
def get_bdcites(wikihandles, years, phrase='baseball digest'):

    for wikihandle in wikihandles:
        for year in years:
            filename = wikihandle + "_" + str(year)
            [user, revid, size, content] = utils.parse_xml(filename)
            for line in utils.get_citelines(content, phrase):
                data = [line, wikihandle, year]
                print "\t".join([unicode(x).encode('utf8') for x in data])
Example #15
0
 def fromString(cls, aString):
     instance = cls()
     elt = utils.parse_xml(aString, 'utf-8')
     elt = elt.getroot()
     for node in elt.getchildren():
         upnp_class_name = node.findtext(
             '{%s}class' % 'urn:schemas-upnp-org:metadata-1-0/upnp/')
         upnp_class = instance.get_upnp_class(upnp_class_name.strip())
         new_node = upnp_class.fromString(ET.tostring(node))
         instance.addItem(new_node)
     return instance
Example #16
0
def parse_revs(wikihandles, years):

    # wikihandles = ["Hank_Aaron"]
    # years = [2011]
    
    for wikihandle in wikihandles:
        for year in years:
            filename = wikihandle + "_" + str(year)
            [user, revid, size, content] = utils.parse_xml(filename)
            [text, img, bd] = utils.parse_wikitext(content)
            data = [wikihandle, year, user, revid, size, text, img, bd]
            print "\t".join([unicode(x).encode('utf8') for x in data])
Example #17
0
    def load(cls, version_fname):
        doc = parse_xml(version_fname)
        root = doc.getroot()
        version = Version()

        for child in list(root):
            tag = child.tag

            if tag == "major":
                if version.major is not None:
                    raise Exception("Only one major per version. (%s) %s\n" %
                                    (child.tag, str(child)))
                else:
                    version.major = child.text.strip()
                    try:
                        version.major = int(version.major)
                    except ValueError:
                        raise Exception(
                            "Received invalid major version. (%s) expecting "
                            "an integer\n" % child.tag)
            elif tag == "minor":
                if version.minor is not None:
                    raise Exception("Only one minor per version. (%s) %s\n" %
                                    (child.tag, str(child)))
                else:
                    version.minor = child.text.strip()
                    try:
                        version.minor = int(version.minor)
                    except ValueError:
                        raise Exception(
                            "Received invalid minor version. (%s) expecting "
                            "an integer\n" % child.tag)
            elif tag == "revision":
                if version.revision is not None:
                    raise Exception(
                        "Only one revision per version. (%s) %s\n" %
                        (child.tag, str(child)))
                else:
                    version.revision = child.text.strip()
                    try:
                        version.revision = int(version.revision)
                    except ValueError:
                        raise Exception(
                            "Received invalid revision version. (%s) expecting "
                            "an integer\n" % child.tag)
            elif tag is COMMENT:
                # ignore comments!
                pass

            else:
                raise Exception("UNKNOWN (%s) %s\n" %
                                (child.tag, version_fname))
        return version
Example #18
0
    def check_response(self, response, request):
        xml_root = parse_xml(response.content)
        response = request.response_class(xml_root)

        calculated_mac = calculate_mac(
            self.secret, *[None if not hasattr(response, field) or
                           getattr(response, field) == ''
                           else getattr(response, field)
                           for field in response.mac_fields]
        )
        check_mac_equivalence(response.MAC, calculated_mac)
        return response
Example #19
0
  def admin_setup(bob_account_id):

    admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
    admin_client.set_app_id(data.app_email)

    # Create a record for Alice and set her at the owner
    record_id = admin_client.create_record(data=data.demographics).response[PRD]['Record'][0]
    admin_client.set_record_owner(data=data.account['account_id'])

    # Create a basic set of carenets
    carenet_names = ['Family2', 'Friends2', 'School/Office']
    for cname in carenet_names:
      admin_client.create_carenet(data='name=' + cname)

    # Check to make sure the admin can list the carenets and the accounts within each one
    carenets = xpath(parse_xml(admin_client.get_record_carenets(record_id = record_id)),'/Carenets/Carenet/@id')

    for carenet_id in carenets:
      assert len(xpath(parse_xml(admin_client.get_carenet_accounts(carenet_id = carenet_id)), '/CarenetAccounts')) > 0

    return record_id
    def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs, disallowed_docs):
        bob_chrome_client = IndivoClient("chrome", "chrome")
        bob_chrome_client.create_session(data.account02)

        # SZ: Bob should NOT be able to read the docs directly in the record
        for doc_id in allowed_docs + disallowed_docs:
            assert_403(bob_chrome_client.read_document(record_id=record_id, document_id=doc_id))

        assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

        # Bob should be able to read the allowed docs
        for doc_id in allowed_docs:
            assert_200(bob_chrome_client.get_carenet_document(carenet_id=carenet_id, document_id=doc_id))

        # Bob should not be able to read the disallowed docs
        for doc_id in disallowed_docs:
            assert_404(bob_chrome_client.get_carenet_document(carenet_id=carenet_id, document_id=doc_id))

        # Bob should be able to list docs in the carenet
        carenet_documents_list = bob_chrome_client.get_carenet_documents(carenet_id=carenet_id).response[PRD][
            "Document"
        ]

        # with a parameter
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id, parameters={"type": "http://indivo.org/vocab/xml/documents#Allergy"}
        ).response[PRD]["Document"]

        # Read carenet allergies
        assert_200(bob_chrome_client.read_carenet_allergies(carenet_id=carenet_id))
        assert_200(bob_chrome_client.read_carenet_problems(carenet_id=carenet_id))

        # Read the contact document, this should work
        contact_doc = parse_xml(
            bob_chrome_client.read_carenet_special_document(carenet_id=carenet_id, special_document="contact")
        )
        contact_name = xpath(
            contact_doc,
            "/ns:Contact/ns:name/ns:fullName/text()",
            namespaces={"ns": "http://indivo.org/vocab/xml/documents#"},
        )
        assert contact_name

        bob_chrome_client.get_account_permissions(account_id=bob_account_id)
        bob_chrome_client.get_carenet_account_permissions(
            carenet_id=carenet_id, record_id=record_id, account_id=bob_account_id
        )

        # Not yet implemented
        # bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

        return True
Example #21
0
def _daily_forecast_from_location_info(location_info,
                                       start_date=None,
                                       num_days=6,
                                       metric=False):
    if not start_date:
        start_date = datetime.date.today()

    # NOTE: the order of the query-string parameters seems to matter; so,
    # we can't use a dictionary to hold the params
    params = location_info + [("format", "24 hourly"),
                              ("startDate", start_date.strftime("%Y-%m-%d")),
                              ("numDays", str(num_days)),
                              ("Unit", "m" if metric else "e")]

    FORECAST_BY_DAY_URL = ("http://www.weather.gov/forecasts/xml"
                           "/sample_products/browser_interface"
                           "/ndfdBrowserClientByDay.php")

    resp = utils.open_url(FORECAST_BY_DAY_URL, params)
    tree = utils.parse_xml(resp)

    if tree.getroot().tag == 'error':
        raise exceptions.NOAAException("Unable to retrieve forecast")

    time_layouts = _parse_time_layouts(tree)
    min_temp_tlk, min_temps = _parse_temperatures_for_type(tree, 'minimum')
    max_temp_tlk, max_temps = _parse_temperatures_for_type(tree, 'maximum')
    conditions_tlk, conditions = _parse_conditions(tree)

    # Time layout keys have to match for us to sequence and group by them
    assert (min_temp_tlk == max_temp_tlk == conditions_tlk)

    time_layout_key = min_temp_tlk
    time_layout = time_layouts[time_layout_key]
    dates = [dt.date() for dt, _ in time_layout]

    forecast = []
    for date, min_temp_value, max_temp_value, condition in zip(
            dates, min_temps, max_temps, conditions):

        # If we're missing any data, don't create the data point
        if utils.any_none([min_temp_value, max_temp_value, condition]):
            continue

        temp_unit = 'C' if metric else 'F'
        min_temp = models.Temperature(min_temp_value, unit=temp_unit)
        max_temp = models.Temperature(max_temp_value, unit=temp_unit)
        datapoint = models.ForecastedCondition(date, min_temp, max_temp,
                                               condition)
        forecast.append(datapoint)

    return forecast
Example #22
0
def _daily_forecast_from_location_info(location_info, start_date=None,
                                       num_days=6, metric=False):
    if not start_date:
        start_date = datetime.date.today()

    # NOTE: the order of the query-string parameters seems to matter; so,
    # we can't use a dictionary to hold the params
    params = location_info + [("format", "24 hourly"),
                              ("startDate", start_date.strftime("%Y-%m-%d")),
                              ("numDays", str(num_days)),
                              ("Unit", "m" if metric else "e")]

    FORECAST_BY_DAY_URL = ("http://www.weather.gov/forecasts/xml"
                           "/sample_products/browser_interface"
                           "/ndfdBrowserClientByDay.php")

    resp = utils.open_url(FORECAST_BY_DAY_URL, params)
    tree = utils.parse_xml(resp)

    if tree.getroot().tag == 'error':
        raise exceptions.NOAAException("Unable to retrieve forecast")

    time_layouts = _parse_time_layouts(tree)
    min_temp_tlk, min_temps = _parse_temperatures_for_type(tree, 'minimum')
    max_temp_tlk, max_temps = _parse_temperatures_for_type(tree, 'maximum')
    conditions_tlk, conditions = _parse_conditions(tree)

    # Time layout keys have to match for us to sequence and group by them
    assert (min_temp_tlk == max_temp_tlk == conditions_tlk)

    time_layout_key = min_temp_tlk
    time_layout = time_layouts[time_layout_key]
    dates = [dt.date() for dt, _ in time_layout]

    forecast = []
    for date, min_temp_value, max_temp_value, condition in zip(
            dates, min_temps, max_temps, conditions):

        # If we're missing any data, don't create the data point
        if utils.any_none([min_temp_value, max_temp_value, condition]):
            continue

        temp_unit = 'C' if metric else 'F'
        min_temp = models.Temperature(min_temp_value, unit=temp_unit)
        max_temp = models.Temperature(max_temp_value, unit=temp_unit)
        datapoint = models.ForecastedCondition(
                date, min_temp, max_temp, condition)
        forecast.append(datapoint)

    return forecast
    def admin_setup(bob_account_id):

        admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
        admin_client.set_app_id(data.app_email)

        # Create a record for Alice and set her at the owner
        record_id = admin_client.create_record(data=data.contact).response[PRD]["Record"][0]
        admin_client.set_record_owner(data=data.account["account_id"])

        # Create a basic set of carenets
        carenet_names = ["Family2", "Friends2", "School/Office"]
        for cname in carenet_names:
            admin_client.create_carenet(data="name=" + cname)

        # Check to make sure the admin can list the carenets and the accounts within each one
        carenets = xpath(parse_xml(admin_client.get_record_carenets(record_id=record_id)), "/Carenets/Carenet/@id")

        for carenet_id in carenets:
            assert (
                len(xpath(parse_xml(admin_client.get_carenet_accounts(carenet_id=carenet_id)), "/CarenetAccounts")) > 0
            )

        return record_id
Example #24
0
 def __process_response(self, resp):
     response = parseString(resp.content)
     if response.getElementsByTagName('SOAP-ENV:Fault'):
         assert self._test, response.getElementsByTagName('detail')[0] \
             .firstChild.data.strip()
         return {
             'faultcode': response.getElementsByTagName('faultcode')[0]
                                  .firstChild.data.strip(),
             'faultstring': response.getElementsByTagName('faultstring')[0]
                                    .firstChild.data.strip(),
             'detail': response.getElementsByTagName('detail')[0]
                               .firstChild.data.strip()}
     element = response.getElementsByTagName('fdggwsapi:FDGGWSApiOrderResponse')
     d = parse_xml(element[0].toxml())['fdggwsapi:FDGGWSApiOrderResponse']['meta']
     return {key.split(':')[1]: value for key, value in d.items()}
Example #25
0
    def parse_date_result(self, xmlpage):
        result = {}
        d = utils.parse_xml(xmlpage)
        if d:
            x = d.getElementsByTagName('TotalPage')
            if x.length > 0:
                totalPage = utils.get_node_value(x[0].childNodes)
                if re.match('\d+$', totalPage):
                    result[self.TOTAL_PAGE] = int(totalPage)

            x = d.getElementsByTagName('Content')
            if x.length > 0:
                htmlPage = utils.get_node_value(x[0].childNodes)
                if htmlPage:
                    result.update(self.parse_html_page(htmlPage))
        return result
Example #26
0
    def parse_date_result(self, xmlpage):
        result = {}
        d = utils.parse_xml(xmlpage)
        if d:
            x = d.getElementsByTagName('TotalPage')
            if x.length > 0:
                totalPage = utils.get_node_value(x[0].childNodes)
                if re.match('\d+$', totalPage):
                    result[self.TOTAL_PAGE] = int(totalPage)

            x = d.getElementsByTagName('Content')
            if x.length > 0:
                htmlPage = utils.get_node_value(x[0].childNodes)
                if htmlPage:
                    result.update(self.parse_html_page(htmlPage))
        return result
Example #27
0
 def load_images(self):
     images = []
     for xml_path in tqdm(self.xml_paths, desc='Loading images'):
         
         # Parse xml image attributes
         xml_dict = parse_xml(xml_path)
         
         # Load and preprocess image
         try:
             image_path = os.path.join(self.image_base_folder, '{}.jpg'.format(xml_dict['filename']))
             image = cv2.imread(image_path, -1)
             image = self.preporcess_image(image, xml_dict)
             images.append(image)
         except:
             continue
         
     images = np.array(images)
     return images
Example #28
0
  def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs, disallowed_docs):
    bob_chrome_client = IndivoClient('chrome', 'chrome')
    bob_chrome_client.create_session(data.account02)

    # SZ: Bob should NOT be able to read the docs directly in the record
    for doc_id in allowed_docs+disallowed_docs:
      assert_403(bob_chrome_client.read_document(record_id=record_id, document_id=doc_id))

    assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

    # Bob should be able to read the allowed docs

    for doc_id in allowed_docs:
      assert_200(bob_chrome_client.get_carenet_document(carenet_id = carenet_id, document_id = doc_id))

    # Bob should not be able to read the disallowed docs
    for doc_id in disallowed_docs:
      assert_404(bob_chrome_client.get_carenet_document(carenet_id = carenet_id, document_id = doc_id))
    
    # Bob should be able to list docs in the carenet
    carenet_documents_list = bob_chrome_client.get_carenet_documents(carenet_id = carenet_id).response[PRD]['Document']

    # with a parameter
    carenet_documents_list = bob_chrome_client.get_carenet_documents(carenet_id = carenet_id, parameters={'type': 'http://indivo.org/vocab/xml/documents#Allergy'}).response[PRD]['Document']

    # Read carenet allergies
    # TODO: replace with generic call
    # assert_200(bob_chrome_client.read_carenet_allergies(carenet_id = carenet_id))

    # Read the demographics document, this should work
    resp = bob_chrome_client.call('GET', '/carenets/%s/demographics'%carenet_id, options={'parameters':{'response_format':'application/xml'}} )
    demographics_doc = parse_xml(resp)
    family_name = xpath(demographics_doc, '/Models/Model/Field[@name="name_family"]/text()')
    assert(family_name)

    bob_chrome_client.get_account_permissions(account_id=bob_account_id)
    bob_chrome_client.get_carenet_account_permissions(carenet_id= carenet_id,
                                                      record_id=record_id, 
                                                      account_id=bob_account_id)

    # Not yet implemented
    #bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

    return True
Example #29
0
	def login(self, username = None, password = None, timeout = 1800):
		"""
		Creates a new session (sessionId) for the related authenticated user.

		Note that when Axeda Platform creates a session for a user, a timeout is
		defined for that session. The session will be valid only while the session
		is effective; if the session times out, additional calls to the Web services
		will return “access defined” errors. Your code should implement error
		handling to ensure the session is still valid.
		"""
		if not username:
			username = self.username

		if not password:
			password = self.password

		if not timeout:
			timeout = self.timeout

		url = self.url_prefix + 'login?principal.username='******'&password='******'&sessionTimeout=' + str(timeout)

		if self.json:
			headers = { 'Accept': 'application/json' }
		else:
			headers = None

		r = utils.get(url, headers = headers, ssl = self.ssl)
		if r.status_code != 200:
			return False

		if self.json:
			self.session_id = str(json.loads(r.content)['wsSessionInfo']['sessionId'])
		else:
			self.session_id = str(utils.parse_xml(r.content, 'sessionId', self.name_space))

		if self.session_id:
			return True
		else:
			return False
Example #30
0
    def load_patron_from_xml(self, xml_fname, ability_groups, fail_fast):
        """
        Load a patron in an xml file.

        """
        # parse the xml
        doc = parse_xml(xml_fname)

        if doc is None:
            raise Exception("Errors in %s" % xml_fname)

        # validate
        error_log = validate_xml(doc)
        if error_log is not None:
            print("Errors (XSD)!")
            print(error_log)
            raise Exception("Errors in %s" % xml_fname)

        root = doc.getroot()
        patron = Patron(xml_fname)
        patron.load(root, ability_groups, fail_fast)
        return patron
Example #31
0
def parse_saml_metadata(source):
    validation = dict()
    validation['error'] = None
    validation['md_expires'] = None
    validation['crt_expires'] = None

    try:
        t = utils.parse_xml(source)
        t = utils.root(t)

        # XSD validation
        utils.validate_document(t)

        # Expiration check
        validation['md_expires'] = utils.metadata_expiration(t)

        # Certificate expiration
        # Everybody seems to use expired TSC's
        #validation['crt_expires'] = utils.certificate_expiration(t)

    except Exception as ex:
        validation['error'] = ex

    return validation
Example #32
0
  def alice_setup(record_id, bob_account_id):

    allergy_type = {'type' : 'http://indivo.org/vocab/xml/documents#Models'}

    alice_chrome_client = IndivoClient('chrome', 'chrome')
    alice_chrome_client.create_session(data.account)
    alice_chrome_client.read_record(record_id=record_id)
    alice_chrome_client.get_account_permissions(account_id=data.account['account_id'])

    alice_chrome_client.get_account_records(account_id = data.account['account_id'])

    # Alice posts a document
    # (We save the first doc instead of zero 
    #   due to the demographics doc already in alice's account)
    alice_chrome_client.post_document(data=data.doc01)
    document_id = alice_chrome_client.read_documents().response[PRD]['Document'][1]

    # Save the document_id in the client's datastore
    alice_chrome_client.ds.document_id = document_id

    # Save the first carenet_id in the client's datastore
    carenet_id = alice_chrome_client.get_record_carenets().response[PRD]['Carenet'][0]

    # post four documents to Alice's record, 2 allergies and 2 immunizations
    document_1_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.allergy)), "/Document/@id")[0]
    document_2_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.allergy)), "/Document/@id")[0]
    document_3_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.immunization)), "/Document/@id")[0]
    document_4_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.immunization)), "/Document/@id")[0]

    # and one more to test nevershare
    document_5_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.allergy)), "/Document/@id")[0]

    # auto-share allergies
    alice_chrome_client.post_autoshare(data=allergy_type, carenet_id=carenet_id)

    assert_200(alice_chrome_client.get_autoshare_bytype_all(record_id=record_id))

    # unshare that one allergy, which should negate the autoshare
    alice_chrome_client.delete_carenet_document(record_id = record_id, document_id = document_2_id, carenet_id=carenet_id)

    # nevershare the third allergy
    alice_chrome_client.document_nevershare_set(record_id = record_id, document_id = document_5_id)

    # immunizations are individually shared (well only one of them)
    alice_chrome_client.post_carenet_document(document_id = document_3_id, carenet_id=carenet_id)
    alice_chrome_client.delete_carenet_document(record_id=record_id, document_id=document_4_id, carenet_id=carenet_id)

    # Alice shares her demographics document(s) with the carenet
    demographics_doc = parse_xml(alice_chrome_client.read_documents(record_id = record_id, parameters={'type':'Demographics'}))
    for doc_id in xpath(demographics_doc, '/Documents/Document/@id'):
      alice_chrome_client.post_carenet_document(record_id = record_id, document_id = doc_id, carenet_id = carenet_id)

    # Alice adds bob_account_id to carenet[0]
    alice_chrome_client.post_carenet_account(carenet_id = carenet_id, data='account_id=' + bob_account_id + '&write=false')

    # Review all accounts within carenet[0]
    assert xpath(parse_xml(alice_chrome_client.get_carenet_accounts(carenet_id = carenet_id)), '/CarenetAccounts')
    alice_chrome_client.get_carenet_apps(carenet_id = carenet_id)

    alice_chrome_client.read_allergies(record_id = record_id)

    # Finally, return the carenet_id, document_id
    # in order to check Bob's access
    # and a second document that is disallowed
    return carenet_id, [document_1_id, document_3_id], [document_2_id, document_4_id, document_5_id]
Example #33
0
    def alice_setup(record_id, bob_account_id):

        allergy_type = {'type': 'http://indivo.org/vocab/xml/documents#Models'}

        alice_chrome_client = IndivoClient('chrome', 'chrome')
        alice_chrome_client.create_session(data.account)
        alice_chrome_client.read_record(record_id=record_id)
        alice_chrome_client.get_account_permissions(
            account_id=data.account['account_id'])

        alice_chrome_client.get_account_records(
            account_id=data.account['account_id'])

        # Alice posts a document
        # (We save the first doc instead of zero
        #   due to the demographics doc already in alice's account)
        alice_chrome_client.post_document(data=data.doc01)
        document_id = alice_chrome_client.read_documents(
        ).response[PRD]['Document'][1]

        # Save the document_id in the client's datastore
        alice_chrome_client.ds.document_id = document_id

        # Save the first carenet_id in the client's datastore
        carenet_id = alice_chrome_client.get_record_carenets(
        ).response[PRD]['Carenet'][0]

        # post four documents to Alice's record, 2 allergies and 2 immunizations
        document_1_id = xpath(
            parse_xml(alice_chrome_client.post_document(data=data.allergy)),
            "/Document/@id")[0]
        document_2_id = xpath(
            parse_xml(alice_chrome_client.post_document(data=data.allergy)),
            "/Document/@id")[0]
        document_3_id = xpath(
            parse_xml(
                alice_chrome_client.post_document(data=data.immunization)),
            "/Document/@id")[0]
        document_4_id = xpath(
            parse_xml(
                alice_chrome_client.post_document(data=data.immunization)),
            "/Document/@id")[0]

        # and one more to test nevershare
        document_5_id = xpath(
            parse_xml(alice_chrome_client.post_document(data=data.allergy)),
            "/Document/@id")[0]

        # auto-share allergies
        alice_chrome_client.post_autoshare(data=allergy_type,
                                           carenet_id=carenet_id)

        assert_200(
            alice_chrome_client.get_autoshare_bytype_all(record_id=record_id))

        # unshare that one allergy, which should negate the autoshare
        alice_chrome_client.delete_carenet_document(record_id=record_id,
                                                    document_id=document_2_id,
                                                    carenet_id=carenet_id)

        # nevershare the third allergy
        alice_chrome_client.document_nevershare_set(record_id=record_id,
                                                    document_id=document_5_id)

        # immunizations are individually shared (well only one of them)
        alice_chrome_client.post_carenet_document(document_id=document_3_id,
                                                  carenet_id=carenet_id)
        alice_chrome_client.delete_carenet_document(record_id=record_id,
                                                    document_id=document_4_id,
                                                    carenet_id=carenet_id)

        # Alice shares her demographics document(s) with the carenet
        demographics_doc = parse_xml(
            alice_chrome_client.read_documents(
                record_id=record_id, parameters={'type': 'Demographics'}))
        for doc_id in xpath(demographics_doc, '/Documents/Document/@id'):
            alice_chrome_client.post_carenet_document(record_id=record_id,
                                                      document_id=doc_id,
                                                      carenet_id=carenet_id)

        # Alice adds bob_account_id to carenet[0]
        alice_chrome_client.post_carenet_account(
            carenet_id=carenet_id,
            data='account_id=' + bob_account_id + '&write=false')

        # Review all accounts within carenet[0]
        assert xpath(
            parse_xml(
                alice_chrome_client.get_carenet_accounts(
                    carenet_id=carenet_id)), '/CarenetAccounts')
        alice_chrome_client.get_carenet_apps(carenet_id=carenet_id)

        alice_chrome_client.read_allergies(record_id=record_id)

        # Finally, return the carenet_id, document_id
        # in order to check Bob's access
        # and a second document that is disallowed
        return carenet_id, [document_1_id, document_3_id
                            ], [document_2_id, document_4_id, document_5_id]
    mean = data["value"]
    std = data["stddev"]
    x_min = mean - 5 * std
    x_max = mean + 5 * std
    dx = (x_max - x_min) / float(200)
    x = []
    x_0 = x_min
    for i in range(200):
        x.append(x_0)
        x_0 += dx
        gauss_output.append(gauss(mean, std, x[i]))
    return [gauss_output, x]


filename = "../ref_data/nt2012q1_ukie_20130618/advanced.xml"
latest_rospa = ut.parse_xml(filename)

filename = "../ref_data/nt2012q1_ukie_201206/advanced.xml"
oldest_rospa = ut.parse_xml(filename)

path = "../plots/old_new_rospa_data/"
for metric in oldest_rospa:
    if metric != "distance":
        plt.figure(metric, figsize=(10, 10))
        for i, rt in enumerate(oldest_rospa[metric]):
            plt.subplot(6, 2, i + 1)
            if oldest_rospa[metric][rt]["stddev"] * latest_rospa[metric][rt]["stddev"] != 0.0:
                old_dist, x_old = get_gauss(oldest_rospa[metric][rt])
                new_dist, x_new = get_gauss(latest_rospa[metric][rt])
                plt.plot(x_old, old_dist, color="c", label="Old-{0}".format(rt))
                plt.plot(x_new, new_dist, color="r")
Example #35
0
    def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs,
                  disallowed_docs):
        bob_chrome_client = IndivoClient('chrome', 'chrome')
        bob_chrome_client.create_session(data.account02)

        # SZ: Bob should NOT be able to read the docs directly in the record
        for doc_id in allowed_docs + disallowed_docs:
            assert_403(
                bob_chrome_client.read_document(record_id=record_id,
                                                document_id=doc_id))

        assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

        # Bob should be able to read the allowed docs

        for doc_id in allowed_docs:
            assert_200(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should not be able to read the disallowed docs
        for doc_id in disallowed_docs:
            assert_404(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should be able to list docs in the carenet
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id).response[PRD]['Document']

        # with a parameter
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id,
            parameters={
                'type': 'http://indivo.org/vocab/xml/documents#Allergy'
            }).response[PRD]['Document']

        # Read carenet allergies
        # TODO: replace with generic call
        # assert_200(bob_chrome_client.read_carenet_allergies(carenet_id = carenet_id))

        # Read the demographics document, this should work
        resp = bob_chrome_client.call(
            'GET',
            '/carenets/%s/demographics' % carenet_id,
            options={'parameters': {
                'response_format': 'application/xml'
            }})
        demographics_doc = parse_xml(resp)
        family_name = xpath(demographics_doc,
                            '/Models/Model/Field[@name="name_family"]/text()')
        assert (family_name)

        bob_chrome_client.get_account_permissions(account_id=bob_account_id)
        bob_chrome_client.get_carenet_account_permissions(
            carenet_id=carenet_id,
            record_id=record_id,
            account_id=bob_account_id)

        # Not yet implemented
        #bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

        return True
Example #36
0
 def fromString(cls, data):
     instance = cls()
     elt = utils.parse_xml(data)
     #elt = ElementTree(elt)
     instance.fromElement(elt.getroot())
     return instance
Example #37
0
def test_account(IndivoClient):
    try:

        chrome_client = IndivoClient('chrome', 'chrome')

        # simplest test case
        chrome_client.create_account({
            'user_email': '*****@*****.**',
            'contact_email': '*****@*****.**',
            'user_pass': '******'
        })
        chrome_client.add_auth_system(account_id='*****@*****.**',
                                      data={
                                          'system': 'password',
                                          'username': '******',
                                          'password': '******'
                                      })

        # create an account
        chrome_client.create_account({
            'user_email': '*****@*****.**',
            'primary_secret_p': '1',
            'secondary_secret_p': '1',
            'contact_email': '*****@*****.**'
        })

        # reset it
        chrome_client.account_reset(account_id='*****@*****.**')

        # get the account info
        account_resp = chrome_client.account_info(account_id='*****@*****.**')
        parsed_resp = ElementTree.fromstring(
            account_resp.response['response_data'])
        secondary_secret = parsed_resp.findtext('secret')

        # get the primary secret
        primary_secret_resp = chrome_client.account_primary_secret(
            account_id='*****@*****.**')
        parsed_resp = ElementTree.fromstring(
            primary_secret_resp.response['response_data'])
        primary_secret = parsed_resp.text

        # initialize it
        chrome_client.account_initialize(
            account_id='*****@*****.**',
            primary_secret=primary_secret,
            data={'secondary_secret': secondary_secret})

        # set username and password
        chrome_client.add_auth_system(account_id='*****@*****.**',
                                      data={
                                          'system': 'password',
                                          'username': '******',
                                          'password': '******'
                                      })

        # set the password to something else
        chrome_client.account_set_password(account_id='*****@*****.**',
                                           data={'password': '******'})

        # change the state back and forth
        chrome_client.account_set_state(account_id='*****@*****.**',
                                        data={'state': 'disabled'})
        chrome_client.account_set_state(account_id='*****@*****.**',
                                        data={'state': 'active'})
        chrome_client.account_set_state(account_id='*****@*****.**',
                                        data={'state': 'retired'})
        assert_403(
            chrome_client.account_set_state(account_id='*****@*****.**',
                                            data={'state': 'active'}))

        # see if we can create a session for it
        chrome_client.create_session({'username': '******', 'user_pass': '******'})

        # now the token is in the client, we can change the password
        chrome_client.account_change_password(account_id='*****@*****.**',
                                              data={
                                                  'old': 'test2',
                                                  'new': 'test3'
                                              })

        # change the info
        assert_200(
            chrome_client.account_info_set(account_id='*****@*****.**',
                                           data={
                                               'contact_email':
                                               '*****@*****.**',
                                               'full_name': 'Ben2 Adida'
                                           }))

        # change the username
        assert_200(
            chrome_client.account_username_set(account_id='*****@*****.**',
                                               data={'username': '******'}))

        chrome_client = IndivoClient('chrome', 'chrome')
        chrome_client.create_session({'username': '******', 'user_pass': '******'})

        # do account search
        chrome_client = IndivoClient('chrome', 'chrome')
        accounts = parse_xml(
            chrome_client.account_search(
                parameters={'contact_email': '*****@*****.**'}))
        accounts2 = parse_xml(
            chrome_client.account_search(
                parameters={'fullname': 'Steve Zabak'}))

        # create an account with a mychildrens auth system
        chrome_client.create_account({
            'user_email': '*****@*****.**',
            'primary_secret_p': '0',
            'secondary_secret_p': '0',
            'contact_email': '*****@*****.**'
        })
        chrome_client.add_auth_system(account_id='*****@*****.**',
                                      data={
                                          'system': 'mychildrens',
                                          'username': '******'
                                      })

        # FIXME: this call doesn't do anything, probably because of some internal magic that fails if there is no password field
        chrome_client.create_session({
            'username': '******',
            'system': 'mychildrens'
        })
    except Exception, e:
        return False, e
Example #38
0
 def parse_data(self, metadata):
     data = parse_xml(metadata)
     self.msgtype = data.get('MsgType').lower()
     self.msg = MSG_TYPES.get(self.msgtype)(data)
def test_account(IndivoClient):
  try:

    chrome_client = IndivoClient('chrome', 'chrome')

    # simplest test case
    chrome_client.create_account({'user_email' : '*****@*****.**', 'contact_email':'*****@*****.**', 'user_pass': '******'})
    chrome_client.add_auth_system(account_id='*****@*****.**', data={'system':'password', 'username':'******', 'password': '******'})
      
    # create an account
    chrome_client.create_account({'user_email' : '*****@*****.**', 'primary_secret_p' : '1', 'secondary_secret_p' : '1', 'contact_email':'*****@*****.**'})

    # reset it
    chrome_client.account_reset(account_id='*****@*****.**')

    # get the account info 
    account_resp = chrome_client.account_info(account_id = '*****@*****.**')
    parsed_resp = ElementTree.fromstring(account_resp.response['response_data'])
    secondary_secret = parsed_resp.findtext('secret')

    # get the primary secret
    primary_secret_resp = chrome_client.account_primary_secret(account_id = '*****@*****.**')
    parsed_resp = ElementTree.fromstring(primary_secret_resp.response['response_data'])
    primary_secret = parsed_resp.text

    # initialize it
    chrome_client.account_initialize(account_id='*****@*****.**', primary_secret=primary_secret, data={'secondary_secret':secondary_secret})

    # set username and password
    chrome_client.add_auth_system(account_id='*****@*****.**', data={'system':'password', 'username':'******', 'password': '******'})

    # set the password to something else
    chrome_client.account_set_password(account_id='*****@*****.**', data={'password':'******'})      
      
    # change the state back and forth
    chrome_client.account_set_state(account_id='*****@*****.**', data={'state': 'disabled'})
    chrome_client.account_set_state(account_id='*****@*****.**', data={'state': 'active'})
    chrome_client.account_set_state(account_id='*****@*****.**', data={'state': 'retired'})
    assert_403(chrome_client.account_set_state(account_id='*****@*****.**', data={'state': 'active'}))

    # see if we can create a session for it
    chrome_client.create_session({'username':'******','user_pass':'******'})

    # now the token is in the client, we can change the password
    chrome_client.account_change_password(account_id = '*****@*****.**', data={'old':'test2','new':'test3'})

    # change the info
    assert_200(chrome_client.account_info_set(account_id= '*****@*****.**', data={'contact_email':'*****@*****.**','full_name':'Ben2 Adida'}))

    # change the username
    assert_200(chrome_client.account_username_set(account_id='*****@*****.**', data={'username':'******'}))

    chrome_client = IndivoClient('chrome', 'chrome')
    chrome_client.create_session({'username':'******','user_pass':'******'})
    
    # do account search
    chrome_client = IndivoClient('chrome', 'chrome')
    accounts = parse_xml(chrome_client.account_search(parameters={'contact_email': '*****@*****.**'}))
    accounts2 = parse_xml(chrome_client.account_search(parameters={'fullname': 'Steve Zabak'}))

    # create an account with a mychildrens auth system
    chrome_client.create_account({'user_email' : '*****@*****.**', 'primary_secret_p' : '0', 'secondary_secret_p' : '0', 'contact_email':'*****@*****.**'})
    chrome_client.add_auth_system(account_id='*****@*****.**', data={'system':'mychildrens', 'username':'******'})
    
    # FIXME: this call doesn't do anything, probably because of some internal magic that fails if there is no password field
    chrome_client.create_session({'username':'******','system':'mychildrens'})
  except Exception, e:
    return False, e
Example #40
0
 def parse(self):
     self.doc = parse_xml(self.fname)
     self._find_resource_ids()
     return self.doc
Example #41
0
    def get_xml(self, url, *args, **kwargs):
        response = self.session.get(url, *args, **kwargs)
        if not response:
            return None

        return parse_xml(response.content)
Example #42
0
    def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs,
                  disallowed_docs):
        bob_chrome_client = IndivoClient('chrome', 'chrome')
        bob_chrome_client.create_session(data.account02)

        # SZ: Bob should NOT be able to read the docs directly in the record
        for doc_id in allowed_docs + disallowed_docs:
            assert_403(
                bob_chrome_client.read_document(record_id=record_id,
                                                document_id=doc_id))

        assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

        # Bob should be able to read the allowed docs
        for doc_id in allowed_docs:
            assert_200(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should not be able to read the disallowed docs
        for doc_id in disallowed_docs:
            assert_404(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should be able to list docs in the carenet
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id).response[PRD]['Document']

        # with a parameter
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id,
            parameters={
                'type': 'http://indivo.org/vocab/xml/documents#Allergy'
            }).response[PRD]['Document']

        # Read carenet allergies
        assert_200(
            bob_chrome_client.read_carenet_allergies(carenet_id=carenet_id))
        assert_200(
            bob_chrome_client.read_carenet_problems(carenet_id=carenet_id))

        # Read the contact document, this should work
        contact_doc = parse_xml(
            bob_chrome_client.read_carenet_special_document(
                carenet_id=carenet_id, special_document='contact'))
        contact_name = xpath(
            contact_doc,
            '/ns:Contact/ns:name/ns:fullName/text()',
            namespaces={'ns': 'http://indivo.org/vocab/xml/documents#'})
        assert (contact_name)

        bob_chrome_client.get_account_permissions(account_id=bob_account_id)
        bob_chrome_client.get_carenet_account_permissions(
            carenet_id=carenet_id,
            record_id=record_id,
            account_id=bob_account_id)

        # Not yet implemented
        #bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

        return True
Example #43
0
    def parse(self, license_fname):
        self.license_fname = license_fname
        self.name = basename(license_fname)
        if not exists(license_fname):
            fail("License file missing %s" % license_fname)
            return

        doc = parse_xml(license_fname)
        if doc is None:
            raise Exception("Can't parse license: %s" % license_fname)
        root = doc.getroot()
        if root.tag != "licenseinfo":
            raise Exception(
                "Bad xml looking for xml with a root tag of licenseinfo "
                "in %s" % license_fname)

        print "----@@@@@@@@@@@@@@@@@@ %s" % license_fname

        for child in list(root):
            tag = child.tag
            if child.text is None:

                if tag not in ("source", "url", "notes"):
                    raise Exception("%s has empty value for %s" %
                                    (license_fname, tag))
                else:
                    text = u""
            else:
                text = unicode(child.text.strip())

            #for attr, value in json_info.items():
            if tag is COMMENT:
                pass
            elif tag == "sig":
                self.sig = text
            elif tag == "type":
                self.resource_type = text
            elif tag == "license":
                self.resource_license = text
            elif tag == "fname":
                # make all our filenames relative to this path (for portability)
                root_dir = abspath(join(dirname(__file__), ".."))
                relative_dir = relpath(dirname(license_fname), start=root_dir)
                self.fname = join(relative_dir, text)
            elif tag == "artist":
                self.artist = text
            elif tag == "artistfullname":
                self.artistfullname = text
            elif tag == "source":
                self.source = text
            elif tag == "url":
                self.url = text
            elif tag == "notes":
                self.notes = text
            else:
                fail("Unknown license information %s in %s" %
                     (tag, license_fname))

        if self.resource_license is None:
            fail("Missing license information 'license' in %s" % license_fname)

        if self.artist is None:
            fail("Missing license information 'artist' in %s" % license_fname)

        if self.source is None:
            fail("Missing license information 'source' in %s" % license_fname)
        return
Example #44
0
 def parse_data(self,metadata):
     data = parse_xml(metadata)
     self.msgtype = data.get('MsgType').lower()
     self.msg = MSG_TYPES.get(self.msgtype)(data)