Example #1
0
class OAuth2App(grok.Model):
    ''' Represents an OAuth2 application instance '''
    grok.implements(IOAuth2App)
    service = FieldProperty(IOAuth2App['service'])
    authtype = FieldProperty(IOAuth2App['authtype'])
    icon = None
    icon_filename = None
    auth_uri = ""
    token_uri = ""
    client_id = None
    secret = None
    scope = None
    token = None
    authorize = None

    grok.traversable('token')
    grok.traversable('authorize')

    def __init__(self, app_id):
        self.app_id = app_id

    def v1_authentication_uri(self, request):
        pass

    def authentication_uri(self, request):
        if self.authtype == u"OAuth-1":
            return self.v1_authentication_uri(request)

        self.state = str(randint(0, 1000))
        self.token = V2TokenRequest(self.token_uri,
                                    client_id=self.client_id,
                                    client_secret=self.secret)
        location.locate(self.token, self, 'token')

        # exchange the code for a token
        redirect_uri = str(grok.url(request, self.token, name="@@tokenview"))
        if redirect_uri.find('/localhost') < 0:
            redirect_uri = redirect_uri.replace("http:", "https:")
        self.authorize = V2Authorization(self.auth_uri,
                                         redirect_uri=redirect_uri,
                                         client_id=self.client_id,
                                         scope=self.scope,
                                         state=self.state)
        location.locate(self.authorize, self, 'authorize')
        self.token.set_redirect_uri(redirect_uri)
        return self.authorize.get_uri()

    @property
    def apptoken(self):
        if self.token and 'token' in self.token.info:
            return token.info['token']
Example #2
0
class Foo(grok.Model):
    grok.traversable('bar')
    grok.traversable('foo')
    grok.traversable(attr='bar', name='namedbar')

    def __init__(self, name):
        self.name = name

    foo = Bar('foo')

    def bar(self):
        return Bar('bar')

    z = "i'm not called"
Example #3
0
class Uvcsite(grok.Application, grok.Container):
    """Application Object for uvc.site
    """
    grok.traversable('plugins')
    
    grok.local_utility(PortalMembership,
                       provides=IHomeFolderManager)

    grok.local_utility(UVCAuthenticator,
                       name=u"principals",
                       provides=IAuthenticatorPlugin)

    grok.local_utility(PluggableAuthentication,
                       IAuthentication,
                       public=True,
                       setup=setup_pau)

    @property
    def plugins(self):
        return uvcsite.plugins.PluginsPanel('plugins', self)

    def getSiteManager(self):
        current = super(Uvcsite, self).getSiteManager()
        if uvcsiteRegistry not in current.__bases__:
            uvcsiteRegistry.__bases__ = tuple(
                [x for x in uvcsiteRegistry.__bases__
                    if (hasattr(x, '_hash_') and
                        x._hash_() != globalSiteManager._hash_())])
            current.__bases__ = (uvcsiteRegistry,) + current.__bases__
        elif current.__bases__[0] is not uvcsiteRegistry:
            current.__bases__ = (uvcsiteRegistry,) + tuple((
                b for b in current.__bases__ if b != uvcsiteRegistry))
        return current
Example #4
0
class V1RequestToken(grok.Model):
    parms = {}
    req_token_uri = None
    auth_uri = None
    access = None
    grok.traversable('access')

    def __init__(self,
                 req_token_uri,
                 auth_uri,
                 consumer_key="",
                 consumer_secret=""):
        super(V1RequestToken, self).__init__()
        self.req_token_uri = req_token_uri
        self.auth_uri = auth_uri
        self.parms = dict(client_key=consumer_key, client_secret=consumer_key)
        self.update_access()

    def client(self, request):
        self.parms['callback_uri'] = str(
            grok.url(request, self, name='@@access_token'))
        return oauth1.Client(**self.parms)

    def update_access(self, **kw):
        self.access = V1AccessToken(**kw)
        location.locate(self.access, self, 'access')

    def process(self, res):
        ''' Expect oauth_token, oauth_token_secret, oauth_callback_confirmed '''
        self.info = json.loads(res)
        kw = self.parms.copy()
        kw.update(self.info)
        self.update_access(**kw)
Example #5
0
class Uvcsite(grok.Application, grok.Container):
    grok.traversable('plugins')

    grok.local_utility(zope.pluggableauth.PluggableAuthentication,
                       zope.authentication.interfaces.IAuthentication,
                       public=True,
                       setup=setup_pau)

    @property
    def plugins(self):
        return uvcsite.plugins.panel.PluginsPanel('plugins', self)
class Appview(grok.View):
    grok.context(MyApp)
    grok.traversable('traversable_method')
    grok.traversable('with_querystring')
    grok.traversable('json_response')

    def render(self):
        return "HELLO"

    def untraversable_method(self):
        return "I'm not traversable!"

    def traversable_method(self):
        return "I'm traversable!"

    def with_querystring(self, name):
        return "Hello " + name

    def json_response(self):
        self.request.response.setHeader('Content-Type', 'application/json')
        data = {'name': 'json'}
        return simplejson.dumps(data)
Example #7
0
class User(grok.Model):
    grok.implements(IUser)
    id = FieldProperty(IUser['id'])
    title = FieldProperty(IUser['title'])
    description = FieldProperty(IUser['description'])
    userno = FieldProperty(IUser['userno'])
    domain = FieldProperty(IUser['domain'])
    login = FieldProperty(IUser['login'])
    secret = FieldProperty(IUser['secret'])
    gw2_apikey = FieldProperty(IUser['gw2_apikey'])
    disco_id = FieldProperty(IUser['disco_id'])

    profile = None
    grok.traversable('profile')

    def __init__(self, userno, id=None):
        self.userno = int(userno)
        self.id = id
Example #8
0
class Club(grok.Model):
    grok.traversable('asdf', name='attr')
    grok.traversable('attr')
    grok.traversable('attr', name='asdf')
    grok.traversable('demo')
    demo = 'something'
Example #9
0
class UserProfile(grok.Model):
    grok.implements(IUserProfile, ILayout)

    # Derived stats    
    health = 0            # 1 Vitality = 10 health)
    armor = 0             # Toughness + Defense
    crit_chance = 0       # (Crit Chance = 5% + Precision / 21
    crit_dmg = 0          # (Crit Dmg = 150% + by Ferocity/15
    boon_duration = 0     # Increased by Concentration (15 = 1%)
    cond_duration = 0     # Increased by Expertise (15 = 1%)
    
    base_health = {'Warrior':9212, 'Necromancer':9212,
                   'Revenant':5922, 'Engineer':5922, 'Ranger':5922, 'Mesmer':5922,
                   'Guardian':1645, 'Thief':1645, 'Elementalist':1645 }
    
    stats = PersistentDict()
    runes = PersistentDict()
    buffs = PersistentList()
    
    selected_weapon = 0
    selected_traits = []
    characters = []
    selected = ''
    refresh = False
    skill_choices = None
    skill_choice = None
    gear = []
    trinkets = []
    amulet = []
    backpack = []
    aquatic = []
    game_modes = ["pve", "pvp", "wvw"]
    gmode = "wvw"
    spec_bg = grok.Container()
    grok.traversable('spec_bg')
    
    def __init__(self, user):
        location.locate(self.spec_bg, self, 'spec_bg')
        self.user = user
        
    def update(self):
        location.locate(self.spec_bg, self, 'spec_bg')
        account = GW2API().account(self.user.gw2_apikey)
        if account is not None:
            self.account = account
        characters = GW2API().characters(self.user.gw2_apikey)
        if characters is not None:
            self.characters = characters
#        self.refresh=True
        if len(self.selected)==0: 
            self.selected = self.characters[0]
            self.refresh = True
        if self.refresh:
            core = GW2API().character_core(self.user.gw2_apikey, self.selected)
            if core is not None: 
                self.core = core
#            self.equipment = GW2API().character_equipment(self.user.gw2_apikey, self.selected)
#            self.skills = GW2API().character_skills(self.user.gw2_apikey, self.selected)
#            self.specializations = GW2API().character_specializations(self.user.gw2_apikey, self.selected)
            self.refresh = False
            
        self.stats = PersistentDict({'Power': 1000, 'Precision': 1000, 'Toughness': 1000, 'Vitality':1000,
                                     'Defense':0, 'ConditionDamage': 0, 'CritDamage':0,
                                     'Concentration':0, 'Expertise':0, 'Ferocity':0, 'Healing':0,
                                     'BoonDuration':0, 'ConditionDuration':0
                                     })
        self.runes = PersistentDict()
        self.buffs = PersistentList()
        
        self.gear = self._gear()
        self.trinkets = self._trinkets()
        self.amulet = self._amulet()
        self.backpack = self._backpack()
        self.weapons = self._weapons()
        self.aquatic = self._aquatic()
        self.profession = GW2API().get_profession(self.core['profession'])
                
        self.skill_choices = None
        if self.profession['name'] == 'Elementalist':
            self.skill_choices = 'attunement'
            if self.skill_choice is None: self.skill_choice = 'Fire'
        
        self.prof_skills = self._profession_skills()
        self.weap_skills = self._weapon_skills()

        self.rune_bonuses = []
        for r in self.runes.values():
            b = r['rune']['bonuses'][:r['count']]
            for effect in b:
                self.rune_bonuses.append(effect)
                if effect.find(' to All Stats')>0:
                    perc = int(effect.split(' ')[0])
                    for stat in ['Power', 'Precision', 'Toughness', 'Vitality', 'Ferocity', 'Healing', 'ConditionDamage']:
                        self.stats[stat] += perc
                elif effect.find('% Boon Duration') > 0:
                    perc = int(effect.split('%')[0])
                    self.stats['BoonDuration'] += perc * 15
                elif self._stat_effect(effect):
                    pass
                else:
                    self.buffs.append(effect)

        self.health = self.stats['Vitality'] * 10 + self.base_health[self.core['profession']]
        self.armor = self.stats['Toughness'] + self.stats['Defense']
        self.crit_chance = (self.stats['Precision']-916) / 21.0
        self.crit_dmg = 150 + (self.stats['CritDamage'] + self.stats['Ferocity']) / 15.0
        self.boon_duration = (self.stats['BoonDuration'] + self.stats['Concentration']) / 15.0
        self.cond_duration = (self.stats['ConditionDuration'] + self.stats['Expertise']) / 15.0
        
#         for i in list(self.spec_bg.keys()):
#             del self.spec_bg[i]

        self.selected_traits = []
        for spec in self.specs():
            for t in spec['traits']:
                if 'description' in t:
                    self.buffs.append("%s - %s"%(t['name'], t['description']))
                else:
                    self.buffs.append(t['name'])            
            img = SpecImage(spec['id']['background'])
            if img.fn not in self.spec_bg.keys():
                img.retrieve()
                self.spec_bg[img.fn] = img
            spec['id']['img_no'] = img.fn
            self.selected_traits.extend([t['name'] for t in spec['traits']])
            
        
        pass

    def gear_title(self, gear):
        try:
            if 'stats' in gear:
                stats = [ "%s: +%s" % (n, s) for n, s in gear['stats']['attributes'].items()]
                return "\n".join(stats)
            else:
                attributes = gear['id']['details']['infix_upgrade']['attributes']
                return "\n".join(['%s: +%s' % (a['attribute'], a['modifier']) for a in attributes])
        except Exception, e:
            print "Cannot determine gear title for %s" % gear
            print "%s" % str(e)
        return ''