<s> from pycsw . core import util <EOL> from pycsw . core . etree import etree <EOL> NAMESPACE = '<STR_LIT>' <EOL> NAMESPACES = { '<STR_LIT>' : NAMESPACE } <EOL> XPATH_MAPPINGS = { } <EOL> def write_record ( result , esn , context , url = None ) : <EOL> '''<STR_LIT>''' <EOL> typename = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if typename == '<STR_LIT>' : <EOL> return etree . fromstring ( util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , context . parser ) <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) , nsmap = NAMESPACES ) <EOL> header = etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> header . attrib [ '<STR_LIT:version>' ] = '<STR_LIT>' <EOL> header . attrib [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> etree . SubElement ( header , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> data = etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> core = etree . SubElement ( data , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> core_meta = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> etree . SubElement ( core_meta , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> language = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> etree . SubElement ( core_meta , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = language <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> etree . SubElement ( core_meta , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> hierarchy_level_val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> standard = etree . SubElement ( core_meta , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = '<STR_LIT>' <EOL> standardver = etree . SubElement ( core_meta , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = '<STR_LIT>' <EOL> hierarchy_level = etree . SubElement ( core_meta , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> scope_code = etree . SubElement ( hierarchy_level , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( scope_code , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = hierarchy_level_val <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> parent_identifier = etree . SubElement ( core_meta , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> scope_code = etree . SubElement ( parent_identifier , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( scope_code , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> citation = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> title = etree . SubElement ( citation , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> title . append ( _get_pt_freetext ( val , language ) ) <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> data_ident = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> abstract = etree . SubElement ( data_ident , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> abstract . append ( _get_pt_freetext ( val , language ) ) <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> topicategory = etree . SubElement ( data_ident , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> cat_code = etree . SubElement ( topicategory , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( cat_code , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> topicategory = etree . SubElement ( data_ident , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> cat_code = etree . SubElement ( topicategory , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( cat_code , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> keywords_val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if keywords_val : <EOL> md_keywords = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> etree . SubElement ( md_keywords , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> keyword = etree . SubElement ( md_keywords , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> for kw in keywords_val . split ( '<STR_LIT:U+002C>' ) : <EOL> keyword . append ( _get_pt_freetext ( kw , language ) ) <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> md_format = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( md_format , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> ci_date = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( ci_date , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> etree . SubElement ( ci_date , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = '<STR_LIT>' <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> ci_date = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( ci_date , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> etree . SubElement ( ci_date , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = '<STR_LIT>' <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> ci_date = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( ci_date , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> etree . SubElement ( ci_date , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = '<STR_LIT>' <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> bboxel = write_extent ( val , context . namespaces ) <EOL> if bboxel is not None : <EOL> core . append ( bboxel ) <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> geo_desc = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( geo_desc , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> val = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> rs_identifier = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> rs_code = etree . SubElement ( rs_identifier , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> rs_code . append ( _get_pt_freetext ( val , language ) ) <EOL> time_begin = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> time_end = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if time_begin : <EOL> temp_ext = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> extent = etree . SubElement ( temp_ext , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> tm_primitive = etree . SubElement ( extent , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( tm_primitive , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = time_begin <EOL> if time_end : <EOL> etree . SubElement ( tm_primitive , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = time_end <EOL> rlinks = util . getqattr ( result , context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if rlinks : <EOL> for link in rlinks . split ( '<STR_LIT>' ) : <EOL> name , description , protocol , url = link . split ( '<STR_LIT:U+002C>' ) <EOL> online_resource = etree . SubElement ( core , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> if protocol : <EOL> etree . SubElement ( online_resource , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = protocol <EOL> if description : <EOL> desc = etree . SubElement ( online_resource , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> desc . append ( _get_pt_freetext ( description , language ) ) <EOL> if name : <EOL> name_el = etree . SubElement ( online_resource , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> name_el . append ( _get_pt_freetext ( name , language ) ) <EOL> linkage = etree . SubElement ( online_resource , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> linkage . append ( _get_pt_freeurl ( url , language ) ) <EOL> return node <EOL> def _get_pt_freetext ( val , language ) : <EOL> freetext = etree . Element ( util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> textgroup = etree . SubElement ( freetext , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> ptgroup = etree . SubElement ( textgroup , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> if language : <EOL> etree . SubElement ( ptgroup , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = language <EOL> etree . SubElement ( ptgroup , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> return freetext <EOL> def _get_pt_freeurl ( val , language ) : <EOL> freeurl = etree . Element ( util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> urlgroup = etree . SubElement ( freeurl , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> ptgroup = etree . SubElement ( urlgroup , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> if language : <EOL> etree . SubElement ( ptgroup , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = language <EOL> etree . SubElement ( ptgroup , util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) . text = val <EOL> return freeurl <EOL> def write_extent ( bbox , nsmap ) : <EOL> '''<STR_LIT>''' <EOL> if bbox is not None : <EOL> try : <EOL> bbox2 = util . wkt2geom ( bbox ) <EOL> except : <EOL> return None <EOL> bounding_box = etree . Element ( util . nspath_eval ( '<STR_LIT>' , NAMESPACES ) ) <EOL> etree . SubElement ( bounding_box , util . nspath_eval ( '<STR_LIT>' , nsmap ) ) . text = str ( bbox2 [ <NUM_LIT:3> ] ) <EOL> etree . SubElement ( bounding_box , util . nspath_eval ( '<STR_LIT>' , nsmap ) ) . text = str ( bbox2 [ <NUM_LIT:1> ] ) <EOL> etree . SubElement ( bounding_box , util . nspath_eval ( '<STR_LIT>' , nsmap ) ) . text = str ( bbox2 [ <NUM_LIT:0> ] ) <EOL> etree . SubElement ( bounding_box , util . nspath_eval ( '<STR_LIT>' , nsmap ) ) . text = str ( bbox2 [ <NUM_LIT:2> ] ) <EOL> return bounding_box <EOL> return None </s>
