Get a namespace preorder, given its hash.

    Return the preorder record on success.
    Return None if not found, or if it expired, or if the namespace was revealed or readied.
176507
def namedb_get_namespace_preorder( db, namespace_preorder_hash, current_block ):
    

    cur = db.cursor()
    select_query = "SELECT * FROM preorders WHERE preorder_hash = ? AND op = ? AND block_number < ?;"
    args = (namespace_preorder_hash, NAMESPACE_PREORDER, current_block + NAMESPACE_PREORDER_EXPIRE)
    preorder_rows = namedb_query_execute( cur, select_query, args )

    preorder_row = preorder_rows.fetchone()
    if preorder_row is None:
        # no such preorder 
        return None 

    preorder_rec = {}
    preorder_rec.update( preorder_row )

    # make sure that the namespace doesn't already exist 
    cur = db.cursor()
    select_query = "SELECT preorder_hash FROM namespaces WHERE preorder_hash = ? AND ((op = ?) OR (op = ? AND reveal_block < ?));"
    args = (namespace_preorder_hash, NAMESPACE_READY, NAMESPACE_REVEAL, current_block + NAMESPACE_REVEAL_EXPIRE)
    ns_rows = namedb_query_execute( cur, select_query, args )

    ns_row = ns_rows.fetchone()
    if ns_row is not None:
        # exists
        return None 

    return preorder_rec
1345570
def get_preorder_burn_info( outputs ):
    
    
    if len(outputs) != 3:
        # not a well-formed preorder 
        return None 
   
    op_fee = outputs[2]['value']
    burn_address = None

    try:
        burn_address = virtualchain.script_hex_to_address(outputs[2]['script'])
        assert burn_address
    except:
        log.error("Not a well-formed preorder burn: {}".format(outputs[2]['script']))
        return None

    return {'op_fee': op_fee, 'burn_address': burn_address}
315642
def get_namespace_entry(self, url: str, name: str) -> Optional[NamespaceEntry]:
        
        entry_filter = and_(Namespace.url == url, NamespaceEntry.name == name)
        result = self.session.query(NamespaceEntry).join(Namespace).filter(entry_filter).all()

        if 0 == len(result):
            return

        if 1 < len(result):
            log.warning('result for get_namespace_entry is too long. Returning first of %s', [str(r) for r in result])

        return result[0]
483111
def defaultNamespace(self):
        
        p = self
        while p is not None:
            if p.expns is not None:
                return None, p.expns
            p = p.parent
        return Namespace.default
789458
def namedb_get_names_in_namespace( cur, namespace_id, current_block, offset=None, count=None ):
    

    unexpired_query, unexpired_args = namedb_select_where_unexpired_names( current_block )

    query = "SELECT name FROM name_records JOIN namespaces ON name_records.namespace_id = namespaces.namespace_id WHERE name_records.namespace_id = ? AND " + unexpired_query + " ORDER BY name "
    args = (namespace_id,) + unexpired_args

    offset_count_query, offset_count_args = namedb_offset_count_predicate( offset=offset, count=count )
    query += offset_count_query + ";"
    args += offset_count_args

    name_rows = namedb_query_execute( cur, query, tuple(args) )
    ret = []
    for name_row in name_rows:
        rec = {}
        rec.update( name_row )
        ret.append( rec['name'] )

    return ret
663390
def namedb_preorder_remove( cur, preorder_hash ):
    
    try:
        query, values = namedb_delete_prepare( cur, 'preorder_hash', preorder_hash, 'preorders' )
    except Exception, e:
        log.exception(e)
        log.error("FATAL: Failed to delete preorder with hash '%s'" % preorder_hash )
        os.abort()

    log.debug(namedb_format_query(query, values))
    namedb_query_execute( cur, query, values )
    return True
520106
def GET_namespaces( self, path_info ):
        
        qs_values = path_info['qs_values']
        offset = qs_values.get('offset', None)
        count = qs_values.get('count', None)

        blockstackd_url = get_blockstackd_url()
        namespaces = blockstackd_client.get_all_namespaces(offset=offset, count=count, hostport=blockstackd_url)
        if json_is_error(namespaces):
            # error
            status_code = namespaces.get('http_status', 502)
            return self._reply_json({'error': namespaces['error']}, status_code=status_code)

        self._reply_json(namespaces)
        return
922735
def get_namespace_cost( db, namespace_id ):
    
    lastblock = db.lastblock
    namespace_units = get_epoch_namespace_price_units(lastblock)
    namespace_fee = price_namespace( namespace_id, lastblock, namespace_units )
    
    # namespace might exist
    namespace = db.get_namespace( namespace_id )
    namespace_fee = int(math.ceil(namespace_fee))

    return {'amount': namespace_fee, 'units': namespace_units, 'namespace': namespace}
884406
def rpc_get_namespace_blockchain_record( self, namespace_id, **con_info ):
        
        if not check_namespace(namespace_id):
            return {'error': 'Invalid name or namespace', 'http_status': 400}

        db = get_db_state(self.working_dir)
        ns = db.get_namespace( namespace_id )
        if ns is None:
            # maybe revealed?
            ns = db.get_namespace_reveal( namespace_id )
            db.close()

            if ns is None:
                return {"error": "No such namespace", 'http_status': 404}

            assert 'opcode' in ns, 'BUG: missing opcode in {}'.format(json.dumps(ns, sort_keys=True))
            ns = self.sanitize_rec(ns)

            ns['ready'] = False
            return self.success_response( {'record': ns} )

        else:
            db.close()
            
            assert 'opcode' in ns, 'BUG: missing opcode in {}'.format(json.dumps(ns, sort_keys=True))
            ns = self.sanitize_rec(ns)

            ns['ready'] = True
            return self.success_response( {'record': ns} )
445888
def has_namespace(self, namespace):
        
        result = requests.get(self._make_url(namespace))
        if result.status_code == 200:
            return True
        elif result.status_code == 404:
            return False
181851
def namespace_for_prefix(self, prefix):
        
        try:
            ni = self.__lookup_prefix(prefix)
        except PrefixNotFoundError:
            return None
        else:
            return ni.uri
792624
def get_entity(resource_name, name, namespace = nil, options = {})
      ns_prefix = build_namespace_prefix(namespace)
      response = handle_exception do
        rest_client[ns_prefix + resource_name + "/#{name}"]
          .get(@headers)
      end
      format_response(options[:as] || @as, response.body)
    end
199246
def get(self):
        """"""
        namespaces = db.ConfigNamespace.order_by(
            ConfigNamespace.sort_order,
            ConfigNamespace.name
        ).all()

        return self.make_response({
            'message': None,
            'namespaces': namespaces
        }, HTTP.OK)
624276
def namespace(namespace = nil, options = {})
      return @namespace unless namespace

      @namespace      = namespace.to_sym if namespace
      @base_namespace = options[:base].to_sym if options[:base]
    end
1370802
def key_for_namespace(cls, namespace):
    
    if namespace:
      return model.Key(cls.KIND_NAME, namespace)
    else:
      return model.Key(cls.KIND_NAME, cls.EMPTY_NAMESPACE_ID)
273321
def get_or_create_namespace(self, url: str) -> Union[Namespace, Dict]:
        
        result = self.get_namespace_by_url(url)

        if result is not None:
            return result

        t = time.time()

        bel_resource = get_bel_resource(url)

        _clean_bel_namespace_values(bel_resource)

        values = bel_resource['Values']

        if not_resource_cachable(bel_resource):
            log.debug('not caching namespace: %s (%d terms in %.2f seconds)', url, len(values), time.time() - t)
            log.debug('loaded uncached namespace: %s (%d)', url, len(values))
            return values

        namespace_insert_values = _get_namespace_insert_values(bel_resource)

        namespace = Namespace(
            url=url,
            **namespace_insert_values
        )
        namespace.entries = [
            NamespaceEntry(name=name, encoding=encoding)
            for name, encoding in values.items()
        ]

        log.info('inserted namespace: %s (%d terms in %.2f seconds)', url, len(values), time.time() - t)

        self.session.add(namespace)
        self.session.commit()

        return namespace
530023
def skin_namespace_hash(options = {})
      { 
        :match   =>  options[:match] ? options[:match] : /[\/]/, 
        :replace =>  options[:replace] ? options[:replace] : "_", 
        :prefix  =>  options[:prefix] ? options[:prefix] : nil,
        :root    =>  options[:root] ? options[:root] : "root"
      }
    end