当前位置: 首页>>代码示例>>Python>>正文


Python Account._by_name方法代码示例

本文整理汇总了Python中r2.models.Account._by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Account._by_name方法的具体用法?Python Account._by_name怎么用?Python Account._by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在r2.models.Account的用法示例。


在下文中一共展示了Account._by_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_response

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
    def process_response(self):
        data = request.POST

        transaction_id = 'RG%s' % data['transaction_id']
        pennies = int(data['pennies'])
        months = int(data['months'])
        status = 'succeeded'

        goldtype = data['goldtype']
        buyer = Account._by_name(data['buyer'])

        if goldtype == 'gift':
            gift_kw = {
                'recipient': Account._by_name(data['recipient']),
                'giftmessage': _force_utf8(data.get('giftmessage', None)),
                'signed': data.get('signed') == 'True',
            }
        else:
            gift_kw = {}

        webhook = Webhook(
            transaction_id=transaction_id,
            pennies=pennies,
            months=months,
            goldtype=goldtype,
            buyer=buyer,
            **gift_kw)
        return status, webhook
开发者ID:jakesyl,项目名称:reddit,代码行数:30,代码来源:ipn.py

示例2: submit_all

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
def submit_all():
    from r2.models import Subdigg, Account, Link, NotFound
    from r2.lib.media import set_media
    from r2.lib.db import queries
    sr = Subdigg._by_name('testmedia')
    author = Account._by_name('testmedia')
    links = []
    for url in test_urls:
        try:
            # delete any existing version of the link
            l = Link._by_url(url, sr)
            print "Deleting %s" % l
            l._deleted = True
            l._commit()
        except NotFound:
            pass

        l = Link._submit(url, url, author, sr, '0.0.0.0')

        try:
            set_media(l)
        except Exception, e:
            print e

        if g.write_query_queue:
            queries.new_link(l)

        links.append(l)
开发者ID:kevinrose,项目名称:diggit,代码行数:30,代码来源:scraper.py

示例3: submit_link

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
def submit_link(user, subreddit, title, url, thumb_url):
    account = Account._by_name(user)
    subreddit = Subreddit._by_name(subreddit)
    ip = '127.0.0.1'

    # submit the link
    link = Link._submit(
        is_self=False,
        title=title,
        content=url,
        author=account,
        sr=subreddit,
        ip=ip,
        spam=False,
    )

    try:
        # force the thumbnail before scraper_q gets in the mix
        image_data = urllib.urlopen(thumb_url).read()
        force_thumbnail(link, image_data)
    except:
        pass

    # various backend processing things
    queries.new_link(link)
    link.update_search_index()

    # wait for the amqp worker to finish up
    worker.join()

    print link.make_permalink_slow()
开发者ID:reddit,项目名称:postcards,代码行数:33,代码来源:submit_link.py

示例4: create_account

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
def create_account(full_name):
    name = full_name.replace(' ', '_')
    retry = 2 # First retry will by name2
    username = name
    while True:
        # Create a new account
        try:
            if dryrun:
                try:
                    account = Account._by_name(username)
                    if account:
                        raise AccountExists
                except NotFound:
                    account = FakeAccount()
                    account.name = username
            else:
                account = register(username, generate_password(), None)
                account.ob_account_name = full_name
                account._commit()
        except AccountExists:
            # This username is taken, generate another, but first limit the retries
            if retry > MAX_RETRIES:
                raise StandardError("Unable to create account for '%s' after %d attempts" % (full_name, retry - 1))
        else:
            return account
        username = "%s%d" % (name, retry)
        retry += 1
开发者ID:AndrewHay,项目名称:lesswrong,代码行数:29,代码来源:import_missing_comments.py

示例5: _gift_using_creddits

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
    def _gift_using_creddits(self, recipient, months=1, thing_fullname=None, proxying_for=None):
        with creddits_lock(c.user):
            if not c.user.employee and c.user.gold_creddits < months:
                err = RedditError("INSUFFICIENT_CREDDITS")
                self.on_validation_error(err)

            note = None
            buyer = c.user
            if c.user.name.lower() in g.live_config["proxy_gilding_accounts"]:
                note = "proxy-%s" % c.user.name
                if proxying_for:
                    try:
                        buyer = Account._by_name(proxying_for)
                    except NotFound:
                        pass

            send_gift(
                buyer=buyer,
                recipient=recipient,
                months=months,
                days=months * 31,
                signed=False,
                giftmessage=None,
                thing_fullname=thing_fullname,
                note=note,
            )

            if not c.user.employee:
                c.user.gold_creddits -= months
                c.user._commit()
开发者ID:Shilohtd,项目名称:reddit,代码行数:32,代码来源:gold.py

示例6: get_authenticated_account

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
    def get_authenticated_account(self):
        from r2.models import Account, NotFound, register

        try:
            authorization = request.environ.get("HTTP_AUTHORIZATION")
            username, password = parse_http_basic(authorization)
        except RequirementException:
            return None

        try:
            account = Account._by_name(username)
        except NotFound:
            if g.auth_trust_http_authorization:
                # note: we're explicitly allowing automatic re-registration of
                # _deleted accounts and login of _banned accounts here because
                # we're trusting you know what you're doing in an SSO situation
                account = register(username, password, request.ip)
            else:
                return None

        # if we're to trust the authorization headers, don't check passwords
        if g.auth_trust_http_authorization:
            return account

        # not all systems support bcrypt in the standard crypt
        if account.password.startswith("$2a$"):
            expected_hash = bcrypt.hashpw(password, account.password)
        else:
            expected_hash = crypt.crypt(password, account.password)

        if not constant_time_compare(expected_hash, account.password):
            return None
        return account
开发者ID:APerson241,项目名称:reddit,代码行数:35,代码来源:http.py

示例7: setUpClass

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
    def setUpClass(cls):
        cls._backup_user = c.user
        cls._backup_loggedin = c.user_is_loggedin

        # Create a dummy account for testing with; won't touch the database
        # as long as we don't `._commit()`
        name = "unit_tester_%s" % uuid.uuid4().hex
        cls._password = uuid.uuid4().hex
        try:
            Account._by_name(name)
            raise AccountExists
        except NotFound:
            cls._account = Account(
                name=name,
                password=bcrypt_password(cls._password)
            )
开发者ID:APerson241,项目名称:reddit,代码行数:18,代码来源:test_vverifypassword.py

示例8: process_response

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
    def process_response(self):
        data = request.POST

        transaction_id = 'RG%s' % data['transaction_id']
        pennies = int(data['pennies'])
        months = int(data['months'])
        status = 'succeeded'

        buyer_name = data['buyer']
        goldtype = data['goldtype']

        buyer = Account._by_name(buyer_name)

        blob = {
            'goldtype': goldtype,
            'account_id': buyer._id,
            'account_name': buyer.name,
            'status': 'initialized',
        }

        if goldtype == 'gift':
            blob['recipient'] = data['recipient']
            giftmessage = data.get('giftmessage', None)
            blob['giftmessage'] = _force_utf8(giftmessage)
            signed = data.get('signed')
            blob['signed'] = True if signed == 'True' else False

        passthrough = generate_blob(blob)

        return status, passthrough, transaction_id, pennies, months
开发者ID:rolmos,项目名称:reddit,代码行数:32,代码来源:ipn.py

示例9: process_response

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
    def process_response(self):
        data = request.POST

        transaction_id = "RG%s" % data["transaction_id"]
        pennies = int(data["pennies"])
        months = int(data["months"])
        status = "succeeded"

        buyer_name = data["buyer"]
        goldtype = data["goldtype"]

        buyer = Account._by_name(buyer_name)

        blob = {"goldtype": goldtype, "account_id": buyer._id, "account_name": buyer.name, "status": "initialized"}

        if goldtype == "gift":
            blob["recipient"] = data["recipient"]
            giftmessage = data.get("giftmessage", None)
            blob["giftmessage"] = _force_utf8(giftmessage)
            signed = data.get("signed")
            blob["signed"] = True if signed == "True" else False

        passthrough = generate_blob(blob)

        return status, passthrough, transaction_id, pennies, months
开发者ID:new-day-international,项目名称:reddit,代码行数:27,代码来源:ipn.py

示例10: process_response

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
    def process_response(self, res):
        from r2.models import Account

        fullname = res.merchantcustomerid.contents[0]
        name = res.description.contents[0]
        customer_id = int(res.customerprofileid.contents[0])
        acct = Account._by_name(name)

        # make sure we are updating the correct account!
        if acct.name == name:
            CustomerID.set(acct, customer_id)
        else:
            raise AuthorizeNetException, "account name doesn't match authorize.net account"

        # parse the ship-to list, and make sure the Account is up todate
        ship_to = []
        for profile in res.findAll("shiptolist"):
            a = Address.fromXML(profile)
            ShippingAddress.add(acct, a.customerAddressId)
            ship_to.append(a)

        # parse the payment profiles, and ditto
        profiles = []
        for profile in res.findAll("paymentprofiles"):
            a = Address.fromXML(profile)
            cc = CreditCard.fromXML(profile.payment)
            payprof = PaymentProfile(a, cc, int(a.customerPaymentProfileId))
            PayID.add(acct, a.customerPaymentProfileId)
            profiles.append(payprof)

        return acct, Profile(acct, profiles, ship_to)
开发者ID:eerock,项目名称:reddit,代码行数:33,代码来源:api.py

示例11: job_send_meetup_email_to_user

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
def job_send_meetup_email_to_user(meetup_id, username):
    meetup = Meetup._byID(meetup_id, data=True)
    try:
      user = Account._by_name(username)
      notify.email_user_about_meetup(user, meetup)
    except NotFound:
      # Users can get deleted so ignore if not found
      pass
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:10,代码来源:run_pending_jobs.py

示例12: enflair

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
def enflair(subreddit_name, account_name, flair_text, flair_class):
    sr = Subreddit._by_name(subreddit_name)
    account = Account._by_name(account_name)

    sr.add_flair(account)

    setattr(account, "flair_%d_text" % sr._id, flair_text)
    setattr(account, "flair_%d_css_class" % sr._id, flair_class)
    account._commit()
开发者ID:chromakode,项目名称:postcards,代码行数:11,代码来源:enflair.py

示例13: ensure_account

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
def ensure_account(name):
    """Look up or register an account and return it."""
    try:
        account = Account._by_name(name)
        print ">> found /u/{}".format(name)
        return account
    except NotFound:
        print ">> registering /u/{}".format(name)
        return register(name, "password", "127.0.0.1")
开发者ID:bobross-fc,项目名称:knowwit,代码行数:11,代码来源:submit_knowwit_data.py

示例14: monitor_mentions

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
def monitor_mentions(comment):
    if not isinstance(comment, Comment):
        return

    if comment._spam or comment._deleted:
        return

    sender = comment.author_slow
    if getattr(sender, "butler_ignore", False):
        # this is an account that generates false notifications, e.g.
        # LinkFixer
        return

    subreddit = comment.subreddit_slow
    usernames = list(extract_user_mentions(comment.body, num=g.butler_max_mentions + 1))
    inbox_class = Inbox.rel(Account, Comment)

    # If more than our allowed number of mentions were passed, don't highlight
    # any of them.
    if len(usernames) > g.butler_max_mentions:
        return

    # Subreddit.can_view stupidly requires this.
    c.user_is_loggedin = True

    for username in usernames:
        try:
            account = Account._by_name(username)
        except NotFound:
            continue

        # most people are aware of when they mention themselves.
        if account == sender:
            continue

        # bail out if that user has the feature turned off
        if not account.pref_monitor_mentions:
            continue

        # don't notify users of things they can't see
        if not subreddit.can_view(account):
            continue

        # don't notify users when a person they've blocked mentions them
        if account.is_enemy(sender):
            continue

        # ensure this comment isn't already in the user's inbox already
        rels = inbox_class._fast_query(
            account,
            comment,
            ("inbox", "selfreply", "mention"),
        )
        if filter(None, rels.values()):
            continue

        notify_mention(account, comment)
开发者ID:Robert77168,项目名称:reddit,代码行数:59,代码来源:butler.py

示例15: _

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _by_name [as 别名]
 def _(username):
     try:
         account = Account._by_name(username)
         if notify_accounts is not None:
             notify_accounts.add(account)
         return True
     except NotFound:
         account = None
         return False
开发者ID:new-day-international,项目名称:reddit,代码行数:11,代码来源:snudown_callbacks.py


注:本文中的r2.models.Account._by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。