Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6225211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:48:08+00:00 2026-05-24T08:48:08+00:00

Google App Engine uses Python 2.5.2, apparently with UCS4 enabled. But the GAE datastore

  • 0

Google App Engine uses Python 2.5.2, apparently with UCS4 enabled. But the GAE datastore uses UTF-8 internally. So if you store u’\ud834\udd0c’ (length 2) to the datastore, when you retrieve it, you get ‘\U0001d10c’ (length 1). I’m trying to count of the number of unicode characters in the string in a way that gives the same result before and after storing it. So I’m trying to normalize the string (from u’\ud834\udd0c’ to ‘\U0001d10c’) as soon as I receive it, before calculating its length and putting it in the datastore. I know I can just encode it to UTF-8 and then decode again, but is there a more straightforward/efficient way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:48:09+00:00Added an answer on May 24, 2026 at 8:48 am

    I know I can just encode it to UTF-8 and then decode again

    Yes, that’s the usual idiom to fix up the problem when you have “UTF-16 surrogates in UCS-4 string” input. But as Mechanical snail said, this input is malformed and you should be fixing whatever produced it in preference.

    is there a more straightforward/efficient way?

    Well… you could do it manually with a regex, like:

    re.sub(
        u'([\uD800-\uDBFF])([\uDC00-\uDFFF])',
        lambda m: unichr((ord(m.group(1))-0xD800<<10)+ord(m.group(2))-0xDC00+0x10000),
        s
    )
    

    Certainly not more straightforward… I also have my doubts as to whether it’s actually more efficient!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On Google App Engine to query the data store with Python, one can use
I'm developing an application for Google App Engine which uses BigTable for its datastore.
I'm trying to run Richfaces 3.3.3Final with Google app engine but richfaces uses javax.imageio.ImageIO
Google App Engine - When I want to store a byte array as one
Since the Google App Engine Datastore is based on Bigtable and we know that's
I need to store a undirected graph in a Google App Engine database. For
Currently Google App Engine supports both Python & Java. Java support is less mature.
I'm unit testing a google app engine app that uses the login setting in
In Google App Engine, all datastore operations in a transaction must operate on entities
I'm using Django 1.1 on Google App Engine through use_library . No Django GAE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.