text:
Provided types map file "/a/lib/typesMap.json" doesn't exist
request:{"seq":0,"type":"request","command":"open","arguments":{"file":"/user/username/projects/solution/api/src/server.ts"}}
Search path: /user/username/projects/solution/api/src
For info: /user/username/projects/solution/api/src/server.ts :: Config file name: /user/username/projects/solution/api/tsconfig.json
Creating configuration project /user/username/projects/solution/api/tsconfig.json
FileWatcher:: Added:: WatchInfo: /user/username/projects/solution/api/tsconfig.json 2000 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Config file
Config: /user/username/projects/solution/api/tsconfig.json : {
 "rootNames": [
  "/user/username/projects/solution/api/src/server.ts"
 ],
 "options": {
  "composite": true,
  "outDir": "/user/username/projects/solution/api/dist",
  "rootDir": "/user/username/projects/solution/api/src",
  "configFilePath": "/user/username/projects/solution/api/tsconfig.json"
 },
 "projectReferences": [
  {
   "path": "/user/username/projects/solution/shared",
   "originalPath": "../shared"
  }
 ]
}
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/api/src 1 undefined Config: /user/username/projects/solution/api/tsconfig.json WatchType: Wild card directory
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/api/src 1 undefined Config: /user/username/projects/solution/api/tsconfig.json WatchType: Wild card directory
Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded
Starting updateGraphWorker: Project: /user/username/projects/solution/api/tsconfig.json
Config: /user/username/projects/solution/shared/tsconfig.json : {
 "rootNames": [
  "/user/username/projects/solution/shared/src/index.ts"
 ],
 "options": {
  "composite": true,
  "outDir": "/user/username/projects/solution/shared/dist",
  "rootDir": "/user/username/projects/solution/shared/src",
  "configFilePath": "/user/username/projects/solution/shared/tsconfig.json"
 }
}
FileWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared/tsconfig.json 2000 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Config file
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared/src 1 undefined Config: /user/username/projects/solution/shared/tsconfig.json WatchType: Wild card directory
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared/src 1 undefined Config: /user/username/projects/solution/shared/tsconfig.json WatchType: Wild card directory
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared 1 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Failed Lookup Locations
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared 1 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Failed Lookup Locations
FileWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared/src/index.ts 500 undefined WatchType: Closed Script info
FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/api/node_modules/@types 1 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/api/node_modules/@types 1 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Type roots
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/api/tsconfig.json WatchType: Type roots
Finishing updateGraphWorker: Project: /user/username/projects/solution/api/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
Project '/user/username/projects/solution/api/tsconfig.json' (Configured)
	Files (3)
	/a/lib/lib.d.ts
	/user/username/projects/solution/shared/src/index.ts
	/user/username/projects/solution/api/src/server.ts

	../../../../../a/lib/lib.d.ts
	  Default library for target 'es3'
	../shared/src/index.ts
	  Imported via "../../shared/dist" from file 'src/server.ts'
	src/server.ts
	  Matched by include pattern 'src' in 'tsconfig.json'

-----------------------------------------------
Search path: /user/username/projects/solution/api
For info: /user/username/projects/solution/api/tsconfig.json :: Config file name: /user/username/projects/solution/tsconfig.json
Creating configuration project /user/username/projects/solution/tsconfig.json
FileWatcher:: Added:: WatchInfo: /user/username/projects/solution/tsconfig.json 2000 undefined Project: /user/username/projects/solution/tsconfig.json WatchType: Config file
Search path: /user/username/projects/solution
For info: /user/username/projects/solution/tsconfig.json :: No config files found.
Project '/user/username/projects/solution/api/tsconfig.json' (Configured)
	Files (3)

-----------------------------------------------
Project '/user/username/projects/solution/tsconfig.json' (Configured)
	Files (0) InitialLoadPending

-----------------------------------------------
Open files:
	FileName: /user/username/projects/solution/api/src/server.ts ProjectRootPath: undefined
		Projects: /user/username/projects/solution/api/tsconfig.json
response:{"responseRequired":false}
request:{"command":"references","arguments":{"file":"/user/username/projects/solution/api/src/server.ts","line":3,"offset":10},"seq":1,"type":"request"}
Search path: /user/username/projects/solution/shared/src
For info: /user/username/projects/solution/shared/src/index.ts :: Config file name: /user/username/projects/solution/shared/tsconfig.json
Creating configuration project /user/username/projects/solution/shared/tsconfig.json
Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded
Starting updateGraphWorker: Project: /user/username/projects/solution/shared/tsconfig.json
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared/node_modules/@types 1 undefined Project: /user/username/projects/solution/shared/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared/node_modules/@types 1 undefined Project: /user/username/projects/solution/shared/tsconfig.json WatchType: Type roots
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/shared/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/shared/tsconfig.json WatchType: Type roots
Finishing updateGraphWorker: Project: /user/username/projects/solution/shared/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
Project '/user/username/projects/solution/shared/tsconfig.json' (Configured)
	Files (2)
	/a/lib/lib.d.ts
	/user/username/projects/solution/shared/src/index.ts

	../../../../../a/lib/lib.d.ts
	  Default library for target 'es3'
	src/index.ts
	  Matched by include pattern 'src' in 'tsconfig.json'

-----------------------------------------------
Search path: /user/username/projects/solution/shared/src
For info: /user/username/projects/solution/shared/src/index.ts :: Config file name: /user/username/projects/solution/shared/tsconfig.json
Loading configured project /user/username/projects/solution/tsconfig.json
Config: /user/username/projects/solution/tsconfig.json : {
 "rootNames": [],
 "options": {
  "configFilePath": "/user/username/projects/solution/tsconfig.json"
 },
 "projectReferences": [
  {
   "path": "/user/username/projects/solution/api",
   "originalPath": "./api"
  },
  {
   "path": "/user/username/projects/solution/app",
   "originalPath": "./app"
  }
 ]
}
Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded
Starting updateGraphWorker: Project: /user/username/projects/solution/tsconfig.json
Config: /user/username/projects/solution/app/tsconfig.json : {
 "rootNames": [
  "/user/username/projects/solution/app/src/app.ts"
 ],
 "options": {
  "composite": true,
  "outDir": "/user/username/projects/solution/app/dist",
  "rootDir": "/user/username/projects/solution/app/src",
  "configFilePath": "/user/username/projects/solution/app/tsconfig.json"
 },
 "projectReferences": [
  {
   "path": "/user/username/projects/solution/shared",
   "originalPath": "../shared"
  }
 ]
}
FileWatcher:: Added:: WatchInfo: /user/username/projects/solution/app/tsconfig.json 2000 undefined Project: /user/username/projects/solution/tsconfig.json WatchType: Config file
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/app/src 1 undefined Config: /user/username/projects/solution/app/tsconfig.json WatchType: Wild card directory
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/app/src 1 undefined Config: /user/username/projects/solution/app/tsconfig.json WatchType: Wild card directory
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/tsconfig.json WatchType: Type roots
Finishing updateGraphWorker: Project: /user/username/projects/solution/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
Different program with same set of files
Creating configuration project /user/username/projects/solution/app/tsconfig.json
Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded
FileWatcher:: Added:: WatchInfo: /user/username/projects/solution/app/src/app.ts 500 undefined WatchType: Closed Script info
Starting updateGraphWorker: Project: /user/username/projects/solution/app/tsconfig.json
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared 1 undefined Project: /user/username/projects/solution/app/tsconfig.json WatchType: Failed Lookup Locations
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/shared 1 undefined Project: /user/username/projects/solution/app/tsconfig.json WatchType: Failed Lookup Locations
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/app/node_modules/@types 1 undefined Project: /user/username/projects/solution/app/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/app/node_modules/@types 1 undefined Project: /user/username/projects/solution/app/tsconfig.json WatchType: Type roots
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/app/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/solution/node_modules/@types 1 undefined Project: /user/username/projects/solution/app/tsconfig.json WatchType: Type roots
Finishing updateGraphWorker: Project: /user/username/projects/solution/app/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
Project '/user/username/projects/solution/app/tsconfig.json' (Configured)
	Files (3)
	/a/lib/lib.d.ts
	/user/username/projects/solution/shared/src/index.ts
	/user/username/projects/solution/app/src/app.ts

	../../../../../a/lib/lib.d.ts
	  Default library for target 'es3'
	../shared/src/index.ts
	  Imported via "../../shared/dist" from file 'src/app.ts'
	src/app.ts
	  Matched by include pattern 'src' in 'tsconfig.json'

-----------------------------------------------
Search path: /user/username/projects/solution/shared/src
For info: /user/username/projects/solution/shared/src/index.ts :: Config file name: /user/username/projects/solution/shared/tsconfig.json
response:{"response":{"refs":[{"file":"/user/username/projects/solution/shared/src/index.ts","start":{"line":1,"offset":28},"end":{"line":1,"offset":31},"contextStart":{"line":1,"offset":28},"contextEnd":{"line":1,"offset":36},"lineText":"export const foo = class { fly() {} };","isWriteAccess":true,"isDefinition":true},{"file":"/user/username/projects/solution/api/src/server.ts","start":{"line":3,"offset":10},"end":{"line":3,"offset":13},"lineText":"instance.fly();","isWriteAccess":false,"isDefinition":false},{"file":"/user/username/projects/solution/app/src/app.ts","start":{"line":3,"offset":10},"end":{"line":3,"offset":13},"lineText":"instance.fly();","isWriteAccess":false,"isDefinition":false}],"symbolName":"fly","symbolStartOffset":10,"symbolDisplayString":"(method) foo.fly(): void"},"responseRequired":true}


text:
/* Tests for DOM 2 Core 'DOMImplementation' object.
*/

var cvs = "$Id: htmltablesectionelement.js 108182 2012-01-13 12:09:02Z sigbjornf $";

testmodule( "HTMLTableSectionElement", cvs );

try {
  var tab1  = document.getElementById("myTableSection");
  var tab2  = document.getElementById("myTableSection2");
  var tab3  = document.getElementById("myTableSection3");
  var row   = document.getElementById("myRow");

  testcase( "object" );

  test("class thead",tab1,"[object HTMLTableSectionElement]");
  test("class tbody",tab2,"[object HTMLTableSectionElement]");
  test("class tfoot",tab3,"[object HTMLTableSectionElement]");

  testcase( "attribute object class" );

  test("rows",tab1.rows,"[object HTMLCollection]");

  testcase( "properties exists" );
  var tab = tab1;
 /*
  tdef("align",tab.align);
  tdef("vAlign",tab.vAlign);
  tdef("rows",tab.rows);
*/

  testcase( "read default property values" );
  tab = tab1;

  test("align",tab.align,"left");
  test("vAlign",tab.vAlign,"middle");
  if(tab.rows != undefined)
  {
    test("rows",tab.rows.length,0);
  }

  testcase( "properties exists, attributes in use" );
  var tab = tab2;

  tdef("align",tab.align);
  tdef("vAlign",tab.vAlign);
  tdef("rows",tab.rows);

  testcase( "read property values from attributes" );
  tab = tab2;

  test("align",tab.align,"right");
  test("vAlign",tab.vAlign,"top");
  if(tab.rows != undefined)
  {
    test("rows",tab.rows.length,1);
    test("rows",tab.rows[0],row);
  }
  testcase( "properties are writeable" );
  tab = tab2;

  tab.align="center";
  test("align",tab.align,"center");
  tab.vAlign="top";
  test("align",tab.vAlign,"top");

  testcase( "properties are not writeable" );

  var rows = tab.rows;
  expect_readonly_exception( "rows", function(){"use strict"; tab.rows = null;} )
  test("rows",tab.rows,rows);

  testcase( "methods exist" );

  tdef("insertRow",tab.insertRow);
  tdef("deleteRow",tab.deleteRow);

  testcase( "insertRow" );

  if(tab2.insertRow != undefined)
  {
    trows = tab1.rows.length;
	cnew = tab1.insertRow(0);
    test("insertRow",cnew,tab1.rows[0]);
    test("insertRow",tab1.rows.length,trows+1);
    trows = tab2.rows.length;
    var cnew = tab2.insertRow(1);
    test("insertRow 2",cnew,tab2.rows[1]);
    test("insertRow 2",tab2.rows.length,trows+1);
    trows = tab2.rows.length;
    expect_DOM_exception("insertRow 3", DOMException.INDEX_SIZE_ERR, function(){tab2.insertRow(-2)} )
    expect_DOM_exception("insertRow 4", DOMException.INDEX_SIZE_ERR, function(){tab2.insertRow(trows+1)} )
    tab2.insertRow(-1);
    test("insertRow 5",tab2.rows.length,trows+1);
  }

  testcase( "deleteRow" );

  if(tab2.deleteRow != undefined)
  {
    var old1 = tab2.rows[1];
    trows = tab2.rows.length;
    tab2.deleteRow(0);
    test("deleteRow",tab2.rows.length,trows-1);
    test("deleteRow",tab2.rows[0],old1);
    trows = tab2.rows.length;
    expect_DOM_exception("deleteRow", DOMException.INDEX_SIZE_ERR, function(){tab2.deleteRow(-2)} )
    expect_DOM_exception("deleteRow", DOMException.INDEX_SIZE_ERR, function(){tab2.deleteRow(trows)} )
    tab2.deleteRow(-1);
    test("deleteRow",tab2.rows.length,trows-1);
  }

} catch (e) { exception(e); }

testmodule_finished();

/* eof */

redpajama_set_name: RedPajamaGithub


text:
package tools

import (
	// Import goversioninfo tool
	_ "github.com/josephspurrier/goversioninfo/cmd/goversioninfo"
	// Import go-bindata tool
	_ "github.com/kevinburke/go-bindata/go-bindata"
	// Import mage tool
	_ "github.com/magefile/mage"
)


text:
import datetime
import re

from django.conf import settings
from django.contrib.sites.models import Site
from django.core import mail
from django.core import management
from django.test import TestCase
from django.utils.hashcompat import sha_constructor

from mailinglist_registration.models import RegistrationProfile
from mailinglist_registration.models import Subscriber

class RegistrationModelTests(TestCase):
    """
    Test the model and manager used in the default backend.

    """
    subscriber_info = {'email': 'alice@example.com'}

    def setUp(self):
        self.old_activation = getattr(settings, 'MAILINGLIST_ACTIVATION_DAYS', None)
        settings.MAILINGLIST_ACTIVATION_DAYS = 7

    def tearDown(self):
        settings.MAILINGLIST_ACTIVATION_DAYS = self.old_activation

    def test_profile_creation(self):
        """
        Creating a registration profile for a subscriber populates the
        profile with the correct subscriber and a SHA1 hash to use as
        activation key.

        """
        new_subscriber = Subscriber.objects.create_subscriber(**self.subscriber_info)
        profile = RegistrationProfile.objects.create_profile(new_subscriber)

        self.assertEqual(RegistrationProfile.objects.count(), 1)
        self.assertEqual(profile.subscriber.id, new_subscriber.id)
        self.failUnless(re.match('^[a-f0-9]{40}$', profile.activation_key))
        self.assertEqual(unicode(profile),
                         "Registration information for alice@example.com")

    def test_activation_email(self):
        """
        ``RegistrationProfile.send_activation_email`` sends an
        email.

        """
        new_subscriber = Subscriber.objects.create_subscriber(**self.subscriber_info)
        profile = RegistrationProfile.objects.create_profile(new_subscriber)
        profile.send_activation_email(Site.objects.get_current())
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, [self.subscriber_info['email']])

    def test_subscriber_creation(self):
        """
        Creating a new subscriber populates the correct data, and sets the
        subscriber's account inactive.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        self.assertEqual(new_subscriber.email, 'alice@example.com')
        self.failIf(new_subscriber.is_active)

    def test_subscriber_creation_email(self):
        """
        By default, creating a new subscriber sends an activation email.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        self.assertEqual(len(mail.outbox), 1)

    def test_subscriber_creation_no_email(self):
        """
        Passing ``send_email=False`` when creating a new subscriber will not
        send an activation email.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    send_email=False,
                                                                    **self.subscriber_info)
        self.assertEqual(len(mail.outbox), 0)

    def test_unexpired_account(self):
        """
        ``RegistrationProfile.activation_key_expired()`` is ``False``
        within the activation window.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        self.failIf(profile.activation_key_expired())

    def test_expired_account(self):
        """
        ``RegistrationProfile.activation_key_expired()`` is ``True``
        outside the activation window.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        new_subscriber.date_joined -= datetime.timedelta(days=settings.MAILINGLIST_ACTIVATION_DAYS + 1)
        new_subscriber.save()
        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        self.failUnless(profile.activation_key_expired())

    def test_valid_activation(self):
        """
        Activating a subscriber within the permitted window makes the
        account active, and resets the activation key.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        activated = RegistrationProfile.objects.activate_subscriber(profile.activation_key)

        self.failUnless(isinstance(activated, Subscriber))
        self.assertEqual(activated.id, new_subscriber.id)
        self.failUnless(activated.is_active)

        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        self.assertEqual(profile.activation_key, RegistrationProfile.ACTIVATED)

    def test_expired_activation(self):
        """
        Attempting to activate outside the permitted window does not
        activate the account.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        new_subscriber.date_joined -= datetime.timedelta(days=settings.MAILINGLIST_ACTIVATION_DAYS + 1)
        new_subscriber.save()

        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        activated = RegistrationProfile.objects.activate_subscriber(profile.activation_key)

        self.failIf(isinstance(activated, Subscriber))
        self.failIf(activated)

        new_subscriber = Subscriber.objects.get(email='alice@example.com')
        self.failIf(new_subscriber.is_active)

        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        self.assertNotEqual(profile.activation_key, RegistrationProfile.ACTIVATED)

    def test_activation_invalid_key(self):
        """
        Attempting to activate with a key which is not a SHA1 hash
        fails.

        """
        self.failIf(RegistrationProfile.objects.activate_subscriber('foo'))

    def test_activation_already_activated(self):
        """
        Attempting to re-activate an already-activated account fails.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        RegistrationProfile.objects.activate_subscriber(profile.activation_key)

        profile = RegistrationProfile.objects.get(subscriber=new_subscriber)
        self.failIf(RegistrationProfile.objects.activate_subscriber(profile.activation_key))

    def test_activation_nonexistent_key(self):
        """
        Attempting to activate with a non-existent key (i.e., one not
        associated with any account) fails.

        """
        # Due to the way activation keys are constructed during
        # registration, this will never be a valid key.
        invalid_key = sha_constructor('foo').hexdigest()
        self.failIf(RegistrationProfile.objects.activate_subscriber(invalid_key))

    def test_expired_subscriber_deletion(self):
        """
        ``RegistrationProfile.objects.delete_expired_subscribers()`` only
        deletes inactive subscribers whose activation window has expired.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        expired_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                        email='bob@example.com')
        expired_subscriber.date_joined -= datetime.timedelta(days=settings.MAILINGLIST_ACTIVATION_DAYS + 1)
        expired_subscriber.save()

        RegistrationProfile.objects.delete_expired_subscribers()
        self.assertEqual(RegistrationProfile.objects.count(), 1)
        self.assertRaises(Subscriber.DoesNotExist, Subscriber.objects.get, email='bob@example.com')

    def test_management_command(self):
        """
        The ``cleanupregistration`` management command properly
        deletes expired accounts.

        """
        new_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                    **self.subscriber_info)
        expired_subscriber = RegistrationProfile.objects.create_inactive_subscriber(site=Site.objects.get_current(),
                                                                        email='bob@example.com')
        expired_subscriber.date_joined -= datetime.timedelta(days=settings.MAILINGLIST_ACTIVATION_DAYS + 1)
        expired_subscriber.save()

        management.call_command('cleanupregistration')
        self.assertEqual(RegistrationProfile.objects.count(), 1)
        self.assertRaises(Subscriber.DoesNotExist, Subscriber.objects.get, email='bob@example.com')


text:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.0.0.

## Code scaffolding

Run `ng generate component component-name --project angular-highcharts` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project angular-highcharts`.
> Note: Don't forget to add `--project angular-highcharts` or else it will be added to the default project in your `angular.json` file.

## Build

Run `ng build angular-highcharts` to build the project. The build artifacts will be stored in the `dist/` directory.

## Publishing

After building your library with `ng build angular-highcharts`, go to the dist folder `cd dist/angular-highcharts` and run `npm publish`.

## Running unit tests

Run `ng test angular-highcharts` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.


text:
layout: post
title: Scheduling Execution of Functions Using Timers
---

In browser js, you use setTimeout and setInterval to defer execution of a function for a specified amount of time

building dynamic applications instead of static web pages

setTimeout scheduled a function to be executed once in the future

cancel execution invoke clearTimeout(func)

setInterval schedules a function to run every given period of time

cancel execution invoke clearInterval(func)

In node, the event loop runs in a loop that process the event queue, and each time the loop is executed its called a tick

callbacks can be scheduled to run on the next tick via process.nextTick  which is native to Node

process object is a global node object

node runtimes are single-threaded event loops

blocking the event loop

example of using process.nextTick:

{% highlight javascript %}

stream.on("data", function(data) { stream.end("my response"); process.nextTick(function() {
fs.unlink("/path/to/file"); });
});

{% endhighlight %}

Use setTimeout instead of SetInterval to force 'serialization'

you can't guarantee that functions wont execute at the same time with set-interval.


text:
package com.goodformentertainment.canary.zown.dao;

import com.goodformentertainment.canary.zown.ZownPlugin;
import com.goodformentertainment.canary.zown.api.IConfigurable;
import com.goodformentertainment.canary.zown.api.IConfiguration;
import com.goodformentertainment.canary.zown.api.ITemplate;
import com.goodformentertainment.canary.zown.api.ITemplateManager;
import com.goodformentertainment.canary.zown.api.IZown;
import com.goodformentertainment.canary.zown.api.Point;
import com.goodformentertainment.canary.zown.api.impl.Configuration;
import com.goodformentertainment.canary.zown.api.impl.MinecraftMapper;
import com.goodformentertainment.canary.zown.api.impl.Template;
import com.goodformentertainment.canary.zown.api.impl.TemplateManager;
import com.goodformentertainment.canary.zown.api.impl.Tree;
import com.goodformentertainment.canary.zown.api.impl.Zown;
import com.goodformentertainment.canary.zown.api.impl.ZownManager;
import net.canarymod.api.entity.Entity;
import net.canarymod.api.world.World;
import net.canarymod.api.world.blocks.BlockType;
import net.canarymod.database.DataAccess;
import net.canarymod.database.Database;
import net.canarymod.database.exceptions.DatabaseReadException;
import net.canarymod.database.exceptions.DatabaseWriteException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataManager {
    private final Database database;

    public DataManager() {
        this(Database.get());
    }

    protected DataManager(final Database database) {
        this.database = database;
    }

    public void loadTemplates(final TemplateManager templateManager) throws DatabaseReadException {
        TemplateDao templateDao = new TemplateDao();
        final List<DataAccess> datasets = new ArrayList<DataAccess>();
        final Map<String, Object> filters = new HashMap<String, Object>();
        database.loadAll(templateDao, datasets, filters);

        for (final DataAccess dataset : datasets) {
            templateDao = (TemplateDao) dataset;

            final Template template = templateManager.addTemplate(templateDao.templateName);
            if (template == null) {
                // Attempted to create duplicate template
                ZownPlugin.LOG.warn("Tried to load a duplicate template: " + templateDao.templateName);
            } else {
                loadConfiguration(template, templateDao);
                ZownPlugin.LOG.debug("Loaded template " + templateDao.templateName);
            }
        }
    }

    public void loadZowns(final World world, final ITemplateManager templateManager,
                          final ZownManager zownManager) throws DatabaseReadException, DatabaseWriteException {
        final String worldName = world.getFqName();

        final ZownDao worldZown = new ZownDao();
        worldZown.worldName = worldName;
        worldZown.zownName = worldName;
        if (worldZown.read()) {
            loadZowns(world, templateManager, zownManager, worldZown);
        } else {
            zownManager.getZown(world);
            ZownPlugin.LOG.info("Created world zown for " + worldName);
        }
    }

    private void loadZowns(final World world, final ITemplateManager templateManager,
                           final ZownManager zownManager, final ZownDao zownDao) throws DatabaseReadException {
        if (zownDao != null && zownDao.hasData()) {
            // Load the referenced template
            ITemplate template = null;
            if (zownDao.templateName != null && !zownDao.templateName.equals("null")) {
                template = templateManager.getTemplate(zownDao.templateName);
                if (template == null) {
                    ZownPlugin.LOG.warn("The specified template " + zownDao.templateName + " doesn't exist");
                }
            }

            // Parse bounds
            Point p1 = null;
            if (zownDao.minPointString != null) {
                p1 = Point.parse(zownDao.minPointString);
            }
            Point p2 = null;
            if (zownDao.maxPointString != null) {
                p2 = Point.parse(zownDao.maxPointString);
            }

            // Add the zown to the manager
            final Tree<Zown> zownTree = zownManager.addZown(world, zownDao.parentZownName,
                    zownDao.zownName, template, p1, p2);
            if (zownTree == null) {
                // Attempted to create duplicate zown
                ZownPlugin.LOG.warn("Tried to load a bad zown: " + zownDao.zownName);
            } else {
                final Zown zown = zownTree.getData();

                if (template != null) {
                    if (zownDao.templateOverride != null && zownDao.templateOverride) {
                        zown.setTemplate((Template) template, true);
                        loadConfiguration(zown, zownDao);
                    } else {
                        zown.setTemplate((Template) template, false);
                    }
                } else {
                    loadConfiguration(zown, zownDao);
                }

                if (zownDao.ownerList != null) {
                    zown.getOwnerUUIDs().addAll(zownDao.ownerList);
                }
                if (zownDao.memberList != null) {
                    zown.getMemberUUIDs().addAll(zownDao.memberList);
                }
                if (zownDao.entryExclusions != null) {
                    zown.getEntryExclusionUUIDs().addAll(zownDao.entryExclusions);
                }

                zown.setWelcomeMessage(zownDao.welcomeMessage);
                zown.setFarewellMessage(zownDao.farewellMessage);

                ZownPlugin.LOG.debug("Loaded zown " + zownDao.zownName);

                // Load child zowns recursively
                final ZownDao childZownDao = new ZownDao();
                final List<DataAccess> datasets = new ArrayList<DataAccess>();
                final Map<String, Object> filters = new HashMap<String, Object>();
                filters.put(ZownDao.WORLD_NAME, zownDao.worldName);
                filters.put(ZownDao.PARENT_ZOWN_NAME, zownDao.zownName);
                database.loadAll(childZownDao, datasets, filters);
                for (final DataAccess da : datasets) {
                    loadZowns(world, templateManager, zownManager, (ZownDao) da);
                }
            }
        }
    }

    public boolean saveTemplate(final Template template) throws DatabaseReadException,
            DatabaseWriteException {
        boolean saved = false;
        if (template != null) {
            saved = saveTemplate(template, template.getName());
        }
        return saved;
    }

    public boolean saveZown(final World world, final Tree<Zown> zown) throws DatabaseReadException,
            DatabaseWriteException {
        boolean saved = false;
        if (zown != null) {
            saved = saveZown(world, zown, zown.getData().getName());
        }
        return saved;
    }

    public boolean saveTemplate(final Template template, final String originalName)
            throws DatabaseReadException, DatabaseWriteException {
        boolean saved = false;
        if (template != null) {
            final TemplateDao templateDao = new TemplateDao();
            templateDao.templateName = originalName;

            // Populate the templateDao id if it exists in the database
            templateDao.read();

            // Set the templateDao data
            templateDao.templateName = template.getName();
            saveConfiguration(template, templateDao);

            saved = templateDao.save();
        }
        return saved;
    }

    public boolean saveZown(final World world, final Tree<Zown> zownTree, final String originalName)
            throws DatabaseReadException, DatabaseWriteException {
        boolean saved = false;
        if (zownTree != null) {
            final ZownDao zownDao = new ZownDao();
            zownDao.worldName = world.getFqName();
            zownDao.zownName = originalName;

            // Populate the zownDao id if it exists in the database
            zownDao.read();

            // Set the zownDao data
            if (!zownTree.isRoot()) {
                zownDao.parentZownName = zownTree.getParent().getData().getName();
            }
            final Zown zown = zownTree.getData();
            zownDao.zownName = zown.getName();
            if (zown.getTemplate() != null) {
                zownDao.templateName = zown.getTemplate().getName();
            }
            zownDao.ownerList = new ArrayList<String>(zown.getOwnerUUIDs());
            zownDao.memberList = new ArrayList<String>(zown.getMemberUUIDs());
            zownDao.entryExclusions = new ArrayList<String>(zown.getEntryExclusionUUIDs());
            if (zown.getMinPoint() != null) {
                zownDao.minPointString = zown.getMinPoint().toString();
            }
            if (zown.getMaxPoint() != null) {
                zownDao.maxPointString = zown.getMaxPoint().toString();
            }

            if (zown.overridesConfiguration()) {
                saveConfiguration(zown, zownDao);
                zownDao.templateOverride = true;
            } else {
                clearConfiguration(zown, zownDao);
                zownDao.templateOverride = false;
            }

            zownDao.welcomeMessage = zown.getWelcomeMessage();
            zownDao.farewellMessage = zown.getFarewellMessage();

            saved = zownDao.save();
        }
        return saved;
    }

    public boolean removeTemplate(final Template template) throws DatabaseReadException,
            DatabaseWriteException {
        final boolean removed = false;
        if (template != null) {
            final TemplateDao templateDao = new TemplateDao();
            templateDao.templateName = template.getName();

            // Populate the templateDao id if it exists in the database
            templateDao.read();

            templateDao.delete();
        }
        return removed;
    }

    public boolean removeZown(final World world, final Tree<? extends IZown> zown)
            throws DatabaseReadException, DatabaseWriteException {
        final boolean removed = false;
        if (zown != null) {
            final ZownDao zownDao = new ZownDao();
            zownDao.worldName = world.getFqName();
            zownDao.zownName = zown.getData().getName();

            // Populate the zownDao id if it exists in the database
            zownDao.read();

            zownDao.delete();
        }
        return removed;
    }

    private void loadConfiguration(final IConfigurable configurable, final AConfigurationDao dao) {
        final IConfiguration config = configurable.getConfiguration();

        // Set owner permissions
        if (dao.ownerPermissionList != null) {
            for (final String perm : dao.ownerPermissionList) {
                config.addOwnerPermission(perm);
            }
        }

        // Set flags
        if (dao.allowList != null) {
            for (final String allow : dao.allowList) {
                config.setFlag(allow, true);
            }
        }
        if (dao.denyList != null) {
            for (final String deny : dao.denyList) {
                config.setFlag(deny, false);
            }
        }

        // Set command restrictions
        if (dao.commandRestrictionsList != null) {
            for (final String cmd : dao.commandRestrictionsList) {
                config.addCommandRestriction(cmd);
            }
        }

        // Set block interface
        if (dao.blockBuildExceptionList != null) {
            for (final String block : dao.blockBuildExceptionList) {
                final BlockType blockType = MinecraftMapper.getBlockType(block);
                if (blockType == null) {
                    ZownPlugin.LOG.warn("Error adding " + block + " to the block build exclusions");
                } else {
                    config.addBlockBuildExclusion(blockType);
                }
            }
        }
        if (dao.blockInteractExceptionList != null) {
            for (final String block : dao.blockInteractExceptionList) {
                final BlockType blockType = MinecraftMapper.getBlockType(block);
                if (blockType == null) {
                    ZownPlugin.LOG.warn("Error adding " + block + " to the block interaction exclusions");
                } else {
                    config.addBlockInteractExclusion(blockType);
                }
            }
        }

        // Set entity interface
        if (dao.entityCreateExceptionList != null) {
            for (final String entity : dao.entityCreateExceptionList) {
                final Class<? extends Entity> entityClass = MinecraftMapper.getEntityClass(entity);
                if (entityClass == null) {
                    ZownPlugin.LOG.warn("Error adding " + entity + " to the entity create exclusions");
                } else {
                    config.addEntityCreateExclusion(entityClass);
                }
            }
        }
        if (dao.entityInteractExceptionList != null) {
            for (final String entity : dao.entityInteractExceptionList) {
                final Class<? extends Entity> entityClass = MinecraftMapper.getEntityClass(entity);
                if (entityClass == null) {
                    ZownPlugin.LOG.warn("Error adding " + entity + " to the entity interaction exclusions");
                } else {
                    config.addEntityInteractExclusion(entityClass);
                }
            }
        }
    }

    private void saveConfiguration(final IConfigurable configurable, final AConfigurationDao dao) {
        final Configuration config = (Configuration) configurable.getConfiguration();

        // Set owner permissions
        dao.ownerPermissionList = new ArrayList<String>(config.getOwnerPermissions());

        // Set flags
        final Map<String, Boolean> flags = config.getFlags();
        dao.allowList = new ArrayList<String>();
        dao.denyList = new ArrayList<String>();
        for (final String flag : flags.keySet()) {
            if (flags.get(flag)) {
                dao.allowList.add(flag);
            } else {
                dao.denyList.add(flag);
            }
        }

        // Set command restrictions
        dao.commandRestrictionsList = new ArrayList<String>(config.getCommandRestrictions());

        // Set block interface
        dao.blockBuildExceptionList = new ArrayList<String>();
        for (final BlockType blockType : config.getBlockBuildExclusions()) {
            dao.blockBuildExceptionList.add(MinecraftMapper.getBlock(blockType));
        }
        dao.blockInteractExceptionList = new ArrayList<String>();
        for (final BlockType blockType : config.getBlockInteractExclusions()) {
            dao.blockInteractExceptionList.add(MinecraftMapper.getBlock(blockType));
        }

        // Set entity interface
        dao.entityCreateExceptionList = new ArrayList<String>();
        for (final Class<? extends Entity> entityClass : config.getEntityCreateExclusions()) {
            dao.entityCreateExceptionList.add(MinecraftMapper.getEntity(entityClass));
        }
        dao.entityInteractExceptionList = new ArrayList<String>();
        for (final Class<? extends Entity> entityClass : config.getEntityInteractExclusions()) {
            dao.entityInteractExceptionList.add(MinecraftMapper.getEntity(entityClass));
        }
    }

    private void clearConfiguration(final IConfigurable configurable, final AConfigurationDao dao) {
        // Set owner permissions
        dao.ownerPermissionList = new ArrayList<String>();

        // Set flags
        dao.allowList = new ArrayList<String>();
        dao.denyList = new ArrayList<String>();

        // Set command restrictions
        dao.commandRestrictionsList = new ArrayList<String>();

        // Set block interface
        dao.blockBuildExceptionList = new ArrayList<String>();
        dao.blockInteractExceptionList = new ArrayList<String>();

        // Set entity interface
        dao.entityCreateExceptionList = new ArrayList<String>();
        dao.entityInteractExceptionList = new ArrayList<String>();
    }
}